HighLAND
TPCdEdxDataCorrection.cxx
1 #include <stdio.h>
2 #include "TPCdEdxDataCorrection.hxx"
3 #include "HighlandAnalysisUtils.hxx"
4 #include "VersioningUtils.hxx"
5 
6 //********************************************************************
8 //********************************************************************
9 
10  char filename[300];
11  if (versionUtils::prod6_corrections)
12  sprintf(filename, "%s/data/TPCdEdxCorrection_p6B.dat", getenv("HIGHLANDCORRECTIONSROOT"));
13  else
14  sprintf(filename, "%s/data/TPCdEdxCorrection_p5F.dat", getenv("HIGHLANDCORRECTIONSROOT"));
15 
16 
17  std::cout << " CT correction data " << filename << std::endl;
18  FILE *pFile = fopen(filename, "r");
19 
20  if (pFile == NULL) {
21  printf("Cannot open file.\n");
22  exit(1);
23  }
24 
25  int run;
26  int subrun;
27 
28  float c[3]; // CT_expected -CT_measured
29  float ec[3]; // error on CT_expected - CT_measured
30 
31  while (fscanf(pFile, "%d%d%f%f%f%f%f%f", &run, &subrun, &c[0], &ec[0], &c[1], &ec[1], &c[2], &ec[2]) == 8) {
32  comb = std::make_pair(run, subrun);
33  corrTPC1[comb] = c[0];
34  corrTPC2[comb] = c[1];
35  corrTPC3[comb] = c[2];
36  }
37 
38  itr = corrTPC1.begin();
39  fclose(pFile);
40 }
41 
42 //********************************************************************
43 double TPCdEdxDataCorrection::GetCorrection(int run, int subrun, unsigned long det) {
44 //********************************************************************
45 
46  comb = std::make_pair(run, subrun);
47 
48  for (; itr != corrTPC1.end(); itr++) {
49  if (comb.first * 1000 + comb.second >= itr->first.first * 1000 + itr->first.second) {
50  itr++;
51 
52  if (comb.first * 1000 + comb.second < itr->first.first * 1000 + itr->first.second) {
53  itr--;
54  comb0 = std::make_pair(itr->first.first, itr->first.second);
55 
56  if (SubDetId::GetSubdetectorEnum(det) == SubDetId::kTPC1)
57  return corrTPC1[comb0];
58  else if (SubDetId::GetSubdetectorEnum(det) == SubDetId::kTPC2)
59  return corrTPC2[comb0];
60  else if (SubDetId::GetSubdetectorEnum(det) == SubDetId::kTPC3)
61  return corrTPC3[comb0];
62  } else {
63  itr--;
64  continue;
65  }
66  }
67 
68  if (itr == corrTPC1.begin())
69  break;
70  }
71 
72  std::cout << "combination not found!!!!!" << run << " " << subrun << std::endl;
73  itr = corrTPC1.begin();
74 
75  return GetCorrection(run, subrun, det);
76 }
77 
78 
79 //********************************************************************
81 //********************************************************************
82 
83  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
84 
85  // No correction for MC
86  if (spill.GetIsMC())
87  return;
88 
89  Int_t subrun = spill.EventInfo->SubRun;
90 
91  for (unsigned int i = 0; i < spill.Bunches.size(); i++) {
92  AnaBunch* bunch = static_cast<AnaBunch*>(spill.Bunches[i]);
93  AnaTrackB* allTpcTracks[100];
94  int nTPC = anaUtils::GetAllTracksUsingDet(*bunch,SubDetId::kTPC, allTpcTracks);
95  for (Int_t j = 0; j < nTPC; j++) {
96  for (int k = 0; k < allTpcTracks[j]->nTPCSegments; k++) {
97  // The raw TPC track
98  AnaTPCParticleB* original = static_cast<const AnaTrackB*>(allTpcTracks[j]->Original)->TPCSegments[k];
99 
100  // The corrected TPC track
101  AnaTPCParticle* tpcTrack = static_cast<AnaTPCParticle*>(allTpcTracks[j]->TPCSegments[k]);
102 
103  // Get the raw CT
104  double CT0 = original->dEdxMeas;
105 
106  // Apply the correction
107  if (CT0 != 999999) {
108  // Apply correction only if the CT is a valid number.
109  tpcTrack->dEdxMeas = CT0 / GetCorrection(spill.EventInfo->Run, subrun, tpcTrack->Detector);
110 
111  //recompute TPC pulls
112  Float_t pulls[4];
113  anaUtils::ComputeTPCPull(*tpcTrack, pulls);
114 
115  tpcTrack->Pullele = pulls[1];
116  tpcTrack->Pullmu = pulls[0];
117  tpcTrack->Pullp = pulls[2];
118  tpcTrack->Pullpi = pulls[3];
119 
120  //for the kaon need to recompute explicitely
121  tpcTrack->Pullk = ((tpcTrack->dEdxMeas - tpcTrack->dEdxexpKaon) / tpcTrack->dEdxSigmaKaon);
122  }
123  }
124  }
125  }
126 }
Float_t Pullmu
Muon pull of the segment: (dEdxMeas-dEdxexpMuon)/dEdxSigmaMuon.
unsigned long Detector
Float_t Pullpi
Pion pull of the segment: (dEdxMeas-dEdxexpPion)/dEdxSigmaPion.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
AnaTPCParticleB * TPCSegments[NMAXTPCS]
The TPC segments that contributed to this global track.
AnaEventInfoB * EventInfo
Run, sunrun, event, time stamp, etc.
All corrections should be registered with the CorrectionManager.
Int_t SubRun
The subrun number.
int nTPCSegments
How many TPC tracks are associated with this track.
const AnaParticleB * Original
Float_t dEdxSigmaKaon
Expected error on the dE/dx measurement, for the proton hypothesis.
bool GetIsMC() const
Return whether this spill is from Monte Carlo or not.
Float_t dEdxMeas
dE/dx as measured by the TPC.
Representation of a global track.
Float_t ComputeTPCPull(const AnaTPCParticleB &track, const std::string &particle)
Function to recompute the pull for a TPC track segment.
static SubDetId::SubDetEnum GetSubdetectorEnum(unsigned long BitField)
Get the single subdetector that this track is from.
Definition: SubDetId.cxx:165
Representation of a TPC segment of a global track.
void Apply(AnaSpillC &spill)
Float_t Pullk
Kaon pull of the segment: (dEdxMeas-dEdxexpPion)/dEdxSigmaKaon.
Float_t Pullp
Proton pull of the segment: (dEdxMeas-dEdxexpProton)/dEdxSigmaProton.
Float_t Pullele
Electron pull of the segment: (dEdxMeas-dEdxexpEle)/dEdxSigmaEle.
Representation of a TPC segment of a global track.
int GetAllTracksUsingDet(const AnaBunchB &bunch, SubDetId::SubDetEnum det, AnaTrackB *selTracks[])
Float_t dEdxexpKaon
Expected dE/dx for a proton, based on the reconstructed momentum.
Int_t Run
The ND280 run number.