HighLAND
ECalTrackEffSystematics.cxx
1 #include "ECalTrackEffSystematics.hxx"
2 #include "CutUtils.hxx"
3 #include "SystematicUtils.hxx"
4 #include "SystId.hxx"
5 #include "EventBoxId.hxx"
6 
7 //#define DEBUG
8 
9 
10 //********************************************************************
11 ECalTrackEffSystematics::ECalTrackEffSystematics(bool comp):BinnedParams("ECalTrackEff",k3D_EFF_ASSYMMETRIC){
12  //********************************************************************
13 
14  _computecounters = comp;
16  if(_computecounters)
18 }
19 
20 //********************************************************************
22  //********************************************************************
23 
24 
25  if(_computecounters)
27 
28  (void)event;
29 
30  // Get the SystBox for this event, and the appropriate selection and branch
31  SystBoxB* SystBox = GetSystBox(event, box.SelectionEnabledIndex, box.SuccessfulBranch);
32 
33  Weight_h eventWeight = 1.;
34 
35 #ifdef DEBUG
36  std::cout << " \n ECalTrackEffSystematics::Apply(): " << SystBox->nRelevantTrueObjects<< std::endl;
37 #endif
38 
39  // Loop over relevant true tracks
40  for (Int_t itrk = 0; itrk < SystBox->nRelevantTrueObjects; itrk++){
41 
42  AnaTrueParticleB* truePart = static_cast<AnaTrueParticleB*>(SystBox->RelevantTrueObjects[itrk]);
43 
44  if (!truePart) continue;
45 
46  // Do fine-tuning of the track relevance via the selection
47  if (!sel.IsRelevantTrueObjectForSystematicInToy(event, box, truePart, SystId::kECalTrackEff, box.SuccessfulBranch)) continue;
48 
49  AnaTrackB* recoTrack = static_cast<AnaTrackB*>(SystBox->RelevantTrueObjectsReco[itrk]);
50 
51  SubDetId::SubDetEnum det[10];
52  int ndet = anaUtils::GetECalDetCrossed(truePart, det);
53  if (ndet != 1) continue;
54 
55  BinnedParamsParams params;
56  int index;
57 
58  int pdg = abs(truePart->PDG);
59 
60  //assume a shower case
61  if (pdg != 13) pdg = 11;
62 
63  if (!GetBinValues(pdg, det[0], truePart->Momentum, params, index)) continue;
64 
65 
66  // check the presence of reco track
67  bool found = (recoTrack) ? SubDetId::GetDetectorUsed(recoTrack->Detector, det[0]) : false;
68 
69  // checked the correspondence, now get the weight
70 
71  Weight_h eventWeight_tmp = 1.;
72 #if useNewWeights
73  eventWeight_tmp = systUtils::ComputeEffLikeWeight(found, toy.GetToyVariations(_index)->Variations[index], params); // New way including data-mc diff
74 #else
75  eventWeight_tmp = systUtils::ComputeEffLikeWeight(found, toy.GetToyVariations(_index)->Variations[2*index],
76  toy.GetToyVariations(_index)->Variations[2*index+1], params);
77 #endif
78 
79 #ifdef DEBUG
80  std::cout << "ecal track found " << found << " eventWeight local " << eventWeight_tmp << std::endl;
81 #endif
82 
83  // Update the total weight
84  eventWeight *= eventWeight_tmp;
85 
86  if(_computecounters)
87  UpdateEfficiencyCounter(index,found);
88 
89  }
90 
91 #ifdef DEBUG
92  std::cout << " eventWeight total " << eventWeight << std::endl;
93 #endif
94 
95  return eventWeight;
96 }
97 
98 //********************************************************************
100  //********************************************************************
101 
102  (void)event;
103 
104  //should cross one ECal only and it should be tracker or Ds
105  SubDetId::SubDetEnum det[20];
106  int ndet = anaUtils::GetECalDetCrossed(static_cast<const AnaTrueParticleB*>(&track), det);
107  if (ndet!=1) return false;
108 
109  return (SubDetId::IsTECALDetector(det[0]) || det[0] == SubDetId::kDSECAL);
110 }
111 
112 //********************************************************************
113 Int_t ECalTrackEffSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
114  //********************************************************************
115 
116  (void)sel;
117  (void)ibranch;
118 
119  IDs[0] = EventBoxTracker::kTracksWithECal;
120  return 1;
121 }
122 
123 //********************************************************************
124 Int_t ECalTrackEffSystematics::GetRelevantTrueObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
125  //********************************************************************
126  (void)sel;
127  (void)ibranch;
128 
130  return 1;
131 }
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 IsRelevantTrueObject(const AnaEventC &event, const AnaTrueObjectC &track) const
Is this track relevant for this systematic ?
int GetECalDetCrossed(const AnaTrueParticleB *track, SubDetId::SubDetEnum det[])
ECal detectors crossed: split based on geom info PECal and TECal sub-detectors, this may not be very ...
Definition: TruthUtils.cxx:315
Int_t SelectionEnabledIndex
The enabled index of this selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:49
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 TrackGroup IDs array for this systematic.
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
Float_t Momentum
The initial momentum of the true particle.
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
bool UpdateEfficiencyCounter(Int_t index, bool correct)
Update the efficiency variables _ncorrect and _nwrong.
Representation of a true Monte Carlo trajectory/particle.
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:46
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
Weight_h ComputeWeight(const ToyExperiment &, const AnaEventC &, const ToyBoxB &)
Apply the systematic.
Int_t PDG
The PDG code of this particle.
Representation of a global track.
Int_t nRelevantTrueObjects
Array of Relevant True RecObjects for each systematic.
Definition: SystBoxB.hxx:24
static bool IsTECALDetector(SubDetId::SubDetEnum det)
Check if a detector enumeration refers to a Tracker ECAL or not.
Definition: SubDetId.cxx:134
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
AnaRecObjectC ** RelevantTrueObjectsReco
Definition: SystBoxB.hxx:29
void InitializeEfficiencyCounter()
Initialize counters.
virtual bool IsRelevantTrueObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaTrueObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this true track relevant for a given systematic (after selection, called for each toy) ...
Int_t GetRelevantTrueObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrueTrackGroup IDs array for this systematic.
Int_t GetNBins()
Get the number of bins.