HighLAND
tutorialCorrection.cxx
1 #include "tutorialCorrection.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "VersioningUtils.hxx"
4 #include "DataClasses.hxx"
5 
6 
7 /* Corrections modify some aspect of the input data (real data or MC), such that data and MC match better each other.
8  The entire analysis will proceed on the modified data.
9  The difference with variation systematics is that this modification is based in very well understood studies (or true facts)
10  which allow us the change with confidence our data. Also the correction is the same for all toy experiments while variation systematics
11  will vary from one toy to another
12 
13  This particular correction moves forward the position of all global tracks by some mm, as specified in
14  an external data file. (tutorialAnalysis/vXrY/tutorialCorrection....dat). This correction is only applied to Real Data
15 
16  For real examples of corrections have a look at highlandCorrections/vXrY/src
17 */
18 
19 
20 //********************************************************************
21 tutorialCorrection::tutorialCorrection() : CorrectionBase(){
22 //********************************************************************
23 
24  // Discriminate between production 6B and production 5F
25  char filename[300];
26  if (versionUtils::prod6_corrections)
27  sprintf(filename, "%s/data/tutorialCorrection_p6B.dat", getenv("TUTORIALANALYSISROOT"));
28  else
29  sprintf(filename, "%s/data/tutorialCorrection_p5F.dat", getenv("TUTORIALANALYSISROOT"));
30 
31  // Read the data file
32  std::cout << " tutorial correction data " << filename << std::endl;
33  FILE *pFile = fopen(filename, "r");
34 
35  if (pFile == NULL) {
36  printf("Cannot open file.\n");
37  exit(1);
38  }
39 
40  Int_t runPeriod;
41  Float_t corr;
42 
43  _nRunPeriods=0;
44 
45  while (fscanf(pFile, "%d%f", &runPeriod, &corr) == 2) {
46  _correction[runPeriod] = corr;
47  _nRunPeriods++;
48  }
49 
50  fclose(pFile);
51 }
52 
53 //********************************************************************
55 //********************************************************************
56 
57  // cast to AnaSpill type because AnaSpillC does not have event info
58  AnaSpill& spill = *static_cast<AnaSpill*>(&spillC);
59 
60  // No correction for MC
61  if (spill.GetIsMC()) return;
62 
63  // Get the run period (from 0 to 6)
64  Int_t runPeriod = anaUtils::GetRunPeriod(spill.EventInfo->Run);
65 
66  // Need a valid runPeriod
67  if (runPeriod<0 && runPeriod>=(Int_t)_nRunPeriods) return;
68 
69  // Move both the start and end position of all global tracks in all bunches
70  for (UInt_t i = 0; i < spill.Bunches.size(); i++) {
71  AnaBunchB* bunch = static_cast<AnaBunchB*>(spill.Bunches[i]);
72  for (UInt_t j = 0; j < bunch->Particles.size(); j++) {
73  AnaTrack* track = static_cast<AnaTrack*>(bunch->Particles[j]);
74  track->PositionStart[2] += _correction[runPeriod];
75  track->PositionEnd[2] += _correction[runPeriod];
76  }
77  }
78 
79 }
80 
Float_t PositionStart[4]
The reconstructed start position of the particle.
Representation of a global track.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
AnaEventInfoB * EventInfo
Run, sunrun, event, time stamp, etc.
All corrections should be registered with the CorrectionManager.
void Apply(AnaSpillC &spill)
int GetRunPeriod(int run, int subrun=-1)
Returns the run period (sequentially: 0,1,2,3,4,5 ...)
bool GetIsMC() const
Return whether this spill is from Monte Carlo or not.
std::vector< AnaParticleB * > Particles
Float_t PositionEnd[4]
The reconstructed end position of the particle.
Int_t Run
The ND280 run number.