Fork me on GitHub

source: git/modules/JetFakeParticle.cc@ e09b9bf

Last change on this file since e09b9bf 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: 5.6 KB
RevLine 
[68dd0df]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 JetFakeParticle
20 *
21 * Converts jet into particle with some PID,
22 * according to parametrized probability.
23 *
24 * \author M. Selvaggi - UCL, Louvain-la-Neuve
25 *
26 */
27
28#include "modules/JetFakeParticle.h"
29
30#include "classes/DelphesClasses.h"
31#include "classes/DelphesFactory.h"
32#include "classes/DelphesFormula.h"
33
34#include "ExRootAnalysis/ExRootClassifier.h"
[341014c]35#include "ExRootAnalysis/ExRootFilter.h"
36#include "ExRootAnalysis/ExRootResult.h"
[68dd0df]37
38#include "TDatabasePDG.h"
[341014c]39#include "TFormula.h"
[68dd0df]40#include "TLorentzVector.h"
[341014c]41#include "TMath.h"
42#include "TObjArray.h"
43#include "TRandom3.h"
44#include "TString.h"
[68dd0df]45
46#include <algorithm>
47#include <iostream>
48#include <sstream>
[341014c]49#include <stdexcept>
[68dd0df]50
51using namespace std;
52
53//------------------------------------------------------------------------------
54
55JetFakeParticle::JetFakeParticle() :
56 fItInputArray(0)
57{
58}
59
60//------------------------------------------------------------------------------
61
62JetFakeParticle::~JetFakeParticle()
63{
64}
65
66//------------------------------------------------------------------------------
67
68void JetFakeParticle::Init()
69{
70 TFakeMap::iterator itEfficiencyMap;
71 ExRootConfParam param;
72 DelphesFormula *formula;
[b631c06]73 Int_t i, size, pdgCode;
[68dd0df]74
75 // read efficiency formulas
76 param = GetParam("EfficiencyFormula");
77 size = param.GetSize();
78
79 fEfficiencyMap.clear();
[b631c06]80
[341014c]81 for(i = 0; i < size / 2; ++i)
[68dd0df]82 {
83 formula = new DelphesFormula;
[341014c]84 formula->Compile(param[i * 2 + 1].GetString());
85 pdgCode = param[i * 2].GetInt();
[b631c06]86
87 if(TMath::Abs(pdgCode) != 11 && TMath::Abs(pdgCode) != 13 && TMath::Abs(pdgCode) != 22)
[68dd0df]88 {
89 throw runtime_error("Jets can only fake into electrons, muons or photons. Other particles are not authorized.");
90 }
[b631c06]91
[341014c]92 fEfficiencyMap[param[i * 2].GetInt()] = formula;
[68dd0df]93 }
94
95 // set default efficiency formula
96 itEfficiencyMap = fEfficiencyMap.find(0);
97 if(itEfficiencyMap == fEfficiencyMap.end())
98 {
99 formula = new DelphesFormula;
100 formula->Compile("0.0");
101
102 fEfficiencyMap[0] = formula;
103 }
[b631c06]104
[68dd0df]105 // import input array
106
107 fInputArray = ImportArray(GetString("InputArray", "FastJetFinder/jets"));
108 fItInputArray = fInputArray->MakeIterator();
109
110 // create output array
111
[b631c06]112 fElectronOutputArray = ExportArray(GetString("ElectronOutputArray", "fakeElectrons"));
113 fMuonOutputArray = ExportArray(GetString("MuonOutputArray", "fakeMuons"));
114 fPhotonOutputArray = ExportArray(GetString("PhotonOutputArray", "fakePhotons"));
[68dd0df]115 fJetOutputArray = ExportArray(GetString("JetOutputArray", "jets"));
116}
117
118//------------------------------------------------------------------------------
119
120void JetFakeParticle::Finish()
121{
122 if(fItInputArray) delete fItInputArray;
123
124 TFakeMap::iterator itEfficiencyMap;
125 DelphesFormula *formula;
126 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
127 {
128 formula = itEfficiencyMap->second;
129 if(formula) delete formula;
130 }
131}
132
133//------------------------------------------------------------------------------
134
135void JetFakeParticle::Process()
136{
[b631c06]137 Candidate *candidate, *fake = 0;
[68dd0df]138 Double_t pt, eta, phi, e;
139 TFakeMap::iterator itEfficiencyMap;
140 DelphesFormula *formula;
[b631c06]141 Int_t pdgCodeOut;
142
[68dd0df]143 Double_t p, r, rs, total;
144
145 fItInputArray->Reset();
[341014c]146 while((candidate = static_cast<Candidate *>(fItInputArray->Next())))
[68dd0df]147 {
148 const TLorentzVector &candidatePosition = candidate->Position;
149 const TLorentzVector &candidateMomentum = candidate->Momentum;
150 eta = candidatePosition.Eta();
151 phi = candidatePosition.Phi();
152 pt = candidateMomentum.Pt();
153 e = candidateMomentum.E();
[b631c06]154
[68dd0df]155 r = gRandom->Uniform();
156 total = 0.0;
[b631c06]157 fake = 0;
158
[68dd0df]159 // loop over map for this jet
160 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
161 {
162 formula = itEfficiencyMap->second;
163 pdgCodeOut = itEfficiencyMap->first;
164
165 p = formula->Eval(pt, eta, phi, e);
166
167 if(total <= r && r < total + p)
168 {
[341014c]169 fake = static_cast<Candidate *>(candidate->Clone());
[b631c06]170
[68dd0df]171 // convert jet
[b631c06]172
[68dd0df]173 if(TMath::Abs(pdgCodeOut) == 11 || TMath::Abs(pdgCodeOut) == 13)
174 {
[b631c06]175 if(candidate->Charge != 0)
176 {
[341014c]177 fake->Charge = candidate->Charge / TMath::Abs(candidate->Charge);
[b631c06]178 }
[68dd0df]179 else
180 {
181 rs = gRandom->Uniform();
[410f3a2]182 fake->Charge = (rs < 0.5) ? -1 : 1;
[b631c06]183 }
[68dd0df]184 }
[b631c06]185
[68dd0df]186 if(TMath::Abs(pdgCodeOut) == 22) fake->PID = 22;
[b631c06]187
[68dd0df]188 if(TMath::Abs(pdgCodeOut) == 11) fElectronOutputArray->Add(fake);
189 if(TMath::Abs(pdgCodeOut) == 13) fMuonOutputArray->Add(fake);
190 if(TMath::Abs(pdgCodeOut) == 22) fPhotonOutputArray->Add(fake);
191
192 break;
193 }
194
195 total += p;
196 }
[b631c06]197
198 if(!fake) fJetOutputArray->Add(candidate);
199 }
[68dd0df]200}
201
202//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.