Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STrackCutStudy.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file STrackCutStudy.cc
1 // ----------------------------------------------------------------------------
2 // 'STrackCutStudy.cc'
3 // Derek Anderson
4 // 12.15.2022
5 //
6 // Reads in the 'ntp_track' Ntuple
7 // generated by the SVtxEvaluator
8 // class and studies the impact
9 // of cutting on various quantities.
10 // ----------------------------------------------------------------------------
11 
12 #define STRACKCUTSTUDY_CC
13 
14 // header files
15 #include "STrackCutStudy.h"
16 #include "STrackCutStudy.io.h"
17 #include "STrackCutStudy.ana.h"
18 #include "STrackCutStudy.hist.h"
19 #include "STrackCutStudy.plot.h"
20 
21 using namespace std;
22 
23 
24 
25 // ctor/dtor ------------------------------------------------------------------
26 
28 
29  // clear member variables
30  sTxtEO.clear();
31  sTxtPU.clear();
32  nTxtEO = 0;
33  nTxtPU = 0;
34  inBatchMode = false;
35  makePlots = false;
36  doPileup = false;
37  doIntNorm = false;
38  doBeforeCuts = false;
39  doAvgClustCalc = false;
40  normalPtFracMin = 0.;
41  normalPtFracMax = 9999.;
42  doPrimaryCut = false;
43  doMVtxCut = false;
44  doVzCut = false;
45  doDcaXyCut = false;
46  doDcaZCut = false;
47  doQualityCut = false;
48 
49  // set whether or not type is truth
50  isTruth[TYPE::TRACK] = false;
51  isTruth[TYPE::TRUTH] = true;
52  isTruth[TYPE::WEIRD_ALL] = false;
53  isTruth[TYPE::WEIRD_SI] = false;
54  isTruth[TYPE::WEIRD_TPC] = false;
55  isTruth[TYPE::NORMAL] = false;
56  isTruth[TYPE::PILEUP] = false;
57  isTruth[TYPE::PRIMARY] = false;
58  isTruth[TYPE::NONPRIM] = false;
59  isTruth[TYPE::TRK_CUT] = false;
60  isTruth[TYPE::TRU_CUT] = true;
61  isTruth[TYPE::WEIRD_CUT] = false;
62  isTruth[TYPE::WEIRD_SI_CUT] = false;
63  isTruth[TYPE::WEIRD_TPC_CUT] = false;
64  isTruth[TYPE::NORM_CUT] = false;
65  isTruth[TYPE::PILE_CUT] = false;
66  isTruth[TYPE::PRIM_CUT] = false;
67  isTruth[TYPE::NONPRIM_CUT] = false;
68 
69  // set whether or not type has pileup
70  isPileup[TYPE::TRACK] = false;
71  isPileup[TYPE::TRUTH] = false;
72  isPileup[TYPE::WEIRD_ALL] = false;
73  isPileup[TYPE::WEIRD_SI] = false;
74  isPileup[TYPE::WEIRD_TPC] = false;
75  isPileup[TYPE::NORMAL] = false;
76  isPileup[TYPE::PILEUP] = true;
77  isPileup[TYPE::PRIMARY] = true;
78  isPileup[TYPE::NONPRIM] = true;
79  isPileup[TYPE::TRK_CUT] = false;
80  isPileup[TYPE::TRU_CUT] = false;
81  isPileup[TYPE::WEIRD_CUT] = false;
82  isPileup[TYPE::WEIRD_SI_CUT] = false;
83  isPileup[TYPE::WEIRD_TPC_CUT] = false;
84  isPileup[TYPE::NORM_CUT] = false;
85  isPileup[TYPE::PILE_CUT] = true;
86  isPileup[TYPE::PRIM_CUT] = true;
87  isPileup[TYPE::NONPRIM_CUT] = true;
88 
89  // set whether or not type is before cuts
90  isBeforeCuts[TYPE::TRACK] = true;
91  isBeforeCuts[TYPE::TRUTH] = true;
92  isBeforeCuts[TYPE::WEIRD_ALL] = true;
93  isBeforeCuts[TYPE::WEIRD_SI] = true;
94  isBeforeCuts[TYPE::WEIRD_TPC] = true;
95  isBeforeCuts[TYPE::NORMAL] = true;
96  isBeforeCuts[TYPE::PILEUP] = true;
97  isBeforeCuts[TYPE::PRIMARY] = true;
98  isBeforeCuts[TYPE::NONPRIM] = true;
99  isBeforeCuts[TYPE::TRK_CUT] = false;
100  isBeforeCuts[TYPE::TRU_CUT] = false;
101  isBeforeCuts[TYPE::WEIRD_CUT] = false;
102  isBeforeCuts[TYPE::WEIRD_SI_CUT] = false;
103  isBeforeCuts[TYPE::WEIRD_TPC_CUT] = false;
104  isBeforeCuts[TYPE::NORM_CUT] = false;
105  isBeforeCuts[TYPE::PILE_CUT] = false;
106  isBeforeCuts[TYPE::PRIM_CUT] = false;
107  isBeforeCuts[TYPE::NONPRIM_CUT] = false;
108 
109  // set whether or not track variable has a truth value
110  trkVarHasTruVal[TRKVAR::VX] = true;
111  trkVarHasTruVal[TRKVAR::VY] = true;
112  trkVarHasTruVal[TRKVAR::VZ] = true;
113  trkVarHasTruVal[TRKVAR::NMMS] = true;
114  trkVarHasTruVal[TRKVAR::NMAP] = true;
115  trkVarHasTruVal[TRKVAR::NINT] = true;
116  trkVarHasTruVal[TRKVAR::NTPC] = true;
117  trkVarHasTruVal[TRKVAR::QUAL] = false;
118  trkVarHasTruVal[TRKVAR::DCAXY] = false;
119  trkVarHasTruVal[TRKVAR::DCAZ] = false;
120  trkVarHasTruVal[TRKVAR::DELDCAXY] = false;
121  trkVarHasTruVal[TRKVAR::DELDCAZ] = false;
122  trkVarHasTruVal[TRKVAR::NCLUST] = true;
123  trkVarHasTruVal[TRKVAR::AVGCLUST] = true;
124 
125  // set whether or not physics variable has a truth value
126  physVarHasTruVal[PHYSVAR::PHI] = true;
127  physVarHasTruVal[PHYSVAR::ETA] = true;
128  physVarHasTruVal[PHYSVAR::PT] = true;
129  physVarHasTruVal[PHYSVAR::DELPHI] = false;
130  physVarHasTruVal[PHYSVAR::DELETA] = false;
131  physVarHasTruVal[PHYSVAR::DELPT] = false;
132 
133  // set type colors
134  fTypeCol[TYPE::TRACK] = 923;
135  fTypeCol[TYPE::TRUTH] = 899;
136  fTypeCol[TYPE::WEIRD_ALL] = 879;
137  fTypeCol[TYPE::WEIRD_SI] = 809;
138  fTypeCol[TYPE::WEIRD_TPC] = 849;
139  fTypeCol[TYPE::NORMAL] = 889;
140  fTypeCol[TYPE::PILEUP] = 923;
141  fTypeCol[TYPE::PRIMARY] = 859;
142  fTypeCol[TYPE::NONPRIM] = 799;
143  fTypeCol[TYPE::TRK_CUT] = 923;
144  fTypeCol[TYPE::TRU_CUT] = 899;
145  fTypeCol[TYPE::WEIRD_CUT] = 879;
146  fTypeCol[TYPE::WEIRD_SI_CUT] = 809;
147  fTypeCol[TYPE::WEIRD_TPC_CUT] = 849;
148  fTypeCol[TYPE::NORM_CUT] = 889;
149  fTypeCol[TYPE::PILE_CUT] = 923;
150  fTypeCol[TYPE::PRIM_CUT] = 859;
151  fTypeCol[TYPE::NONPRIM_CUT] = 799;
152 
153  // set type markers
154  fTypeMar[TYPE::TRACK] = 20;
155  fTypeMar[TYPE::TRUTH] = 24;
156  fTypeMar[TYPE::WEIRD_ALL] = 26;
157  fTypeMar[TYPE::WEIRD_SI] = 5;
158  fTypeMar[TYPE::WEIRD_TPC] = 2;
159  fTypeMar[TYPE::NORMAL] = 32;
160  fTypeMar[TYPE::PILEUP] = 20;
161  fTypeMar[TYPE::PRIMARY] = 26;
162  fTypeMar[TYPE::NONPRIM] = 32;
163  fTypeMar[TYPE::TRK_CUT] = 20;
164  fTypeMar[TYPE::TRU_CUT] = 24;
165  fTypeMar[TYPE::WEIRD_CUT] = 26;
166  fTypeMar[TYPE::WEIRD_SI_CUT] = 5;
167  fTypeMar[TYPE::WEIRD_TPC_CUT] = 2;
168  fTypeMar[TYPE::NORM_CUT] = 32;
169  fTypeMar[TYPE::PILE_CUT] = 20;
170  fTypeMar[TYPE::PRIM_CUT] = 26;
171  fTypeMar[TYPE::NONPRIM_CUT] = 32;
172 
173  // set type names
174  sTrkNames[TYPE::TRACK] = "AllTrack";
175  sTrkNames[TYPE::TRUTH] = "AllTruth";
176  sTrkNames[TYPE::WEIRD_ALL] = "AllWeird";
177  sTrkNames[TYPE::WEIRD_SI] = "AllSiWeird";
178  sTrkNames[TYPE::WEIRD_TPC] = "AllTpcWeird";
179  sTrkNames[TYPE::NORMAL] = "AllNormal";
180  sTrkNames[TYPE::PILEUP] = "AllPileup";
181  sTrkNames[TYPE::PRIMARY] = "AllPrimePileup";
182  sTrkNames[TYPE::NONPRIM] = "AllNonPrimePileup";
183  sTrkNames[TYPE::TRK_CUT] = "CutTrack";
184  sTrkNames[TYPE::TRU_CUT] = "CutTruth";
185  sTrkNames[TYPE::WEIRD_CUT] = "CutWeird";
186  sTrkNames[TYPE::WEIRD_SI_CUT] = "CutSiWeird";
187  sTrkNames[TYPE::WEIRD_TPC_CUT] = "CutTpcWeird";
188  sTrkNames[TYPE::NORM_CUT] = "CutNormal";
189  sTrkNames[TYPE::PILE_CUT] = "CutPileup";
190  sTrkNames[TYPE::PRIM_CUT] = "CutPrimePileup";
191  sTrkNames[TYPE::NONPRIM_CUT] = "CutNonPrimePileup";
192 
193  // set type plot labels
194  sTrkLabels[TYPE::TRACK] = "Tracks (before cuts)";
195  sTrkLabels[TYPE::TRUTH] = "Truth tracks (before cuts)";
196  sTrkLabels[TYPE::WEIRD_ALL] = "Weird tracks (before cuts)";
197  sTrkLabels[TYPE::WEIRD_SI] = "Weird tracks (Si seed, before cuts)";
198  sTrkLabels[TYPE::WEIRD_TPC] = "Weird tracks (TPC seed, before cuts)";
199  sTrkLabels[TYPE::NORMAL] = "Normal tracks (before cuts)";
200  sTrkLabels[TYPE::PILEUP] = "Including pileup tracks (all, before cuts)";
201  sTrkLabels[TYPE::PRIMARY] = "Including pileup tracks (only primary, before cuts)";
202  sTrkLabels[TYPE::NONPRIM] = "Including pileup gracks (non-primary, before cuts)";
203  sTrkLabels[TYPE::TRK_CUT] = "Tracks (after cuts)";
204  sTrkLabels[TYPE::TRU_CUT] = "Truth tracks (after cuts)";
205  sTrkLabels[TYPE::WEIRD_CUT] = "Weird tracks (after cuts)";
206  sTrkLabels[TYPE::WEIRD_SI_CUT] = "Weird tracks (Si seed, after cuts)";
207  sTrkLabels[TYPE::WEIRD_TPC_CUT] = "Weird tracks (TPC seed, after cuts)";
208  sTrkLabels[TYPE::NORM_CUT] = "Normal tracks (after cuts)";
209  sTrkLabels[TYPE::PILE_CUT] = "Including pileup tracks (all, after cuts)";
210  sTrkLabels[TYPE::PRIM_CUT] = "Including pileup tracks (only primary, after cuts)";
211  sTrkLabels[TYPE::NONPRIM_CUT] = "Including pileup gracks (non-primary, after cuts)";
212 
213  // set track variable names
214  sTrkVars[TRKVAR::VX] = "Vx";
215  sTrkVars[TRKVAR::VY] = "Vy";
216  sTrkVars[TRKVAR::VZ] = "Vz";
217  sTrkVars[TRKVAR::NMMS] = "NMms";
218  sTrkVars[TRKVAR::NMAP] = "NMap";
219  sTrkVars[TRKVAR::NINT] = "NInt";
220  sTrkVars[TRKVAR::NTPC] = "NTpc";
221  sTrkVars[TRKVAR::QUAL] = "Qual";
222  sTrkVars[TRKVAR::DCAXY] = "DcaXY";
223  sTrkVars[TRKVAR::DCAZ] = "DcaZ";
224  sTrkVars[TRKVAR::DELDCAXY] = "DeltaDcaXY";
225  sTrkVars[TRKVAR::DELDCAZ] = "DeltaDcaZ";
226  sTrkVars[TRKVAR::NCLUST] = "NClust";
227  sTrkVars[TRKVAR::AVGCLUST] = "AvgClustSize";
228 
229  // set physics variable names
230  sPhysVars[PHYSVAR::PHI] = "Phi";
231  sPhysVars[PHYSVAR::ETA] = "Eta";
232  sPhysVars[PHYSVAR::PT] = "Pt";
233  sPhysVars[PHYSVAR::DELPHI] = "DeltaPhi";
234  sPhysVars[PHYSVAR::DELETA] = "DeltaEta";
235  sPhysVars[PHYSVAR::DELPT] = "DeltaPt";
236  cout << "\n Beginning track cut study." << endl;
237 
238 } // end ctor
239 
240 
241 
242 
244 
245  const bool doTuplesExist = (ntTrkEO || ntTrkPU);
246  if (!doTuplesExist) {
247  return;
248  } else {
249  delete ntTrkEO -> GetCurrentFile();
250  delete ntTrkPU -> GetCurrentFile();
251  }
252 
253 } // end dtor
254 
255 
256 
257 // main methods --------------------------------------------------------------
258 
260 
261  // announce method
262  cout << " Initializing:" << endl;
263  InitFiles();
264  InitTuples();
265  InitHists();
266  MakeCutText();
267  return;
268 
269 } // end Init()
270 
271 
272 
274 
275  // check for tree and announce method
276  const bool isEmbedGood = ntTrkEO;
277  const bool isPileGood = !(doPileup && ntTrkPU);
278  const bool doTuplesExist = (isEmbedGood && isPileGood);
279  if (!doTuplesExist) {
280  cerr << "PANIC: no input tuples!\n"
281  << " ntTrkEO = " << ntTrkEO << ", ntTrkPU = " << ntTrkPU
282  << endl;
283  assert(doTuplesExist);
284  }
285  cout << " Analyzing:" <<endl;
286 
287  // prepare for embed-only entry loop
288  Long64_t nEntriesEO = ntTrkEO -> GetEntries();
289  cout << " Beginning embed-only entry loop: " << nEntriesEO << " entries to process..." << endl;
290 
291  // arrays for filling histograms
292  Double_t recoTrkVars[NTrkVar];
293  Double_t trueTrkVars[NTrkVar];
294  Double_t recoPhysVars[NPhysVar];
295  Double_t truePhysVars[NPhysVar];
296 
297  // loop over embed-only tuple entries
298  Long64_t nBytesEO(0);
299  for (Long64_t iEntry = 0; iEntry < nEntriesEO; iEntry++) {
300 
301  // grab entry
302  const Long64_t bytesEO = ntTrkEO -> GetEntry(iEntry);
303  if (bytesEO < 0.) {
304  cerr << "WARNING: something wrong with embed-only entry #" << iEntry << "! Aborting loop!" << endl;
305  break;
306  }
307  nBytesEO += bytesEO;
308 
309  // announce progress
310  const Long64_t iProg = iEntry + 1;
311  if (inBatchMode) {
312  cout << " Processing embed-only entry " << iProg << "/" << nEntriesEO << "..." << endl;
313  } else {
314  if (iProg == nEntriesEO) {
315  cout << " Processing embed-only entry " << iProg << "/" << nEntriesEO << "..." << endl;
316  } else {
317  cout << " Processing embed-only entry " << iProg << "/" << nEntriesEO << "...\r" << flush;
318  }
319  }
320 
321  // perform calculations
322  const Double_t umDcaXY = dca3dxy * 10000;
323  const Double_t umDcaZ = dca3dz * 10000;
324  const Double_t deltaDcaXY = abs(dca3dxy / dca3dxysigma);
325  const Double_t deltaDcaZ = abs(dca3dz / dca3dzsigma);
326  const Double_t deltaEta = abs(deltaeta / eta);
327  const Double_t deltaPhi = abs(deltaphi / phi);
328  const Double_t deltaPt = abs(deltapt / pt);
329  const Double_t ptFrac = pt /gpt;
330 
331  // set reco track variables
332  recoTrkVars[TRKVAR::VX] = vx;
333  recoTrkVars[TRKVAR::VY] = vy;
334  recoTrkVars[TRKVAR::VZ] = vz;
335  recoTrkVars[TRKVAR::NMMS] = (Double_t) nlmms;
336  recoTrkVars[TRKVAR::NMAP] = (Double_t) nlmaps;
337  recoTrkVars[TRKVAR::NINT] = (Double_t) nlintt;
338  recoTrkVars[TRKVAR::NTPC] = (Double_t) ntpc;
339  recoTrkVars[TRKVAR::QUAL] = quality;
340  recoTrkVars[TRKVAR::DCAXY] = umDcaXY;
341  recoTrkVars[TRKVAR::DCAZ] = umDcaZ;
342  recoTrkVars[TRKVAR::DELDCAXY] = deltaDcaXY;
343  recoTrkVars[TRKVAR::DELDCAZ] = deltaDcaZ;
344  recoTrkVars[TRKVAR::NCLUST] = 0.;
345  recoTrkVars[TRKVAR::AVGCLUST] = 0.;
346 
347  // set true track variables
348  trueTrkVars[TRKVAR::VX] = gvx;
349  trueTrkVars[TRKVAR::VY] = gvy;
350  trueTrkVars[TRKVAR::VZ] = gvz;
351  trueTrkVars[TRKVAR::NMMS] = (Double_t) gnlmms;
352  trueTrkVars[TRKVAR::NMAP] = (Double_t) gnlmaps;
353  trueTrkVars[TRKVAR::NINT] = (Double_t) gnlintt;
354  trueTrkVars[TRKVAR::NTPC] = (Double_t) gntpc;
355  trueTrkVars[TRKVAR::QUAL] = quality;
356  trueTrkVars[TRKVAR::DCAXY] = umDcaXY;
357  trueTrkVars[TRKVAR::DCAZ] = umDcaZ;
358  trueTrkVars[TRKVAR::DELDCAXY] = deltaDcaXY;
359  trueTrkVars[TRKVAR::DELDCAZ] = deltaDcaZ;
360  trueTrkVars[TRKVAR::NCLUST] = 0.;
361  trueTrkVars[TRKVAR::AVGCLUST] = 0.;
362 
363  // set reco phys variables
364  recoPhysVars[PHYSVAR::PHI] = phi;
365  recoPhysVars[PHYSVAR::ETA] = eta;
366  recoPhysVars[PHYSVAR::PT] = pt;
367  recoPhysVars[PHYSVAR::DELPHI] = deltaPhi;
368  recoPhysVars[PHYSVAR::DELETA] = deltaEta;
369  recoPhysVars[PHYSVAR::DELPT] = deltaPt;
370 
371  // set true phys variables
372  truePhysVars[PHYSVAR::PHI] = gphi;
373  truePhysVars[PHYSVAR::ETA] = geta;
374  truePhysVars[PHYSVAR::PT] = gpt;
375  truePhysVars[PHYSVAR::DELPHI] = deltaPhi;
376  truePhysVars[PHYSVAR::DELETA] = deltaEta;
377  truePhysVars[PHYSVAR::DELPT] = deltaPt;
378 
379  // check for weird tracks
380  const Bool_t hasSiSeed = (nmaps == 3);
381  const Bool_t hasTpcSeed = (nmaps == 0);
382  const Bool_t isPrimary = (gprimary == 1);
383  const Bool_t isWeirdTrack = ((ptFrac < normalPtFracMin) || (ptFrac > normalPtFracMax));
384 
385  // fill all track histograms
386  if (doBeforeCuts) {
387  FillTrackHistograms(TYPE::TRACK, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
388  FillTruthHistograms(TYPE::TRUTH, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
389 
390  // fill all embed_only weird histograms
391  if (isWeirdTrack) {
392  FillTrackHistograms(TYPE::WEIRD_ALL, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
393  if (hasSiSeed) FillTrackHistograms(TYPE::WEIRD_SI, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
394  if (hasTpcSeed) FillTrackHistograms(TYPE::WEIRD_TPC, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
395  } else {
396  FillTrackHistograms(TYPE::NORMAL, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
397  }
398  }
399 
400  // apply cuts
401  const Bool_t isGoodTrk = ApplyCuts(isPrimary, (UInt_t) nlmaps, (UInt_t) ntpc, vz, umDcaXY, umDcaZ, quality);
402  if (!isGoodTrk) continue;
403 
404  // fill cut track histograms
405  FillTrackHistograms(TYPE::TRK_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
406  FillTruthHistograms(TYPE::TRU_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
407 
408  // fill cut embed_only weird histograms
409  if (isWeirdTrack) {
410  FillTrackHistograms(TYPE::WEIRD_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
411  if (hasSiSeed) FillTrackHistograms(TYPE::WEIRD_SI_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
412  if (hasTpcSeed) FillTrackHistograms(TYPE::WEIRD_TPC_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
413  } else {
414  FillTrackHistograms(TYPE::NORM_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
415  }
416  } // end embed-only entry loop
417  cout << " Finished embed-only entry loop." << endl;
418 
419  // prepare for with-pileup entry loop
420  if (doPileup) {
421  Long64_t nEntriesPU = ntTrkPU -> GetEntries();
422  cout << " Beginning with-pileup entry loop: " << nEntriesPU << " entries to process..." << endl;
423 
424  // loop over with-pileup tuple entries
425  Long64_t nBytesPU(0);
426  for (Long64_t iEntry = 0; iEntry < nEntriesPU; iEntry++) {
427 
428  // grab entry
429  const Long64_t bytesPU = ntTrkPU -> GetEntry(iEntry);
430  if (bytesPU < 0.) {
431  cerr << "WARNING: something wrong with with-pileup entry #" << iEntry << "! Aborting loop!" << endl;
432  break;
433  }
434  nBytesPU += bytesPU;
435 
436  // announce progress
437  const Long64_t iProg = iEntry + 1;
438  if (inBatchMode) {
439  cout << " Processing with-pileup entry " << iProg << "/" << nEntriesPU << "..." << endl;
440  } else {
441  if (iProg == nEntriesPU) {
442  cout << " Processing with-pileup entry " << iProg << "/" << nEntriesPU << "..." << endl;
443  } else {
444  cout << " Processing with-pileup entry " << iProg << "/" << nEntriesPU << "...\r" << flush;
445  }
446  }
447 
448  // perform calculations
449  const Double_t umDcaXY = pu_dca3dxy * 10000;
450  const Double_t umDcaZ = pu_dca3dz * 10000;
451  const Double_t deltaDcaXY = abs(pu_dca3dxy / pu_dca3dxysigma);
452  const Double_t deltaDcaZ = abs(pu_dca3dz / pu_dca3dzsigma);
453  const Double_t deltaEta = abs(pu_deltaeta / pu_eta);
454  const Double_t deltaPhi = abs(pu_deltaphi / pu_phi);
455  const Double_t deltaPt = abs(pu_deltapt / pu_pt);
456 
457  // check if values are defined
458  const Bool_t thereAreNans = (isnan(pu_dca3dxy) || isnan(pu_dca3dz) || isnan(pu_eta) || isnan(pu_phi) || isnan(pu_pt));
459  if (thereAreNans) continue;
460 
461  // set reco track variables
462  recoTrkVars[TRKVAR::VX] = pu_vx;
463  recoTrkVars[TRKVAR::VY] = pu_vy;
464  recoTrkVars[TRKVAR::VZ] = pu_vz;
465  recoTrkVars[TRKVAR::NMMS] = (Double_t) pu_nlmms;
466  recoTrkVars[TRKVAR::NMAP] = (Double_t) pu_nlmaps;
467  recoTrkVars[TRKVAR::NINT] = (Double_t) pu_nlintt;
468  recoTrkVars[TRKVAR::NTPC] = (Double_t) pu_ntpc;
469  recoTrkVars[TRKVAR::QUAL] = pu_quality;
470  recoTrkVars[TRKVAR::DCAXY] = umDcaXY;
471  recoTrkVars[TRKVAR::DCAZ] = umDcaZ;
472  recoTrkVars[TRKVAR::DELDCAXY] = deltaDcaXY;
473  recoTrkVars[TRKVAR::DELDCAZ] = deltaDcaZ;
474  recoTrkVars[TRKVAR::NCLUST] = 0.;
475  recoTrkVars[TRKVAR::AVGCLUST] = 0.;
476 
477  // set true track variables
478  trueTrkVars[TRKVAR::VX] = pu_gvx;
479  trueTrkVars[TRKVAR::VY] = pu_gvy;
480  trueTrkVars[TRKVAR::VZ] = pu_gvz;
481  trueTrkVars[TRKVAR::NMMS] = (Double_t) pu_gnlmms;
482  trueTrkVars[TRKVAR::NMAP] = (Double_t) pu_gnlmaps;
483  trueTrkVars[TRKVAR::NINT] = (Double_t) pu_gnlintt;
484  trueTrkVars[TRKVAR::NTPC] = (Double_t) pu_gntpc;
485  trueTrkVars[TRKVAR::QUAL] = pu_quality;
486  trueTrkVars[TRKVAR::DCAXY] = umDcaXY;
487  trueTrkVars[TRKVAR::DCAZ] = umDcaZ;
488  trueTrkVars[TRKVAR::DELDCAXY] = deltaDcaXY;
489  trueTrkVars[TRKVAR::DELDCAZ] = deltaDcaZ;
490  trueTrkVars[TRKVAR::NCLUST] = 0.;
491  trueTrkVars[TRKVAR::AVGCLUST] = 0.;
492 
493  // set reco phys variables
494  recoPhysVars[PHYSVAR::PHI] = pu_phi;
495  recoPhysVars[PHYSVAR::ETA] = pu_eta;
496  recoPhysVars[PHYSVAR::PT] = pu_pt;
497  recoPhysVars[PHYSVAR::DELPHI] = deltaPhi;
498  recoPhysVars[PHYSVAR::DELETA] = deltaEta;
499  recoPhysVars[PHYSVAR::DELPT] = deltaPt;
500 
501  // set true phys variables
502  truePhysVars[PHYSVAR::PHI] = gphi;
503  truePhysVars[PHYSVAR::ETA] = geta;
504  truePhysVars[PHYSVAR::PT] = gpt;
505  truePhysVars[PHYSVAR::DELPHI] = deltaPhi;
506  truePhysVars[PHYSVAR::DELETA] = deltaEta;
507  truePhysVars[PHYSVAR::DELPT] = deltaPt;
508 
509  // check for primary tracks
510  const Bool_t isPrimary = (pu_gprimary == 1);
511 
512  // fill all histograms
513  if (doBeforeCuts) {
514  FillTrackHistograms(TYPE::PILEUP, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
515  if (isPrimary) {
516  FillTrackHistograms(TYPE::PRIMARY, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
517  } else {
518  FillTrackHistograms(TYPE::NONPRIM, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
519  }
520  }
521 
522  // apply cuts
523  const Bool_t isGoodTrk = ApplyCuts(isPrimary, (UInt_t) pu_nlmaps, (UInt_t) pu_ntpc, pu_vz, umDcaXY, umDcaZ, pu_quality);
524  if (!isGoodTrk) continue;
525 
526  // fill cut histograms
527  FillTrackHistograms(TYPE::PILE_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
528  if (isPrimary) {
529  FillTrackHistograms(TYPE::PRIM_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
530  } else {
531  FillTrackHistograms(TYPE::NONPRIM_CUT, recoTrkVars, trueTrkVars, recoPhysVars, truePhysVars);
532  }
533  } // end with-pileup entry loop
534  cout << " Finished with-pileup entry loop." << endl;
535  } // end if (doPileup)
536 
537  // normalize histograms if needed
538  if (doIntNorm) NormalizeHists();
539  return;
540 
541 } // end Analyze()
542 
543 
544 
546 
547  // announce method
548  cout << " Ending:" << endl;
549 
550  // set histogram styles
551  SetHistStyles();
552 
553  // plot labels/directories to save in
554  if (makePlots) {
555  const TString sLabelAllEO("EmbedOnly_BeforeCuts");
556  const TString sLabelCutEO("EmbedOnly_AfterCuts");
557  const TString sLabelOddEO("EmbedOnly_WeirdVsNormal");
558  const TString sLabelAllPU("WithPileup_BeforeCuts");
559  const TString sLabelCutPU("WithPileup_AfterCuts");
560  const TString sDirPlotAllEO("EmbedOnlyPlots_BeforeCuts");
561  const TString sDirPlotCutEO("EmbedOnlyPlots_AfterCuts");
562  const TString sDirPlotOddEO("EmbedOnlyPlots_WeirdVsNormal");
563  const TString sDirPlotAllPU("AllWithPileupPlots");
564  const TString sDirPlotCutPU("CutWithPileupPlots");
565 
566  // track types to plot together
567  const Ssiz_t nToDrawAllEO(3);
568  const Ssiz_t nToDrawCutEO(3);
569  const Ssiz_t nToDrawOddEO(3);
570  const Ssiz_t nToDrawAllPU(3);
571  const Ssiz_t nToDrawCutPU(3);
572  const Int_t sToDrawAllEO[nToDrawAllEO] = {TYPE::TRACK, TYPE::TRUTH, TYPE::WEIRD_ALL};
573  const Int_t sToDrawCutEO[nToDrawCutEO] = {TYPE::TRK_CUT, TYPE::TRU_CUT, TYPE::WEIRD_CUT};
574  const Int_t sToDrawOddEO[nToDrawOddEO] = {TYPE::WEIRD_SI_CUT, TYPE::WEIRD_TPC_CUT, TYPE::NORM_CUT};
575  const Int_t sToDrawAllPU[nToDrawAllPU] = {TYPE::PILEUP, TYPE::PRIMARY, TYPE::NONPRIM};
576  const Int_t sToDrawCutPU[nToDrawCutPU] = {TYPE::PILE_CUT, TYPE::PRIM_CUT, TYPE::NONPRIM_CUT};
577 
578  // create desired plots
579  ConstructPlots(nToDrawCutEO, sToDrawCutEO, sDirPlotCutEO, sLabelCutEO);
580  ConstructPlots(nToDrawOddEO, sToDrawOddEO, sDirPlotOddEO, sLabelOddEO);
581  if (doBeforeCuts) {
582  ConstructPlots(nToDrawAllEO, sToDrawAllEO, sDirPlotAllEO, sLabelAllEO);
583  }
584  if (doPileup) {
585  ConstructPlots(nToDrawCutPU, sToDrawCutPU, sDirPlotCutPU, sLabelCutPU);
586  if (doBeforeCuts) ConstructPlots(nToDrawAllPU, sToDrawAllPU, sDirPlotAllPU, sLabelAllPU);
587  }
588  cout << " Created plots." << endl;
589  }
590 
591  // save histograms
592  SaveHists();
593 
594  // close files
595  fOut -> cd();
596  fOut -> Close();
597  fInEO -> cd();
598  fInEO -> Close();
599  fInPU -> cd();
600  fInPU -> Close();
601  cout << " Closed files.\n"
602  << " Finished track cut study!\n"
603  << endl;
604  return ;
605 
606 } // end End()
607 
608 // end ------------------------------------------------------------------------