Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDeltaPtCutStudy.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SDeltaPtCutStudy.h
1 // ----------------------------------------------------------------------------
2 // 'SDeltaPtCutStudy.h'
3 // Derek Anderson
4 // 06.29.2023
5 //
6 // Reads in the 'ntp_track' Ntuple
7 // generated by the SVtxEvaluator
8 // class and studies how deltapt/pt
9 // varies with quality cuts.
10 // ----------------------------------------------------------------------------
11 
12 #ifndef SDELTAPTCUTSTUDY_H
13 #define SDELTAPTCUTSTUDY_H
14 
15 // standard c includes
16 #include <array>
17 #include <cmath>
18 #include <vector>
19 #include <cassert>
20 #include <cstdlib>
21 #include <utility>
22 #include <iostream>
23 // root includes
24 #include <TH1.h>
25 #include <TH2.h>
26 #include <TF1.h>
27 #include <TPad.h>
28 #include <TFile.h>
29 #include <TLine.h>
30 #include <TGraph.h>
31 #include <TError.h>
32 #include <TString.h>
33 #include <TNtuple.h>
34 #include <TLegend.h>
35 #include <TCanvas.h>
36 #include <TVector.h>
37 #include <TPaveText.h>
38 #include <TDirectory.h>
39 
40 using namespace std;
41 
42 
43 
44 // SDeltaPtCutStudy definition ------------------------------------------------
45 
47 
48  // constants
49  enum Const {
50  NPad = 2,
51  NPar = 3,
52  NVtx = 4,
53  NRange = 2,
54  NTypes = 3,
56  };
57 
58  public:
59 
60  // ctor/dtor [*.cc]
63 
64  // main methods [*.cc]
65  void Init();
66  void Analyze();
67  void End();
68 
69  // setters [*.io.h]
70  void SetInputOutputFiles(const TString sInput, const TString sOutput);
71  void SetInputTuples(const TString sTrack, const TString sTruth);
72  void SetGeneralTrackCuts(const uint32_t nInttCut, const uint32_t nMvtxCut, const uint32_t nTpcCut, const double qualCut, const double vzCut, const double ptCut);
73  void SetSigmaFitGuesses(const array<float, Const::NPar> hiGuess, const array<float, Const::NPar> loGuess);
74  void SetNormAndFitRanges(const pair<float, float> norm, const pair<float, float> ptFit, const pair<float, float> deltaFit);
75  void SetPlotRanges(const pair<float, float> ptRange, const pair<float, float> fracRange, const pair<float, float> deltaRange);
76  void SetGeneralStyleParameters(const array<uint32_t, Const::NTypes> arrCol, const array<uint32_t, Const::NTypes> arrMar);
77  void SetGeneralHistParameters(const uint32_t fill, const uint32_t line, const uint32_t width, const uint32_t font, const uint32_t align, const uint32_t center);
78  void SetHistBaseNames(const TString sProj, const TString sDelta, const TString sTrue, const TString sReco, const TString sFrac, const TString sTrack);
79  void SetPlotText(const vector<TString> plotText);
80  void SetEffRebinParameters(const bool doRebin, const size_t nRebin = 2);
81  void SetProjectionParameters(const vector<tuple<double, TString, uint32_t, uint32_t, uint32_t>> projParams);
82  void SetFlatCutParameters(const vector<tuple<double, TString, uint32_t, uint32_t, bool>> flatParams);
83  void SetPtDependCutParameters(const vector<tuple<double, TString, uint32_t, uint32_t, uint32_t, bool>> ptDependParams);
84 
85  private:
86 
87  // io methods [*.io.h]
88  void OpenFiles();
89  void GetTuples();
90  void SaveOutput();
91  void CloseFiles();
92 
93  // system methods [*.sys.h]
94  void InitVectors();
95  void InitTuples();
96  void InitHists();
97 
98  // analysis methods [*.ana.h]
99  void ApplyFlatDeltaPtCuts();
100  void ApplyPtDependentDeltaPtCuts();
101  void FillTruthHistograms();
102  void CreateSigmaGraphs();
103  void CalculateRejectionFactors();
104  void CalculateEfficiencies();
105 
106  // plot methods [*.plot.h]
107  void SetStyles();
108  void MakePlots();
109 
110  // io parameters
111  TFile* fInput;
112  TFile* fOutput;
113  TNtuple* ntTrack;
114  TNtuple* ntTruth;
115  TString sInFile;
116  TString sOutFile;
117  TString sInTrack;
118  TString sInTruth;
119 
120  // general cut parameters
121  uint32_t nInttTrkMin = 1;
122  uint32_t nMVtxTrkMin = 2;
123  uint32_t nTpcTrkMin = 35;
124  double qualTrkMax = 10.;
125  double vzTrkMax = 10.;
126  double ptTrkMin = 0.1;
127 
128  // sigma calculation parameters
129  array<float, Const::NPar> sigHiGuess = {1., -1., 1.};
130  array<float, Const::NPar> sigLoGuess = {1., -1., 1.};
131  array<float, Const::NRange> normRange = {0.2, 1.2};
132  array<float, Const::NRange> ptFitRange = {0.5, 40.};
133  array<float, Const::NRange> deltaFitRange = {0., 0.1};
134 
135  // projection parameters
136  size_t nProj = 0;
137  vector<double> ptProj;
138  vector<TString> sProjSuffix;
139  vector<TString> sPtProj;
140  vector<uint32_t> fColProj;
141  vector<uint32_t> fMarProj;
142  vector<uint32_t> fColFit;
143 
144  // flat delta-pt cut parameters
145  size_t nDPtCuts = 0;
146  size_t iCutToDraw = 0;
147  vector<double> ptDeltaMax;
148  vector<TString> sDPtSuffix;
149  vector<uint32_t> fColCut;
150  vector<uint32_t> fMarCut;
151 
152  // pt-dependent delta-pt cut parameters
153  size_t nSigCuts = 0;
154  size_t iSigToDraw = 0;
155  vector<double> ptDeltaSig;
156  vector<TString> sSigSuffix;
157  vector<uint32_t> fColSig;
158  vector<uint32_t> fMarSig;
159  vector<uint32_t> fColSigFit;
160 
161  // histogram base names
162  TString sPtProjBase = "DeltaPtProj";
163  TString sPtDeltaBase = "DeltaPt";
164  TString sPtTrueBase = "PtTrue";
165  TString sPtRecoBase = "PtReco";
166  TString sPtFracBase = "PtFrac";
167  TString sPtTrkTruBase = "PtTrkTruth";
168 
169  // plot text
170  size_t nTxt = 0;
171  vector<TString> sInfo;
172 
173  // plot range parameters
174  array<float, Const::NRange> rPtRange = {0., 60.};
175  array<float, Const::NRange> rFracRange = {0., 4.};
176  array<float, Const::NRange> rDeltaRange = {0., 0.1};
177 
178  // general histogram style parameters
179  uint32_t fFil = 0;
180  uint32_t fLin = 1;
181  uint32_t fWid = 1;
182  uint32_t fTxt = 42;
183  uint32_t fAln = 12;
184  uint32_t fCnt = 1;
185  uint32_t fColTrue = 923;
186  uint32_t fColPure = 923;
187  uint32_t fColTrk = 809;
188  uint32_t fMarTrue = 20;
189  uint32_t fMarPure = 20;
190  uint32_t fMarTrk = 46;
191  size_t nEffRebin = 5;
192  bool doEffRebin = true;
193 
194  // track tuple addresses
195  float trk_event;
196  float trk_seed;
197  float trk_trackID;
199  float trk_px;
200  float trk_py;
201  float trk_pz;
202  float trk_pt;
203  float trk_eta;
204  float trk_phi;
205  float trk_deltapt;
208  float trk_charge;
209  float trk_quality;
210  float trk_chisq;
211  float trk_ndf;
212  float trk_nhits;
213  float trk_nmaps;
214  float trk_nintt;
215  float trk_ntpc;
216  float trk_nmms;
217  float trk_ntpc1;
218  float trk_ntpc11;
219  float trk_ntpc2;
220  float trk_ntpc3;
221  float trk_nlmaps;
222  float trk_nlintt;
223  float trk_nltpc;
224  float trk_nlmms;
225  float trk_layers;
227  float trk_vx;
228  float trk_vy;
229  float trk_vz;
230  float trk_dca2d;
232  float trk_dca3dxy;
234  float trk_dca3dz;
236  float trk_pcax;
237  float trk_pcay;
238  float trk_pcaz;
240  float trk_gflavor;
241  float trk_gnhits;
242  float trk_gnmaps;
243  float trk_gnintt;
244  float trk_gntpc;
245  float trk_gnmms;
246  float trk_gnlmaps;
247  float trk_gnlintt;
248  float trk_gnltpc;
249  float trk_gnlmms;
250  float trk_gpx;
251  float trk_gpy;
252  float trk_gpz;
253  float trk_gpt;
254  float trk_geta;
255  float trk_gphi;
256  float trk_gvx;
257  float trk_gvy;
258  float trk_gvz;
259  float trk_gvt;
260  float trk_gfpx;
261  float trk_gfpy;
262  float trk_gfpz;
263  float trk_gfx;
264  float trk_gfy;
265  float trk_gfz;
266  float trk_gembed;
269  float trk_nwrong;
272  float trk_ntrutpc;
273  float trk_ntrumms;
288 
289  // truth tuple addresses
290  float tru_event;
291  float tru_seed;
294  float tru_gflavor;
295  float tru_gnhits;
296  float tru_gnmaps;
297  float tru_gnintt;
298  float tru_gnmms;
299  float tru_gnintt1;
300  float tru_gnintt2;
301  float tru_gnintt3;
302  float tru_gnintt4;
303  float tru_gnintt5;
304  float tru_gnintt6;
305  float tru_gnintt7;
306  float tru_gnintt8;
307  float tru_gntpc;
308  float tru_gnlmaps;
309  float tru_gnlintt;
310  float tru_gnltpc;
311  float tru_gnlmms;
312  float tru_gpx;
313  float tru_gpy;
314  float tru_gpz;
315  float tru_gpt;
316  float tru_geta;
317  float tru_gphi;
318  float tru_gvx;
319  float tru_gvy;
320  float tru_gvz;
321  float tru_gvt;
322  float tru_gfpx;
323  float tru_gfpy;
324  float tru_gfpz;
325  float tru_gfx;
326  float tru_gfy;
327  float tru_gfz;
328  float tru_gembed;
330  float tru_trackID;
331  float tru_px;
332  float tru_py;
333  float tru_pz;
334  float tru_pt;
335  float tru_eta;
336  float tru_phi;
337  float tru_deltapt;
340  float tru_charge;
341  float tru_quality;
342  float tru_chisq;
343  float tru_ndf;
344  float tru_nhits;
345  float tru_layers;
346  float tru_nmaps;
347  float tru_nintt;
348  float tru_ntpc;
349  float tru_nmms;
350  float tru_ntpc1;
351  float tru_ntpc11;
352  float tru_ntpc2;
353  float tru_ntpc3;
354  float tru_nlmaps;
355  float tru_nlintt;
356  float tru_nltpc;
357  float tru_nlmms;
359  float tru_vx;
360  float tru_vy;
361  float tru_vz;
362  float tru_dca2d;
364  float tru_dca3dxy;
366  float tru_dca3dz;
368  float tru_pcax;
369  float tru_pcay;
370  float tru_pcaz;
372  float tru_nwrong;
375  float tru_ntrutpc;
376  float tru_ntrumms;
391 
392  // for sigma calculation
393  vector<double> muProj;
394  vector<double> sigProj;
395  vector<vector<double>> muHiProj;
396  vector<vector<double>> muLoProj;
397 
398  // for flat delta-pt cut rejection
399  vector<uint64_t> nNormCut;
400  vector<uint64_t> nNormSig;
401  vector<uint64_t> nWeirdCut;
402  vector<uint64_t> nWeirdSig;
403  vector<double> rejCut;
404  vector<double> rejSig;
405 
406  // for tuple loops
407  uint64_t nTrks;
408  uint64_t nTrus;
409 
410  // general 1d histograms
411  TH1D* hEff;
412  TH1D* hPtTruth;
413  TH1D* hPtDelta;
414  TH1D* hPtTrack;
415  TH1D* hPtFrac;
416  TH1D* hPtTrkTru;
417 
418  // 1d projection & cut-dependent histograms
419  vector<TH1D*> hPtDeltaProj;
420  vector<TH1D*> hPtDeltaCut;
421  vector<TH1D*> hPtDeltaSig;
422  vector<TH1D*> hPtTrackCut;
423  vector<TH1D*> hPtTrackSig;
424  vector<TH1D*> hPtFracCut;
425  vector<TH1D*> hPtFracSig;
426  vector<TH1D*> hPtTrkTruCut;
427  vector<TH1D*> hPtTrkTruSig;
428  vector<TH1D*> hEffCut;
429  vector<TH1D*> hEffSig;
430 
431 
432  // general 2d histograms
437 
438  // 2d cut-dependent histograms
439  vector<TH2D*> hPtDeltaVsFracCut;
440  vector<TH2D*> hPtDeltaVsFracSig;
441  vector<TH2D*> hPtDeltaVsTrueCut;
442  vector<TH2D*> hPtDeltaVsTrueSig;
443  vector<TH2D*> hPtDeltaVsTrackCut;
444  vector<TH2D*> hPtDeltaVsTrackSig;
445  vector<TH2D*> hPtTrueVsTrackCut;
446  vector<TH2D*> hPtTrueVsTrackSig;
447 
448  // functions
449  vector<TF1*> fPtDeltaProj;
450  vector<TF1*> fMuHiProj;
451  vector<TF1*> fMuLoProj;
452 
453  // general graphs
454  TGraph* grMuProj;
455  TGraph* grSigProj;
456  TGraph* grRejCut;
457  TGraph* grRejSig;
458 
459  // cut-dependent graphs
460  vector<TGraph*> grMuHiProj;
461  vector<TGraph*> grMuLoProj;
462 
463 }; // end SDeltaPtCutStudy definition
464 
465 #endif
466 
467 // end ------------------------------------------------------------------------