HighLAND
IgnoreRightECalRuns3and4Correction.cxx
1 #include "IgnoreRightECalRuns3and4Correction.hxx"
2 #include "HighlandAnalysisUtils.hxx"
3 #include <VersioningUtils.hxx>
4 #include "Parameters.hxx"
5 #include <iostream>
6 
7 //********************************************************************
9  //********************************************************************
10  _runs_MC.clear();
11  _runs_Data.clear();
12 
13  std::string base = "highlandCorrections.IgnoreRightECal.Runs.";
14  int pairing = 1;
15 
16  // Read in the MC run periods to apply the correction for
17  std::string curr = GetParamString(base + "MC.Lower.", pairing);
18 
19  while (ND::params().HasParameter(curr)) {
20  int lower = ND::params().GetParameterI(curr);
21  curr = GetParamString(base + "MC.Upper.", pairing);
22  int upper = ND::params().GetParameterI(curr);
23  std::pair<int, int> p(lower, upper);
24  _runs_MC.push_back(p);
25  pairing++;
26  curr = GetParamString(base + "MC.Lower.", pairing);
27  }
28 
29  // Read in the Data run periods to apply the correction for
30  pairing = 1;
31  curr = GetParamString(base + "Data.Lower.", pairing);
32 
33  while (ND::params().HasParameter(curr)) {
34  int lower = ND::params().GetParameterI(curr);
35  curr = GetParamString(base + "Data.Upper.", pairing);
36  int upper = ND::params().GetParameterI(curr);
37  std::pair<int, int> p(lower, upper);
38  _runs_Data.push_back(p);
39  pairing++;
40  curr = GetParamString(base + "Data.Lower.", pairing);
41  }
42 }
43 
44 //********************************************************************
45 std::string IgnoreRightECalRuns3and4Correction::GetParamString(std::string base, int pairing) {
46  //********************************************************************
47  std::stringstream ss;
48  ss << base << pairing;
49  return ss.str();
50 }
51 
52 //********************************************************************
54  //********************************************************************
55 
56  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
57 
58  if (!ShouldApplyCorrection(spill)) {
59  return;
60  }
61 
62  for (unsigned int i = 0; i < spill.Bunches.size(); i++) {
63 
64  AnaTrackB* allEcalTracks[100];
65  int nECAL = anaUtils::GetAllTracksUsingDet(*(static_cast<AnaBunch*>(spill.Bunches[i])), SubDetId::kECAL, allEcalTracks);
66 
67  for (Int_t j = 0; j < nECAL; j++) {
68  AnaTrackB* track = allEcalTracks[j];
69  AnaECALParticleB* ECALSegments[100];
70  int nECALSegments = 0;
71 
72  // Only keep the ECal segment if it's not in the Right ECal
73  for (Int_t i=0;i<track->nECALSegments;i++){
74  AnaECALParticleB* ecal = track->ECALSegments[i];
75 
76  if (ecal->Detector != SubDetId::kRightTECAL) {
77  ECALSegments[i] = ecal;
78  nECALSegments++;
79  track->ECALSegments[i] = NULL;
80  continue;
81  }
82 
83  delete track->ECALSegments[i];
84  track->ECALSegments[i] = NULL;
85  }
86 
87  track->nECALSegments = nECALSegments;
88  for (Int_t i=0;i<nECALSegments;i++)
89  track->ECALSegments[i] = ECALSegments[i];
90 
91  // should also change the detector bit so to remove the right ecal
92  // unfortunately not way to change the kinematics of the end point in a consistent way
93  unsigned long det = 0;
94  for(UInt_t i = 0; i < SubDetId::kInvalidSubdetector; i++){
95  SubDetId::SubDetEnum idet = static_cast<SubDetId::SubDetEnum>(i);
96 
97  if (idet == SubDetId::kRightTECAL)
98  continue;
99 
100  if(!SubDetId::GetDetectorUsed(track->Detector, idet)) continue;
101 
102  SubDetId::SetDetectorUsed(det, idet);
103  }
104 
106 
107  track->Detector = det;
108 
109 
110  }
111  }
112 }
113 
114 //********************************************************************
115 bool IgnoreRightECalRuns3and4Correction::ShouldApplyCorrection(AnaSpillC& spillBB) {
116  //********************************************************************
117 
118  // Run 3 and 4 dead Right ECal TFBs are simulated in MC appropriately for production 6
119  // so there is no need to apply the correction in this case
120  if (versionUtils::prod6_corrections)
121  return false;
122 
123 
124  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
125 
126  int run = spill.EventInfo->Run;
127  std::vector<std::pair<int, int> >& runs = spill.GetIsMC() ? _runs_MC : _runs_Data;
128 
129  for (unsigned int i = 0; i < runs.size(); i++) {
130  if (run >= runs[i].first && run <= runs[i].second) {
131  return true;
132  }
133  }
134 
135  return false;
136 
137 }
unsigned long Detector
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
AnaECALParticleB * ECALSegments[NMAXECALS]
The ECAL segments that contributed to this global track.
int nECALSegments
How many ECAL tracks are associated with this track.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
static void SetDetectorSystemFields(unsigned long &BitField)
Definition: SubDetId.cxx:81
Representation of an ECAL segment of a global track.
AnaEventInfoB * EventInfo
Run, sunrun, event, time stamp, etc.
static bool GetDetectorUsed(unsigned long BitField, SubDetId::SubDetEnum det)
Method to see if a certain subdetector or subdetector system is used.
Definition: SubDetId.cxx:40
All corrections should be registered with the CorrectionManager.
static void SetDetectorUsed(unsigned long &BitField, SubDetId::SubDetEnum det)
Method to set a certain subdetector or subdetector system to used used.
Definition: SubDetId.cxx:36
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
bool GetIsMC() const
Return whether this spill is from Monte Carlo or not.
Representation of a global track.
void Apply(AnaSpillC &spill)
Apply the variation to all tracks with TPC info.
int GetAllTracksUsingDet(const AnaBunchB &bunch, SubDetId::SubDetEnum det, AnaTrackB *selTracks[])
Int_t Run
The ND280 run number.