Fork me on GitHub

source: git/modules/RunPUPPI.cc@ fa33983

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

add PUPPI and RunPUPPI module

  • Property mode set to 100644
File size: 11.7 KB
Line 
1#include "modules/RunPUPPI.h"
2
3#include "PUPPI/puppiCleanContainer.hh"
4#include "PUPPI/RecoObj.hh"
5#include "PUPPI/puppiParticle.hh"
6#include "PUPPI/puppiAlgoBin.hh"
7
8#include "classes/DelphesClasses.h"
9#include "classes/DelphesFactory.h"
10#include "classes/DelphesFormula.h"
11
12#include <algorithm>
13#include <stdexcept>
14#include <iostream>
15#include <sstream>
16#include <vector>
17
18using namespace std;
19
20//------------------------------------------------------------------------------
21RunPUPPI::RunPUPPI() :
22 fItTrackInputArray(0),
23 fItNeutralInputArray(0)
24{}
25
26//------------------------------------------------------------------------------
27RunPUPPI::~RunPUPPI(){}
28
29//------------------------------------------------------------------------------
30
31void RunPUPPI::Init(){
32
33 // input collection
34 fTrackInputArray = ImportArray(GetString("TrackInputArray", "Calorimeter/towers"));
35 fItTrackInputArray = fTrackInputArray->MakeIterator();
36 fNeutralInputArray = ImportArray(GetString("NeutralInputArray", "Calorimeter/towers"));
37 fItNeutralInputArray = fNeutralInputArray->MakeIterator();
38 fPVInputArray = ImportArray(GetString("PVInputArray", "PV"));
39 fPVItInputArray = fPVInputArray->MakeIterator();
40
41
42 // puppi parameters
43 fMinPuppiWeight = GetDouble("MinPuppiWeight", 0.01);
44 fUseExp = GetBool("UseExp", false);
45
46 // read eta min ranges
47 ExRootConfParam param = GetParam("EtaMinBin");
48 fEtaMinBin.clear();
49 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fEtaMinBin.push_back(param[iMap].GetDouble());
50
51 // read eta max ranges
52 param = GetParam("EtaMaxBin");
53 fEtaMaxBin.clear();
54 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fEtaMaxBin.push_back(param[iMap].GetDouble());
55
56 // read pt min value
57 param = GetParam("PtMinBin");
58 fPtMinBin.clear();
59 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fPtMinBin.push_back(param[iMap].GetDouble());
60
61 // read cone size
62 param = GetParam("ConeSizeBin");
63 fConeSizeBin.clear();
64 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fConeSizeBin.push_back(param[iMap].GetDouble());
65
66 // read RMS min pt
67 param = GetParam("RMSPtMinBin");
68 fRMSPtMinBin.clear();
69 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fRMSPtMinBin.push_back(param[iMap].GetDouble());
70
71 // read RMS scale factor
72 param = GetParam("RMSScaleFactorBin");
73 fRMSScaleFactorBin.clear();
74 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fRMSScaleFactorBin.push_back(param[iMap].GetDouble());
75
76 // read neutral pt min cut
77 param = GetParam("NeutralMinEBin");
78 fNeutralMinEBin.clear();
79 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fNeutralMinEBin.push_back(param[iMap].GetDouble());
80
81 // read neutral pt min slope
82 param = GetParam("NeutralPtSlope");
83 fNeutralPtSlope.clear();
84 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fNeutralPtSlope.push_back(param[iMap].GetDouble());
85
86 // read apply chs
87 param = GetParam("ApplyCHS");
88 fApplyCHS.clear();
89 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fApplyCHS.push_back(param[iMap].GetBool());
90
91 // read use charged
92 param = GetParam("UseCharged");
93 fUseCharged.clear();
94 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fUseCharged.push_back(param[iMap].GetBool());
95
96 // read apply chs correction
97 param = GetParam("ApplyLowPUCorr");
98 fApplyLowPUCorr.clear();
99 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fApplyLowPUCorr.push_back(param[iMap].GetBool());
100
101 // read metric id
102 param = GetParam("MetricId");
103 fMetricId.clear();
104 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fMetricId.push_back(param[iMap].GetInt());
105
106 // create output array
107 fOutputArray = ExportArray(GetString("OutputArray", "puppiParticles"));
108 fOutputTrackArray = ExportArray(GetString("OutputArrayTracks", "puppiTracks"));
109 fOutputNeutralArray = ExportArray(GetString("OutputArrayNeutrals", "puppiNeutrals"));
110}
111
112//------------------------------------------------------------------------------
113
114void RunPUPPI::Finish(){
115 if(fItTrackInputArray) delete fItTrackInputArray;
116 if(fItNeutralInputArray) delete fItNeutralInputArray;
117}
118
119//------------------------------------------------------------------------------
120
121void RunPUPPI::Process(){
122
123 Candidate *candidate, *particle;
124 TLorentzVector momentum;
125
126 DelphesFactory *factory = GetFactory();
127
128 // loop over input objects
129 fItTrackInputArray->Reset();
130 fItNeutralInputArray->Reset();
131 fPVItInputArray->Reset();
132
133 std::vector<Candidate> InputParticles;
134 InputParticles.clear();
135
136 // take the leading vertex
137 float PVZ = 0.;
138 Candidate *pv = static_cast<Candidate*>(fPVItInputArray->Next());
139 if (pv) PVZ = pv->Position.Z();
140
141 // Fill input particles for puppi
142 std::vector<RecoObj> puppiInputVector;
143
144 // Loop on charge track candidate
145 while((candidate = static_cast<Candidate*>(fItTrackInputArray->Next()))){
146
147 momentum = candidate->Momentum;
148
149 RecoObj curRecoObj;
150 curRecoObj.pt = momentum.Pt();
151 curRecoObj.eta = momentum.Eta();
152 curRecoObj.phi = momentum.Phi();
153 curRecoObj.m = momentum.M();
154 particle = static_cast<Candidate*>(candidate->GetCandidates()->Last());
155 if (candidate->IsRecoPU and candidate->Charge !=0) { // if it comes fromPU vertexes after the resolution smearing and the dZ matching within resolution
156 curRecoObj.id = 2;
157 curRecoObj.vtxId = candidate->IsPU;
158 if(TMath::Abs(candidate->PID) == 11) curRecoObj.pfType = 2;
159 else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
160 else if(TMath::Abs(candidate->PID) == 22) curRecoObj.pfType = 4;
161 else curRecoObj.pfType = 1;
162 curRecoObj.dZ = particle->Position.Z()-PVZ;
163 }
164 else if(!candidate->IsRecoPU and candidate->Charge !=0) {
165 curRecoObj.id = 1; // charge from LV
166 curRecoObj.vtxId = 1; // from PV
167 if(TMath::Abs(candidate->PID) == 11) curRecoObj.pfType = 2;
168 else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
169 else if(TMath::Abs(candidate->PID) == 22) curRecoObj.pfType = 4;
170 else curRecoObj.pfType = 1;
171 curRecoObj.dZ = particle->Position.Z()-PVZ;
172 }
173 else {
174 std::cerr<<" RunPUPPI: problem with a charged track --> it has charge 0 "<<std::endl;
175 continue;
176 }
177
178 puppiInputVector.push_back(curRecoObj);
179 InputParticles.push_back(*candidate);
180 }
181
182 // Loop on neutral calo cells
183 while((candidate = static_cast<Candidate*>(fItNeutralInputArray->Next()))){
184
185 momentum = candidate->Momentum;
186
187 RecoObj curRecoObj;
188 curRecoObj.pt = momentum.Pt();
189 curRecoObj.eta = momentum.Eta();
190 curRecoObj.phi = momentum.Phi();
191 curRecoObj.m = momentum.M();
192 particle = static_cast<Candidate*>(candidate->GetCandidates()->Last());
193
194
195 if(candidate->Charge == 0){
196 curRecoObj.id = 0; // neutrals have id==0
197 curRecoObj.vtxId = 0; // neutrals have vtxId==0
198 if(TMath::Abs(candidate->PID) == 11) curRecoObj.pfType = 2;
199 else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
200 else if(TMath::Abs(candidate->PID) == 22) curRecoObj.pfType = 4;
201 else curRecoObj.pfType = 5;
202 curRecoObj.dZ = particle->Position.Z()-PVZ;
203 }
204 else{
205 std::cerr<<" RunPUPPI: problem with a neutrals cells --> it has charge !=0 "<<std::endl;
206 continue;
207 }
208 puppiInputVector.push_back(curRecoObj);
209 InputParticles.push_back(*candidate);
210 }
211
212 // Create algorithm list for puppi
213 std::vector<puppiAlgoBin> puppiAlgo;
214 if(puppiAlgo.empty()){
215 if(!(fEtaMinBin.size() == fEtaMaxBin.size() and fEtaMinBin.size() == fPtMinBin.size() and fEtaMinBin.size() == fConeSizeBin.size() and fEtaMinBin.size() == fRMSPtMinBin.size()
216 and fEtaMinBin.size() == fRMSScaleFactorBin.size() and fEtaMinBin.size() == fNeutralMinEBin.size() and fEtaMinBin.size() == fNeutralPtSlope.size()
217 and fEtaMinBin.size() == fApplyCHS.size() and fEtaMinBin.size() == fUseCharged.size()
218 and fEtaMinBin.size() == fApplyLowPUCorr.size() and fEtaMinBin.size() == fMetricId.size())) {
219 std::cerr<<" Error in PUPPI configuration, algo info should have the same size --> exit from the code"<<std::endl;
220 std::exit(EXIT_FAILURE);
221 }
222
223 for( size_t iAlgo = 0 ; iAlgo < fEtaMinBin.size() ; iAlgo++){
224 puppiAlgoBin algoTmp ;
225 algoTmp.fEtaMin_ = fEtaMinBin.at(iAlgo);
226 algoTmp.fEtaMax_ = fEtaMaxBin.at(iAlgo);
227 algoTmp.fPtMin_ = fPtMinBin.at(iAlgo);
228 algoTmp.fConeSize_ = fConeSizeBin.at(iAlgo);
229 algoTmp.fRMSPtMin_ = fRMSPtMinBin.at(iAlgo);
230 algoTmp.fRMSScaleFactor_ = fRMSScaleFactorBin.at(iAlgo);
231 algoTmp.fNeutralMinE_ = fNeutralMinEBin.at(iAlgo);
232 algoTmp.fNeutralPtSlope_ = fNeutralPtSlope.at(iAlgo);
233 algoTmp.fApplyCHS_ = fApplyCHS.at(iAlgo);
234 algoTmp.fUseCharged_ = fUseCharged.at(iAlgo);
235 algoTmp.fApplyLowPUCorr_ = fApplyLowPUCorr.at(iAlgo);
236 algoTmp.fMetricId_ = fMetricId.at(iAlgo);
237 if(std::find(puppiAlgo.begin(),puppiAlgo.end(),algoTmp) != puppiAlgo.end()) continue;
238 puppiAlgo.push_back(algoTmp);
239 }
240 }
241
242 // Create PUPPI container
243 puppiCleanContainer curEvent(puppiInputVector,puppiAlgo,fMinPuppiWeight,fUseExp);
244 std::vector<fastjet::PseudoJet> puppiParticles = curEvent.puppiEvent();
245
246 // Loop on final particles
247 for (std::vector<fastjet::PseudoJet>::iterator it = puppiParticles.begin() ; it != puppiParticles.end() ; it++) {
248 if(it->user_index() <= int(InputParticles.size())){
249 candidate = factory->NewCandidate();
250 candidate = dynamic_cast<Candidate*>(InputParticles.at(it->user_index()).Clone());
251 candidate->Momentum.SetXYZT(it->px(),it->py(),it->pz(),it->e());
252 fOutputArray->Add(candidate);
253 if( puppiInputVector.at(it->user_index()).id == 1 or puppiInputVector.at(it->user_index()).id == 2) fOutputTrackArray->Add(candidate);
254 else if (puppiInputVector.at(it->user_index()).id == 0) fOutputNeutralArray->Add(candidate);
255 }
256 else{
257 std::cerr<<" particle not found in the input Array --> skip "<<std::endl;
258 continue;
259 }
260 }
261
262}
Note: See TracBrowser for help on using the repository browser.