[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 TauTagging
|
---|
| 20 | *
|
---|
| 21 | * Determines origin of jet,
|
---|
| 22 | * applies b-tagging efficiency (miss identification rate) formulas
|
---|
| 23 | * and sets b-tagging flags
|
---|
| 24 | *
|
---|
| 25 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
| 26 | *
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include "modules/TauTagging.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 |
|
---|
| 43 | #include <algorithm>
|
---|
| 44 | #include <iostream>
|
---|
| 45 | #include <sstream>
|
---|
[341014c] | 46 | #include <stdexcept>
|
---|
[d7d2da3] | 47 |
|
---|
| 48 | using namespace std;
|
---|
| 49 |
|
---|
| 50 | //------------------------------------------------------------------------------
|
---|
| 51 | TauTaggingPartonClassifier::TauTaggingPartonClassifier(const TObjArray *array) :
|
---|
| 52 | fParticleInputArray(array)
|
---|
| 53 | {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | //------------------------------------------------------------------------------
|
---|
| 57 |
|
---|
| 58 | Int_t TauTaggingPartonClassifier::GetCategory(TObject *object)
|
---|
| 59 | {
|
---|
| 60 | Candidate *tau = static_cast<Candidate *>(object);
|
---|
[50d7259] | 61 | Candidate *daughter1 = 0;
|
---|
| 62 | Candidate *daughter2 = 0;
|
---|
[341014c] | 63 |
|
---|
[d7d2da3] | 64 | const TLorentzVector &momentum = tau->Momentum;
|
---|
[50d7259] | 65 | Int_t pdgCode, i, j;
|
---|
[d7d2da3] | 66 |
|
---|
| 67 | pdgCode = TMath::Abs(tau->PID);
|
---|
| 68 | if(pdgCode != 15) return -1;
|
---|
| 69 |
|
---|
| 70 | if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
|
---|
| 71 |
|
---|
| 72 | if(tau->D1 < 0) return -1;
|
---|
| 73 |
|
---|
[8ab9694] | 74 | if(tau->D2 < tau->D1) return -1;
|
---|
| 75 |
|
---|
[341014c] | 76 | if(tau->D1 >= fParticleInputArray->GetEntriesFast() || tau->D2 >= fParticleInputArray->GetEntriesFast())
|
---|
[6c565cc] | 77 | {
|
---|
| 78 | throw runtime_error("tau's daughter index is greater than the ParticleInputArray size");
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[d7d2da3] | 81 | for(i = tau->D1; i <= tau->D2; ++i)
|
---|
| 82 | {
|
---|
[50d7259] | 83 | daughter1 = static_cast<Candidate *>(fParticleInputArray->At(i));
|
---|
| 84 | pdgCode = TMath::Abs(daughter1->PID);
|
---|
[9e08f27] | 85 | //if(pdgCode == 11 || pdgCode == 13 || pdgCode == 15)
|
---|
| 86 | // return -1;
|
---|
| 87 | if(pdgCode == 24)
|
---|
[50d7259] | 88 | {
|
---|
[341014c] | 89 | if(daughter1->D1 < 0) return -1;
|
---|
| 90 | for(j = daughter1->D1; j <= daughter1->D2; ++j)
|
---|
| 91 | {
|
---|
| 92 | daughter2 = static_cast<Candidate *>(fParticleInputArray->At(j));
|
---|
| 93 | pdgCode = TMath::Abs(daughter2->PID);
|
---|
| 94 | if(pdgCode == 11 || pdgCode == 13) return -1;
|
---|
| 95 | }
|
---|
[50d7259] | 96 | }
|
---|
[d7d2da3] | 97 | }
|
---|
| 98 | return 0;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | //------------------------------------------------------------------------------
|
---|
| 102 |
|
---|
| 103 | TauTagging::TauTagging() :
|
---|
| 104 | fClassifier(0), fFilter(0),
|
---|
| 105 | fItPartonInputArray(0), fItJetInputArray(0)
|
---|
| 106 | {
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | //------------------------------------------------------------------------------
|
---|
| 110 |
|
---|
| 111 | TauTagging::~TauTagging()
|
---|
| 112 | {
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | //------------------------------------------------------------------------------
|
---|
| 116 |
|
---|
| 117 | void TauTagging::Init()
|
---|
| 118 | {
|
---|
[341014c] | 119 | map<Int_t, DelphesFormula *>::iterator itEfficiencyMap;
|
---|
[d7d2da3] | 120 | ExRootConfParam param;
|
---|
| 121 | DelphesFormula *formula;
|
---|
| 122 | Int_t i, size;
|
---|
| 123 |
|
---|
[7e227ae] | 124 | fBitNumber = GetInt("BitNumber", 0);
|
---|
| 125 |
|
---|
[d7d2da3] | 126 | fDeltaR = GetDouble("DeltaR", 0.5);
|
---|
| 127 |
|
---|
| 128 | // read efficiency formulas
|
---|
| 129 | param = GetParam("EfficiencyFormula");
|
---|
| 130 | size = param.GetSize();
|
---|
| 131 |
|
---|
| 132 | fEfficiencyMap.clear();
|
---|
[341014c] | 133 | for(i = 0; i < size / 2; ++i)
|
---|
[d7d2da3] | 134 | {
|
---|
| 135 | formula = new DelphesFormula;
|
---|
[341014c] | 136 | formula->Compile(param[i * 2 + 1].GetString());
|
---|
[d7d2da3] | 137 |
|
---|
[341014c] | 138 | fEfficiencyMap[param[i * 2].GetInt()] = formula;
|
---|
[d7d2da3] | 139 | }
|
---|
| 140 |
|
---|
| 141 | // set default efficiency formula
|
---|
| 142 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
| 143 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
| 144 | {
|
---|
| 145 | formula = new DelphesFormula;
|
---|
| 146 | formula->Compile("0.0");
|
---|
| 147 |
|
---|
| 148 | fEfficiencyMap[0] = formula;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | // import input array(s)
|
---|
| 152 |
|
---|
| 153 | fParticleInputArray = ImportArray(GetString("ParticleInputArray", "Delphes/allParticles"));
|
---|
| 154 |
|
---|
| 155 | fClassifier = new TauTaggingPartonClassifier(fParticleInputArray);
|
---|
| 156 | fClassifier->fPTMin = GetDouble("TauPTMin", 1.0);
|
---|
| 157 | fClassifier->fEtaMax = GetDouble("TauEtaMax", 2.5);
|
---|
| 158 |
|
---|
| 159 | fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons"));
|
---|
| 160 | fItPartonInputArray = fPartonInputArray->MakeIterator();
|
---|
| 161 |
|
---|
| 162 | fFilter = new ExRootFilter(fPartonInputArray);
|
---|
| 163 |
|
---|
| 164 | fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
|
---|
| 165 | fItJetInputArray = fJetInputArray->MakeIterator();
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | //------------------------------------------------------------------------------
|
---|
| 169 |
|
---|
| 170 | void TauTagging::Finish()
|
---|
| 171 | {
|
---|
[341014c] | 172 | map<Int_t, DelphesFormula *>::iterator itEfficiencyMap;
|
---|
[d7d2da3] | 173 | DelphesFormula *formula;
|
---|
| 174 |
|
---|
| 175 | if(fFilter) delete fFilter;
|
---|
| 176 | if(fClassifier) delete fClassifier;
|
---|
| 177 | if(fItJetInputArray) delete fItJetInputArray;
|
---|
| 178 | if(fItPartonInputArray) delete fItPartonInputArray;
|
---|
| 179 |
|
---|
| 180 | for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
|
---|
| 181 | {
|
---|
| 182 | formula = itEfficiencyMap->second;
|
---|
| 183 | if(formula) delete formula;
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | //------------------------------------------------------------------------------
|
---|
| 188 |
|
---|
| 189 | void TauTagging::Process()
|
---|
| 190 | {
|
---|
[9e08f27] | 191 | Candidate *jet, *tau, *daughter, *part;
|
---|
[f229d8a] | 192 | TLorentzVector tauMomentum;
|
---|
[95fbe30] | 193 | Double_t pt, eta, phi, e, eff;
|
---|
[d7d2da3] | 194 | TObjArray *tauArray;
|
---|
[341014c] | 195 | map<Int_t, DelphesFormula *>::iterator itEfficiencyMap;
|
---|
[d7d2da3] | 196 | DelphesFormula *formula;
|
---|
[f229d8a] | 197 | Int_t pdgCode, charge, i;
|
---|
[d7d2da3] | 198 |
|
---|
| 199 | // select taus
|
---|
| 200 | fFilter->Reset();
|
---|
| 201 | tauArray = fFilter->GetSubArray(fClassifier, 0);
|
---|
| 202 |
|
---|
| 203 | // loop over all input jets
|
---|
| 204 | fItJetInputArray->Reset();
|
---|
[9e08f27] | 205 |
|
---|
[d7d2da3] | 206 | while((jet = static_cast<Candidate *>(fItJetInputArray->Next())))
|
---|
| 207 | {
|
---|
[9e08f27] | 208 |
|
---|
[d7d2da3] | 209 | const TLorentzVector &jetMomentum = jet->Momentum;
|
---|
| 210 | pdgCode = 0;
|
---|
| 211 | charge = gRandom->Uniform() > 0.5 ? 1 : -1;
|
---|
| 212 | eta = jetMomentum.Eta();
|
---|
| 213 | phi = jetMomentum.Phi();
|
---|
| 214 | pt = jetMomentum.Pt();
|
---|
[7e227ae] | 215 | e = jetMomentum.E();
|
---|
[d7d2da3] | 216 |
|
---|
| 217 | // loop over all input taus
|
---|
[341014c] | 218 | if(tauArray)
|
---|
| 219 | {
|
---|
[69bf964] | 220 | TIter itTauArray(tauArray);
|
---|
| 221 | while((tau = static_cast<Candidate *>(itTauArray.Next())))
|
---|
[d7d2da3] | 222 | {
|
---|
[69bf964] | 223 | if(tau->D1 < 0) continue;
|
---|
| 224 |
|
---|
[341014c] | 225 | if(tau->D1 >= fParticleInputArray->GetEntriesFast() || tau->D2 >= fParticleInputArray->GetEntriesFast())
|
---|
[69bf964] | 226 | {
|
---|
| 227 | throw runtime_error("tau's daughter index is greater than the ParticleInputArray size");
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | tauMomentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
|
---|
| 231 |
|
---|
| 232 | for(i = tau->D1; i <= tau->D2; ++i)
|
---|
| 233 | {
|
---|
| 234 | daughter = static_cast<Candidate *>(fParticleInputArray->At(i));
|
---|
| 235 | if(TMath::Abs(daughter->PID) == 16) continue;
|
---|
| 236 | tauMomentum += daughter->Momentum;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | if(jetMomentum.DeltaR(tauMomentum) <= fDeltaR)
|
---|
| 240 | {
|
---|
| 241 | pdgCode = 15;
|
---|
| 242 | charge = tau->Charge;
|
---|
| 243 | }
|
---|
[d7d2da3] | 244 | }
|
---|
| 245 | }
|
---|
[9e08f27] | 246 |
|
---|
| 247 | // fake electrons and muons
|
---|
| 248 |
|
---|
| 249 | if (pdgCode == 0)
|
---|
| 250 | {
|
---|
| 251 |
|
---|
| 252 | Double_t drMin = fDeltaR;
|
---|
| 253 | fItPartonInputArray->Reset();
|
---|
| 254 | while((part = static_cast<Candidate *>(fItPartonInputArray->Next())))
|
---|
| 255 | {
|
---|
| 256 | if(TMath::Abs(part->PID) == 11 || TMath::Abs(part->PID) == 13)
|
---|
| 257 | {
|
---|
| 258 | tauMomentum = part->Momentum;
|
---|
| 259 | if (tauMomentum.Pt() < fClassifier->fPTMin) continue;
|
---|
| 260 | if (TMath::Abs(tauMomentum.Eta()) > fClassifier->fEtaMax) continue;
|
---|
| 261 |
|
---|
| 262 | Double_t dr = jetMomentum.DeltaR(tauMomentum);
|
---|
| 263 | if( dr < drMin)
|
---|
| 264 | {
|
---|
| 265 | drMin = dr;
|
---|
| 266 | pdgCode = TMath::Abs(part->PID);
|
---|
| 267 | charge = part->Charge;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 |
|
---|
[d7d2da3] | 273 | // find an efficency formula
|
---|
| 274 | itEfficiencyMap = fEfficiencyMap.find(pdgCode);
|
---|
| 275 | if(itEfficiencyMap == fEfficiencyMap.end())
|
---|
| 276 | {
|
---|
| 277 | itEfficiencyMap = fEfficiencyMap.find(0);
|
---|
| 278 | }
|
---|
| 279 | formula = itEfficiencyMap->second;
|
---|
| 280 |
|
---|
| 281 | // apply an efficency formula
|
---|
[95fbe30] | 282 | eff = formula->Eval(pt, eta, phi, e);
|
---|
[7429c6a] | 283 | jet->TauTag |= (gRandom->Uniform() <= eff) << fBitNumber;
|
---|
[341014c] | 284 | jet->TauWeight = eff;
|
---|
[7429c6a] | 285 |
|
---|
[d7d2da3] | 286 | // set tau charge
|
---|
| 287 | jet->Charge = charge;
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | //------------------------------------------------------------------------------
|
---|