1 |
|
---|
2 | /** \class TrackCountingTauTagging
|
---|
3 | *
|
---|
4 | * Determines origin of jet,
|
---|
5 | * applies b-tagging efficiency (miss identification rate) formulas
|
---|
6 | * and sets b-tagging flags
|
---|
7 | *
|
---|
8 | * $Date: 2013-07-12 00:22:27 +0200 (Fri, 12 Jul 2013) $
|
---|
9 | * $Revision: 1217 $
|
---|
10 | *
|
---|
11 | *
|
---|
12 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
13 | *
|
---|
14 | */
|
---|
15 |
|
---|
16 | #include "modules/TrackCountingTauTagging.h"
|
---|
17 |
|
---|
18 | #include "classes/DelphesClasses.h"
|
---|
19 | #include "classes/DelphesFactory.h"
|
---|
20 | #include "classes/DelphesFormula.h"
|
---|
21 |
|
---|
22 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
23 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
24 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
25 |
|
---|
26 | #include "TMath.h"
|
---|
27 | #include "TString.h"
|
---|
28 | #include "TFormula.h"
|
---|
29 | #include "TRandom3.h"
|
---|
30 | #include "TObjArray.h"
|
---|
31 | #include "TDatabasePDG.h"
|
---|
32 | #include "TLorentzVector.h"
|
---|
33 |
|
---|
34 | #include <algorithm>
|
---|
35 | #include <stdexcept>
|
---|
36 | #include <iostream>
|
---|
37 | #include <sstream>
|
---|
38 |
|
---|
39 | using namespace std;
|
---|
40 |
|
---|
41 | //------------------------------------------------------------------------------
|
---|
42 |
|
---|
43 | class TrackCountingTauTaggingPartonClassifier : public ExRootClassifier
|
---|
44 | {
|
---|
45 | public:
|
---|
46 |
|
---|
47 | TrackCountingTauTaggingPartonClassifier(const TObjArray *array);
|
---|
48 |
|
---|
49 | Int_t GetCategory(TObject *object);
|
---|
50 |
|
---|
51 | Double_t fEtaMax, fPTMin;
|
---|
52 |
|
---|
53 | const TObjArray *fParticleInputArray;
|
---|
54 | };
|
---|
55 |
|
---|
56 | //------------------------------------------------------------------------------
|
---|
57 | TrackCountingTauTaggingPartonClassifier::TrackCountingTauTaggingPartonClassifier(const TObjArray *array) :
|
---|
58 | fParticleInputArray(array)
|
---|
59 | {
|
---|
60 | }
|
---|
61 |
|
---|
62 | //------------------------------------------------------------------------------
|
---|
63 |
|
---|
64 | Int_t TrackCountingTauTaggingPartonClassifier::GetCategory(TObject *object)
|
---|
65 | {
|
---|
66 | Candidate *tau = static_cast<Candidate *>(object);
|
---|
67 | Candidate *daughter1 = 0;
|
---|
68 | Candidate *daughter2 = 0;
|
---|
69 |
|
---|
70 | const TLorentzVector &momentum = tau->Momentum;
|
---|
71 | Int_t pdgCode, i, j;
|
---|
72 |
|
---|
73 | pdgCode = TMath::Abs(tau->PID);
|
---|
74 | if(pdgCode != 15) return -1;
|
---|
75 |
|
---|
76 | if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
|
---|
77 |
|
---|
78 | if(tau->D1 < 0) return -1;
|
---|
79 |
|
---|
80 | if(tau->D2 < tau->D1) return -1;
|
---|
81 |
|
---|
82 | if(tau->D1 >= fParticleInputArray->GetEntriesFast() ||
|
---|
83 | tau->D2 >= fParticleInputArray->GetEntriesFast())
|
---|
84 | {
|
---|
85 | throw runtime_error("tau's daughter index is greater than the ParticleInputArray size");
|
---|
86 | }
|
---|
87 |
|
---|
88 | for(i = tau->D1; i <= tau->D2; ++i)
|
---|
89 | {
|
---|
90 | daughter1 = static_cast<Candidate *>(fParticleInputArray->At(i));
|
---|
91 | pdgCode = TMath::Abs(daughter1->PID);
|
---|
92 | if(pdgCode == 11 || pdgCode == 13 || pdgCode == 15) return -1;
|
---|
93 | else if(pdgCode == 24)
|
---|
94 | {
|
---|
95 | if(daughter1->D1 < 0) return -1;
|
---|
96 | for(j = daughter1->D1; j <= daughter1->D2; ++j)
|
---|
97 | {
|
---|
98 | daughter2 = static_cast<Candidate*>(fParticleInputArray->At(j));
|
---|
99 | pdgCode = TMath::Abs(daughter2->PID);
|
---|
100 | if(pdgCode == 11 || pdgCode == 13) return -1;
|
---|
101 | }
|
---|
102 |
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | return 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 | //------------------------------------------------------------------------------
|
---|
110 |
|
---|
111 | TrackCountingTauTagging::TrackCountingTauTagging() :
|
---|
112 | fClassifier(0), fFilter(0),
|
---|
113 | fItPartonInputArray(0), fItTrackInputArray(0), fItJetInputArray(0)
|
---|
114 | {
|
---|
115 | }
|
---|
116 |
|
---|
117 | //------------------------------------------------------------------------------
|
---|
118 |
|
---|
119 | TrackCountingTauTagging::~TrackCountingTauTagging()
|
---|
120 | {
|
---|
121 | }
|
---|
122 |
|
---|
123 | //------------------------------------------------------------------------------
|
---|
124 |
|
---|
125 | void TrackCountingTauTagging::Init()
|
---|
126 | {
|
---|
127 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
|
---|
128 | ExRootConfParam param;
|
---|
129 | DelphesFormula *formula;
|
---|
130 | Int_t i, size;
|
---|
131 |
|
---|
132 | fDeltaR = GetDouble("DeltaR", 0.5);
|
---|
133 | fDeltaRTrack = GetDouble("DeltaRTrack", 0.2);
|
---|
134 | fTrackPTMin = GetDouble("TrackPTMin", 1.0);
|
---|
135 |
|
---|
136 | // read efficiency formulas
|
---|
137 | param = GetParam("EfficiencyFormula");
|
---|
138 | size = param.GetSize();
|
---|
139 |
|
---|
140 | fEfficiencyMap.clear();
|
---|
141 | for(i = 0; i < size/2; ++i)
|
---|
142 | {
|
---|
143 | formula = new DelphesFormula;
|
---|
144 | formula->Compile(param[i*2 + 1].GetString());
|
---|
145 |
|
---|
146 | fEfficiencyMap[param[i*2].GetInt()] = formula;
|
---|
147 | }
|
---|
148 |
|
---|
149 | // set default efficiency formula
|
---|
150 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
151 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
152 | {
|
---|
153 | formula = new DelphesFormula;
|
---|
154 | formula->Compile("0.0");
|
---|
155 |
|
---|
156 | fEfficiencyMap[0] = formula;
|
---|
157 | }
|
---|
158 |
|
---|
159 | // import input array(s)
|
---|
160 |
|
---|
161 | fParticleInputArray = ImportArray(GetString("ParticleInputArray", "Delphes/allParticles"));
|
---|
162 |
|
---|
163 | fClassifier = new TrackCountingTauTaggingPartonClassifier(fParticleInputArray);
|
---|
164 | fClassifier->fPTMin = GetDouble("TauPTMin", 1.0);
|
---|
165 | fClassifier->fEtaMax = GetDouble("TauEtaMax", 2.5);
|
---|
166 |
|
---|
167 | fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons"));
|
---|
168 | fItPartonInputArray = fPartonInputArray->MakeIterator();
|
---|
169 |
|
---|
170 | fTrackInputArray = ImportArray(GetString("TrackInputArray", "TrackMerger/tracks"));
|
---|
171 | fItTrackInputArray = fTrackInputArray->MakeIterator();
|
---|
172 |
|
---|
173 | fFilter = new ExRootFilter(fPartonInputArray);
|
---|
174 |
|
---|
175 | fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
|
---|
176 | fItJetInputArray = fJetInputArray->MakeIterator();
|
---|
177 | }
|
---|
178 |
|
---|
179 | //------------------------------------------------------------------------------
|
---|
180 |
|
---|
181 | void TrackCountingTauTagging::Finish()
|
---|
182 | {
|
---|
183 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
|
---|
184 | DelphesFormula *formula;
|
---|
185 |
|
---|
186 | if(fFilter) delete fFilter;
|
---|
187 | if(fClassifier) delete fClassifier;
|
---|
188 | if(fItJetInputArray) delete fItJetInputArray;
|
---|
189 | if(fItTrackInputArray) delete fItTrackInputArray;
|
---|
190 | if(fItPartonInputArray) delete fItPartonInputArray;
|
---|
191 |
|
---|
192 | for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
|
---|
193 | {
|
---|
194 | formula = itEfficiencyMap->second;
|
---|
195 | if(formula) delete formula;
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | //------------------------------------------------------------------------------
|
---|
200 |
|
---|
201 | void TrackCountingTauTagging::Process()
|
---|
202 | {
|
---|
203 | Candidate *jet, *tau, *track, *daughter;
|
---|
204 | TLorentzVector tauMomentum;
|
---|
205 | Double_t pt, eta, phi;
|
---|
206 | TObjArray *tauArray;
|
---|
207 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
|
---|
208 | DelphesFormula *formula;
|
---|
209 | Int_t pdgCode, charge, i, identifier;
|
---|
210 |
|
---|
211 | // select taus
|
---|
212 | fFilter->Reset();
|
---|
213 | tauArray = fFilter->GetSubArray(fClassifier, 0);
|
---|
214 |
|
---|
215 | if(tauArray == 0) return;
|
---|
216 |
|
---|
217 | TIter itTauArray(tauArray);
|
---|
218 |
|
---|
219 | // loop over all input jets
|
---|
220 | fItJetInputArray->Reset();
|
---|
221 | while((jet = static_cast<Candidate *>(fItJetInputArray->Next())))
|
---|
222 | {
|
---|
223 | identifier = 0;
|
---|
224 | const TLorentzVector &jetMomentum = jet->Momentum;
|
---|
225 | pdgCode = 0;
|
---|
226 | charge = 0;
|
---|
227 | eta = jetMomentum.Eta();
|
---|
228 | phi = jetMomentum.Phi();
|
---|
229 | pt = jetMomentum.Pt();
|
---|
230 |
|
---|
231 | // loop over all input tracks
|
---|
232 | fItTrackInputArray->Reset();
|
---|
233 | while((track = static_cast<Candidate *>(fItTrackInputArray->Next())))
|
---|
234 | {
|
---|
235 | if((track->Momentum).Pt() < fTrackPTMin) continue;
|
---|
236 | if(jetMomentum.DeltaR(track->Momentum) <= fDeltaRTrack) {
|
---|
237 | identifier -= 1;
|
---|
238 | charge += track->Charge;
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | // loop over all input taus
|
---|
243 | itTauArray.Reset();
|
---|
244 | bool matchedTau = false;
|
---|
245 | while((tau = static_cast<Candidate *>(itTauArray.Next())))
|
---|
246 | {
|
---|
247 | if(tau->D1 < 0) continue;
|
---|
248 |
|
---|
249 | if(tau->D1 >= fParticleInputArray->GetEntriesFast() ||
|
---|
250 | tau->D2 >= fParticleInputArray->GetEntriesFast())
|
---|
251 | {
|
---|
252 | throw runtime_error("tau's daughter index is greater than the ParticleInputArray size");
|
---|
253 | }
|
---|
254 |
|
---|
255 | tauMomentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
|
---|
256 |
|
---|
257 | for(i = tau->D1; i <= tau->D2; ++i)
|
---|
258 | {
|
---|
259 | daughter = static_cast<Candidate *>(fParticleInputArray->At(i));
|
---|
260 | if(TMath::Abs(daughter->PID) == 16) continue;
|
---|
261 | tauMomentum += daughter->Momentum;
|
---|
262 | }
|
---|
263 |
|
---|
264 | if(jetMomentum.DeltaR(tauMomentum) <= fDeltaR)
|
---|
265 | {
|
---|
266 | matchedTau = true;
|
---|
267 | pdgCode = 15;
|
---|
268 | }
|
---|
269 | }
|
---|
270 | if(matchedTau)
|
---|
271 | identifier *= -1;
|
---|
272 | // find an efficency formula
|
---|
273 | // If the identifier is larger than 2, set it to 2 (multiprong requires at least 2 tracks)
|
---|
274 | if (identifier > 2)
|
---|
275 | identifier = 2;
|
---|
276 | else if (identifier < -2)
|
---|
277 | identifier = -2;
|
---|
278 |
|
---|
279 |
|
---|
280 | itEfficiencyMap = fEfficiencyMap.find(identifier);
|
---|
281 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
282 | {
|
---|
283 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
284 | }
|
---|
285 | formula = itEfficiencyMap->second;
|
---|
286 |
|
---|
287 | // apply an efficency formula
|
---|
288 |
|
---|
289 | // apply an efficency formula
|
---|
290 | jet->TauTag = gRandom->Uniform() <= formula->Eval(pt, eta);
|
---|
291 | // set tau charge
|
---|
292 | jet->Charge = charge;
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | //------------------------------------------------------------------------------
|
---|