Fork me on GitHub

source: git/modules/TauTagging.cc@ 20dc57b

Last change on this file since 20dc57b was 20dc57b, checked in by Sho Iwamoto <contact@…>, 10 years ago

variables should be declared closer to where used

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20/** \class TauTagging
21 *
22 * Determines origin of jet,
23 * applies b-tagging efficiency (miss identification rate) formulas
24 * and sets b-tagging flags
25 *
26 * \author P. Demin - UCL, Louvain-la-Neuve
27 *
28 */
29
30#include "modules/TauTagging.h"
31
32#include "classes/DelphesClasses.h"
33#include "classes/DelphesFactory.h"
34#include "classes/DelphesFormula.h"
35
36#include "TMath.h"
37#include "TString.h"
38#include "TFormula.h"
39#include "TRandom3.h"
40#include "TObjArray.h"
41#include "TDatabasePDG.h"
42#include "TLorentzVector.h"
43
44#include <algorithm>
45#include <stdexcept>
46#include <iostream>
47#include <sstream>
48
49using namespace std;
50
51
52//------------------------------------------------------------------------------
53TauTaggingPartonClassifier::TauTaggingPartonClassifier(const TObjArray *array) :
54 fParticleInputArray(array)
55{
56}
57
58//------------------------------------------------------------------------------
59
60Int_t TauTaggingPartonClassifier::GetCategory(TObject *object)
61{
62 Candidate *tau = static_cast<Candidate *>(object);
63
64 const TLorentzVector &momentum = tau->Momentum;
65
66 Int_t pdgCode = TMath::Abs(tau->PID);
67 if(pdgCode != 15) return -1;
68
69 if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
70
71 if(tau->D1 < 0) return -1;
72
73 if(tau->D2 < tau->D1) return -1;
74
75 if(tau->D1 >= fParticleInputArray->GetEntriesFast() ||
76 tau->D2 >= fParticleInputArray->GetEntriesFast())
77 {
78 throw runtime_error("tau's daughter index is greater than the ParticleInputArray size");
79 }
80
81 for(Int_t i = tau->D1; i <= tau->D2; ++i)
82 {
83 Candidate *daughter1 = static_cast<Candidate *>(fParticleInputArray->At(i));
84 pdgCode = TMath::Abs(daughter1->PID);
85 if(pdgCode == 11 || pdgCode == 13 || pdgCode == 15) return -1;
86 else if(pdgCode == 24)
87 {
88 if(daughter1->D1 < 0) return -1;
89 for(Int_t j = daughter1->D1; j <= daughter1->D2; ++j)
90 {
91 Candidate *daughter2 = static_cast<Candidate*>(fParticleInputArray->At(j));
92 pdgCode = TMath::Abs(daughter2->PID);
93 if(pdgCode == 11 || pdgCode == 13) return -1;
94 }
95
96 }
97 }
98
99 return 0;
100}
101
102//------------------------------------------------------------------------------
103
104TauTagging::TauTagging() :
105 fClassifier(0), fFilter(0),
106 fItPartonInputArray(0), fItJetInputArray(0)
107{
108}
109
110//------------------------------------------------------------------------------
111
112TauTagging::~TauTagging()
113{
114}
115
116//------------------------------------------------------------------------------
117
118void TauTagging::Init()
119{
120 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
121 ExRootConfParam param;
122 DelphesFormula *formula;
123 Int_t i, size;
124
125 fDeltaR = GetDouble("DeltaR", 0.5);
126
127 // read efficiency formulas
128 param = GetParam("EfficiencyFormula");
129 size = param.GetSize();
130
131 fEfficiencyMap.clear();
132 for(i = 0; i < size/2; ++i)
133 {
134 formula = new DelphesFormula;
135 formula->Compile(param[i*2 + 1].GetString());
136
137 fEfficiencyMap[param[i*2].GetInt()] = formula;
138 }
139
140 // set default efficiency formula
141 itEfficiencyMap = fEfficiencyMap.find(0);
142 if(itEfficiencyMap == fEfficiencyMap.end())
143 {
144 formula = new DelphesFormula;
145 formula->Compile("0.0");
146
147 fEfficiencyMap[0] = formula;
148 }
149
150 // import input array(s)
151
152 fParticleInputArray = ImportArray(GetString("ParticleInputArray", "Delphes/allParticles"));
153
154 fClassifier = new TauTaggingPartonClassifier(fParticleInputArray);
155 fClassifier->fPTMin = GetDouble("TauPTMin", 1.0);
156 fClassifier->fEtaMax = GetDouble("TauEtaMax", 2.5);
157
158 fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons"));
159 fItPartonInputArray = fPartonInputArray->MakeIterator();
160
161 fFilter = new ExRootFilter(fPartonInputArray);
162
163 fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
164 fItJetInputArray = fJetInputArray->MakeIterator();
165}
166
167//------------------------------------------------------------------------------
168
169void TauTagging::Finish()
170{
171 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
172 DelphesFormula *formula;
173
174 if(fFilter) delete fFilter;
175 if(fClassifier) delete fClassifier;
176 if(fItJetInputArray) delete fItJetInputArray;
177 if(fItPartonInputArray) delete fItPartonInputArray;
178
179 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
180 {
181 formula = itEfficiencyMap->second;
182 if(formula) delete formula;
183 }
184}
185
186//------------------------------------------------------------------------------
187
188void TauTagging::Process()
189{
190 Candidate *jet, *tau, *daughter;
191 TLorentzVector tauMomentum;
192 Double_t pt, eta, phi;
193 TObjArray *tauArray;
194 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
195 DelphesFormula *formula;
196 Int_t pdgCode, charge, i;
197
198 // select taus
199 fFilter->Reset();
200 tauArray = fFilter->GetSubArray(fClassifier, 0);
201
202 if(tauArray == 0) return;
203
204 TIter itTauArray(tauArray);
205
206 // loop over all input jets
207 fItJetInputArray->Reset();
208 while((jet = static_cast<Candidate *>(fItJetInputArray->Next())))
209 {
210 const TLorentzVector &jetMomentum = jet->Momentum;
211 pdgCode = 0;
212 charge = gRandom->Uniform() > 0.5 ? 1 : -1;
213 eta = jetMomentum.Eta();
214 phi = jetMomentum.Phi();
215 pt = jetMomentum.Pt();
216
217 // loop over all input taus
218 itTauArray.Reset();
219 while((tau = static_cast<Candidate *>(itTauArray.Next())))
220 {
221 if(tau->D1 < 0) continue;
222
223 if(tau->D1 >= fParticleInputArray->GetEntriesFast() ||
224 tau->D2 >= fParticleInputArray->GetEntriesFast())
225 {
226 throw runtime_error("tau's daughter index is greater than the ParticleInputArray size");
227 }
228
229 tauMomentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
230
231 for(i = tau->D1; i <= tau->D2; ++i)
232 {
233 daughter = static_cast<Candidate *>(fParticleInputArray->At(i));
234 if(TMath::Abs(daughter->PID) == 16) continue;
235 tauMomentum += daughter->Momentum;
236 }
237
238 if(jetMomentum.DeltaR(tauMomentum) <= fDeltaR)
239 {
240 pdgCode = 15;
241 charge = tau->Charge;
242 }
243 }
244 // find an efficency formula
245 itEfficiencyMap = fEfficiencyMap.find(pdgCode);
246 if(itEfficiencyMap == fEfficiencyMap.end())
247 {
248 itEfficiencyMap = fEfficiencyMap.find(0);
249 }
250 formula = itEfficiencyMap->second;
251
252 // apply an efficency formula
253 jet->TauTag = gRandom->Uniform() <= formula->Eval(pt, eta);
254 // set tau charge
255 jet->Charge = charge;
256 }
257}
258
259//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.