Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-03 08:08:38

0001 // ----------------------------------------------------------------------------
0002 // 'SDeltaPtCutStudy.h'
0003 // Derek Anderson
0004 // 06.29.2023
0005 //
0006 // Reads in the 'ntp_track' Ntuple
0007 // generated by the SVtxEvaluator
0008 // class and studies how deltapt/pt
0009 // varies with quality cuts.
0010 // ----------------------------------------------------------------------------
0011 
0012 #ifndef SDELTAPTCUTSTUDY_H
0013 #define SDELTAPTCUTSTUDY_H
0014 
0015 // standard c includes
0016 #include <array>
0017 #include <cmath>
0018 #include <vector>
0019 #include <cassert>
0020 #include <cstdlib>
0021 #include <utility>
0022 #include <iostream>
0023 // root includes
0024 #include <TH1.h>
0025 #include <TH2.h>
0026 #include <TF1.h>
0027 #include <TPad.h>
0028 #include <TFile.h>
0029 #include <TLine.h>
0030 #include <TGraph.h>
0031 #include <TError.h>
0032 #include <TString.h>
0033 #include <TNtuple.h>
0034 #include <TLegend.h>
0035 #include <TCanvas.h>
0036 #include <TVector.h>
0037 #include <TPaveText.h>
0038 #include <TDirectory.h>
0039 
0040 using namespace std;
0041 
0042 
0043 
0044 // SDeltaPtCutStudy definition ------------------------------------------------
0045 
0046 class SDeltaPtCutStudy {
0047 
0048   // constants
0049   enum Const {
0050     NPad     = 2,
0051     NPar     = 3,
0052     NVtx     = 4,
0053     NRange   = 2,
0054     NTypes   = 3,
0055     NTrkCuts = 6
0056   };
0057 
0058   public:
0059 
0060     // ctor/dtor [*.cc]
0061     SDeltaPtCutStudy();
0062     ~SDeltaPtCutStudy();
0063 
0064     // main methods [*.cc]
0065     void Init();
0066     void Analyze();
0067     void End();
0068 
0069     // setters [*.io.h]
0070     void SetInputOutputFiles(const TString sInput, const TString sOutput);
0071     void SetInputTuples(const TString sTrack, const TString sTruth);
0072     void SetGeneralTrackCuts(const uint32_t nInttCut, const uint32_t nMvtxCut, const uint32_t nTpcCut, const double qualCut, const double vzCut, const double ptCut);
0073     void SetSigmaFitGuesses(const array<float, Const::NPar> hiGuess, const array<float, Const::NPar> loGuess);
0074     void SetNormAndFitRanges(const pair<float, float> norm, const pair<float, float> ptFit, const pair<float, float> deltaFit); 
0075     void SetPlotRanges(const pair<float, float> ptRange, const pair<float, float> fracRange, const pair<float, float> deltaRange);
0076     void SetGeneralStyleParameters(const array<uint32_t, Const::NTypes> arrCol, const array<uint32_t, Const::NTypes> arrMar);
0077     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);
0078     void SetHistBaseNames(const TString sProj, const TString sDelta, const TString sTrue, const TString sReco, const TString sFrac, const TString sTrack);
0079     void SetPlotText(const vector<TString> plotText);
0080     void SetEffRebinParameters(const bool doRebin, const size_t nRebin = 2);
0081     void SetProjectionParameters(const vector<tuple<double, TString, uint32_t, uint32_t, uint32_t>> projParams);
0082     void SetFlatCutParameters(const vector<tuple<double, TString, uint32_t, uint32_t, bool>> flatParams);
0083     void SetPtDependCutParameters(const vector<tuple<double, TString, uint32_t, uint32_t, uint32_t, bool>> ptDependParams);
0084 
0085   private:
0086 
0087     // io methods [*.io.h]
0088     void OpenFiles();
0089     void GetTuples();
0090     void SaveOutput();
0091     void CloseFiles();
0092 
0093     // system methods [*.sys.h]
0094     void InitVectors();
0095     void InitTuples();
0096     void InitHists();
0097 
0098     // analysis methods [*.ana.h]
0099     void ApplyFlatDeltaPtCuts();
0100     void ApplyPtDependentDeltaPtCuts();
0101     void FillTruthHistograms();
0102     void CreateSigmaGraphs();
0103     void CalculateRejectionFactors();
0104     void CalculateEfficiencies();
0105 
0106     // plot methods [*.plot.h]
0107     void SetStyles();
0108     void MakePlots();
0109 
0110     // io parameters
0111     TFile*   fInput;
0112     TFile*   fOutput;
0113     TNtuple* ntTrack;
0114     TNtuple* ntTruth;
0115     TString  sInFile;
0116     TString  sOutFile;
0117     TString  sInTrack;
0118     TString  sInTruth;
0119 
0120     // general cut parameters
0121     uint32_t nInttTrkMin = 1;
0122     uint32_t nMVtxTrkMin = 2;
0123     uint32_t nTpcTrkMin  = 35;
0124     double   qualTrkMax  = 10.;
0125     double   vzTrkMax    = 10.;
0126     double   ptTrkMin    = 0.1;
0127 
0128     // sigma calculation parameters
0129     array<float, Const::NPar>   sigHiGuess    = {1., -1., 1.};
0130     array<float, Const::NPar>   sigLoGuess    = {1., -1., 1.};
0131     array<float, Const::NRange> normRange     = {0.2, 1.2};
0132     array<float, Const::NRange> ptFitRange    = {0.5, 40.};
0133     array<float, Const::NRange> deltaFitRange = {0.,  0.1};
0134 
0135     // projection parameters
0136     size_t           nProj = 0;
0137     vector<double>   ptProj;
0138     vector<TString>  sProjSuffix;
0139     vector<TString>  sPtProj;
0140     vector<uint32_t> fColProj;
0141     vector<uint32_t> fMarProj;
0142     vector<uint32_t> fColFit;
0143 
0144     // flat delta-pt cut parameters
0145     size_t           nDPtCuts   = 0;
0146     size_t           iCutToDraw = 0;
0147     vector<double>   ptDeltaMax;
0148     vector<TString>  sDPtSuffix;
0149     vector<uint32_t> fColCut;
0150     vector<uint32_t> fMarCut;
0151 
0152     // pt-dependent delta-pt cut parameters
0153     size_t           nSigCuts   = 0;
0154     size_t           iSigToDraw = 0;
0155     vector<double>   ptDeltaSig;
0156     vector<TString>  sSigSuffix;
0157     vector<uint32_t> fColSig;
0158     vector<uint32_t> fMarSig;
0159     vector<uint32_t> fColSigFit;
0160 
0161     // histogram base names
0162     TString sPtProjBase   = "DeltaPtProj";
0163     TString sPtDeltaBase  = "DeltaPt";
0164     TString sPtTrueBase   = "PtTrue";
0165     TString sPtRecoBase   = "PtReco";
0166     TString sPtFracBase   = "PtFrac";
0167     TString sPtTrkTruBase = "PtTrkTruth";
0168 
0169     // plot text
0170     size_t          nTxt = 0;
0171     vector<TString> sInfo;
0172 
0173     // plot range parameters
0174     array<float, Const::NRange> rPtRange    = {0., 60.};
0175     array<float, Const::NRange> rFracRange  = {0., 4.};
0176     array<float, Const::NRange> rDeltaRange = {0., 0.1};
0177 
0178     // general histogram style parameters
0179     uint32_t fFil       = 0;
0180     uint32_t fLin       = 1;
0181     uint32_t fWid       = 1;
0182     uint32_t fTxt       = 42;
0183     uint32_t fAln       = 12;
0184     uint32_t fCnt       = 1;
0185     uint32_t fColTrue   = 923;
0186     uint32_t fColPure   = 923;
0187     uint32_t fColTrk    = 809;
0188     uint32_t fMarTrue   = 20;
0189     uint32_t fMarPure   = 20;
0190     uint32_t fMarTrk    = 46;
0191     size_t   nEffRebin  = 5;
0192     bool     doEffRebin = true;
0193 
0194     // track tuple addresses
0195     float trk_event;
0196     float trk_seed;
0197     float trk_trackID;
0198     float trk_crossing;
0199     float trk_px;
0200     float trk_py;
0201     float trk_pz;
0202     float trk_pt;
0203     float trk_eta;
0204     float trk_phi;
0205     float trk_deltapt;
0206     float trk_deltaeta;
0207     float trk_deltaphi;
0208     float trk_charge;
0209     float trk_quality;
0210     float trk_chisq;
0211     float trk_ndf;
0212     float trk_nhits;
0213     float trk_nmaps;
0214     float trk_nintt;
0215     float trk_ntpc;
0216     float trk_nmms;
0217     float trk_ntpc1;
0218     float trk_ntpc11;
0219     float trk_ntpc2;
0220     float trk_ntpc3;
0221     float trk_nlmaps;
0222     float trk_nlintt;
0223     float trk_nltpc;
0224     float trk_nlmms;
0225     float trk_layers;
0226     float trk_vertexID;
0227     float trk_vx;
0228     float trk_vy;
0229     float trk_vz;
0230     float trk_dca2d;
0231     float trk_dca2dsigma;
0232     float trk_dca3dxy;
0233     float trk_dca3dxysigma;
0234     float trk_dca3dz;
0235     float trk_dca3dzsigma;
0236     float trk_pcax;
0237     float trk_pcay;
0238     float trk_pcaz;
0239     float trk_gtrackID;
0240     float trk_gflavor;
0241     float trk_gnhits;
0242     float trk_gnmaps;
0243     float trk_gnintt;
0244     float trk_gntpc;
0245     float trk_gnmms;
0246     float trk_gnlmaps;
0247     float trk_gnlintt;
0248     float trk_gnltpc;
0249     float trk_gnlmms;
0250     float trk_gpx;
0251     float trk_gpy;
0252     float trk_gpz;
0253     float trk_gpt;
0254     float trk_geta;
0255     float trk_gphi;
0256     float trk_gvx;
0257     float trk_gvy;
0258     float trk_gvz;
0259     float trk_gvt;
0260     float trk_gfpx;
0261     float trk_gfpy;
0262     float trk_gfpz;
0263     float trk_gfx;
0264     float trk_gfy;
0265     float trk_gfz;
0266     float trk_gembed;
0267     float trk_gprimary;
0268     float trk_nfromtruth;
0269     float trk_nwrong;
0270     float trk_ntrumaps;
0271     float trk_ntruintt;
0272     float trk_ntrutpc;
0273     float trk_ntrumms;
0274     float trk_ntrutpc1;
0275     float trk_ntrutpc11;
0276     float trk_ntrutpc2;
0277     float trk_ntrutpc3;
0278     float trk_layersfromtruth;
0279     float trk_nhittpcall;
0280     float trk_nhittpcin;
0281     float trk_nhittpcmid;
0282     float trk_nhittpcout;
0283     float trk_nclusall;
0284     float trk_nclustpc;
0285     float trk_nclusintt;
0286     float trk_nclusmaps;
0287     float trk_nclusmms;
0288 
0289     // truth tuple addresses
0290     float tru_event;
0291     float tru_seed;
0292     float tru_gntracks;
0293     float tru_gtrackID;
0294     float tru_gflavor;
0295     float tru_gnhits;
0296     float tru_gnmaps;
0297     float tru_gnintt;
0298     float tru_gnmms;
0299     float tru_gnintt1;
0300     float tru_gnintt2;
0301     float tru_gnintt3;
0302     float tru_gnintt4;
0303     float tru_gnintt5;
0304     float tru_gnintt6;
0305     float tru_gnintt7;
0306     float tru_gnintt8;
0307     float tru_gntpc;
0308     float tru_gnlmaps;
0309     float tru_gnlintt;
0310     float tru_gnltpc;
0311     float tru_gnlmms;
0312     float tru_gpx;
0313     float tru_gpy;
0314     float tru_gpz;
0315     float tru_gpt;
0316     float tru_geta;
0317     float tru_gphi;
0318     float tru_gvx;
0319     float tru_gvy;
0320     float tru_gvz;
0321     float tru_gvt;
0322     float tru_gfpx;
0323     float tru_gfpy;
0324     float tru_gfpz;
0325     float tru_gfx;
0326     float tru_gfy;
0327     float tru_gfz;
0328     float tru_gembed;
0329     float tru_gprimary;
0330     float tru_trackID;
0331     float tru_px;
0332     float tru_py;
0333     float tru_pz;
0334     float tru_pt;
0335     float tru_eta;
0336     float tru_phi;
0337     float tru_deltapt;
0338     float tru_deltaeta;
0339     float tru_deltaphi;
0340     float tru_charge;
0341     float tru_quality;
0342     float tru_chisq;
0343     float tru_ndf;
0344     float tru_nhits;
0345     float tru_layers;
0346     float tru_nmaps;
0347     float tru_nintt;
0348     float tru_ntpc;
0349     float tru_nmms;
0350     float tru_ntpc1;
0351     float tru_ntpc11;
0352     float tru_ntpc2;
0353     float tru_ntpc3;
0354     float tru_nlmaps;
0355     float tru_nlintt;
0356     float tru_nltpc;
0357     float tru_nlmms;
0358     float tru_vertexID;
0359     float tru_vx;
0360     float tru_vy;
0361     float tru_vz;
0362     float tru_dca2d;
0363     float tru_dca2dsigma;
0364     float tru_dca3dxy;
0365     float tru_dca3dxysigma;
0366     float tru_dca3dz;
0367     float tru_dca3dzsigma;
0368     float tru_pcax;
0369     float tru_pcay;
0370     float tru_pcaz;
0371     float tru_nfromtruth;
0372     float tru_nwrong;
0373     float tru_ntrumaps;
0374     float tru_ntruintt;
0375     float tru_ntrutpc;
0376     float tru_ntrumms;
0377     float tru_ntrutpc1;
0378     float tru_ntrutpc11;
0379     float tru_ntrutpc2;
0380     float tru_ntrutpc3;
0381     float tru_layersfromtruth;
0382     float tru_nhittpcall;
0383     float tru_nhittpcin;
0384     float tru_nhittpcmid;
0385     float tru_nhittpcout;
0386     float tru_nclusall;
0387     float tru_nclustpc;
0388     float tru_nclusintt;
0389     float tru_nclusmaps;
0390     float tru_nclusmms;
0391 
0392     // for sigma calculation
0393     vector<double>         muProj;
0394     vector<double>         sigProj;
0395     vector<vector<double>> muHiProj;
0396     vector<vector<double>> muLoProj;
0397 
0398     // for flat delta-pt cut rejection
0399     vector<uint64_t> nNormCut;
0400     vector<uint64_t> nNormSig;
0401     vector<uint64_t> nWeirdCut;
0402     vector<uint64_t> nWeirdSig;
0403     vector<double>   rejCut;
0404     vector<double>   rejSig;
0405 
0406     // for tuple loops
0407     uint64_t nTrks;
0408     uint64_t nTrus;
0409 
0410     // general 1d histograms
0411     TH1D* hEff;
0412     TH1D* hPtTruth;
0413     TH1D* hPtDelta;
0414     TH1D* hPtTrack;
0415     TH1D* hPtFrac;
0416     TH1D* hPtTrkTru;
0417 
0418     // 1d projection & cut-dependent histograms
0419     vector<TH1D*> hPtDeltaProj;
0420     vector<TH1D*> hPtDeltaCut;
0421     vector<TH1D*> hPtDeltaSig;
0422     vector<TH1D*> hPtTrackCut;
0423     vector<TH1D*> hPtTrackSig;
0424     vector<TH1D*> hPtFracCut;
0425     vector<TH1D*> hPtFracSig;
0426     vector<TH1D*> hPtTrkTruCut;
0427     vector<TH1D*> hPtTrkTruSig;
0428     vector<TH1D*> hEffCut;
0429     vector<TH1D*> hEffSig;
0430 
0431 
0432     // general 2d histograms
0433     TH2D* hPtDeltaVsFrac;
0434     TH2D* hPtDeltaVsTrue;
0435     TH2D* hPtDeltaVsTrack;
0436     TH2D* hPtTrueVsTrack;
0437 
0438     // 2d cut-dependent histograms
0439     vector<TH2D*> hPtDeltaVsFracCut;
0440     vector<TH2D*> hPtDeltaVsFracSig;
0441     vector<TH2D*> hPtDeltaVsTrueCut;
0442     vector<TH2D*> hPtDeltaVsTrueSig;
0443     vector<TH2D*> hPtDeltaVsTrackCut;
0444     vector<TH2D*> hPtDeltaVsTrackSig;
0445     vector<TH2D*> hPtTrueVsTrackCut;
0446     vector<TH2D*> hPtTrueVsTrackSig;
0447 
0448     // functions
0449     vector<TF1*> fPtDeltaProj;
0450     vector<TF1*> fMuHiProj;
0451     vector<TF1*> fMuLoProj;
0452 
0453     // general graphs
0454     TGraph* grMuProj;
0455     TGraph* grSigProj;
0456     TGraph* grRejCut;
0457     TGraph* grRejSig;
0458 
0459     // cut-dependent graphs
0460     vector<TGraph*> grMuHiProj;
0461     vector<TGraph*> grMuLoProj;
0462 
0463 };  // end SDeltaPtCutStudy definition
0464 
0465 #endif
0466 
0467 // end ------------------------------------------------------------------------