Fork me on GitHub

source: git/modules/BTagging.cc@ fb21bc8

ImprovedOutputFile Timing dual_readout llp
Last change on this file since fb21bc8 was 264bf40, checked in by pavel <pavel@…>, 12 years ago

define BTag and TauTag as UInt_t and use them as a set of bits

  • Property mode set to 100644
File size: 5.2 KB
Line 
1
2/** \class BTagging
3 *
4 * Determines origin of jet,
5 * applies b-tagging efficiency (miss identification rate) formulas
6 * and sets b-tagging flags
7 *
8 * $Date$
9 * $Revision$
10 *
11 *
12 * \author P. Demin - UCL, Louvain-la-Neuve
13 *
14 */
15
16#include "modules/BTagging.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
39using namespace std;
40
41//------------------------------------------------------------------------------
42
43class BTaggingPartonClassifier : public ExRootClassifier
44{
45public:
46
47 BTaggingPartonClassifier() {}
48
49 Int_t GetCategory(TObject *object);
50
51 Double_t fEtaMax, fPTMin;
52};
53
54//------------------------------------------------------------------------------
55
56Int_t BTaggingPartonClassifier::GetCategory(TObject *object)
57{
58 Candidate *parton = static_cast<Candidate*>(object);
59 const TLorentzVector &momentum = parton->Momentum;
60 Int_t pdgCode;
61
62 if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
63
64 pdgCode = TMath::Abs(parton->PID);
65 if(pdgCode != 21 && pdgCode > 5) return -1;
66
67 return 0;
68}
69
70//------------------------------------------------------------------------------
71
72BTagging::BTagging() :
73 fClassifier(0), fFilter(0),
74 fItPartonInputArray(0), fItJetInputArray(0)
75{
76 fClassifier = new BTaggingPartonClassifier;
77}
78
79//------------------------------------------------------------------------------
80
81BTagging::~BTagging()
82{
83 if(fClassifier) delete fClassifier;
84}
85
86//------------------------------------------------------------------------------
87
88void BTagging::Init()
89{
90 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
91 ExRootConfParam param;
92 DelphesFormula *formula;
93 Int_t i, size;
94
95 fBitNumber = GetInt("BitNumber", 0);
96
97 fDeltaR = GetDouble("DeltaR", 0.5);
98
99 fClassifier->fPTMin = GetDouble("PartonPTMin", 1.0);
100 fClassifier->fEtaMax = GetDouble("PartonEtaMax", 2.5);
101
102 // read efficiency formulas
103 param = GetParam("EfficiencyFormula");
104 size = param.GetSize();
105
106 fEfficiencyMap.clear();
107 for(i = 0; i < size/2; ++i)
108 {
109 formula = new DelphesFormula;
110 formula->Compile(param[i*2 + 1].GetString());
111
112 fEfficiencyMap[param[i*2].GetInt()] = formula;
113 }
114
115 // set default efficiency formula
116 itEfficiencyMap = fEfficiencyMap.find(0);
117 if(itEfficiencyMap == fEfficiencyMap.end())
118 {
119 formula = new DelphesFormula;
120 formula->Compile("0.0");
121
122 fEfficiencyMap[0] = formula;
123 }
124
125 // import input array(s)
126
127 fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons"));
128 fItPartonInputArray = fPartonInputArray->MakeIterator();
129
130 fFilter = new ExRootFilter(fPartonInputArray);
131
132 fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
133 fItJetInputArray = fJetInputArray->MakeIterator();
134}
135
136//------------------------------------------------------------------------------
137
138void BTagging::Finish()
139{
140 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
141 DelphesFormula *formula;
142
143 if(fFilter) delete fFilter;
144 if(fItJetInputArray) delete fItJetInputArray;
145 if(fItPartonInputArray) delete fItPartonInputArray;
146
147 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
148 {
149 formula = itEfficiencyMap->second;
150 if(formula) delete formula;
151 }
152}
153
154//------------------------------------------------------------------------------
155
156void BTagging::Process()
157{
158 Candidate *jet, *parton;
159 Double_t pt, eta, phi;
160 TObjArray *partonArray;
161 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
162 DelphesFormula *formula;
163 Int_t pdgCode, pdgCodeMax;
164
165 // select quark and gluons
166 fFilter->Reset();
167 partonArray = fFilter->GetSubArray(fClassifier, 0);
168
169 if(partonArray == 0) return;
170
171 TIter itPartonArray(partonArray);
172
173 // loop over all input jets
174 fItJetInputArray->Reset();
175 while((jet = static_cast<Candidate*>(fItJetInputArray->Next())))
176 {
177 const TLorentzVector &jetMomentum = jet->Momentum;
178 pdgCodeMax = -1;
179 eta = jetMomentum.Eta();
180 phi = jetMomentum.Phi();
181 pt = jetMomentum.Pt();
182
183 // loop over all input partons
184 itPartonArray.Reset();
185 while((parton = static_cast<Candidate*>(itPartonArray.Next())))
186 {
187 pdgCode = TMath::Abs(parton->PID);
188 if(pdgCode == 21) pdgCode = 0;
189 if(jetMomentum.DeltaR(parton->Momentum) <= fDeltaR)
190 {
191 if(pdgCodeMax < pdgCode) pdgCodeMax = pdgCode;
192 }
193 }
194 if(pdgCodeMax == 0) pdgCodeMax = 21;
195 if(pdgCodeMax == -1) pdgCodeMax = 0;
196
197 // find an efficency formula
198 itEfficiencyMap = fEfficiencyMap.find(pdgCodeMax);
199 if(itEfficiencyMap == fEfficiencyMap.end())
200 {
201 itEfficiencyMap = fEfficiencyMap.find(0);
202 }
203 formula = itEfficiencyMap->second;
204
205 // apply an efficency formula
206 jet->BTag |= (gRandom->Uniform() <= formula->Eval(pt, eta)) << fBitNumber;
207 }
208}
209
210//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.