[14436f6] | 1 | /*
|
---|
| 2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
| 3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
| 4 | *
|
---|
| 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.
|
---|
| 9 | *
|
---|
| 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.
|
---|
| 14 | *
|
---|
| 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 |
|
---|
| 19 | /** \class PhotonID
|
---|
| 20 | *
|
---|
| 21 | * Applies complex photon Id. Reconstructed photon candidtes are first separated into matched and non-matched to gen particles.
|
---|
| 22 | * Non-matched pass the "fake" efficiency. Matched photons get further splitted into isolated and non-isolated (user can choose criterion for isolation)
|
---|
| 23 | * Isolated photons pass the "prompt" efficiency while the non-isolated pass the "non-prompt" efficiency
|
---|
| 24 | *
|
---|
| 25 | * \author M. Selvaggi CERN
|
---|
| 26 | *
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include "modules/PhotonID.h"
|
---|
| 30 |
|
---|
| 31 | #include "classes/DelphesClasses.h"
|
---|
| 32 | #include "classes/DelphesFactory.h"
|
---|
| 33 | #include "classes/DelphesFormula.h"
|
---|
| 34 |
|
---|
| 35 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
[341014c] | 36 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
| 37 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
[14436f6] | 38 |
|
---|
| 39 | #include "TDatabasePDG.h"
|
---|
[341014c] | 40 | #include "TFormula.h"
|
---|
[14436f6] | 41 | #include "TLorentzVector.h"
|
---|
[341014c] | 42 | #include "TMath.h"
|
---|
| 43 | #include "TObjArray.h"
|
---|
| 44 | #include "TRandom3.h"
|
---|
| 45 | #include "TString.h"
|
---|
[14436f6] | 46 |
|
---|
[341014c] | 47 | #include <algorithm>
|
---|
[14436f6] | 48 | #include <iostream>
|
---|
| 49 | #include <sstream>
|
---|
[341014c] | 50 | #include <stdexcept>
|
---|
[14436f6] | 51 |
|
---|
| 52 | using namespace std;
|
---|
| 53 |
|
---|
| 54 | //------------------------------------------------------------------------------
|
---|
| 55 |
|
---|
| 56 | PhotonID::PhotonID() :
|
---|
[341014c] | 57 | fPromptFormula(0), fNonPromptFormula(0), fFakeFormula(0), fItInputPhotonArray(0), fItInputGenArray(0)
|
---|
[14436f6] | 58 | {
|
---|
[341014c] | 59 | fPromptFormula = new DelphesFormula;
|
---|
| 60 | fNonPromptFormula = new DelphesFormula;
|
---|
| 61 | fFakeFormula = new DelphesFormula;
|
---|
[14436f6] | 62 | }
|
---|
| 63 |
|
---|
| 64 | //------------------------------------------------------------------------------
|
---|
| 65 |
|
---|
| 66 | PhotonID::~PhotonID()
|
---|
| 67 | {
|
---|
| 68 | if(fPromptFormula) delete fPromptFormula;
|
---|
| 69 | if(fNonPromptFormula) delete fNonPromptFormula;
|
---|
| 70 | if(fFakeFormula) delete fFakeFormula;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | //------------------------------------------------------------------------------
|
---|
| 74 |
|
---|
| 75 | void PhotonID::Init()
|
---|
| 76 | {
|
---|
| 77 |
|
---|
| 78 | // read PhotonID formulae
|
---|
| 79 | fPromptFormula->Compile(GetString("PromptFormula", "1.0"));
|
---|
| 80 | fNonPromptFormula->Compile(GetString("NonPromptFormula", "1.0"));
|
---|
| 81 | fFakeFormula->Compile(GetString("FakeFormula", "1.0"));
|
---|
[341014c] | 82 |
|
---|
[14436f6] | 83 | // import input arrays
|
---|
| 84 | fInputPhotonArray = ImportArray(GetString("InputPhotonArray", "PhotonIsolation/photons"));
|
---|
| 85 | fItInputPhotonArray = fInputPhotonArray->MakeIterator();
|
---|
| 86 |
|
---|
| 87 | // use filtered collection for speed
|
---|
| 88 | fInputGenArray = ImportArray(GetString("InputGenArray", "GenParticleFilter/filteredParticles"));
|
---|
| 89 | fItInputGenArray = fInputGenArray->MakeIterator();
|
---|
| 90 |
|
---|
| 91 | // min pt to be considered, make sure this threshold is higher than threshold in particle filter
|
---|
| 92 | fPTMin = GetDouble("PTMin", 10.0);
|
---|
| 93 |
|
---|
| 94 | // to be tuned, since FS and delphes have different isolation profiles
|
---|
| 95 | fRelIsoMax = GetDouble("fRelIsoMax", 0.3);
|
---|
| 96 |
|
---|
| 97 | // create output array
|
---|
| 98 | fOutputArray = ExportArray(GetString("OutputArray", "photons"));
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | //------------------------------------------------------------------------------
|
---|
| 102 |
|
---|
| 103 | void PhotonID::Finish()
|
---|
| 104 | {
|
---|
| 105 | if(fItInputPhotonArray) delete fItInputPhotonArray;
|
---|
| 106 | if(fItInputGenArray) delete fItInputGenArray;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | //------------------------------------------------------------------------------
|
---|
| 110 |
|
---|
| 111 | void PhotonID::Process()
|
---|
[341014c] | 112 | {
|
---|
[14436f6] | 113 | Candidate *candidate, *mother;
|
---|
| 114 | Double_t pt, eta, phi, e;
|
---|
| 115 | Double_t relIso;
|
---|
| 116 | Bool_t isolated;
|
---|
[341014c] | 117 |
|
---|
[14436f6] | 118 | //cout<< "---- new event ---------"<<endl;
|
---|
| 119 |
|
---|
| 120 | fItInputPhotonArray->Reset();
|
---|
[341014c] | 121 | while((candidate = static_cast<Candidate *>(fItInputPhotonArray->Next())))
|
---|
[14436f6] | 122 | {
|
---|
| 123 |
|
---|
| 124 | mother = candidate;
|
---|
[341014c] | 125 | candidate = static_cast<Candidate *>(candidate->Clone());
|
---|
[14436f6] | 126 | candidate->AddCandidate(mother);
|
---|
| 127 |
|
---|
| 128 | const TLorentzVector &candidatePosition = candidate->Position;
|
---|
| 129 | const TLorentzVector &candidateMomentum = candidate->Momentum;
|
---|
| 130 | eta = candidatePosition.Eta();
|
---|
| 131 | phi = candidatePosition.Phi();
|
---|
| 132 | pt = candidateMomentum.Pt();
|
---|
| 133 | e = candidateMomentum.E();
|
---|
| 134 |
|
---|
[341014c] | 135 | if(pt < fPTMin) continue;
|
---|
[14436f6] | 136 |
|
---|
| 137 | //cout<< " ---- photon -----: "<<pt<<","<<eta<<","<<phi<<endl;
|
---|
[341014c] | 138 |
|
---|
[14436f6] | 139 | // find out if photon matches does not match photon in gen collection and apply fae efficiency
|
---|
[341014c] | 140 | if(isFake(candidate))
|
---|
[14436f6] | 141 | {
|
---|
| 142 | //cout<<" Fake!"<<endl;
|
---|
| 143 |
|
---|
| 144 | if(gRandom->Uniform() > fFakeFormula->Eval(pt, eta, phi, e)) continue;
|
---|
| 145 | //cout<<" passed"<<endl;
|
---|
| 146 | candidate->Status = 3;
|
---|
| 147 | fOutputArray->Add(candidate);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | // if matches photon in gen collection
|
---|
| 151 | else
|
---|
| 152 | {
|
---|
| 153 | relIso = candidate->IsolationVar;
|
---|
| 154 | isolated = (relIso < 0.3);
|
---|
| 155 | //cout<<" Prompt!: "<<relIso<<endl;
|
---|
| 156 |
|
---|
| 157 | // if isolated apply prompt formula
|
---|
[341014c] | 158 | if(isolated)
|
---|
[14436f6] | 159 | {
|
---|
| 160 | //cout<<" isolated!: "<<relIso<<endl;
|
---|
| 161 | if(gRandom->Uniform() > fPromptFormula->Eval(pt, eta, phi, e)) continue;
|
---|
| 162 | //cout<<" passed"<<endl;
|
---|
| 163 | candidate->Status = 1;
|
---|
| 164 | fOutputArray->Add(candidate);
|
---|
| 165 | }
|
---|
[341014c] | 166 |
|
---|
[14436f6] | 167 | // if non-isolated apply non-prompt formula
|
---|
| 168 | else
|
---|
| 169 | {
|
---|
| 170 | //cout<<" non-isolated!: "<<relIso<<endl;
|
---|
| 171 | if(gRandom->Uniform() > fNonPromptFormula->Eval(pt, eta, phi, e)) continue;
|
---|
| 172 | //cout<<" passed"<<endl;
|
---|
| 173 | candidate->Status = 2;
|
---|
| 174 | fOutputArray->Add(candidate);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | //------------------------------------------------------------------------------
|
---|
| 181 |
|
---|
[341014c] | 182 | Bool_t PhotonID::isFake(const Candidate *obj)
|
---|
| 183 | {
|
---|
[14436f6] | 184 |
|
---|
| 185 | const TLorentzVector &mom_rec = obj->Momentum;
|
---|
[341014c] | 186 |
|
---|
[14436f6] | 187 | Bool_t matches = false;
|
---|
| 188 | fItInputGenArray->Reset();
|
---|
| 189 | Candidate *gen;
|
---|
[341014c] | 190 |
|
---|
| 191 | while((gen = static_cast<Candidate *>(fItInputGenArray->Next())))
|
---|
[14436f6] | 192 | {
|
---|
| 193 | const TLorentzVector &mom_gen = gen->Momentum;
|
---|
| 194 | Int_t status = gen->Status;
|
---|
| 195 | Int_t pdgCode = TMath::Abs(gen->PID);
|
---|
[341014c] | 196 | Float_t dPtOverPt = TMath::Abs((mom_gen.Pt() - mom_rec.Pt()) / mom_rec.Pt());
|
---|
[14436f6] | 197 | Float_t deltaR = mom_gen.DeltaR(mom_rec);
|
---|
| 198 |
|
---|
[341014c] | 199 | if(status != 1) continue;
|
---|
| 200 | if(pdgCode != 22) continue;
|
---|
| 201 | if(dPtOverPt > 0.5) continue;
|
---|
| 202 | if(deltaR > 0.1) continue;
|
---|
[14436f6] | 203 |
|
---|
| 204 | matches = true;
|
---|
| 205 | break;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | return !matches;
|
---|
| 209 | }
|
---|