Fork me on GitHub

source: git/modules/JetFakeParticle.cc@ 68dd0df

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 68dd0df was 68dd0df, checked in by Michele Selvaggi <michele.selvaggi@…>, 9 years ago

added JetFakeParticle module

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