Fork me on GitHub

source: git/modules/BTagging.cc@ 4f7f2cd

ImprovedOutputFile Timing
Last change on this file since 4f7f2cd was 341014c, checked in by Pavel Demin <pavel-demin@…>, 5 years ago

apply .clang-format to all .h, .cc and .cpp files

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[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/** \class BTagging
20 *
21 * Determines origin of jet,
22 * applies b-tagging efficiency (miss identification rate) formulas
[fe0273c]23 * and sets b-tagging flags
[d7d2da3]24 *
25 * \author P. Demin - UCL, Louvain-la-Neuve
26 *
27 */
28
29#include "modules/BTagging.h"
30
31#include "classes/DelphesClasses.h"
32#include "classes/DelphesFactory.h"
33#include "classes/DelphesFormula.h"
34
35#include "TDatabasePDG.h"
[341014c]36#include "TFormula.h"
[d7d2da3]37#include "TLorentzVector.h"
[341014c]38#include "TMath.h"
39#include "TObjArray.h"
40#include "TRandom3.h"
41#include "TString.h"
[d7d2da3]42
[fe0273c]43#include <algorithm>
[d7d2da3]44#include <iostream>
45#include <sstream>
[341014c]46#include <stdexcept>
[d7d2da3]47
48using namespace std;
49
50//------------------------------------------------------------------------------
51
52BTagging::BTagging() :
[1180bc1]53 fItJetInputArray(0)
[d7d2da3]54{
55}
56
57//------------------------------------------------------------------------------
58
59BTagging::~BTagging()
60{
61}
62
63//------------------------------------------------------------------------------
64
65void BTagging::Init()
66{
[341014c]67 map<Int_t, DelphesFormula *>::iterator itEfficiencyMap;
[d7d2da3]68 ExRootConfParam param;
69 DelphesFormula *formula;
70 Int_t i, size;
71
[264bf40]72 fBitNumber = GetInt("BitNumber", 0);
73
[d7d2da3]74 // read efficiency formulas
75 param = GetParam("EfficiencyFormula");
76 size = param.GetSize();
[fe0273c]77
[d7d2da3]78 fEfficiencyMap.clear();
[341014c]79 for(i = 0; i < size / 2; ++i)
[d7d2da3]80 {
81 formula = new DelphesFormula;
[341014c]82 formula->Compile(param[i * 2 + 1].GetString());
[d7d2da3]83
[341014c]84 fEfficiencyMap[param[i * 2].GetInt()] = formula;
[d7d2da3]85 }
86
87 // set default efficiency formula
88 itEfficiencyMap = fEfficiencyMap.find(0);
89 if(itEfficiencyMap == fEfficiencyMap.end())
90 {
91 formula = new DelphesFormula;
92 formula->Compile("0.0");
93
94 fEfficiencyMap[0] = formula;
95 }
96
97 // import input array(s)
98
99 fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
100 fItJetInputArray = fJetInputArray->MakeIterator();
101}
102
103//------------------------------------------------------------------------------
104
105void BTagging::Finish()
106{
[341014c]107 map<Int_t, DelphesFormula *>::iterator itEfficiencyMap;
[d7d2da3]108 DelphesFormula *formula;
109
110 if(fItJetInputArray) delete fItJetInputArray;
111
112 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
113 {
114 formula = itEfficiencyMap->second;
115 if(formula) delete formula;
116 }
117}
118
119//------------------------------------------------------------------------------
120
121void BTagging::Process()
122{
[fe0273c]123 Candidate *jet;
[95aa610]124 Double_t pt, eta, phi, e;
[341014c]125 map<Int_t, DelphesFormula *>::iterator itEfficiencyMap;
[d7d2da3]126 DelphesFormula *formula;
127
128 // loop over all input jets
129 fItJetInputArray->Reset();
[341014c]130 while((jet = static_cast<Candidate *>(fItJetInputArray->Next())))
[d7d2da3]131 {
132 const TLorentzVector &jetMomentum = jet->Momentum;
133 eta = jetMomentum.Eta();
134 phi = jetMomentum.Phi();
135 pt = jetMomentum.Pt();
[95aa610]136 e = jetMomentum.E();
[d7d2da3]137
[8497ac6]138 // find an efficiency formula
[fe0273c]139 itEfficiencyMap = fEfficiencyMap.find(jet->Flavor);
[d7d2da3]140 if(itEfficiencyMap == fEfficiencyMap.end())
141 {
142 itEfficiencyMap = fEfficiencyMap.find(0);
143 }
144 formula = itEfficiencyMap->second;
145
[8497ac6]146 // apply an efficiency formula
[95aa610]147 jet->BTag |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
[fe0273c]148
[8497ac6]149 // find an efficiency formula for algo flavor definition
[fe0273c]150 itEfficiencyMap = fEfficiencyMap.find(jet->FlavorAlgo);
151 if(itEfficiencyMap == fEfficiencyMap.end())
152 {
153 itEfficiencyMap = fEfficiencyMap.find(0);
154 }
155 formula = itEfficiencyMap->second;
156
[8497ac6]157 // apply an efficiency formula
[fe0273c]158 jet->BTagAlgo |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
159
[8497ac6]160 // find an efficiency formula for phys flavor definition
[fe0273c]161 itEfficiencyMap = fEfficiencyMap.find(jet->FlavorPhys);
162 if(itEfficiencyMap == fEfficiencyMap.end())
163 {
164 itEfficiencyMap = fEfficiencyMap.find(0);
165 }
166 formula = itEfficiencyMap->second;
167
[8497ac6]168 // apply an efficiency formula
[fe0273c]169 jet->BTagPhys |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
[d7d2da3]170 }
171}
172
173//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.