[5] | 1 | |
---|
| 2 | /** \class TauTagging |
---|
| 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-03-21 00:23:25 +0100 (Thu, 21 Mar 2013) $ |
---|
| 9 | * $Revision: 1065 $ |
---|
| 10 | * |
---|
| 11 | * |
---|
| 12 | * \author P. Demin - UCL, Louvain-la-Neuve |
---|
| 13 | * |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "modules/TauTagging.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 | |
---|
| 39 | using namespace std; |
---|
| 40 | |
---|
| 41 | //------------------------------------------------------------------------------ |
---|
| 42 | |
---|
| 43 | class TauTaggingPartonClassifier : public ExRootClassifier |
---|
| 44 | { |
---|
| 45 | public: |
---|
| 46 | |
---|
| 47 | TauTaggingPartonClassifier(const TObjArray *array); |
---|
| 48 | |
---|
| 49 | Int_t GetCategory(TObject *object); |
---|
| 50 | |
---|
| 51 | Double_t fEtaMax, fPTMin; |
---|
| 52 | |
---|
| 53 | const TObjArray *fParticleInputArray; |
---|
| 54 | }; |
---|
| 55 | |
---|
| 56 | //------------------------------------------------------------------------------ |
---|
| 57 | TauTaggingPartonClassifier::TauTaggingPartonClassifier(const TObjArray *array) : |
---|
| 58 | fParticleInputArray(array) |
---|
| 59 | { |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | //------------------------------------------------------------------------------ |
---|
| 63 | |
---|
| 64 | Int_t TauTaggingPartonClassifier::GetCategory(TObject *object) |
---|
| 65 | { |
---|
| 66 | Candidate *tau = static_cast<Candidate *>(object); |
---|
| 67 | Candidate *daughter = 0; |
---|
| 68 | const TLorentzVector &momentum = tau->Momentum; |
---|
| 69 | Int_t pdgCode, i; |
---|
| 70 | |
---|
| 71 | pdgCode = TMath::Abs(tau->PID); |
---|
| 72 | if(pdgCode != 15) return -1; |
---|
| 73 | |
---|
| 74 | if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1; |
---|
| 75 | |
---|
| 76 | if(tau->D1 < 0) return -1; |
---|
| 77 | |
---|
| 78 | for(i = tau->D1; i <= tau->D2; ++i) |
---|
| 79 | { |
---|
| 80 | daughter = static_cast<Candidate *>(fParticleInputArray->At(i)); |
---|
| 81 | pdgCode = TMath::Abs(daughter->PID); |
---|
| 82 | if(pdgCode == 11 || pdgCode == 13 || pdgCode == 15 || pdgCode == 24) return -1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | return 0; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | //------------------------------------------------------------------------------ |
---|
| 89 | |
---|
| 90 | TauTagging::TauTagging() : |
---|
| 91 | fClassifier(0), fFilter(0), |
---|
| 92 | fItPartonInputArray(0), fItJetInputArray(0) |
---|
| 93 | { |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | //------------------------------------------------------------------------------ |
---|
| 97 | |
---|
| 98 | TauTagging::~TauTagging() |
---|
| 99 | { |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | //------------------------------------------------------------------------------ |
---|
| 103 | |
---|
| 104 | void TauTagging::Init() |
---|
| 105 | { |
---|
| 106 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap; |
---|
| 107 | ExRootConfParam param; |
---|
| 108 | DelphesFormula *formula; |
---|
| 109 | Int_t i, size; |
---|
| 110 | |
---|
| 111 | fDeltaR = GetDouble("DeltaR", 0.5); |
---|
| 112 | |
---|
| 113 | // read efficiency formulas |
---|
| 114 | param = GetParam("EfficiencyFormula"); |
---|
| 115 | size = param.GetSize(); |
---|
| 116 | |
---|
| 117 | fEfficiencyMap.clear(); |
---|
| 118 | for(i = 0; i < size/2; ++i) |
---|
| 119 | { |
---|
| 120 | formula = new DelphesFormula; |
---|
| 121 | formula->Compile(param[i*2 + 1].GetString()); |
---|
| 122 | |
---|
| 123 | fEfficiencyMap[param[i*2].GetInt()] = formula; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // set default efficiency formula |
---|
| 127 | itEfficiencyMap = fEfficiencyMap.find(0); |
---|
| 128 | if(itEfficiencyMap == fEfficiencyMap.end()) |
---|
| 129 | { |
---|
| 130 | formula = new DelphesFormula; |
---|
| 131 | formula->Compile("0.0"); |
---|
| 132 | |
---|
| 133 | fEfficiencyMap[0] = formula; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // import input array(s) |
---|
| 137 | |
---|
| 138 | fParticleInputArray = ImportArray(GetString("ParticleInputArray", "Delphes/allParticles")); |
---|
| 139 | |
---|
| 140 | fClassifier = new TauTaggingPartonClassifier(fParticleInputArray); |
---|
| 141 | fClassifier->fPTMin = GetDouble("TauPTMin", 1.0); |
---|
| 142 | fClassifier->fEtaMax = GetDouble("TauEtaMax", 2.5); |
---|
| 143 | |
---|
| 144 | fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons")); |
---|
| 145 | fItPartonInputArray = fPartonInputArray->MakeIterator(); |
---|
| 146 | |
---|
| 147 | fFilter = new ExRootFilter(fPartonInputArray); |
---|
| 148 | |
---|
| 149 | fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets")); |
---|
| 150 | fItJetInputArray = fJetInputArray->MakeIterator(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | //------------------------------------------------------------------------------ |
---|
| 154 | |
---|
| 155 | void TauTagging::Finish() |
---|
| 156 | { |
---|
| 157 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap; |
---|
| 158 | DelphesFormula *formula; |
---|
| 159 | |
---|
| 160 | if(fFilter) delete fFilter; |
---|
| 161 | if(fClassifier) delete fClassifier; |
---|
| 162 | if(fItJetInputArray) delete fItJetInputArray; |
---|
| 163 | if(fItPartonInputArray) delete fItPartonInputArray; |
---|
| 164 | |
---|
| 165 | for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap) |
---|
| 166 | { |
---|
| 167 | formula = itEfficiencyMap->second; |
---|
| 168 | if(formula) delete formula; |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | //------------------------------------------------------------------------------ |
---|
| 173 | |
---|
| 174 | void TauTagging::Process() |
---|
| 175 | { |
---|
| 176 | Candidate *jet, *tau; |
---|
| 177 | Double_t pt, eta, phi; |
---|
| 178 | TObjArray *tauArray; |
---|
| 179 | map< Int_t, DelphesFormula * >::iterator itEfficiencyMap; |
---|
| 180 | DelphesFormula *formula; |
---|
| 181 | Int_t pdgCode, charge; |
---|
| 182 | |
---|
| 183 | // select taus |
---|
| 184 | fFilter->Reset(); |
---|
| 185 | tauArray = fFilter->GetSubArray(fClassifier, 0); |
---|
| 186 | |
---|
| 187 | if(tauArray == 0) return; |
---|
| 188 | |
---|
| 189 | TIter itTauArray(tauArray); |
---|
| 190 | |
---|
| 191 | // loop over all input jets |
---|
| 192 | fItJetInputArray->Reset(); |
---|
| 193 | while((jet = static_cast<Candidate *>(fItJetInputArray->Next()))) |
---|
| 194 | { |
---|
| 195 | const TLorentzVector &jetMomentum = jet->Momentum; |
---|
| 196 | pdgCode = 0; |
---|
| 197 | charge = gRandom->Uniform() > 0.5 ? 1 : -1; |
---|
| 198 | eta = jetMomentum.Eta(); |
---|
| 199 | phi = jetMomentum.Phi(); |
---|
| 200 | pt = jetMomentum.Pt(); |
---|
| 201 | |
---|
| 202 | // loop over all input taus |
---|
| 203 | itTauArray.Reset(); |
---|
| 204 | while((tau = static_cast<Candidate *>(itTauArray.Next()))) |
---|
| 205 | { |
---|
| 206 | if(jetMomentum.DeltaR(tau->Momentum) <= fDeltaR) |
---|
| 207 | { |
---|
| 208 | pdgCode = 15; |
---|
| 209 | charge = tau->Charge; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | // find an efficency formula |
---|
| 213 | itEfficiencyMap = fEfficiencyMap.find(pdgCode); |
---|
| 214 | if(itEfficiencyMap == fEfficiencyMap.end()) |
---|
| 215 | { |
---|
| 216 | itEfficiencyMap = fEfficiencyMap.find(0); |
---|
| 217 | } |
---|
| 218 | formula = itEfficiencyMap->second; |
---|
| 219 | |
---|
| 220 | // apply an efficency formula |
---|
| 221 | jet->TauTag = gRandom->Uniform() <= formula->Eval(pt, eta); |
---|
| 222 | // set tau charge |
---|
| 223 | jet->Charge = charge; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | //------------------------------------------------------------------------------ |
---|