HighLAND
EventWeightBase.cxx
1 #include "EventWeightBase.hxx"
2 #include "MultiThread.hxx"
3 
4 
5 //********************************************************************
6 void EventWeightBase::InitializeEvent(const AnaEventC& event, const SelectionBase& sel, Int_t ibranch){
7 //********************************************************************
8 
9  Int_t uniqueID = 0;
10 
11 #ifdef MULTITHREAD
12  uniqueID = event.UniqueID;
13 #endif
14 
15  // Delete the SystBox when it exists and create a new one.
16  // TODO: It is probably faster to just reset the arrays
17 
18  // Get the selection index;
19  Int_t isel=sel.GetEnabledIndex();
20 
21  // Nothing to do when this box already created and filled
22  if(_systBoxes[isel][ibranch][uniqueID]) return;
23 
24  // Create the box
25  _systBoxes[isel][ibranch][uniqueID] = new SystBoxB();
26 
27  // Fill the SystBox with the relevant recObjects and true recObjects tor this systematic
28  FillSystBox(event, sel, ibranch);
29 }
30 
31 //********************************************************************
32 void EventWeightBase::FillSystBox(const AnaEventC& event, const SelectionBase& sel, Int_t ibranch){
33 //********************************************************************
34 
35  Int_t uniqueID = 0;
36 
37 #ifdef MULTITHREAD
38  uniqueID = event.UniqueID;
39 #endif
40 
41  // Get the selection index;
42  Int_t isel=sel.GetEnabledIndex();
43 
44  // Get the SystBox
45  SystBoxB& box = *_systBoxes[isel][ibranch][uniqueID];
46 
47  // Get the EventBox for the input selection
48  EventBoxB* EventBox = event.EventBoxes[sel.GetEventBoxId()];
49 
50  // Get the recObject groups relevant for this seystematic
51  Int_t* groups;
52  anaUtils::CreateArray(groups,10);
53  Int_t nGroups = GetRelevantRecObjectGroups(sel, ibranch, groups);
54  anaUtils::ResizeArray(groups,nGroups);
55 
56  if (nGroups>0){
57  // compute the total number of objects in all groups
58  Int_t nMaxRecObjects=0;
59  for (Int_t g = 0; g<nGroups;g++)
60  nMaxRecObjects += EventBox->nRecObjectsInGroup[groups[g]];
61 
62  // create the array of RelevantRecObjects
63  if (box.RelevantRecObjects) delete [] box.RelevantRecObjects;
64  anaUtils::CreateArray(box.RelevantRecObjects, nMaxRecObjects);
65  box.nRelevantRecObjects=0;
66 
67  // Loop over groups and over recObjects in each group
68  for (Int_t g = 0; g<nGroups;g++){
69  for (Int_t i=0;i<EventBox->nRecObjectsInGroup[groups[g]];i++){
70  AnaRecObjectC* recObject = EventBox->RecObjectsInGroup[groups[g]][i];
71 
72  // Is it relevant for this systematic ?
73  if (IsRelevantRecObject(event, *recObject))
74  // Is it relevant for this selection and systematic ?
75  if (sel.IsRelevantRecObjectForSystematic(event,recObject,_index,ibranch))
76  box.RelevantRecObjects[box.nRelevantRecObjects++]= recObject;
77  }
78  }
79  // Resize the array once we know the number of objects
80  if (box.nRelevantRecObjects != nMaxRecObjects)
81  anaUtils::ResizeArray(box.RelevantRecObjects, box.nRelevantRecObjects);
82  }
83 
84  // Delete the groups array
85  if (groups) delete [] groups;
86 
87  // Fill the array of groups for true recObjects
88  anaUtils::CreateArray(groups,10);
89  Int_t nTrueGroups = GetRelevantTrueObjectGroups(sel, ibranch, groups);
90  anaUtils::ResizeArray(groups,nTrueGroups);
91 
92 
93  if (nTrueGroups>0){
94  // compute the total number of objects in all groups
95  Int_t nMaxRecObjects=0;
96  for (Int_t g = 0; g<nTrueGroups;g++)
97  nMaxRecObjects += EventBox->nTrueObjectsInGroup[groups[g]];
98 
99  // create the array of RelevantTrueObjects
100  if (box.RelevantRecObjects) delete [] box.RelevantTrueObjects;
101  anaUtils::CreateArray(box.RelevantTrueObjects, nMaxRecObjects);
102  box.nRelevantTrueObjects=0;
103 
104  // Loop over groups and over true recObjects in each group
105  for (Int_t g = 0; g<nTrueGroups;g++){
106  for (Int_t i=0;i<EventBox->nTrueObjectsInGroup[groups[g]];i++){
107  AnaTrueObjectC* trueRecObject = EventBox->TrueObjectsInGroup[groups[g]][i];
108 
109  // Is it relevant for this systematic ?
110  if (IsRelevantTrueObject(event, *trueRecObject))
111  // Is it relevant for this selection and systematic ?
112  if (sel.IsRelevantTrueObjectForSystematic(event,trueRecObject,_index,ibranch))
113  box.RelevantTrueObjects[box.nRelevantTrueObjects++]= trueRecObject;
114  }
115  }
116  // Resize the array once we know the number of objects
117  if (box.nRelevantTrueObjects != nMaxRecObjects)
118  anaUtils::ResizeArray(box.RelevantTrueObjects, box.nRelevantTrueObjects);
119  }
120 
121  // Delete the groups array
122  if (groups) delete [] groups;
123 
124 
125  // Fill the true-reco association. Only for some eff-like systematics
126  FillTrueRecoAssociation(*_systBoxes[isel][ibranch][uniqueID]);
127 
128 }
129 
130 //********************************************************************
132 //********************************************************************
133  if (box.RelevantTrueObjectsReco) delete [] box.RelevantTrueObjectsReco;
134 
135  // Create the box of true-rec association only for the first toy
136  anaUtils::CreateArray(box.RelevantTrueObjectsReco, box.nRelevantTrueObjects);
137 
138  for (Int_t itrue=0;itrue< box.nRelevantTrueObjects; itrue++){
139  AnaTrueObjectC* trueRecObject = box.RelevantTrueObjects[itrue];
140 
141  box.RelevantTrueObjectsReco[itrue] = NULL;
142 
143  // Is there any reconstructed recObject associated to this true recObject ?
144  for (Int_t irec=0;irec<(int) box.nRelevantRecObjects; irec++){
145  AnaRecObjectC* recObject = box.RelevantRecObjects[irec];
146  if (CheckTrueRecoAssociation(*trueRecObject, *recObject)){
147  box.RelevantTrueObjectsReco[itrue] = recObject;
148  break;
149  }
150  }
151  }
152 }
153 
154 //********************************************************************
155 bool EventWeightBase::CheckTrueRecoAssociation(const AnaTrueObjectC& trueObject, const AnaRecObjectC& recObject) const{
156 //********************************************************************
157 
158  // TrueObject must exist
159  if (!recObject.TrueObject) return false;
160 
161  // This is the simplest true-reco association. This method can be overwritten by the derived classes
162  if(trueObject.ID==recObject.TrueObject->ID) return true;
163  return false;
164 }
Int_t _index
The index of this systematic (needed by SystematicsManager);.
virtual void InitializeEvent(const AnaEventC &event, const SelectionBase &sel, Int_t ibranch)
Initialize the SystBox for this event.
virtual Int_t GetRelevantRecObjectGroups(const SelectionBase &, Int_t ibranch, Int_t *IDs) const
Get the IDs of the RecObject groups that are relevant for this systematic in a given selection...
EventBoxId_h GetEventBoxId() const
Returns the Id of the EventBox to be used in this selection.
virtual bool CheckTrueRecoAssociation(const AnaTrueObjectC &trueRecObject, const AnaRecObjectC &track) const
Criteria for true-reco association for this systematic.
AnaTrueObjectC * TrueObject
The link to the true oject that most likely generated this reconstructed object.
virtual Int_t GetRelevantTrueObjectGroups(const SelectionBase &, Int_t ibranch, Int_t *IDs) const
Get the IDs of the TrueObject groups that are relevant for this systematic in a given selection...
Int_t ID
The ID of the trueObj, which corresponds to the ID of the TTruthParticle that created it...
Int_t nRecObjectsInGroup[NMAXRECOBJECTGROUPS]
----—— RecObjects and TrueRecObjects used in the selection and systematics ------------—— ...
virtual void FillSystBox(const AnaEventC &event, const SelectionBase &sel, Int_t ibranch)
Fills the SystBox.
void FillTrueRecoAssociation(SystBoxB &box)
Fll the true-reco association array.
Int_t nRelevantTrueObjects
Array of Relevant True RecObjects for each systematic.
Definition: SystBoxB.hxx:24
AnaRecObjectC ** RelevantTrueObjectsReco
Definition: SystBoxB.hxx:29
virtual bool IsRelevantRecObjectForSystematic(const AnaEventC &, AnaRecObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this track relevant for a given systematic (prior to selection, call when initializing the event...
virtual bool IsRelevantRecObject(const AnaEventC &, const AnaRecObjectC &) const
Check whether a AnaRecObject is relevant for this systematic or not.
virtual bool IsRelevantTrueObjectForSystematic(const AnaEventC &, AnaTrueObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this true track relevant for a given systematic (prior to selection, call when initializing the ev...
Int_t nTrueObjectsInGroup[NMAXTRUEOBJECTGROUPS]
Different groups of rec objects used for systematics.
Int_t nRelevantRecObjects
----—— Relevant rec objects and true objects for each systematic ------------—— ...
Definition: SystBoxB.hxx:20
SystBoxB **** _systBoxes
----—— Relevant objects for this systematic ------------——
Int_t GetEnabledIndex() const
Get the Selection index.
virtual bool IsRelevantTrueObject(const AnaEventC &, const AnaTrueObjectC &) const
Check whether a AnaTrueObject is relevant for this systematic or not.