Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDeltaPtCutStudy.io.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SDeltaPtCutStudy.io.h
1 // ----------------------------------------------------------------------------
2 // 'SDeltaPtCutStudy.io.h'
3 // Derek Anderson
4 // 07.06.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 #pragma once
13 
14 using namespace std;
15 
16 
17 
18 // public io methods ----------------------------------------------------------
19 
20 void SDeltaPtCutStudy::SetInputOutputFiles(const TString sInput, const TString sOutput) {
21 
22  sInFile = sInput;
23  sOutFile = sOutput;
24  cout << " Set input/output files:\n"
25  << " input = " << sInFile.Data() << "\n"
26  << " output = " << sOutFile.Data()
27  << endl;
28  return;
29 
30 } // end 'SetInputOutputFiles(TString, TString)'
31 
32 
33 
34 void SDeltaPtCutStudy::SetInputTuples(const TString sTrack, const TString sTruth) {
35 
36  sInTrack = sTrack;
37  sInTruth = sTruth;
38  cout << " Set track/truth tuples:\n"
39  << " track tuple = " << sInTrack.Data() << "\n"
40  << " truth tuple = " << sInTruth.Data()
41  << endl;
42  return;
43 
44 } // end 'SetInputTuples(TString, TString)'
45 
46 
47 
48 void SDeltaPtCutStudy::SetGeneralTrackCuts(const uint32_t nInttCut, const uint32_t nMvtxCut, const uint32_t nTpcCut, const double qualCut, const double vzCut, const double ptCut) {
49 
50  nInttTrkMin = nInttCut;
51  nMVtxTrkMin = nMvtxCut;
52  nTpcTrkMin = nTpcCut;
53  qualTrkMax = qualCut;
54  vzTrkMax = vzCut;
55  ptTrkMin = ptCut;
56  cout << " Set general track cuts:\n"
57  << " nIntt > " << nInttTrkMin << "\n"
58  << " nMvtx > " << nMVtxTrkMin << "\n"
59  << " nTpc > " << nTpcTrkMin << "\n"
60  << " quality < " << qualTrkMax << "\n"
61  << " |vz| < " << vzTrkMax << "\n"
62  << " pt > " << ptTrkMin
63  << endl;
64  return;
65 
66 } // end 'SetGeneralTrackCuts(uint32_t, uint32_t, uint32_t, double, double, double)'
67 
68 
69 
70 void SDeltaPtCutStudy::SetSigmaFitGuesses(const array<float, Const::NPar> hiGuess, const array<float, Const::NPar> loGuess) {
71 
72  for (uint8_t iPar = 0; iPar < Const::NPar; iPar++) {
73  sigHiGuess[iPar] = hiGuess[iPar];
74  sigLoGuess[iPar] = loGuess[iPar];
75  }
76  cout << " Set sigma(delta-pt / pt) fit guesses:\n"
77  << " high guess parameters = (" << sigHiGuess[0] << ", " << sigHiGuess[1] << ", " << sigHiGuess[2] << ")\n"
78  << " low guess parameters = (" << sigLoGuess[0] << ", " << sigLoGuess[1] << ", " << sigLoGuess[2] << ")"
79  << endl;
80  return;
81 
82 } // end 'SetSigmaFitGuesses(array<float>, array<float>)'
83 
84 
85 
86 void SDeltaPtCutStudy::SetNormAndFitRanges(const pair<float, float> norm, const pair<float, float> ptFit, const pair<float, float> deltaFit) {
87 
88  normRange[0] = norm.first;
89  normRange[1] = norm.second;
90  ptFitRange[0] = ptFit.first;
91  ptFitRange[1] = ptFit.second;
92  deltaFitRange[0] = deltaFit.first;
93  deltaFitRange[1] = deltaFit.second;
94  cout << " Set normalization and fit ranges:\n"
95  << " normalization = (" << normRange[0] << ", " << normRange[1] << ")\n"
96  << " pt fit = (" << ptFitRange[0] << ", " << ptFitRange[1] << ")\n"
97  << " delta-pt fit = (" << deltaFitRange[0] << ", " << deltaFitRange[1] << ")"
98  << endl;
99  return;
100 
101 } // end 'SetNormAndFitRange(pair<float, float>, pair<float, float>, pair<float, float>)'
102 
103 
104 
105 void SDeltaPtCutStudy::SetPlotRanges(const pair<float, float> ptRange, const pair<float, float> fracRange, const pair<float, float> deltaRange) {
106 
107  rPtRange[0] = ptRange.first;
108  rPtRange[1] = ptRange.second;
109  rFracRange[0] = fracRange.first;
110  rFracRange[1] = fracRange.second;
111  rDeltaRange[0] = deltaRange.first;
112  rDeltaRange[1] = deltaRange.second;
113  cout << " Set plot ranges:\n"
114  << " pt = (" << rPtRange[0] << ", " << rPtRange[1] << ")\n"
115  << " frac = (" << rFracRange[0] << ", " << rFracRange[1] << ")\n"
116  << " delta = (" << rDeltaRange[0] << ", " << rDeltaRange[1] << ")"
117  << endl;
118  return;
119 
120 } // end 'SetPlotRanges(pair<float, float>, pair<float, float>, pair<float, float>)'
121 
122 
123 
124 void SDeltaPtCutStudy::SetGeneralStyleParameters(const array<uint32_t, Const::NTypes> arrCol, const array<uint32_t, Const::NTypes> arrMar) {
125 
126  fColTrue = arrCol[0];
127  fColPure = arrCol[1];
128  fColTrk = arrCol[2];
129  fMarTrue = arrMar[0];
130  fMarPure = arrMar[1];
131  fMarTrk = arrMar[2];
132  cout << " Set general style parameters:\n"
133  << " colors (true, pure, track) = (" << fColTrue << ", " << fColPure << ", " << fColTrk << ")\n"
134  << " markers (true, pure, track) = (" << fMarTrue << ", " << fMarPure << ", " << fMarTrk << ")"
135  << endl;
136  return;
137 
138 } // end 'SetGeneralStyleParameters(array<uint32_t>, array<uint32_t>)'
139 
140 
141 
142 void SDeltaPtCutStudy::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) {
143 
144  fFil = fill;
145  fLin = line;
146  fWid = width;
147  fTxt = font;
148  fAln = align;
149  fCnt = center;
150  cout << " Set general histogram parameters:\n"
151  << " fill = " << fFil << "\n"
152  << " line = " << fLin << "\n"
153  << " width = " << fWid << "\n"
154  << " font = " << fTxt << "\n"
155  << " align = " << fAln << "\n"
156  << " center = " << fCnt
157  << endl;
158  return;
159 
160 } // end 'SetGeneralHistParameters(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)'
161 
162 
163 
164 void SDeltaPtCutStudy::SetHistBaseNames(const TString sProj, const TString sDelta, const TString sTrue, const TString sReco, const TString sFrac, const TString sTrack) {
165 
166  sPtProjBase = sProj;
167  sPtDeltaBase = sDelta;
168  sPtTrueBase = sTrue;
169  sPtRecoBase = sReco;
170  sPtFracBase = sFrac;
171  sPtTrkTruBase = sTrack;
172  cout << " Set histogram base names:\n"
173  << " " << sPtProjBase << "\n"
174  << " " << sPtDeltaBase << "\n"
175  << " " << sPtTrueBase << "\n"
176  << " " << sPtRecoBase << "\n"
177  << " " << sPtFracBase << "\n"
178  << " " << sPtTrkTruBase
179  << endl;
180  return;
181 
182 } // end 'SetHistBaseNames(TString, TString, TString, TString, TString, TString)'
183 
184 
185 
186 void SDeltaPtCutStudy::SetPlotText(const vector<TString> plotText) {
187 
188  nTxt = plotText.size();
189  sInfo = plotText;
190 
191  cout << " Set plot text:" << endl;
192  for (size_t iTxt = 0; iTxt < nTxt; iTxt++) {
193  cout << " " << sInfo[iTxt] << endl;
194  }
195  return;
196 
197 } // end 'SetPlotText(vector<TString>)'
198 
199 
200 
201 void SDeltaPtCutStudy::SetEffRebinParameters(const bool doRebin, const size_t nRebin) {
202 
203  doEffRebin = doRebin;
204  nEffRebin = nRebin;
205  cout << " Set efficiency rebinning parameters:\n"
206  << " do rebin? = " << doEffRebin << "\n"
207  << " nRebin = " << nEffRebin
208  << endl;
209  return;
210 
211 } // end 'SetRebinParameters(bool, size_t)'
212 
213 
214 
215 void SDeltaPtCutStudy::SetProjectionParameters(const vector<tuple<double, TString, uint32_t, uint32_t, uint32_t>> projParams) {
216 
217  nProj = projParams.size();
218  for (auto param : projParams) {
219  ptProj.push_back(get<0>(param));
220  sProjSuffix.push_back(get<1>(param));
221  fColProj.push_back(get<2>(param));
222  fMarProj.push_back(get<3>(param));
223  fColFit.push_back(get<4>(param));
224  }
225 
226  cout << " Set projection parameters." << endl;
227  return;
228 
229 } // end 'SetProjectionParameters(vector<tuple<double, TString, uint32_t, uint32_t, uint32_t>>)'
230 
231 
232 
233 void SDeltaPtCutStudy::SetFlatCutParameters(const vector<tuple<double, TString, uint32_t, uint32_t, bool>> flatParams) {
234 
235  bool cutSelected = false;
236  size_t iParam = 0;
237  for (auto param : flatParams) {
238 
239  // read in parameters
240  ptDeltaMax.push_back(get<0>(param));
241  sDPtSuffix.push_back(get<1>(param));
242  fColCut.push_back(get<2>(param));
243  fMarCut.push_back(get<3>(param));
244 
245  // determine which cut to draw
246  if (!cutSelected && get<4>(param)) {
247  iCutToDraw = iParam;
248  cutSelected = true;
249  }
250  ++iParam;
251  }
252  nDPtCuts = flatParams.size();
253 
254  cout << " Set flat delta-pt cut parameters." << endl;
255  return;
256 
257 } // end 'SetFlatCutParameters(vector<tuple<double, TString, uint32_t, uint32_t, bool>>)'
258 
259 
260 
261 void SDeltaPtCutStudy::SetPtDependCutParameters(const vector<tuple<double, TString, uint32_t, uint32_t, uint32_t, bool>> ptDependParams) {
262 
263  bool cutSelected = false;
264  size_t iParam = 0;
265  for (auto param : ptDependParams) {
266 
267  // read in parameters
268  ptDeltaSig.push_back(get<0>(param));
269  sSigSuffix.push_back(get<1>(param));
270  fColSig.push_back(get<2>(param));
271  fMarSig.push_back(get<3>(param));
272  fColSigFit.push_back(get<4>(param));
273 
274  // determine which cut to draw
275  if (!cutSelected && get<5>(param)) {
276  iCutToDraw = iParam;
277  cutSelected = true;
278  }
279  ++iParam;
280  }
281  nSigCuts = ptDependParams.size();
282 
283  cout << " Set pt-dependent delta-pt cut parameters." << endl;
284  return;
285 
286 } // end 'SetFlatCutParameters(vector<tuple<double, TString, uint32_t, uint32_t, uint32_t, bool>>)'
287 
288 
289 
290 // private io methods ---------------------------------------------------------
291 
293 
294  fOutput = new TFile(sOutFile.Data(), "recreate");
295  fInput = new TFile(sInFile.Data(), "read");
296  if (!fInput || !fOutput) {
297  cerr << "PANIC: couldn't open a file!\n"
298  << " fInput = " << fInput << "\n"
299  << " fOutput = " << fOutput << "\n"
300  << endl;
301  assert(fOutput && fInput);
302  }
303 
304  cout << " Opened files." << endl;
305  return;
306 
307 } // end 'OpenFiles()'
308 
309 
310 
312 
313  ntTrack = (TNtuple*) fInput -> Get(sInTrack.Data());
314  ntTruth = (TNtuple*) fInput -> Get(sInTruth.Data());
315  if (!ntTrack || !ntTruth) {
316  cerr << "PANIC: couldn't grab aninput tuple!\n"
317  << " ntTrack = " << ntTrack << "\n"
318  << " ntTruth = " << ntTruth << "\n"
319  << endl;
320  assert(ntTrack && ntTruth);
321  }
322 
323  cout << " Grabbed input tuples." << endl;
324  return;
325 
326 } // 'GetTuples()'
327 
328 
329 
331 
332  // make directories
333  TDirectory *dNoCut = (TDirectory*) fOutput -> mkdir("NoCuts");
334  TDirectory *dFlatCut = (TDirectory*) fOutput -> mkdir("FlatCuts");
335  TDirectory *dSigmaCut = (TDirectory*) fOutput -> mkdir("SigmaCuts");
336  TDirectory *dProject = (TDirectory*) fOutput -> mkdir("Projections");
337  cout << " Made output directories." << endl;
338 
339  // save histograms
340  fOutput -> cd();
341  dNoCut -> cd();
342  hEff -> Write();
343  hPtTruth -> Write();
344  hPtDelta -> Write();
345  hPtTrack -> Write();
346  hPtFrac -> Write();
347  hPtTrkTru -> Write();
348  hPtDeltaVsFrac -> Write();
349  hPtDeltaVsTrue -> Write();
350  hPtDeltaVsTrack -> Write();
351  hPtTrueVsTrack -> Write();
352 
353  // save flat delta-pt cut histograms
354  dFlatCut -> cd();
355  grRejCut -> Write();
356  for (size_t iCut = 0; iCut < nDPtCuts; iCut++) {
357  hEffCut[iCut] -> Write();
358  hPtDeltaCut[iCut] -> Write();
359  hPtTrackCut[iCut] -> Write();
360  hPtFracCut[iCut] -> Write();
361  hPtTrkTruCut[iCut] -> Write();
362  hPtDeltaVsFracCut[iCut] -> Write();
363  hPtDeltaVsTrueCut[iCut] -> Write();
364  hPtDeltaVsTrackCut[iCut] -> Write();
365  hPtTrueVsTrackCut[iCut] -> Write();
366  }
367 
368  // save pt-dependent delta-pt cut histograms
369  dSigmaCut -> cd();
370  grRejSig -> Write();
371  for (size_t iSig = 0; iSig < nSigCuts; iSig++) {
372  hEffSig[iSig] -> Write();
373  hPtDeltaSig[iSig] -> Write();
374  hPtTrackSig[iSig] -> Write();
375  hPtFracSig[iSig] -> Write();
376  hPtTrkTruSig[iSig] -> Write();
377  hPtDeltaVsFracSig[iSig] -> Write();
378  hPtDeltaVsTrueSig[iSig] -> Write();
379  hPtDeltaVsTrackSig[iSig] -> Write();
380  hPtTrueVsTrackSig[iSig] -> Write();
381  }
382 
383  // save delta-pt projection histograms
384  dProject -> cd();
385  grMuProj -> Write();
386  grSigProj -> Write();
387  for (size_t iProj = 0; iProj < nProj; iProj++) {
388  hPtDeltaProj[iProj] -> Write();
389  fPtDeltaProj[iProj] -> Write();
390  }
391  for (size_t iSig = 0; iSig < nSigCuts; iSig++) {
392  fMuHiProj[iSig] -> Write();
393  fMuLoProj[iSig] -> Write();
394  grMuHiProj[iSig] -> Write();
395  grMuLoProj[iSig] -> Write();
396  }
397 
398  cout << " Saved output." << endl;
399  return;
400 
401 } // end 'SaveOutput()'
402 
403 
404 
406 
407  fOutput -> cd();
408  fOutput -> Close();
409  fInput -> cd();
410  fInput -> Close();
411 
412  cout << " Closed files." << endl;
413  return;
414 
415 } // end 'CloseFiles()'
416 
417 // end ------------------------------------------------------------------------