Fork me on GitHub

source: git/modules/RunPUPPI.cc@ e57c062

ImprovedOutputFile Timing dual_readout llp
Last change on this file since e57c062 was 509d1b4, checked in by Michele Selvaggi <michele.selvaggi@…>, 6 years ago

fixed possible mem leak

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