HighLAND
ECalEmHipPIDSystematics.cxx
1 #include "ECalEmHipPIDSystematics.hxx"
2 #include "CutUtils.hxx"
3 #include "SystematicUtils.hxx"
4 #include "SystId.hxx"
5 #include "EventBoxId.hxx"
6 
7 //#define DEBUG
8 
9 //********************************************************************
10 ECalEmHipPIDSystematics::ECalEmHipPIDSystematics(bool comp):BinnedParams("ECal_EMHIPPID", k3D_EFF_ASSYMMETRIC){
11  //********************************************************************
12 
13  _computecounters = comp;
15  if(_computecounters)
17 }
18 
19 //********************************************************************
21  //********************************************************************
22 
23 
24  if(_computecounters)
26 
27  (void)event;
28 
29  // Get the SystBox for this event, and the appropriate selection and branch
30  SystBoxB* SystBox = GetSystBox(event, boxB.SelectionEnabledIndex, boxB.SuccessfulBranch);
31 
32  Weight_h eventWeight = 1.;
33 
34 #ifdef DEBUG
35  std::cout << " \n ECalEmHipPIDSystematics::Apply(): " << SystBox->nRelevantRecObjects<< std::endl;
36 #endif
37 
38  AnaECALParticleB* ecalTracks[NMAXPARTICLES];
39 
40  // Loop over relevant tracks
41  for (Int_t itrk = 0; itrk < SystBox->nRelevantRecObjects; itrk++){
42 
43  AnaTrackB* track = static_cast<AnaTrackB*>(SystBox->RelevantRecObjects[itrk]);
44 
45  if (!track) continue;
46 
47  if (!sel.IsRelevantRecObjectForSystematicInToy(event, boxB, track, SystId::kECalEmHipPID, boxB.SuccessfulBranch)) continue;
48 
49  // Should have a true track
50  AnaTrueParticleB* truePart = track->GetTrueParticle();
51  if (!truePart) continue;
52 
53  // Get the ECal segment
54  int count = anaUtils::GetTrackerDsEcals(track, ecalTracks);
55 
56  if (count < 1) continue;
57 
58  AnaECALParticleB* ecalTrack = ecalTracks[0];
59  if (!ecalTrack) continue;
60 
61  Float_t PIDEmHip = ecalTrack->PIDEmHip;
62 
63  // Get the PDG
64  int pdg = abs(truePart->PDG);
65 
66  BinnedParamsParams params;
67  int index;
68 
69  // Better way of doing this?
70  if(pdg == 211 || pdg == 321) pdg = 13;
71 
72  if (!GetBinValues(pdg, SubDetId::GetSubdetectorEnum(ecalTrack->Detector), truePart->Momentum, params, index)) continue;
73 
74  // Use "proper" eff/1-eff value depending on the sign of PIDEmHip, once the uncertainties are gaussian, should be fine!
75  bool found = true;
76  if(PIDEmHip > 0){ // track case
77  params.meanDATA = 1 - params.meanDATA;
78  params.meanMC = 1 - params.meanMC;
79  }
80 
81  // Found the correspondence, now get the weight
82 #if useNewWeights
83  eventWeight = systUtils::ComputeEffLikeWeight(found, toy.GetToyVariations(_index)->Variations[index], params); // New way including data-mc diff
84 #else
85  eventWeight = systUtils::ComputeEffLikeWeight(found, toy.GetToyVariations(_index)->Variations[2*index],
86  toy.GetToyVariations(_index)->Variations[2*index+1], params);
87 #endif
88 
89 #ifdef DEBUG
90  std::cout<<"ecal track PIDEmHip "<< found << " eventWeight local " << eventWeight << std::endl;
91 #endif
92 
93  if(_computecounters)
94  UpdateEfficiencyCounter(index,found);
95 
96  }
97 
98  return eventWeight;
99 }
100 
101 
102 //********************************************************************
104  //********************************************************************
105 
106  (void)event;
107 
108  const AnaTrackB& track = *static_cast<const AnaTrackB*>(&recObj);
109 
110  // Should use exactly one Tracker/DsECal detector --> optimized for tracker analysis at the moment
111  int count = (int)(anaUtils::TrackUsesDet(track, SubDetId::kTopTECAL)) +
112  (int)(anaUtils::TrackUsesDet(track, SubDetId::kBottomTECAL)) +
113  (int)(anaUtils::TrackUsesDet(track, SubDetId::kLeftTECAL)) +
114  (int)(anaUtils::TrackUsesDet(track, SubDetId::kRightTECAL)) +
115  (int)(anaUtils::TrackUsesDet(track, SubDetId::kDSECAL));
116 
117  if (count != 1) return false;
118 
119  return true;
120 
121 }
122 
123 
124 //********************************************************************
125 Int_t ECalEmHipPIDSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
126  //********************************************************************
127 
128  (void)sel;
129  (void)ibranch;
130  IDs[0] = EventBoxTracker::kTracksWithECal;
131  return 1;
132 }
133 
134 
Int_t _index
The index of this systematic (needed by SystematicsManager);.
bool IsRelevantRecObject(const AnaEventC &event, const AnaRecObjectC &recObj) const
Is this track relevant for this systematic ?
unsigned long Detector
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
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.
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.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
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) ...
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)
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
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[])