Fork me on GitHub

source: git/modules/IdentificationMap.cc@ df35033

ImprovedOutputFile Timing dual_readout llp
Last change on this file since df35033 was cab38f6, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

remove svn tags and fix formatting

  • Property mode set to 100644
File size: 5.4 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 IdentificationMap
21 *
22 * Converts particles with some PDG code into another particle,
23 * according to parametrized probability.
24 *
25 * \author M. Selvaggi - UCL, Louvain-la-Neuve
26 *
27 */
28
29#include "modules/IdentificationMap.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
52using namespace std;
53
54//------------------------------------------------------------------------------
55
56IdentificationMap::IdentificationMap() :
57 fItInputArray(0)
58{
59}
60
61//------------------------------------------------------------------------------
62
63IdentificationMap::~IdentificationMap()
64{
65}
66
67//------------------------------------------------------------------------------
68
69void IdentificationMap::Init()
70{
71 // read efficiency formula
72
73
74 TMisIDMap::iterator itEfficiencyMap;
75 ExRootConfParam param;
76 DelphesFormula *formula;
77 Int_t i, size, pdg;
78
79 // read efficiency formulas
80 param = GetParam("EfficiencyFormula");
81 size = param.GetSize();
82
83 fEfficiencyMap.clear();
84 for(i = 0; i < size/3; ++i)
85 {
86 formula = new DelphesFormula;
87 formula->Compile(param[i*3 + 2].GetString());
88 pdg = param[i*3].GetInt();
89 fEfficiencyMap.insert(make_pair(pdg,make_pair(param[i*3 + 1].GetInt(),formula)));
90
91 // cout<<param[i*3].GetInt()<<","<<param[i*3+1].GetInt()<<","<<param[i*3 + 2].GetString()<<endl;
92
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("1.0");
101
102 fEfficiencyMap.insert(make_pair(0,make_pair(0,formula)));
103 }
104
105 // import input array
106
107 fInputArray = ImportArray(GetString("InputArray", "ParticlePropagator/stableParticles"));
108 fItInputArray = fInputArray->MakeIterator();
109
110 // create output array
111
112 fOutputArray = ExportArray(GetString("OutputArray", "stableParticles"));
113}
114
115//------------------------------------------------------------------------------
116
117void IdentificationMap::Finish()
118{
119 if(fItInputArray) delete fItInputArray;
120
121 TMisIDMap::iterator itEfficiencyMap;
122 DelphesFormula *formula;
123 for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
124 {
125 formula = (itEfficiencyMap->second).second;
126 if(formula) delete formula;
127 }
128
129}
130
131//------------------------------------------------------------------------------
132
133void IdentificationMap::Process()
134{
135 Candidate *candidate;
136 Double_t pt, eta, phi;
137 TMisIDMap::iterator itEfficiencyMap;
138 pair <TMisIDMap::iterator, TMisIDMap::iterator> range;
139 DelphesFormula *formula;
140 Int_t pdgIn, pdgOut, charge;
141
142 Double_t P, Pi;
143
144 // cout<<"------------ New Event ------------"<<endl;
145
146 fItInputArray->Reset();
147 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
148 {
149 const TLorentzVector &candidatePosition = candidate->Position;
150 const TLorentzVector &candidateMomentum = candidate->Momentum;
151 eta = candidatePosition.Eta();
152 phi = candidatePosition.Phi();
153 pt = candidateMomentum.Pt();
154 pdgIn = candidate->PID;
155 charge = candidate->Charge;
156
157 // cout<<"------------ New Candidate ------------"<<endl;
158 // cout<<candidate->PID<<" "<<pt<<","<<eta<<","<<phi<<endl;
159
160 P = 1.0;
161
162 //first check that PID of this particle is specified in cfg, if not set look for PID=0
163
164 itEfficiencyMap = fEfficiencyMap.find(pdgIn);
165
166 range = fEfficiencyMap.equal_range(pdgIn);
167 if(range.first == range.second) range = fEfficiencyMap.equal_range(-pdgIn);
168 if(range.first == range.second) range = fEfficiencyMap.equal_range(0);
169
170 //loop over submap for this pid
171 for (TMisIDMap::iterator it=range.first; it!=range.second; ++it)
172 {
173
174 formula = (it->second).second;
175 pdgOut = (it->second).first;
176
177 Pi = formula->Eval(pt, eta);
178
179 // check that sum of probabilities does not exceed 1.
180 P = (P - Pi)/P;
181
182 if( P < 0.0 ) continue;
183 else
184 {
185
186 //randomly assign a PID to particle according to map
187 Double_t rndm = gRandom->Uniform();
188
189 if(rndm > P)
190 {
191 //change PID of particle
192 if(pdgOut != 0) candidate->PID = charge*pdgOut;
193 fOutputArray->Add(candidate);
194 break;
195 }
196 }
197
198 }
199
200 }
201
202}
203
204//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.