HighLAND
FGDHybridTrackEffSystematics.cxx
1 #include "FGDHybridTrackEffSystematics.hxx"
2 #include "ND280AnalysisUtils.hxx"
3 #include "EventBoxTracker.hxx"
4 #include "SystematicUtils.hxx"
5 #include "ToyBoxTracker.hxx"
6 #include "SystId.hxx"
7 #include "EventBoxId.hxx"
8 
9 
10 //********************************************************************
11 FGDHybridTrackEffSystematics::FGDHybridTrackEffSystematics(bool comp):EventWeightBase(1){
12 //********************************************************************
13 
14  _computecounters=comp;
15  _fgd1 = new BinnedParams("FGD1HybridTrackEff_p6B",BinnedParams::k2D_EFF_ASSYMMETRIC);
16  _fgd2 = new BinnedParams("FGD2HybridTrackEff_p6B",BinnedParams::k2D_EFF_ASSYMMETRIC);
17  SetNParameters(2*(_fgd1->GetNBins()+_fgd2->GetNBins()));
18 
19  if(_computecounters){
20  _fgd1->InitializeEfficiencyCounter();
21  _fgd2->InitializeEfficiencyCounter();
22  }
23 }
24 
25 //********************************************************************
27 //********************************************************************
28 
29  Weight_h eventWeight=1;
30  BinnedParamsParams params;
31 
32  // Cast the ToyBox to the appropriate type
33  const ToyBoxTracker& box = *static_cast<const ToyBoxTracker*>(&boxB);
34 
35  // Get the SystBox for this event, and the appropriate selection and branch
37 
38  if(_computecounters){
39  _fgd1->InitializeEfficiencyCounter();
40  _fgd2->InitializeEfficiencyCounter();
41  }
42  // Get the direction of the main track
43  AnaTrackB *maintrack = box.MainTrack;
44  if(!maintrack) return eventWeight;
45 
46  for (Int_t itrue=0;itrue< SystBox->nRelevantTrueObjects; itrue++){
47  AnaTrueParticleB* trueTrack = static_cast<AnaTrueParticleB*>(SystBox->RelevantTrueObjects[itrue]);
48 
49  // TODO by now the reco track associated to the true is the first one found, we should use instead a criteria to decide.
50  // by now since it's very rare it's like that.
51  // retrieve the reconstructed track associated
52  AnaTrackB* recoTrack = static_cast<AnaTrackB*>(SystBox->RelevantTrueObjectsReco[itrue]);
53 
54  // Get the cos (theta), where theta is the angle between the main track and the FGD track
55  Float_t costheta = 0;
56  if (recoTrack)
57  costheta = anaUtils::ScalarProduct(maintrack->DirectionStart, recoTrack->DirectionStart);
58  else
59  costheta = anaUtils::ScalarProduct(maintrack->DirectionStart, trueTrack->Direction);
60 
61  Float_t pdg=(Float_t)trueTrack->PDG;
62  bool found = (recoTrack);
63 
64  // Get the FGD tracking efficiency
65  Int_t index;
66  if(box.DetectorFV==SubDetId::kFGD1){
67  if(!_fgd1->GetBinValues(fabs(pdg),costheta, params, index)) continue;
68  // save the index of the varied parameters into the systematics box
69  if(_computecounters)
70  _fgd1->UpdateEfficiencyCounter(index,found);
71  }
72  else if(box.DetectorFV==SubDetId::kFGD2){
73  if(!_fgd2->GetBinValues(fabs(pdg),costheta, params, index)) continue;
74  if(_computecounters)
75  _fgd2->UpdateEfficiencyCounter(index,found);
76 
77  }
78  else return eventWeight;
79 
80  eventWeight *= systUtils::ComputeEffLikeWeight(true, toy, GetIndex(), index, params);
81  }
82 
83  return eventWeight;
84 
85 }
86 
87 //********************************************************************
89 //********************************************************************
90 
91  EventBoxB* EventBox = event.EventBoxes[EventBoxId::kEventBoxTracker];
92 
93  //we should not take into account the tracks that are matched to the tpc,
94  //this is done in tpc-fgd matching efficiency
95  for (Int_t i=0;i<EventBox->nRecObjectsInGroup[EventBoxTracker::kTracksWithTPC];i++){
96  AnaRecObjectC* track = EventBox->RecObjectsInGroup[EventBoxTracker::kTracksWithTPC][i];
97  if (CheckTrueRecoAssociation(trueTrack, *track))
98  return false;
99  }
100 
101  return true;
102 }
103 
104 //********************************************************************
105 Int_t FGDHybridTrackEffSystematics::GetRelevantRecObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
106 //********************************************************************
107 
108  SubDetId_h det = sel.GetDetectorFV(ibranch);
109 
110  if (det == SubDetId::kFGD1){
111  IDs[0] = EventBoxTracker::kTracksWithFGD1AndNoTPC;
112  return 1;
113  }
114  else if (det == SubDetId::kFGD2){
115  IDs[0] = EventBoxTracker::kTracksWithFGD2AndNoTPC;
116  return 1;
117  }
118  else if (det == SubDetId::kFGD){
119  IDs[0] = EventBoxTracker::kTracksWithFGD1AndNoTPC;
120  IDs[1] = EventBoxTracker::kTracksWithFGD2AndNoTPC;
121  return 2;
122  }
123 
124  return 0;
125 }
126 
127 //********************************************************************
128 Int_t FGDHybridTrackEffSystematics::GetRelevantTrueObjectGroups(const SelectionBase& sel, Int_t ibranch, Int_t* IDs) const{
129 //********************************************************************
130 
131  SubDetId_h det = sel.GetDetectorFV(ibranch);
132 
133  if (det == SubDetId::kFGD1){
134  IDs[0] = EventBoxTracker::kTrueParticlesChargedInFGD1AndNoTPCInBunch;
135  return 1;
136  }
137  else if (det == SubDetId::kFGD2){
138  IDs[0] = EventBoxTracker::kTrueParticlesChargedInFGD2AndNoTPCInBunch;
139  return 1;
140  }
141  else if (det == SubDetId::kFGD){
142  IDs[0] = EventBoxTracker::kTrueParticlesChargedInFGD1AndNoTPCInBunch;
143  IDs[1] = EventBoxTracker::kTrueParticlesChargedInFGD2AndNoTPCInBunch;
144  return 2;
145  }
146 
147  return 0;
148 }
Weight_h ComputeWeight(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &box)
Int_t GetRelevantTrueObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrueTrackGroup IDs array for this systematic.
Int_t GetIndex() const
Return the index of this systematic.
Int_t SelectionEnabledIndex
The enabled index of this selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:49
virtual bool CheckTrueRecoAssociation(const AnaTrueObjectC &trueRecObject, const AnaRecObjectC &track) const
Criteria for true-reco association for this systematic.
SubDetId_h DetectorFV
Indicate the FV we are interested in.
Definition: ToyBoxB.hxx:52
SystBoxB * GetSystBox(const AnaEventC &event, Int_t isel=0, Int_t ibranch=0) const
Get the SystBox corresponding to a selection, branch and event.
AnaTrackB * MainTrack
For storing the Main Track (The lepton candidate in geranal: HMN or HMP track)
void SetNParameters(int N)
Set the number of systematic parameters associated to this systematic.
Int_t nRecObjectsInGroup[NMAXRECOBJECTGROUPS]
----—— RecObjects and TrueRecObjects used in the selection and systematics ------------—— ...
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
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
bool IsRelevantTrueObject(const AnaEventC &event, const AnaTrueObjectC &trueTrack) const
Is this true track relevant for this systematic ?
Float_t DirectionStart[3]
The reconstructed start direction of the particle.
AnaRecObjectC ** RelevantTrueObjectsReco
Definition: SystBoxB.hxx:29
Int_t GetRelevantRecObjectGroups(const SelectionBase &sel, Int_t ibranch, Int_t *IDs) const
Get the TrackGroup IDs array for this systematic.
Float_t ScalarProduct(Float_t *array1, Float_t *array2, Int_t size=3)
Scalar product of two Float_t arrays. Provided their size.
Definition: CoreUtils.cxx:222
Float_t Direction[3]
The initial direction of the true particle.
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.