Fork me on GitHub

source: git/modules/PileUpJetID.cc@ 505a779

ImprovedOutputFile Timing
Last change on this file since 505a779 was 341014c, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

apply .clang-format to all .h, .cc and .cpp files

  • Property mode set to 100644
File size: 10.3 KB
RevLine 
[6cdc544]1
[24d005f]2/** \class PileUpJetID
3 *
[2862770]4 * CMS PileUp Jet ID Variables
[24d005f]5 *
[2862770]6 * \author S. Zenz
[24d005f]7 *
8 */
9
10#include "modules/PileUpJetID.h"
11
12#include "classes/DelphesClasses.h"
13#include "classes/DelphesFactory.h"
14#include "classes/DelphesFormula.h"
15
16#include "ExRootAnalysis/ExRootClassifier.h"
[341014c]17#include "ExRootAnalysis/ExRootFilter.h"
18#include "ExRootAnalysis/ExRootResult.h"
[24d005f]19
20#include "TFormula.h"
[341014c]21#include "TMath.h"
[24d005f]22#include "TObjArray.h"
[341014c]23#include "TRandom3.h"
24#include "TString.h"
[2862770]25//#include "TDatabasePDG.h"
[24d005f]26#include "TLorentzVector.h"
27
28#include <algorithm>
29#include <iostream>
30#include <sstream>
[341014c]31#include <stdexcept>
[24d005f]32
33using namespace std;
34
35//------------------------------------------------------------------------------
36
37PileUpJetID::PileUpJetID() :
[341014c]38 fItJetInputArray(0), fTrackInputArray(0), fNeutralInputArray(0)
[24d005f]39{
40}
41
42//------------------------------------------------------------------------------
43
44PileUpJetID::~PileUpJetID()
45{
46}
47
48//------------------------------------------------------------------------------
49
50void PileUpJetID::Init()
51{
[2862770]52
[24d005f]53 fJetPTMin = GetDouble("JetPTMin", 20.0);
54 fParameterR = GetDouble("ParameterR", 0.5);
55 fUseConstituents = GetInt("UseConstituents", 0);
56
[341014c]57 fMeanSqDeltaRMaxBarrel = GetDouble("MeanSqDeltaRMaxBarrel", 0.1);
58 fBetaMinBarrel = GetDouble("BetaMinBarrel", 0.1);
59 fMeanSqDeltaRMaxEndcap = GetDouble("MeanSqDeltaRMaxEndcap", 0.1);
60 fBetaMinEndcap = GetDouble("BetaMinEndcap", 0.1);
61 fMeanSqDeltaRMaxForward = GetDouble("MeanSqDeltaRMaxForward", 0.1);
[2862770]62 fJetPTMinForNeutrals = GetDouble("JetPTMinForNeutrals", 20.0);
63 fNeutralPTMin = GetDouble("NeutralPTMin", 2.0);
64
[24d005f]65 fAverageEachTower = false; // for timing
66
67 // import input array(s)
68
69 fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
70 fItJetInputArray = fJetInputArray->MakeIterator();
71
[2862770]72 fTrackInputArray = ImportArray(GetString("TrackInputArray", "ParticlePropagator/tracks"));
[24d005f]73 fItTrackInputArray = fTrackInputArray->MakeIterator();
74
[2862770]75 fNeutralInputArray = ImportArray(GetString("NeutralInputArray", "ParticlePropagator/tracks"));
[24d005f]76 fItNeutralInputArray = fNeutralInputArray->MakeIterator();
[6cdc544]77
78 // create output array(s)
[24d005f]79
[6cdc544]80 fOutputArray = ExportArray(GetString("OutputArray", "jets"));
[2862770]81
[341014c]82 fNeutralsInPassingJets = ExportArray(GetString("NeutralsInPassingJets", "eflowtowers"));
[24d005f]83}
84
85//------------------------------------------------------------------------------
86
87void PileUpJetID::Finish()
88{
[2862770]89 // cout << "In finish" << endl;
90
[24d005f]91 if(fItJetInputArray) delete fItJetInputArray;
92 if(fItTrackInputArray) delete fItTrackInputArray;
93 if(fItNeutralInputArray) delete fItNeutralInputArray;
94}
95
96//------------------------------------------------------------------------------
97
98void PileUpJetID::Process()
99{
100 Candidate *candidate, *constituent;
101 TLorentzVector momentum, area;
[6cdc544]102
[2862770]103 Candidate *trk;
[54b6dfc]104
[24d005f]105 // loop over all input candidates
106 fItJetInputArray->Reset();
[341014c]107 while((candidate = static_cast<Candidate *>(fItJetInputArray->Next())))
[24d005f]108 {
109 momentum = candidate->Momentum;
110 area = candidate->Area;
111
[2862770]112 float sumT0 = 0.;
113 float sumT1 = 0.;
114 float sumT10 = 0.;
115 float sumT20 = 0.;
116 float sumT30 = 0.;
117 float sumT40 = 0.;
118 float sumWeightsForT = 0.;
[839deb7]119 candidate->NTimeHits = 0;
[2862770]120
121 float sumpt = 0.;
122 float sumptch = 0.;
123 float sumptchpv = 0.;
124 float sumptchpu = 0.;
125 float sumdrsqptsq = 0.;
126 float sumptsq = 0.;
127 int nc = 0;
128 int nn = 0;
129 float pt_ann[5];
130
[341014c]131 for(int i = 0; i < 5; i++)
132 {
[2862770]133 pt_ann[i] = 0.;
[24d005f]134 }
135
[341014c]136 if(fUseConstituents)
137 {
[24d005f]138 TIter itConstituents(candidate->GetCandidates());
[341014c]139 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
140 {
[2862770]141 float pt = constituent->Momentum.Pt();
142 float dr = candidate->Momentum.DeltaR(constituent->Momentum);
[341014c]143 // cout << " There exists a constituent with dr=" << dr << endl;
144 sumpt += pt;
145 sumdrsqptsq += dr * dr * pt * pt;
146 sumptsq += pt * pt;
147 if(constituent->Charge == 0)
148 {
149 nn++;
150 }
151 else
152 {
153 if(constituent->IsRecoPU)
154 {
155 sumptchpu += pt;
156 }
157 else
158 {
159 sumptchpv += pt;
160 }
161 sumptch += pt;
162 nc++;
163 }
164 for(int i = 0; i < 5; i++)
165 {
166 if(dr > 0.1 * i && dr < 0.1 * (i + 1))
167 {
168 pt_ann[i] += pt;
169 }
170 }
171 float tow_sumT = 0;
172 float tow_sumW = 0;
173 for(int i = 0; i < constituent->ECalEnergyTimePairs.size(); i++)
174 {
175 float w = TMath::Sqrt(constituent->ECalEnergyTimePairs[i].first);
176 if(fAverageEachTower)
177 {
178 tow_sumT += w * constituent->ECalEnergyTimePairs[i].second;
[2862770]179 tow_sumW += w;
[341014c]180 }
181 else
182 {
183 sumT0 += w * constituent->ECalEnergyTimePairs[i].second;
184 sumT1 += w * gRandom->Gaus(constituent->ECalEnergyTimePairs[i].second, 0.001);
185 sumT10 += w * gRandom->Gaus(constituent->ECalEnergyTimePairs[i].second, 0.010);
186 sumT20 += w * gRandom->Gaus(constituent->ECalEnergyTimePairs[i].second, 0.020);
187 sumT30 += w * gRandom->Gaus(constituent->ECalEnergyTimePairs[i].second, 0.030);
188 sumT40 += w * gRandom->Gaus(constituent->ECalEnergyTimePairs[i].second, 0.040);
189 sumWeightsForT += w;
190 candidate->NTimeHits++;
191 }
192 }
193 if(fAverageEachTower && tow_sumW > 0.)
194 {
195 sumT0 += tow_sumT;
196 sumT1 += tow_sumW * gRandom->Gaus(tow_sumT / tow_sumW, 0.001);
197 sumT10 += tow_sumW * gRandom->Gaus(tow_sumT / tow_sumW, 0.0010);
198 sumT20 += tow_sumW * gRandom->Gaus(tow_sumT / tow_sumW, 0.0020);
199 sumT30 += tow_sumW * gRandom->Gaus(tow_sumT / tow_sumW, 0.0030);
200 sumT40 += tow_sumW * gRandom->Gaus(tow_sumT / tow_sumW, 0.0040);
201 sumWeightsForT += tow_sumW;
202 candidate->NTimeHits++;
203 }
[24d005f]204 }
[341014c]205 }
206 else
207 {
[24d005f]208 // Not using constituents, using dr
209 fItTrackInputArray->Reset();
[341014c]210 while((trk = static_cast<Candidate *>(fItTrackInputArray->Next())))
211 {
212 if(trk->Momentum.DeltaR(candidate->Momentum) < fParameterR)
213 {
214 float pt = trk->Momentum.Pt();
215 sumpt += pt;
216 sumptch += pt;
217 if(trk->IsRecoPU)
218 {
219 sumptchpu += pt;
220 }
221 else
222 {
223 sumptchpv += pt;
224 }
225 float dr = candidate->Momentum.DeltaR(trk->Momentum);
226 sumdrsqptsq += dr * dr * pt * pt;
227 sumptsq += pt * pt;
228 nc++;
229 for(int i = 0; i < 5; i++)
230 {
231 if(dr > 0.1 * i && dr < 0.1 * (i + 1))
232 {
233 pt_ann[i] += pt;
234 }
235 }
236 }
[24d005f]237 }
238 fItNeutralInputArray->Reset();
[341014c]239 while((constituent = static_cast<Candidate *>(fItNeutralInputArray->Next())))
240 {
241 if(constituent->Momentum.DeltaR(candidate->Momentum) < fParameterR)
242 {
243 float pt = constituent->Momentum.Pt();
244 sumpt += pt;
245 float dr = candidate->Momentum.DeltaR(constituent->Momentum);
246 sumdrsqptsq += dr * dr * pt * pt;
247 sumptsq += pt * pt;
248 nn++;
249 for(int i = 0; i < 5; i++)
250 {
251 if(dr > 0.1 * i && dr < 0.1 * (i + 1))
252 {
253 pt_ann[i] += pt;
254 }
255 }
256 }
[24d005f]257 }
258 }
[6cdc544]259
[341014c]260 if(sumptch > 0.)
261 {
262 candidate->Beta = sumptchpv / sumptch;
263 candidate->BetaStar = sumptchpu / sumptch;
264 }
265 else
266 {
[2862770]267 candidate->Beta = -999.;
268 candidate->BetaStar = -999.;
[6cdc544]269 }
[341014c]270 if(sumptsq > 0.)
271 {
272 candidate->MeanSqDeltaR = sumdrsqptsq / sumptsq;
273 }
274 else
275 {
[2862770]276 candidate->MeanSqDeltaR = -999.;
[24d005f]277 }
278 candidate->NCharged = nc;
279 candidate->NNeutrals = nn;
[341014c]280 if(sumpt > 0.)
281 {
[24d005f]282 candidate->PTD = TMath::Sqrt(sumptsq) / sumpt;
[341014c]283 for(int i = 0; i < 5; i++)
284 {
285 candidate->FracPt[i] = pt_ann[i] / sumpt;
[24d005f]286 }
[341014c]287 }
288 else
289 {
[2862770]290 candidate->PTD = -999.;
[341014c]291 for(int i = 0; i < 5; i++)
292 {
[2862770]293 candidate->FracPt[i] = -999.;
[24d005f]294 }
295 }
296
297 fOutputArray->Add(candidate);
[2862770]298
299 // New stuff
300 /*
301 fMeanSqDeltaRMaxBarrel = GetDouble("MeanSqDeltaRMaxBarrel",0.1);
302 fBetaMinBarrel = GetDouble("BetaMinBarrel",0.1);
303 fMeanSqDeltaRMaxEndcap = GetDouble("MeanSqDeltaRMaxEndcap",0.1);
304 fBetaMinEndcap = GetDouble("BetaMinEndcap",0.1);
305 fMeanSqDeltaRMaxForward = GetDouble("MeanSqDeltaRMaxForward",0.1);
306 */
307
308 bool passId = false;
[341014c]309 if(candidate->Momentum.Pt() > fJetPTMinForNeutrals && candidate->MeanSqDeltaR > -0.1)
310 {
311 if(fabs(candidate->Momentum.Eta()) < 1.5)
312 {
313 passId = ((candidate->Beta > fBetaMinBarrel) && (candidate->MeanSqDeltaR < fMeanSqDeltaRMaxBarrel));
314 }
315 else if(fabs(candidate->Momentum.Eta()) < 4.0)
316 {
317 passId = ((candidate->Beta > fBetaMinEndcap) && (candidate->MeanSqDeltaR < fMeanSqDeltaRMaxEndcap));
318 }
319 else
320 {
321 passId = (candidate->MeanSqDeltaR < fMeanSqDeltaRMaxForward);
[2862770]322 }
323 }
324
[341014c]325 // cout << " Pt Eta MeanSqDeltaR Beta PassId " << candidate->Momentum.Pt()
[2862770]326 // << " " << candidate->Momentum.Eta() << " " << candidate->MeanSqDeltaR << " " << candidate->Beta << " " << passId << endl;
327
[341014c]328 if(passId)
329 {
330 if(fUseConstituents)
331 {
332 TIter itConstituents(candidate->GetCandidates());
333 while((constituent = static_cast<Candidate *>(itConstituents.Next())))
334 {
335 if(constituent->Charge == 0 && constituent->Momentum.Pt() > fNeutralPTMin)
336 {
337 fNeutralsInPassingJets->Add(constituent);
338 // cout << " Constitutent added Pt Eta Charge " << constituent->Momentum.Pt() << " " << constituent->Momentum.Eta() << " " << constituent->Charge << endl;
339 }
340 }
341 }
342 else
343 { // use DeltaR
344 fItNeutralInputArray->Reset();
345 while((constituent = static_cast<Candidate *>(fItNeutralInputArray->Next())))
346 {
347 if(constituent->Momentum.DeltaR(candidate->Momentum) < fParameterR && constituent->Momentum.Pt() > fNeutralPTMin)
348 {
349 fNeutralsInPassingJets->Add(constituent);
350 // cout << " Constitutent added Pt Eta Charge " << constituent->Momentum.Pt() << " " << constituent->Momentum.Eta() << " " << constituent->Charge << endl;
351 }
352 }
[2862770]353 }
354 }
[24d005f]355 }
356}
357
358//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.