Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STrackCutStudy.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file STrackCutStudy.h
1 // ----------------------------------------------------------------------------
2 // 'STrackCutStudy.h'
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 #ifndef STRACKCUTSTUDY_H
13 #define STRACKCUTSTUDY_H
14 
15 // standard c includes
16 #include <cmath>
17 #include <vector>
18 #include <cassert>
19 #include <cstdlib>
20 #include <utility>
21 #include <iostream>
22 // root includes
23 #include <TH1.h>
24 #include <TH2.h>
25 #include <TPad.h>
26 #include <TFile.h>
27 #include <TMath.h>
28 #include <TError.h>
29 #include <TNtuple.h>
30 #include <TString.h>
31 #include <TLegend.h>
32 #include <TCanvas.h>
33 #include <TPaveText.h>
34 #include <TDirectory.h>
35 
36 using namespace std;
37 
38 // global constants
39 static const Ssiz_t NVtx(4);
40 static const Ssiz_t NType(18);
41 static const Ssiz_t NTrkVar(14);
42 static const Ssiz_t NPhysVar(6);
43 static const Ssiz_t NRange(2);
44 static const Ssiz_t NPanel(2);
45 static const UInt_t FTxt(42);
46 
47 
48 
50 
51  public:
52 
53  // enums
54  enum TRKVAR {
55  VX = 0,
56  VY = 1,
57  VZ = 2,
58  NMMS = 3,
59  NMAP = 4,
60  NINT = 5,
61  NTPC = 6,
62  QUAL = 7,
63  DCAXY = 8,
64  DCAZ = 9,
65  DELDCAXY = 10,
66  DELDCAZ = 11,
67  NCLUST = 12,
68  AVGCLUST = 13
69  };
70  enum PHYSVAR {
71  PHI = 0,
72  ETA = 1,
73  PT = 2,
74  DELPHI = 3,
75  DELETA = 4,
76  DELPT = 5
77  };
78  enum TYPE {
79  TRACK = 0,
80  TRUTH = 1,
81  WEIRD_ALL = 2,
82  WEIRD_SI = 3,
83  WEIRD_TPC = 4,
84  NORMAL = 5,
85  PILEUP = 6,
86  PRIMARY = 7,
87  NONPRIM = 8,
88  TRK_CUT = 9,
89  TRU_CUT = 10,
90  WEIRD_CUT = 11,
91  WEIRD_SI_CUT = 12,
92  WEIRD_TPC_CUT = 13,
93  NORM_CUT = 14,
94  PILE_CUT = 15,
95  PRIM_CUT = 16,
96  NONPRIM_CUT = 17
97  };
98 
99  // ctor/dtor
100  STrackCutStudy();
101  ~STrackCutStudy();
102 
103  // public methods
104  void SetBatchMode(const Bool_t doBatch=false);
105  void SetInputOutputFiles(const TString sEmbedOnlyInput, const TString sPileupInput, const TString sOutput);
106  void SetInputTuples(const TString sEmbedOnlyTuple, const TString sPileupTuple, const TString sEmbedOnlyClusterTuple="");
107  void SetStudyParameters(const Bool_t plots, const Bool_t pileup, const Bool_t intNorm, const Bool_t beforeCuts, const Bool_t avgClustCalc, const Double_t weirdFracMin, const Double_t weirdFracMax);
108  void SetCutFlags(const Bool_t doPrimary, const Bool_t doTpc, const Bool_t doMVtx, const Bool_t doVz, const Bool_t doDcaXY, const Bool_t doDcaZ, const Bool_t doQuality);
109  void SetTrackCuts(const pair<UInt_t, UInt_t> nMVtxRange, const pair<UInt_t, UInt_t> nTpcRange, const pair<Double_t, Double_t> vzRange, const pair<Double_t, Double_t> dcaXyRange, const pair <Double_t, Double_t> dcaZRange, const pair<Double_t, Double_t> qualityRange);
110  void SetPlotText(const Ssiz_t nTxtE, const Ssiz_t nTxtP, const TString sTxtE[], const TString sTxtP[]);
111  void Init();
112  void Analyze();
113  void End();
114 
115  private:
116 
117  // io/sys members
118  TFile *fOut;
119  TFile *fInEO;
120  TFile *fInPU;
121  Bool_t inBatchMode;
122  TString sInFileEO;
123  TString sInFilePU;
124  TString sInTupleEO;
125  TString sInTuplePU;
126  TString sInClustEO;
127  TString sOutfile;
128  TNtuple *ntTrkEO;
129  TNtuple *ntTrkPU;
130  TNtuple *ntClustEO;
131 
132  // track type/variable names/styles/labels [set in ctor, *.cc]
133  Bool_t isTruth[NType];
134  Bool_t isPileup[NType];
135  Bool_t isBeforeCuts[NType];
136  Bool_t trkVarHasTruVal[NTrkVar];
137  Bool_t physVarHasTruVal[NPhysVar];
138  UInt_t fTypeCol[NType];
139  UInt_t fTypeMar[NType];
140  TString sTrkNames[NType];
141  TString sTrkLabels[NType];
142  TString sTrkVars[NTrkVar];
143  TString sPhysVars[NPhysVar];
144 
145  // track-variable histograms
146  TH1D *hTrkVar[NType][NTrkVar];
147  TH1D *hTrkVarDiff[NType][NTrkVar];
148  TH1D *hTrkVarFrac[NType][NTrkVar];
149  TH2D *hTrkVarVsNTpc[NType][NTrkVar];
150  TH2D *hTrkVarVsDcaXY[NType][NTrkVar];
151  TH2D *hTrkVarVsDcaZ[NType][NTrkVar];
152  TH2D *hTrkVarVsPtReco[NType][NTrkVar];
153  TH2D *hTrkVarVsPtTrue[NType][NTrkVar];
154  TH2D *hTrkVarVsPtFrac[NType][NTrkVar];
155 
156  // physics-variable histograms
157  TH1D *hPhysVar[NType][NPhysVar];
158  TH1D *hPhysVarDiff[NType][NPhysVar];
159  TH1D *hPhysVarFrac[NType][NPhysVar];
160  TH2D *hPhysVarVsNTpc[NType][NPhysVar];
161  TH2D *hPhysVarVsDcaXY[NType][NPhysVar];
162  TH2D *hPhysVarVsDcaZ[NType][NPhysVar];
163  TH2D *hPhysVarVsPtReco[NType][NPhysVar];
164  TH2D *hPhysVarVsPtTrue[NType][NPhysVar];
165  TH2D *hPhysVarVsPtFrac[NType][NPhysVar];
166 
167  // text parameters
168  Ssiz_t nTxtEO;
169  Ssiz_t nTxtPU;
170  TPaveText *ptCut;
171  vector<TString> sTxtEO;
172  vector<TString> sTxtPU;
173 
174  // study parameters
175  Bool_t makePlots;
176  Bool_t doPileup;
177  Bool_t doIntNorm;
178  Bool_t doBeforeCuts;
180  Double_t normalPtFracMin;
181  Double_t normalPtFracMax;
182 
183  // track cuts
184  Bool_t doPrimaryCut;
185  Bool_t doMVtxCut;
186  Bool_t doTpcCut;
187  Bool_t doVzCut;
188  Bool_t doDcaXyCut;
189  Bool_t doDcaZCut;
190  Bool_t doQualityCut;
191  pair<UInt_t, UInt_t> nMVtxCut;
192  pair<UInt_t, UInt_t> nTpcCut;
193  pair<Double_t, Double_t> vzCut;
194  pair<Double_t, Double_t> dcaXyCut;
195  pair<Double_t, Double_t> dcaZCut;
196  pair<Double_t, Double_t> qualityCut;
197 
198  // embed-only leaves
199  Float_t event;
200  Float_t seed;
201  Float_t trackID;
202  Float_t crossing;
203  Float_t px;
204  Float_t py;
205  Float_t pz;
206  Float_t pt;
207  Float_t eta;
208  Float_t phi;
209  Float_t deltapt;
210  Float_t deltaeta;
211  Float_t deltaphi;
212  Float_t charge;
213  Float_t quality;
214  Float_t chisq;
215  Float_t ndf;
216  Float_t nhits;
217  Float_t nmaps;
218  Float_t nintt;
219  Float_t ntpc;
220  Float_t nmms;
221  Float_t ntpc1;
222  Float_t ntpc11;
223  Float_t ntpc2;
224  Float_t ntpc3;
225  Float_t nlmaps;
226  Float_t nlintt;
227  Float_t nltpc;
228  Float_t nlmms;
229  Float_t layers;
230  Float_t vertexID;
231  Float_t vx;
232  Float_t vy;
233  Float_t vz;
234  Float_t dca2d;
235  Float_t dca2dsigma;
236  Float_t dca3dxy;
237  Float_t dca3dxysigma;
238  Float_t dca3dz;
239  Float_t dca3dzsigma;
240  Float_t pcax;
241  Float_t pcay;
242  Float_t pcaz;
243  Float_t gtrackID;
244  Float_t gflavor;
245  Float_t gnhits;
246  Float_t gnmaps;
247  Float_t gnintt;
248  Float_t gntpc;
249  Float_t gnmms;
250  Float_t gnlmaps;
251  Float_t gnlintt;
252  Float_t gnltpc;
253  Float_t gnlmms;
254  Float_t gpx;
255  Float_t gpy;
256  Float_t gpz;
257  Float_t gpt;
258  Float_t geta;
259  Float_t gphi;
260  Float_t gvx;
261  Float_t gvy;
262  Float_t gvz;
263  Float_t gvt;
264  Float_t gfpx;
265  Float_t gfpy;
266  Float_t gfpz;
267  Float_t gfx;
268  Float_t gfy;
269  Float_t gfz;
270  Float_t gembed;
271  Float_t gprimary;
272  Float_t nfromtruth;
273  Float_t nwrong;
274  Float_t ntrumaps;
275  Float_t ntruintt;
276  Float_t ntrutpc;
277  Float_t ntrumms;
278  Float_t ntrutpc1;
279  Float_t ntrutpc11;
280  Float_t ntrutpc2;
281  Float_t ntrutpc3;
283  Float_t nhittpcall;
284  Float_t nhittpcin;
285  Float_t nhittpcmid;
286  Float_t nhittpcout;
287  Float_t nclusall;
288  Float_t nclustpc;
289  Float_t nclusintt;
290  Float_t nclusmaps;
291  Float_t nclusmms;
292 
293  // with-pileup leaves
294  Float_t pu_event;
295  Float_t pu_seed;
296  Float_t pu_gntracks;
297  Float_t pu_gtrackID;
298  Float_t pu_gflavor;
299  Float_t pu_gnhits;
300  Float_t pu_gnmaps;
301  Float_t pu_gnintt;
302  Float_t pu_gnmms;
303  Float_t pu_gnintt1;
304  Float_t pu_gnintt2;
305  Float_t pu_gnintt3;
306  Float_t pu_gnintt4;
307  Float_t pu_gnintt5;
308  Float_t pu_gnintt6;
309  Float_t pu_gnintt7;
310  Float_t pu_gnintt8;
311  Float_t pu_gntpc;
312  Float_t pu_gnlmaps;
313  Float_t pu_gnlintt;
314  Float_t pu_gnltpc;
315  Float_t pu_gnlmms;
316  Float_t pu_gpx;
317  Float_t pu_gpy;
318  Float_t pu_gpz;
319  Float_t pu_gpt;
320  Float_t pu_geta;
321  Float_t pu_gphi;
322  Float_t pu_gvx;
323  Float_t pu_gvy;
324  Float_t pu_gvz;
325  Float_t pu_gvt;
326  Float_t pu_gfpx;
327  Float_t pu_gfpy;
328  Float_t pu_gfpz;
329  Float_t pu_gfx;
330  Float_t pu_gfy;
331  Float_t pu_gfz;
332  Float_t pu_gembed;
333  Float_t pu_gprimary;
334  Float_t pu_trackID;
335  Float_t pu_px;
336  Float_t pu_py;
337  Float_t pu_pz;
338  Float_t pu_pt;
339  Float_t pu_eta;
340  Float_t pu_phi;
341  Float_t pu_deltapt;
342  Float_t pu_deltaeta;
343  Float_t pu_deltaphi;
344  Float_t pu_charge;
345  Float_t pu_quality;
346  Float_t pu_chisq;
347  Float_t pu_ndf;
348  Float_t pu_nhits;
349  Float_t pu_layers;
350  Float_t pu_nmaps;
351  Float_t pu_nintt;
352  Float_t pu_ntpc;
353  Float_t pu_nmms;
354  Float_t pu_ntpc1;
355  Float_t pu_ntpc11;
356  Float_t pu_ntpc2;
357  Float_t pu_ntpc3;
358  Float_t pu_nlmaps;
359  Float_t pu_nlintt;
360  Float_t pu_nltpc;
361  Float_t pu_nlmms;
362  Float_t pu_vertexID;
363  Float_t pu_vx;
364  Float_t pu_vy;
365  Float_t pu_vz;
366  Float_t pu_dca2d;
367  Float_t pu_dca2dsigma;
368  Float_t pu_dca3dxy;
370  Float_t pu_dca3dz;
371  Float_t pu_dca3dzsigma;
372  Float_t pu_pcax;
373  Float_t pu_pcay;
374  Float_t pu_pcaz;
375  Float_t pu_nfromtruth;
376  Float_t pu_nwrong;
377  Float_t pu_ntrumaps;
378  Float_t pu_ntruintt;
379  Float_t pu_ntrutpc;
380  Float_t pu_ntrumms;
381  Float_t pu_ntrutpc1;
382  Float_t pu_ntrutpc11;
383  Float_t pu_ntrutpc2;
384  Float_t pu_ntrutpc3;
386  Float_t pu_nhittpcall;
387  Float_t pu_nhittpcin;
388  Float_t pu_nhittpcmid;
389  Float_t pu_nhittpcout;
390  Float_t pu_nclusall;
391  Float_t pu_nclustpc;
392  Float_t pu_nclusintt;
393  Float_t pu_nclusmaps;
394  Float_t pu_nclusmms;
395 
396  // i/o methods [*.io.h]
397  void InitFiles();
398  void InitTuples();
399  void SaveHists();
400 
401  // analysis methods [*.ana.h]
402  Bool_t ApplyCuts(const Bool_t isPrimary, const UInt_t trkNMVtx, const UInt_t trkNTpc, const Double_t trkVz, const Double_t trkDcaXY, const Double_t trkDcaZ, const Double_t trkQuality);
403  Bool_t DoClusterCalculation();
404 
405  // histogram methods [*.hist.h]
406  void InitHists();
407  void NormalizeHists();
408  void SetHistStyles();
409  void FillTrackHistograms(const Int_t type, const Double_t recoTrkVars[], const Double_t trueTrkVars[], const Double_t recoPhysVars[], const Double_t truePhysVars[]);
410  void FillTruthHistograms(const Int_t type, const Double_t recoTrkVars[], const Double_t trueTrkVars[], const Double_t recoPhysVars[], const Double_t truePhysVars[]);
411 
412  // plot methods [*.plot.h]
413  void MakeCutText();
414  void ConstructPlots(const Ssiz_t nToDraw, const Int_t typesToDraw[], const TString sDirToSaveTo, const TString sPlotLabel);
415 
416 }; // end STrackCutStudy definition
417 
418 #endif
419 
420 // end ------------------------------------------------------------------------