HighLAND
PileUpCorrection.cxx
1 #include "PileUpCorrection.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "VersioningUtils.hxx"
4 #include "DataClasses.hxx"
5 
6 //********************************************************************
7 PileUpCorrection::PileUpCorrection() : CorrectionBase(){
8 //********************************************************************
9 
10  char filename[300];
11  if (versionUtils::prod6_corrections)
12  sprintf(filename, "%s/data/PileUpFGD1Correction_p6B.dat", getenv("HIGHLANDCORRECTIONSROOT"));
13  else
14  sprintf(filename, "%s/data/PileUpFGD1Correction_p5F.dat", getenv("HIGHLANDCORRECTIONSROOT"));
15 
16  std::cout << " PileUp correction data " << filename << std::endl;
17  FILE *pFile = fopen(filename, "r");
18 
19  if (pFile == NULL) {
20  printf("Cannot open file.\n");
21  exit(1);
22  }
23 
24  Int_t runPeriod;
25  Float_t corr;
26 
27  _nRunPeriods=0;
28 
29  while (fscanf(pFile, "%d%f", &runPeriod, &corr) == 2) {
30  _correction[runPeriod] = corr;
31  _nRunPeriods++;
32  }
33 
34  fclose(pFile);
35 }
36 
37 //********************************************************************
39 //********************************************************************
40 
41  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
42 
43  // No correction for data
44  if (!spill.GetIsMC()) return;
45 
46  // Get the run period (from 0 to 6)
47  Int_t runPeriod = anaUtils::GetRunPeriod(spill.EventInfo->Run);
48 
49  // Need a valid runPeriod
50  if (runPeriod<0 && runPeriod>=(Int_t)_nRunPeriods) return;
51 
52  // Apply the corection
53  for (UInt_t i = 0; i < spill.Bunches.size(); i++)
54  spill.Bunches[i]->Weight *= 1-_correction[runPeriod];
55 }
56 
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.
Int_t Run
The ND280 run number.