HighLAND
ECalPIDSystematics.cxx
1 #include "ECalPIDSystematics.hxx"
2 #include "CutUtils.hxx"
3 #include "SystematicUtils.hxx"
4 #include "SystId.hxx"
5 #include "EventBoxId.hxx"
6 
7 
8 //#define DEBUG
9 
10 
11 //********************************************************************
12 ECalPIDSystematics::ECalPIDSystematics(bool comp):BinnedParams("ECalPID", k3D_EFF_ASSYMMETRIC){
13  //********************************************************************
14 
15  _computecounters = comp;
17  if(_computecounters)
19 }
20 
21 //********************************************************************
22 Weight_h ECalPIDSystematics::ComputeWeight(const ToyExperiment& toy, const AnaEventC& event, const ToyBoxB& box, const SelectionBase& sel){
23  //********************************************************************
24 
25 
26  if(_computecounters)
28 
29  (void)event;
30 
31  // Get the SystBox for this event, and the appropriate selection and branch
32  SystBoxB* SystBox = GetSystBox(event, box.SelectionEnabledIndex, box.SuccessfulBranch);
33 
34  Weight_h eventWeight = 1.;
35 
36 #ifdef DEBUG
37  std::cout << " \n ECalPIDSystematics::Apply(): " << SystBox->nRelevantRecObjects<< std::endl;
38 #endif
39 
40  AnaECALParticleB* ecalTracks[NMAXPARTICLES];
41 
42  // Loop over relevant tracks
43  for (Int_t itrk = 0; itrk < SystBox->nRelevantRecObjects; itrk++){
44 
45  AnaTrackB* track = static_cast<AnaTrackB*>(SystBox->RelevantRecObjects[itrk]);
46 
47  if (!track) continue;
48 
49  if (!sel.IsRelevantRecObjectForSystematicInToy(event, box, track, SystId::kECalPID, box.SuccessfulBranch)) continue;
50 
51  // Should have a true track
52  AnaTrueParticleB* trueTrack = track->GetTrueParticle();
53  if (!trueTrack) continue;
54 
55  // Get the ECal segment
56  int count = anaUtils::GetTrackerDsEcals(track, ecalTracks);
57 
58  if (count < 1) continue;
59 
60  AnaECALParticleB* ecalTrack = ecalTracks[0];
61 
62  if (!ecalTrack) continue;
63 
64  Float_t PIDMipEm = ecalTrack->PIDMipEm;
65 
66  // Get the PDG
67  int pdg = abs(trueTrack->PDG);
68 
69  BinnedParamsParams params;
70  int index;
71 
72  // Do not have a pion control sample, same as muons for now - need to revise
73  if (pdg == 211) pdg = 13;
74 
75  if (!GetBinValues(pdg, SubDetId::GetSubdetectorEnum(ecalTrack->Detector), trueTrack->Momentum, params, index)) continue;
76 
77  // The systematics is estimated in the following way: given a certain PID, what is the efficiency to reconstruct it as
78  // a shower like object (i.e. PIDMipEm>0), these very numbers are stored in the data file,
79  // hence relatively large numbers for electrons and small ones for muons, we then base the systematic
80  // propagation on the pure eff-like case, depending on the parameter sign we use the proper efficiency number:
81  // eff or 1-eff
82 
83  // No inefficiency based on what said above
84  bool found = true;
85 
86  // Use "proper" eff/1-eff value depending on the sign of PIDMipEm, once the uncertainties are gaussian, should be fine!
87  if (PIDMipEm < 0 ){ // track case
88  params.meanDATA = 1 - params.meanDATA;
89  params.meanMC = 1 - params.meanMC;
90  }
91 
92  // Found the correspondence, now get the weight
93  Weight_h eventWeight_tmp = 1.;
94 #if useNewWeights
95  eventWeight_tmp = systUtils::ComputeEffLikeWeight(found, toy.GetToyVariations(_index)->Variations[index], params); // New way including data-mc diff
96 #else
97  eventWeight_tmp = systUtils::ComputeEffLikeWeight(found, toy.GetToyVariations(_index)->Variations[2*index],
98  toy.GetToyVariations(_index)->Variations[2*index+1], params);
99 #endif
100 
101 #ifdef DEBUG
102  std::cout<<"ecal track PIDMipEm "<< found << " eventWeight local " << eventWeight_tmp << std::endl;
103 #endif
104 
105  // Update the total weight
106  eventWeight *= eventWeight_tmp;
107 
108  if(_computecounters)
109  UpdateEfficiencyCounter(index,found);
110 
111  }
112 
113 #ifdef DEBUG
114  std::cout << " eventWeight total " << eventWeight << std::endl;
115 #endif
116 
117  return eventWeight;
118 }
119 
120 
121 //********************************************************************
122 bool ECalPIDSystematics::IsRelevantRecObject(const AnaEventC& event, const AnaRecObjectC& recObj) const{
123  //********************************************************************
124 
125  (void)event;
126 
127  const AnaTrackB& track = *static_cast<const AnaTrackB*>(&recObj);
128 
129  // Should use exactly one Tracker/DsECal detector --> optimized for tracker analysis at the moment
130  int count = (int)(anaUtils::TrackUsesDet(track, SubDetId::kTopTECAL)) +
131  (int)(anaUtils::TrackUsesDet(track, SubDetId::kBottomTECAL)) +
132  (int)(anaUtils::TrackUsesDet(track, SubDetId::kLeftTECAL)) +
133  (int)(anaUtils::TrackUsesDet(track, SubDetId::kRightTECAL)) +
134  (int)(anaUtils::TrackUsesDet(track, SubDetId::kDSECAL));
135 
136  if (count != 1) return false;
137 
138  return true;
139 
140 }
141 
142 
143 //********************************************************************
144 Int_t ECalPIDSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
145  //********************************************************************
146 
147  (void)sel;
148  (void)ibranch;
149  IDs[0] = EventBoxTracker::kTracksWithECal;
150  return 1;
151 }
152 
153 
Int_t _index
The index of this systematic (needed by SystematicsManager);.
unsigned long Detector
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
bool IsRelevantRecObject(const AnaEventC &event, const AnaRecObjectC &recObj) const
Is this track relevant for this systematic ?
Int_t SelectionEnabledIndex
The enabled index of this selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:49
Representation of an ECAL segment of a global track.
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the RecObjectGroup IDs array for this systematic.
Float_t Momentum
The initial momentum of the true particle.
bool TrackUsesDet(const AnaTrackB &track, SubDetId::SubDetEnum det)
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
Float_t meanDATA
The mean value for each of the systematic parameters of the control sample.
bool UpdateEfficiencyCounter(Int_t index, bool correct)
Update the efficiency variables _ncorrect and _nwrong.
Representation of a true Monte Carlo trajectory/particle.
virtual bool IsRelevantRecObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaRecObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this track relevant for a given systematic (after selection, called for each toy) ...
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:46
Int_t PDG
The PDG code of this particle.
Float_t meanMC
The mean value for each of the systematic parameters of the control sample.
Representation of a global track.
static SubDetId::SubDetEnum GetSubdetectorEnum(unsigned long BitField)
Get the single subdetector that this track is from.
Definition: SubDetId.cxx:165
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
void InitializeEfficiencyCounter()
Initialize counters.
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
Int_t GetNBins()
Get the number of bins.
int GetTrackerDsEcals(AnaTrackB *track, AnaECALParticleB *selTracks[])