HighLAND
FGDECalMatchEffSystematics.cxx
1 #include "FGDECalMatchEffSystematics.hxx"
2 #include "CutUtils.hxx"
3 #include "SystematicUtils.hxx"
4 #include "SystId.hxx"
5 
6 //#define DEBUG
7 
8 
9 //********************************************************************
10 FGDECalMatchEffSystematics::FGDECalMatchEffSystematics(bool comp):BinnedParams("FGDECalMatchEff",k3D_EFF_ASSYMMETRIC){
11  //********************************************************************
12 
13  _computecounters=comp;
15  if(_computecounters)
17 }
18 
19 //********************************************************************
20 FGDECalMatchEffSystematics::FGDECalMatchEffSystematics(bool computecounters, const std::string& name, BinnedParams::TypeEnum type):
21  BinnedParams(name, type){
22  //********************************************************************
23  _computecounters = computecounters;
25  if(_computecounters)
27 }
28 
29 //********************************************************************
31  //********************************************************************
32 
33 
34  if(_computecounters)
36 
37  (void)event;
38 
39  // Get the SystBox for this event, and the appropriate selection and branch
40  SystBoxB* SystBox = GetSystBox(event, box.SelectionEnabledIndex, box.SuccessfulBranch);
41 
42  Weight_h eventWeight = 1.;
43 
44 #ifdef DEBUG
45  std::cout << "FGDECalMatchEffSystematics::Apply(): " << SystBox->nRelevantTrueObjects<< std::endl;
46 #endif
47 
48  // Loop over relevant true tracks
49  for (Int_t itrk = 0; itrk < SystBox->nRelevantTrueObjects; itrk++){
50 
51  AnaTrueParticleB* truePart = static_cast<AnaTrueParticleB*>(SystBox->RelevantTrueObjects[itrk]);
52 
53  AnaTrackB* recoTrack = static_cast<AnaTrackB*>(SystBox->RelevantTrueObjectsReco[itrk]);
54 
55  if (!truePart || !recoTrack) continue;
56 
57 
58  // Do fine-tuning of the track relevance via the selection
59  if (!sel.IsRelevantTrueObjectForSystematicInToy(event, box, truePart, SystId::kFgdECalMatchEff, box.SuccessfulBranch)) continue;
60 
61 
62  SubDetId::SubDetEnum fgd_det[5];
63 
64  int nfgd_det = anaUtils::GetFGDDetCrossed(truePart, fgd_det);
65 
66  if(nfgd_det==0) continue;
67 
68  // Get ecal segment (wont work if call for TECAL)
69  AnaParticleB* ecal = anaUtils::GetSegmentWithMostNodesInDet(*(recoTrack), SubDetId::kECAL);
70 
71  if(!ecal)
72  continue;
73 
74  Float_t* dir = anaUtils::GetSLineDir(ecal->PositionStart, ecal->PositionEnd);
75 
76  // Check the direction of the reco track
77  dir[2] *= ((recoTrack->DirectionStart[2]*dir[2] >= 0) ? 1. : -1.);
78 
79  BinnedParamsParams params;
80  int index;
81 
82  if (!GetBinValues(fgd_det[0], SubDetId::GetSubdetectorEnum(ecal->Detector), dir[2], params, index)) continue;
83 
84  // Found the correspondence, now check detector bits
85  bool found = SubDetId::GetDetectorUsed(recoTrack->Detector, fgd_det[0]);
86 
87  eventWeight *= systUtils::ComputeEffLikeWeight(found, toy, GetIndex(), index, params);
88 
89 #ifdef DEBUG
90  std::cout<<"fgd-ecal found "<< found<<" eventWeight "<<eventWeight<<std::endl;
91 #endif
92 
93  if(_computecounters)
94  UpdateEfficiencyCounter(index,found);
95 
96  }
97 
98  return eventWeight;
99 }
100 
101 //********************************************************************
103  //********************************************************************
104 
105  (void)event;
106 
107  //should cross at least two layers in FGD
108  if (anaUtils::TrueParticleCrossesFGD(static_cast<const AnaTrueParticleB*>(&track)))
109  return true;
110 
111  return false;
112 
113 }
114 
115 //**************************************************
117  //**************************************************
118 
119  (void)event;
120  //should use Barrel ECal since ECal iso-tracking efficiency is treated elsewhere
121 
122  if (SubDetId::GetDetectorUsed( track.Detector, SubDetId::kTECAL) &&
123  !SubDetId::GetDetectorUsed( track.Detector, SubDetId::kDSECAL) &&
124  !SubDetId::GetDetectorUsed( track.Detector, SubDetId::kPECAL) &&
125  !SubDetId::GetDetectorUsed( track.Detector, SubDetId::kTPC))
126  return true;
127 
128  return false;
129 }
130 
131 //********************************************************************
132 Int_t FGDECalMatchEffSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
133  //********************************************************************
134 
135  SubDetId_h det = sel.GetDetectorFV(ibranch);
136 
137  if (det == SubDetId::kFGD1){
138  IDs[0] = EventBoxTracker::kTracksWithFGD1AndNoTPC;
139  return 1;
140  }
141  else if (det == SubDetId::kFGD2){
142  IDs[0] = EventBoxTracker::kTracksWithFGD2AndNoTPC;
143  return 1;
144  }
145  else if (det == SubDetId::kFGD){
146  IDs[0] = EventBoxTracker::kTracksWithFGD1AndNoTPC;
147  IDs[1] = EventBoxTracker::kTracksWithFGD2AndNoTPC;
148  return 2;
149  }
150 
151  return 0;
152 }
153 
154 //********************************************************************
155 Int_t FGDECalMatchEffSystematics::GetRelevantTrueObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
156  //********************************************************************
157 
158  SubDetId_h det = sel.GetDetectorFV(ibranch);
159  //may change in future
160  if (det == SubDetId::kFGD1){
162  return 1;
163  }
164  else if (det == SubDetId::kFGD2){
165  IDs[0] = EventBoxTracker::kTrueParticlesChargedInFGD2ECalHAInBunch;
166  return 1;
167  }
168  else if (det == SubDetId::kFGD){
170  IDs[1] = EventBoxTracker::kTrueParticlesChargedInFGD2ECalHAInBunch;
171  return 2;
172  }
173 
174  return 0;
175 }
Float_t PositionStart[4]
The reconstructed start position of the particle.
unsigned long Detector
Int_t GetIndex() const
Return the index of this systematic.
Int_t GetRelevantTrueObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrueTrackGroup IDs array for this systematic.
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.
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
bool GetBinValues(Float_t value, Float_t &mean, Float_t &sigma)
Gets the bin values for a 1D source.
bool TrueParticleCrossesFGD(const AnaTrueParticleB *track, SubDetId::SubDetEnum det=SubDetId::kFGD)
Whether a true track crosses a FGD so to be able to deposit charge in at least two layers...
Definition: TruthUtils.cxx:237
bool UpdateEfficiencyCounter(Int_t index, bool correct)
Update the efficiency variables _ncorrect and _nwrong.
Representation of a true Monte Carlo trajectory/particle.
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
SubDetEnum
Enumeration of all detector systems and subdetectors.
Definition: SubDetId.hxx:25
Representation of a global track.
Int_t nRelevantTrueObjects
Array of Relevant True RecObjects for each systematic.
Definition: SystBoxB.hxx:24
static SubDetId::SubDetEnum GetSubdetectorEnum(unsigned long BitField)
Get the single subdetector that this track is from.
Definition: SubDetId.cxx:165
int GetFGDDetCrossed(const AnaTrueParticleB *track, SubDetId::SubDetEnum det[])
FGD detectors crossed.
Definition: TruthUtils.cxx:398
bool IsRelevantTrueObject(const AnaEventC &event, const AnaTrueObjectC &track) const
Is this track relevant for this systematic ?
Float_t DirectionStart[3]
The reconstructed start direction of the particle.
AnaRecObjectC ** RelevantTrueObjectsReco
Definition: SystBoxB.hxx:29
TypeEnum
Enumerator describing the values that _type member can take.
Float_t * GetSLineDir(Float_t *start, Float_t *end)
Direction assuming straight line between given start and end points.
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
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) ...
AnaParticleB * GetSegmentWithMostNodesInDet(const AnaTrackB &track, SubDetId::SubDetEnum det)
Method to get the subtrack with most nodes in a given detector.
Representation of a reconstructed particle (track or shower).
Int_t GetNBins()
Get the number of bins.
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.
bool IsRelevantRecObject(const AnaEventC &event, const AnaRecObjectC &track) const
Is this track relevant for this systematic ?
Float_t PositionEnd[4]
The reconstructed end position of the particle.