[b443089] | 1 | /*
|
---|
| 2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
| 3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
[1fa50c2] | 4 | *
|
---|
[b443089] | 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.
|
---|
[1fa50c2] | 9 | *
|
---|
[b443089] | 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.
|
---|
[1fa50c2] | 14 | *
|
---|
[b443089] | 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 |
|
---|
[d7d2da3] | 19 |
|
---|
| 20 | /** \class BTagging
|
---|
| 21 | *
|
---|
| 22 | * Determines origin of jet,
|
---|
| 23 | * applies b-tagging efficiency (miss identification rate) formulas
|
---|
[fe0273c] | 24 | * and sets b-tagging flags
|
---|
[d7d2da3] | 25 | *
|
---|
| 26 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
| 27 | *
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | #include "modules/BTagging.h"
|
---|
| 31 |
|
---|
| 32 | #include "classes/DelphesClasses.h"
|
---|
| 33 | #include "classes/DelphesFactory.h"
|
---|
| 34 | #include "classes/DelphesFormula.h"
|
---|
| 35 |
|
---|
| 36 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
| 37 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
| 38 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
| 39 |
|
---|
| 40 | #include "TMath.h"
|
---|
| 41 | #include "TString.h"
|
---|
| 42 | #include "TFormula.h"
|
---|
| 43 | #include "TRandom3.h"
|
---|
| 44 | #include "TObjArray.h"
|
---|
| 45 | #include "TDatabasePDG.h"
|
---|
| 46 | #include "TLorentzVector.h"
|
---|
| 47 |
|
---|
[fe0273c] | 48 | #include <algorithm>
|
---|
[d7d2da3] | 49 | #include <stdexcept>
|
---|
| 50 | #include <iostream>
|
---|
| 51 | #include <sstream>
|
---|
| 52 |
|
---|
| 53 | using namespace std;
|
---|
| 54 |
|
---|
| 55 | //------------------------------------------------------------------------------
|
---|
| 56 |
|
---|
| 57 | class BTaggingPartonClassifier : public ExRootClassifier
|
---|
| 58 | {
|
---|
| 59 | public:
|
---|
| 60 |
|
---|
| 61 | BTaggingPartonClassifier() {}
|
---|
| 62 |
|
---|
| 63 | Int_t GetCategory(TObject *object);
|
---|
[fe0273c] | 64 |
|
---|
[d7d2da3] | 65 | Double_t fEtaMax, fPTMin;
|
---|
| 66 | };
|
---|
| 67 |
|
---|
| 68 | //------------------------------------------------------------------------------
|
---|
| 69 |
|
---|
| 70 | Int_t BTaggingPartonClassifier::GetCategory(TObject *object)
|
---|
| 71 | {
|
---|
| 72 | Candidate *parton = static_cast<Candidate*>(object);
|
---|
| 73 | const TLorentzVector &momentum = parton->Momentum;
|
---|
| 74 | Int_t pdgCode;
|
---|
| 75 |
|
---|
| 76 | if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
|
---|
[fe0273c] | 77 |
|
---|
[d7d2da3] | 78 | pdgCode = TMath::Abs(parton->PID);
|
---|
| 79 | if(pdgCode != 21 && pdgCode > 5) return -1;
|
---|
| 80 |
|
---|
| 81 | return 0;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | //------------------------------------------------------------------------------
|
---|
| 85 |
|
---|
| 86 | BTagging::BTagging() :
|
---|
| 87 | fClassifier(0), fFilter(0),
|
---|
| 88 | fItPartonInputArray(0), fItJetInputArray(0)
|
---|
| 89 | {
|
---|
| 90 | fClassifier = new BTaggingPartonClassifier;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | //------------------------------------------------------------------------------
|
---|
| 94 |
|
---|
| 95 | BTagging::~BTagging()
|
---|
| 96 | {
|
---|
| 97 | if(fClassifier) delete fClassifier;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | //------------------------------------------------------------------------------
|
---|
| 101 |
|
---|
| 102 | void BTagging::Init()
|
---|
| 103 | {
|
---|
| 104 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
|
---|
| 105 | ExRootConfParam param;
|
---|
| 106 | DelphesFormula *formula;
|
---|
| 107 | Int_t i, size;
|
---|
| 108 |
|
---|
[264bf40] | 109 | fBitNumber = GetInt("BitNumber", 0);
|
---|
| 110 |
|
---|
[d7d2da3] | 111 | fDeltaR = GetDouble("DeltaR", 0.5);
|
---|
| 112 |
|
---|
| 113 | fClassifier->fPTMin = GetDouble("PartonPTMin", 1.0);
|
---|
| 114 | fClassifier->fEtaMax = GetDouble("PartonEtaMax", 2.5);
|
---|
| 115 |
|
---|
| 116 | // read efficiency formulas
|
---|
| 117 | param = GetParam("EfficiencyFormula");
|
---|
| 118 | size = param.GetSize();
|
---|
[fe0273c] | 119 |
|
---|
[d7d2da3] | 120 | fEfficiencyMap.clear();
|
---|
| 121 | for(i = 0; i < size/2; ++i)
|
---|
| 122 | {
|
---|
| 123 | formula = new DelphesFormula;
|
---|
| 124 | formula->Compile(param[i*2 + 1].GetString());
|
---|
| 125 |
|
---|
| 126 | fEfficiencyMap[param[i*2].GetInt()] = formula;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | // set default efficiency formula
|
---|
| 130 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
| 131 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
| 132 | {
|
---|
| 133 | formula = new DelphesFormula;
|
---|
| 134 | formula->Compile("0.0");
|
---|
| 135 |
|
---|
| 136 | fEfficiencyMap[0] = formula;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | // import input array(s)
|
---|
| 140 |
|
---|
| 141 | fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons"));
|
---|
| 142 | fItPartonInputArray = fPartonInputArray->MakeIterator();
|
---|
| 143 |
|
---|
| 144 | fFilter = new ExRootFilter(fPartonInputArray);
|
---|
[fe0273c] | 145 |
|
---|
[d7d2da3] | 146 | fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
|
---|
| 147 | fItJetInputArray = fJetInputArray->MakeIterator();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | //------------------------------------------------------------------------------
|
---|
| 151 |
|
---|
| 152 | void BTagging::Finish()
|
---|
| 153 | {
|
---|
| 154 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
|
---|
| 155 | DelphesFormula *formula;
|
---|
| 156 |
|
---|
| 157 | if(fFilter) delete fFilter;
|
---|
| 158 | if(fItJetInputArray) delete fItJetInputArray;
|
---|
| 159 | if(fItPartonInputArray) delete fItPartonInputArray;
|
---|
| 160 |
|
---|
| 161 | for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
|
---|
| 162 | {
|
---|
| 163 | formula = itEfficiencyMap->second;
|
---|
| 164 | if(formula) delete formula;
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | //------------------------------------------------------------------------------
|
---|
| 169 |
|
---|
| 170 | void BTagging::Process()
|
---|
| 171 | {
|
---|
[fe0273c] | 172 | Candidate *jet;
|
---|
[95aa610] | 173 | Double_t pt, eta, phi, e;
|
---|
[d7d2da3] | 174 | TObjArray *partonArray;
|
---|
| 175 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
|
---|
| 176 | DelphesFormula *formula;
|
---|
| 177 |
|
---|
| 178 | // select quark and gluons
|
---|
| 179 | fFilter->Reset();
|
---|
| 180 | partonArray = fFilter->GetSubArray(fClassifier, 0);
|
---|
[fe0273c] | 181 |
|
---|
[d7d2da3] | 182 | if(partonArray == 0) return;
|
---|
| 183 |
|
---|
| 184 | TIter itPartonArray(partonArray);
|
---|
[fe0273c] | 185 |
|
---|
[d7d2da3] | 186 | // loop over all input jets
|
---|
| 187 | fItJetInputArray->Reset();
|
---|
| 188 | while((jet = static_cast<Candidate*>(fItJetInputArray->Next())))
|
---|
| 189 | {
|
---|
| 190 | const TLorentzVector &jetMomentum = jet->Momentum;
|
---|
| 191 | eta = jetMomentum.Eta();
|
---|
| 192 | phi = jetMomentum.Phi();
|
---|
| 193 | pt = jetMomentum.Pt();
|
---|
[95aa610] | 194 | e = jetMomentum.E();
|
---|
[d7d2da3] | 195 |
|
---|
[8497ac6] | 196 | // find an efficiency formula
|
---|
[fe0273c] | 197 | itEfficiencyMap = fEfficiencyMap.find(jet->Flavor);
|
---|
[d7d2da3] | 198 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
| 199 | {
|
---|
| 200 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
| 201 | }
|
---|
| 202 | formula = itEfficiencyMap->second;
|
---|
| 203 |
|
---|
[8497ac6] | 204 | // apply an efficiency formula
|
---|
[95aa610] | 205 | jet->BTag |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
|
---|
[fe0273c] | 206 |
|
---|
[8497ac6] | 207 | // find an efficiency formula for algo flavor definition
|
---|
[fe0273c] | 208 | itEfficiencyMap = fEfficiencyMap.find(jet->FlavorAlgo);
|
---|
| 209 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
| 210 | {
|
---|
| 211 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
| 212 | }
|
---|
| 213 | formula = itEfficiencyMap->second;
|
---|
| 214 |
|
---|
[8497ac6] | 215 | // apply an efficiency formula
|
---|
[fe0273c] | 216 | jet->BTagAlgo |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
|
---|
| 217 |
|
---|
[8497ac6] | 218 | // find an efficiency formula for phys flavor definition
|
---|
[fe0273c] | 219 | itEfficiencyMap = fEfficiencyMap.find(jet->FlavorPhys);
|
---|
| 220 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
| 221 | {
|
---|
| 222 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
| 223 | }
|
---|
| 224 | formula = itEfficiencyMap->second;
|
---|
| 225 |
|
---|
[8497ac6] | 226 | // apply an efficiency formula
|
---|
[fe0273c] | 227 | jet->BTagPhys |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
|
---|
[d7d2da3] | 228 | }
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | //------------------------------------------------------------------------------
|
---|