Fork me on GitHub

source: svn/trunk/modules/BTagging.cc@ 1272

Last change on this file since 1272 was 1099, checked in by Pavel Demin, 11 years ago

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

  • Property svn:keywords set to Id Revision Date
File size: 5.2 KB
RevLine 
[694]1
[814]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: 2013-04-26 10:39:14 +0000 (Fri, 26 Apr 2013) $
9 * $Revision: 1099 $
10 *
11 *
12 * \author P. Demin - UCL, Louvain-la-Neuve
13 *
14 */
15
[694]16#include "modules/BTagging.h"
17
18#include "classes/DelphesClasses.h"
[703]19#include "classes/DelphesFactory.h"
[766]20#include "classes/DelphesFormula.h"
[694]21
[703]22#include "ExRootAnalysis/ExRootResult.h"
[694]23#include "ExRootAnalysis/ExRootFilter.h"
24#include "ExRootAnalysis/ExRootClassifier.h"
25
26#include "TMath.h"
27#include "TString.h"
28#include "TFormula.h"
[703]29#include "TRandom3.h"
30#include "TObjArray.h"
31#include "TDatabasePDG.h"
[694]32#include "TLorentzVector.h"
33
[703]34#include <algorithm>
35#include <stdexcept>
[694]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
[718]62 if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
[694]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() :
[703]73 fClassifier(0), fFilter(0),
[694]74 fItPartonInputArray(0), fItJetInputArray(0)
75{
76 fClassifier = new BTaggingPartonClassifier;
77}
78
79//------------------------------------------------------------------------------
80
81BTagging::~BTagging()
82{
[703]83 if(fClassifier) delete fClassifier;
[694]84}
85
86//------------------------------------------------------------------------------
87
88void BTagging::Init()
89{
[766]90 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
[703]91 ExRootConfParam param;
[766]92 DelphesFormula *formula;
[703]93 Int_t i, size;
94
[1099]95 fBitNumber = GetInt("BitNumber", 0);
96
[694]97 fDeltaR = GetDouble("DeltaR", 0.5);
98
99 fClassifier->fPTMin = GetDouble("PartonPTMin", 1.0);
100 fClassifier->fEtaMax = GetDouble("PartonEtaMax", 2.5);
101
[870]102 // read efficiency formulas
[703]103 param = GetParam("EfficiencyFormula");
104 size = param.GetSize();
105
106 fEfficiencyMap.clear();
107 for(i = 0; i < size/2; ++i)
108 {
[766]109 formula = new DelphesFormula;
[704]110 formula->Compile(param[i*2 + 1].GetString());
[694]111
[703]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 {
[766]119 formula = new DelphesFormula;
[703]120 formula->Compile("0.0");
121
122 fEfficiencyMap[0] = formula;
123 }
124
[694]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{
[766]140 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
141 DelphesFormula *formula;
[703]142
[694]143 if(fFilter) delete fFilter;
144 if(fItJetInputArray) delete fItJetInputArray;
145 if(fItPartonInputArray) delete fItPartonInputArray;
[703]146
147 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
148 {
149 formula = itEfficiencyMap->second;
150 if(formula) delete formula;
151 }
[694]152}
153
154//------------------------------------------------------------------------------
155
156void BTagging::Process()
157{
158 Candidate *jet, *parton;
[870]159 Double_t pt, eta, phi;
[694]160 TObjArray *partonArray;
[766]161 map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
162 DelphesFormula *formula;
[694]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 {
[870]177 const TLorentzVector &jetMomentum = jet->Momentum;
[694]178 pdgCodeMax = -1;
[870]179 eta = jetMomentum.Eta();
180 phi = jetMomentum.Phi();
181 pt = jetMomentum.Pt();
182
[694]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;
[718]189 if(jetMomentum.DeltaR(parton->Momentum) <= fDeltaR)
[694]190 {
191 if(pdgCodeMax < pdgCode) pdgCodeMax = pdgCode;
192 }
193 }
194 if(pdgCodeMax == 0) pdgCodeMax = 21;
195 if(pdgCodeMax == -1) pdgCodeMax = 0;
196
[703]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
[694]205 // apply an efficency formula
[1099]206 jet->BTag |= (gRandom->Uniform() <= formula->Eval(pt, eta)) << fBitNumber;
[694]207 }
208}
209
210//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.