Fork me on GitHub

source: git/modules/RunPUPPI.cc@ e40b9cf

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

fix impact parameter dZ in RunPUPPI

  • Property mode set to 100644
File size: 11.3 KB
Line 
1#include "modules/RunPUPPI.h"
2
3#include "PUPPI/RecoObj2.hh"
4#include "PUPPI/AlgoObj.hh"
5#include "PUPPI/PuppiContainer.hh"
6
7#include "fastjet/PseudoJet.hh"
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;
20using namespace fastjet;
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();
41 // puppi parameters
42 fApplyNoLep = GetBool("UseNoLep", true);
43 fMinPuppiWeight = GetDouble("MinPuppiWeight", 0.01);
44 fUseExp = GetBool("UseExp", false);
45 // read eta min ranges
46 ExRootConfParam param = GetParam("EtaMinBin");
47 fEtaMinBin.clear();
48 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fEtaMinBin.push_back(param[iMap].GetDouble());
49 // read eta max ranges
50 param = GetParam("EtaMaxBin");
51 fEtaMaxBin.clear();
52 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fEtaMaxBin.push_back(param[iMap].GetDouble());
53 // read pt min value
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());
65 // read RMS scale factor
66 param = GetParam("RMSScaleFactorBin");
67 fRMSScaleFactorBin.clear();
68 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fRMSScaleFactorBin.push_back(param[iMap].GetDouble());
69 // read neutral pt min cut
70 param = GetParam("NeutralMinEBin");
71 fNeutralMinEBin.clear();
72 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fNeutralMinEBin.push_back(param[iMap].GetDouble());
73 // read neutral pt min slope
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
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
82 param = GetParam("UseCharged");
83 fUseCharged.clear();
84 for(int iMap = 0; iMap < param.GetSize(); ++iMap) fUseCharged.push_back(param[iMap].GetBool());
85 // read apply chs correction
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());
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());
97 // create output array
98 fOutputArray = ExportArray(GetString("OutputArray", "puppiParticles"));
99 fOutputTrackArray = ExportArray(GetString("OutputArrayTracks", "puppiTracks"));
100 fOutputNeutralArray = ExportArray(GetString("OutputArrayNeutrals", "puppiNeutrals"));
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);
138}
139
140//------------------------------------------------------------------------------
141
142void RunPUPPI::Finish(){
143 if(fItTrackInputArray) delete fItTrackInputArray;
144 if(fItNeutralInputArray) delete fItNeutralInputArray;
145}
146
147//------------------------------------------------------------------------------
148
149void RunPUPPI::Process(){
150
151 Candidate *candidate, *particle;
152 TLorentzVector momentum;
153
154 //DelphesFactory *factory = GetFactory();
155
156 // loop over input objects
157 fItTrackInputArray ->Reset();
158 fItNeutralInputArray ->Reset();
159 fPVItInputArray ->Reset();
160
161 std::vector<Candidate *> InputParticles;
162 InputParticles.clear();
163
164 // take the leading vertex
165 float PVZ = 0.;
166 Candidate *pv = static_cast<Candidate*>(fPVItInputArray->Next());
167 if (pv) PVZ = pv->Position.Z();
168 // Fill input particles for puppi
169 std::vector<RecoObj> puppiInputVector;
170 puppiInputVector.clear();
171 int lNBad = 0;
172 // Loop on charge track candidate
173 while((candidate = static_cast<Candidate*>(fItTrackInputArray->Next()))){
174 momentum = candidate->Momentum;
175 RecoObj curRecoObj;
176 curRecoObj.pt = momentum.Pt();
177 curRecoObj.eta = momentum.Eta();
178 curRecoObj.phi = momentum.Phi();
179 curRecoObj.m = momentum.M();
180 particle = static_cast<Candidate*>(candidate->GetCandidates()->At(0));//if(fApplyNoLep && TMath::Abs(candidate->PID) == 11) continue; //Dumb cut to minimize the nolepton on electron
181 //if(fApplyNoLep && TMath::Abs(candidate->PID) == 13) continue;
182 if (candidate->IsRecoPU and candidate->Charge !=0) { // if it comes fromPU vertexes after the resolution smearing and the dZ matching within resolution
183 lNBad++;
184 curRecoObj.id = 2;
185 curRecoObj.vtxId = 0.7*(fPVInputArray->GetEntries()); //Hack apply reco vtx efficiency of 70% for calibration
186 if(TMath::Abs(candidate->PID) == 11) curRecoObj.pfType = 2;
187 else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
188 else if(TMath::Abs(candidate->PID) == 22) curRecoObj.pfType = 4;
189 else curRecoObj.pfType = 1;
190 curRecoObj.dZ = particle->Position.Z()-PVZ;
191 }
192 else if(!candidate->IsRecoPU && candidate->Charge !=0) {
193 curRecoObj.id = 1; // charge from LV
194 curRecoObj.vtxId = 1; // from PV
195 if(TMath::Abs(candidate->PID) == 11) curRecoObj.pfType = 2;
196 else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
197 else if(TMath::Abs(candidate->PID) == 22) curRecoObj.pfType = 4;
198 else curRecoObj.pfType = 1;
199 curRecoObj.dZ = particle->Position.Z()-PVZ;
200 }
201 else {
202 std::cerr<<" RunPUPPI: problem with a charged track --> it has charge 0 "<<std::endl;
203 continue;
204 }
205
206 puppiInputVector.push_back(curRecoObj);
207 InputParticles.push_back(candidate);
208 }
209
210 // Loop on neutral calo cells
211 while((candidate = static_cast<Candidate*>(fItNeutralInputArray->Next()))){
212 momentum = candidate->Momentum;
213 RecoObj curRecoObj;
214 curRecoObj.pt = momentum.Pt();
215 curRecoObj.eta = momentum.Eta();
216 curRecoObj.phi = momentum.Phi();
217 curRecoObj.m = momentum.M();
218 curRecoObj.charge = 0;
219 particle = static_cast<Candidate*>(candidate->GetCandidates()->At(0));
220 if(candidate->Charge == 0){
221 curRecoObj.id = 0; // neutrals have id==0
222 curRecoObj.vtxId = 0; // neutrals have vtxId==0
223 if(TMath::Abs(candidate->PID) == 11) curRecoObj.pfType = 2;
224 else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
225 else if(TMath::Abs(candidate->PID) == 22) curRecoObj.pfType = 4;
226 else curRecoObj.pfType = 5;
227 curRecoObj.dZ = particle->Position.Z()-PVZ;
228 }
229 else{
230 std::cerr<<" RunPUPPI: problem with a neutrals cells --> it has charge !=0 "<<std::endl;
231 continue;
232 }
233 puppiInputVector.push_back(curRecoObj);
234 InputParticles.push_back(candidate);
235 }
236 // Create PUPPI container
237 fPuppi->initialize(puppiInputVector);
238 fPuppi->puppiWeights();
239 std::vector<PseudoJet> puppiParticles = fPuppi->puppiParticles();
240
241 // Loop on final particles
242 for (std::vector<PseudoJet>::iterator it = puppiParticles.begin() ; it != puppiParticles.end() ; it++) {
243 if(it->user_index() <= int(InputParticles.size())){
244 candidate = static_cast<Candidate *>(InputParticles.at(it->user_index())->Clone());
245 candidate->Momentum.SetPxPyPzE(it->px(),it->py(),it->pz(),it->e());
246 fOutputArray->Add(candidate);
247 if( puppiInputVector.at(it->user_index()).id == 1 or puppiInputVector.at(it->user_index()).id == 2) fOutputTrackArray->Add(candidate);
248 else if (puppiInputVector.at(it->user_index()).id == 0) fOutputNeutralArray->Add(candidate);
249 }
250 else{
251 std::cerr<<" particle not found in the input Array --> skip "<<std::endl;
252 continue;
253 }
254 }
255
256}
Note: See TracBrowser for help on using the repository browser.