Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:17

0001 // ----------------------------------------------------------------------------
0002 // 'CalculateSigmaDca.cxx'
0003 // Derek Anderson
0004 // 10.11.2023
0005 //
0006 // Quick script to fit sigma-dca/dca distributions
0007 // to figure out pt-dependent cut from SCorrelatorJetTree
0008 // track QA tuples.
0009 
0010 // c utilities
0011 #include <string>
0012 #include <vector>
0013 #include <utility>
0014 #include <iostream>
0015 // root classes
0016 #include <TH1.h>
0017 #include <TH2.h>
0018 #include <TF1.h>
0019 #include <TFile.h>
0020 #include <TMath.h>
0021 #include <TError.h>
0022 #include <TNtuple.h>
0023 #include <TString.h>
0024 #include <TCanvas.h>
0025 #include <TObjArray.h>
0026 #include <TPaveText.h>
0027 #include <TGraphErrors.h>
0028 
0029 using namespace std;
0030 
0031 // global constants
0032 static const size_t NDca(2);
0033 static const size_t NPar(4);
0034 static const size_t NObj(2);
0035 static const size_t NVtx(4);
0036 
0037 
0038 
0039 void CalculateSigmaDca() {
0040 
0041   // lower verbosity
0042   gErrorIgnoreLevel = kError;
0043   cout << "\n  Starting sigma-dca/dca calculation..." << endl;
0044 
0045   // options ------------------------------------------------------------------
0046 
0047   // io parameters
0048   const string sInput("../SCorrelatorJetTree/output/condor/final_merge/correlatorJetTree.pp200py8jet10run8_forVtxCutTest_onlyPrimTrks.d22m10y2023.root");
0049   const string sTuple("QA/Tracks/ntTrkQA"); 
0050   const string sOutput("dcaSigmaCalc.pp200py8jet10run8_smallSample_onlyPrimTrks_withCubicFitAndPtRange.d22m10y2023.root");
0051 
0052   // histogram parameters
0053   const array<string, NDca> sDcaVsPtAll = {"hDcaXYvsPtAll",       "hDcaZvsPtAll"};
0054   const array<string, NDca> sDcaVsPtSel = {"hDcaXYvsPtSel",       "hDcaZvsPtSel"};
0055   const array<string, NDca> sDcaName    = {"hDcaXY",              "hDcaZ"};
0056   const array<string, NDca> sWidthName  = {"hWidthDcaXY",         "hWidthDcaZ"};
0057   const array<string, NDca> sTitleWidth = {"#DeltaDCA_{xy} [cm]", "#DeltaDCA_{z} [cm]"};
0058   const array<string, NDca> sTitleDca   = {"DCA_{xy} [cm]",       "DCA_{z} [cm]"};
0059   const string              sTitlePt("p_{T}^{trk} [GeV/c]");
0060   const string              sDcaXYvsZAll("hDcaXYvsZAll");
0061   const string              sDcaXYvsZSel("hDcaXYvsZSel");
0062 
0063   // fit parameters
0064   const uint16_t            cut(0);
0065   const string              sDcaFit("gaus(0)");
0066   const string              sWidthFit("[0]+[1]/x+[2]/(x*x)+[3]/(x*x*x)");
0067   const string              sDcaOpt("QNR");
0068   const string              sWidthOpt("R");
0069   const string              sParam("_2");
0070   const pair<float, float>  ptFitRange    = {1., 15.};
0071   const array<string, NDca> sDcaFitName   = {"fFitDcaXY",   "fFitDcaZ"};
0072   const array<string, NDca> sWidthFitName = {"fFitWidthXY", "fFitWidthZ"};
0073   const array<float,  NPar> fWidthGuess   = {1., 1., 1., 1.};
0074 
0075   // cut parameters
0076   const bool   doOtherCuts(true);
0077   const float  nMvtxMin(2.);
0078   const float  nInttMin(1.);
0079   const float  nTpcMin(24.);
0080   const float  qualMax(10.);
0081   const float  etaMax(1.1);
0082   const float  ptMin(0.1);
0083   const float  nCut(3.);
0084   const string sAll("all tracks");
0085   const string sSel("selected tracks");
0086 
0087   // plot options
0088   const pair<float, float>  ptPlotRange    = {0.,    25.};
0089   const pair<float, float>  dcaPlotRange   = {-0.5,  0.5};
0090   const pair<float, float>  widthPlotRange = {0.001, 0.05};
0091   const array<string, NDca> sDcaWidthPlot  = {"cWidthDcaXY", "cWidthDcaZ"};
0092   const array<string, NDca> sDcaVsPtPlot   = {"cDcaXYvsPt",  "cDcaZvsPt"};
0093   const string              sDcaXYvsZPlot("cDcaXYvsZ");
0094 
0095   // text parameters
0096   const vector<string> sText = {
0097     "#bf{#it{sPHENIX}} simulation [Run 8]",
0098     "PYTHIA-8, JS 10 GeV sample",
0099     "#bf{reco. tracks}"
0100   };
0101 
0102   // open files & initialize tuple --------------------------------------------
0103 
0104   // open file
0105   TFile* fOutput = new TFile(sOutput.data(), "recreate");
0106   TFile* fInput  = new TFile(sInput.data(),  "read");
0107   if (!fOutput || !fInput) {
0108     cerr << "PANIC: couldn't open a file!\n"
0109          << "       fOutput = " << fOutput << ", " << fInput << "\n"
0110          << endl;
0111     return;
0112   }
0113   cout << "    Opened files." << endl;
0114 
0115   // grab input tuple
0116   TNtuple* ntInput = (TNtuple*) fInput -> Get(sTuple.data());
0117   if (!ntInput) {
0118     cerr << "PANIC: couldn't grab input tuple!\n" << endl;
0119     return;
0120   }
0121   cout << "    Grabbed input tuple." << endl;
0122 
0123   // declare leaves
0124   float pt;
0125   float eta;
0126   float phi;
0127   float energy;
0128   float dcaxy;
0129   float dcaz;
0130   float deltapt;
0131   float quality;
0132   float nmvtxlayer;
0133   float ninttlayer;
0134   float ntpclayer;
0135 
0136   // set branch addresses
0137   ntInput -> SetBranchAddress("pt",        &pt);
0138   ntInput -> SetBranchAddress("eta",       &eta);
0139   ntInput -> SetBranchAddress("phi",       &phi);
0140   ntInput -> SetBranchAddress("energy",    &energy);
0141   ntInput -> SetBranchAddress("dcaxy",     &dcaxy);
0142   ntInput -> SetBranchAddress("dcaz",      &dcaz);
0143   ntInput -> SetBranchAddress("deltapt",   &deltapt);
0144   ntInput -> SetBranchAddress("quality",   &quality);
0145   ntInput -> SetBranchAddress("nmvtxlayer",&nmvtxlayer);
0146   ntInput -> SetBranchAddress("ninttlayer",&ninttlayer);
0147   ntInput -> SetBranchAddress("ntpclayer", &ntpclayer);
0148   cout << "    Set input tuple branches." << endl;
0149 
0150   // initialize histograms ----------------------------------------------------
0151 
0152   // histogram binning
0153   const tuple<size_t, pair<float, float>> dcaBins = {2000, make_pair(-5., 5.)};
0154   const tuple<size_t, pair<float, float>> ptBins  = {100,  make_pair(0.,  100.)};
0155 
0156   // declare histograms
0157   array<TH1D*, NDca> arrDcaWidth;
0158   array<TH2D*, NDca> arrDcaVsPtAll;
0159   array<TH2D*, NDca> arrDcaVsPtSel;
0160   for (size_t iDca = 0; iDca < NDca; iDca++) {
0161     arrDcaWidth[iDca] = new TH1D(
0162       sWidthName[iDca].data(),
0163       "",
0164       get<0>(ptBins),
0165       get<1>(ptBins).first,
0166       get<1>(ptBins).second
0167     );
0168     arrDcaVsPtAll[iDca] = new TH2D(
0169       sDcaVsPtAll[iDca].data(),
0170       sAll.data(),
0171       get<0>(ptBins),
0172       get<1>(ptBins).first,
0173       get<1>(ptBins).second,
0174       get<0>(dcaBins),
0175       get<1>(dcaBins).first,
0176       get<1>(dcaBins).second
0177     );
0178     arrDcaVsPtSel[iDca] = new TH2D(
0179       sDcaVsPtSel[iDca].data(),
0180       sSel.data(),
0181       get<0>(ptBins),
0182       get<1>(ptBins).first,
0183       get<1>(ptBins).second,
0184       get<0>(dcaBins),
0185       get<1>(dcaBins).first,
0186       get<1>(dcaBins).second
0187     );
0188   }
0189 
0190   TH2D* hDcaXYvsZAll = new TH2D(
0191     sDcaXYvsZAll.data(),
0192     sAll.data(),
0193     get<0>(dcaBins),
0194     get<1>(dcaBins).first,
0195     get<1>(dcaBins).second,
0196     get<0>(dcaBins),
0197     get<1>(dcaBins).first,
0198     get<1>(dcaBins).second
0199   );
0200   TH2D* hDcaXYvsZSel = new TH2D(
0201     sDcaXYvsZSel.data(),
0202     sSel.data(),
0203     get<0>(dcaBins),
0204     get<1>(dcaBins).first,
0205     get<1>(dcaBins).second,
0206     get<0>(dcaBins),
0207     get<1>(dcaBins).first,
0208     get<1>(dcaBins).second
0209   );
0210   cout << "    Initialized output histograms." << endl;
0211 
0212   // 1st entry loop -------------------------------------------------------------
0213 
0214   // start entry loop
0215   uint64_t nEntries = ntInput -> GetEntries();
0216   cout << "    Starting 1st entry loop: " << nEntries << " to process" << endl;
0217 
0218   uint64_t nBytes = 0;
0219   for (uint64_t iEntry = 0; iEntry < nEntries; iEntry++) {
0220 
0221     // grab entry
0222     const uint64_t bytes = ntInput -> GetEntry(iEntry);
0223     if (bytes < 0) {
0224       cerr << "WARNING: issue with entry " << iEntry << "! Aborting loop!" << endl;
0225       break;
0226     } else {
0227       nBytes += bytes;
0228     }
0229 
0230     // announce progress
0231     const uint64_t iProg = iEntry + 1;
0232     if (iProg == nEntries) {
0233       cout << "      Processing entry " << iProg << "/" << nEntries << "..." << endl;
0234     } else {
0235       cout << "      Processing entry " << iProg << "/" << nEntries << "...\r" << flush;
0236     }
0237 
0238     // apply cuts other than dca if needed
0239     if (doOtherCuts) {
0240       const bool isNumMvtxGood = (nmvtxlayer > nMvtxMin);
0241       const bool isNumInttGood = (ninttlayer > nInttMin);
0242       const bool isNumTpcGood  = (ntpclayer  > nTpcMin);
0243       const bool isQualityGood = (quality    < qualMax);
0244       const bool isEtaGood     = (abs(eta)   < etaMax);
0245       const bool isPtGood      = (pt         > ptMin);
0246       const bool isTrackGood   = (isNumMvtxGood && isNumInttGood && isNumTpcGood && isQualityGood && isEtaGood && isPtGood);
0247       if (!isTrackGood) continue;
0248     }
0249 
0250     // fill histograms
0251     arrDcaVsPtAll[0] -> Fill(pt,   dcaxy);
0252     arrDcaVsPtAll[1] -> Fill(pt,   dcaz);
0253     hDcaXYvsZAll     -> Fill(dcaz, dcaxy);
0254 
0255   }  // end entry loop 1
0256   cout << "    Finished 1st entry loop!" << endl;
0257 
0258   // get & fit widths ---------------------------------------------------------
0259 
0260   array<TF1*, NDca> arrWidthFits;
0261   for (size_t iDca = 0; iDca < NDca; iDca++) {
0262 
0263     // create result name
0264     TString sResult(sDcaVsPtAll[iDca].data());
0265     sResult.Append(sParam.data());
0266 
0267     // determine dca range
0268     const uint64_t iStart = arrDcaVsPtAll[iDca] -> FindFirstBinAbove(0., 1);
0269     const uint64_t iStop  = arrDcaVsPtAll[iDca] -> FindLastBinAbove(0.,  1);
0270     const float    start  = arrDcaVsPtAll[iDca] -> GetXaxis() -> GetBinLowEdge(iStart);
0271     const float    stop   = arrDcaVsPtAll[iDca] -> GetXaxis() -> GetBinLowEdge(iStop + 1);
0272 
0273     // declare fit and parameter pointers
0274     TF1*       fDcaFit   = new TF1(sDcaFitName[iDca].data(), sDcaFit.data(), start, stop);
0275     TObjArray* arrParams = NULL;
0276 
0277     // fit slices of dca vs pt
0278     arrDcaVsPtAll[iDca]  -> FitSlicesY(fDcaFit, iStart, iStop, cut, sDcaOpt.data(), arrParams);
0279     arrDcaWidth[iDca] =  (TH1D*) gDirectory -> Get(sResult.Data()) -> Clone();
0280 
0281     // declare width fit function
0282     arrWidthFits[iDca] = new TF1(sWidthFitName[iDca].data(), sWidthFit.data(), start, stop);
0283     for (size_t iPar = 0; iPar < NPar; iPar++) {
0284       arrWidthFits[iDca] -> SetParameters(iPar, fWidthGuess[iPar]);
0285     }
0286 
0287     // fit width of dca distributions 
0288     arrDcaWidth[iDca] -> Fit(arrWidthFits[iDca], sWidthOpt.data(), "", ptFitRange.first, ptFitRange.second);
0289     arrDcaWidth[iDca] -> SetName(sWidthName[iDca].data());
0290   }  // end dca variable loop
0291 
0292   // 2nd entry loop -------------------------------------------------------------
0293 
0294   // start entry loop
0295   cout << "    Starting 2nd entry loop: applying a cut of " << nCut << " times the DCA width" << endl;
0296 
0297   nBytes = 0;
0298   for (uint64_t iEntry = 0; iEntry < nEntries; iEntry++) {
0299 
0300     // grab entry
0301     const uint64_t bytes = ntInput -> GetEntry(iEntry);
0302     if (bytes < 0) {
0303       cerr << "WARNING: issue with entry " << iEntry << "! Aborting loop!" << endl;
0304       break;
0305     } else {
0306       nBytes += bytes;
0307     }
0308 
0309     // announce progress
0310     const uint64_t iProg = iEntry + 1;
0311     if (iProg == nEntries) {
0312       cout << "      Processing entry " << iProg << "/" << nEntries << "..." << endl;
0313     } else {
0314       cout << "      Processing entry " << iProg << "/" << nEntries << "...\r" << flush;
0315     }
0316 
0317     // apply cuts other than dca if needed
0318     if (doOtherCuts) {
0319       const bool isNumMvtxGood = (nmvtxlayer > nMvtxMin);
0320       const bool isNumInttGood = (ninttlayer > nInttMin);
0321       const bool isNumTpcGood  = (ntpclayer  > nTpcMin);
0322       const bool isQualityGood = (quality    < qualMax);
0323       const bool isEtaGood     = (abs(eta)   < etaMax);
0324       const bool isPtGood      = (pt         > ptMin);
0325       const bool isTrackGood   = (isNumMvtxGood && isNumInttGood && isNumTpcGood && isQualityGood && isEtaGood && isPtGood);
0326       if (!isTrackGood) continue;
0327     }
0328 
0329     // calculate max dca
0330     const double dcaWidthXY = arrWidthFits[0] -> Eval(pt);
0331     const double dcaWidthZ  = arrWidthFits[1] -> Eval(pt);
0332     const double dcaMaxXY   = nCut * dcaWidthXY;
0333     const double dcaMaxZ    = nCut * dcaWidthZ;
0334 
0335     // apply cuts
0336     const bool isTrkInDcaCutXY = (abs(dcaxy) < dcaMaxXY);
0337     const bool isTrkInDcaCutZ  = (abs(dcaz)  < dcaMaxZ);
0338     const bool isTrkInDcaCut   = (isTrkInDcaCutXY && isTrkInDcaCutZ);
0339     if (!isTrkInDcaCut) continue;
0340 
0341     // fill histograms
0342     arrDcaVsPtSel[0] -> Fill(pt, dcaxy);
0343     arrDcaVsPtSel[1] -> Fill(pt, dcaz);
0344     hDcaXYvsZSel     -> Fill(dcaz, dcaxy);
0345 
0346   }  // end entry loop 1
0347   cout << "    Finished 2nd entry loop!" << endl;
0348 
0349   // make cut lines -----------------------------------------------------------
0350 
0351   // line options
0352   const uint16_t fColLin(2);
0353   const uint16_t fStyLin(1);
0354   const uint16_t fWidLin(2);
0355 
0356   array<TF1*, NDca>  arrFitsNeg;
0357   array<TF1*, NDca>  arrFitsPos;
0358   array<float, NPar> arrNegParams;
0359   array<float, NPar> arrPosParams;
0360   for (size_t iDca = 0; iDca < NDca; iDca++) {
0361 
0362     // make name
0363     const TString sFitBase = arrWidthFits[iDca] -> GetName();
0364     TString       sFitNeg  = sFitBase;
0365     TString       sFitPos  = sFitBase;
0366     sFitNeg.Append("_Neg");
0367     sFitPos.Append("_Pos");
0368 
0369     // set parameters
0370     for (size_t iPar = 0; iPar < NPar; iPar++) {
0371       arrNegParams[iPar]  = arrWidthFits[iDca] -> GetParameter(iPar);
0372       arrPosParams[iPar]  = arrWidthFits[iDca] -> GetParameter(iPar);
0373       arrNegParams[iPar] *= (-1. * nCut);
0374       arrPosParams[iPar] *= nCut;
0375     }
0376 
0377     // make functions
0378     arrFitsNeg[iDca] = (TF1*) arrWidthFits[iDca] -> Clone();
0379     arrFitsPos[iDca] = (TF1*) arrWidthFits[iDca] -> Clone();
0380     arrFitsNeg[iDca] -> SetName(sFitNeg.Data());
0381     arrFitsPos[iDca] -> SetName(sFitPos.Data());
0382     arrFitsNeg[iDca] -> SetLineColor(fColLin);
0383     arrFitsPos[iDca] -> SetLineColor(fColLin);
0384     arrFitsNeg[iDca] -> SetLineStyle(fStyLin);
0385     arrFitsPos[iDca] -> SetLineStyle(fStyLin);
0386     arrFitsNeg[iDca] -> SetLineWidth(fWidLin);
0387     arrFitsPos[iDca] -> SetLineWidth(fWidLin);
0388     for (size_t iPar = 0; iPar < NPar; iPar++) {
0389       arrFitsNeg[iDca] -> SetParameter(iPar, arrNegParams[iPar]);
0390       arrFitsPos[iDca] -> SetParameter(iPar, arrPosParams[iPar]);
0391     }
0392   }  // end variable loops
0393   cout << "    Made cut lines." << endl;
0394 
0395   // make plots ---------------------------------------------------------------
0396 
0397   // hist options
0398   const uint16_t fCol(1);
0399   const uint16_t fMar(20);
0400   const uint16_t fLin(1);
0401   const uint16_t fWid(1);
0402   const uint16_t fFil(0);
0403   const uint16_t fTxt(42);
0404   const uint16_t fCnt(1);
0405   const float    fOffX(1.1);
0406   const float    fOffY(1.3);
0407   const float    fTtl(0.04);
0408   const float    fLbl(0.03);
0409 
0410   // set dca-specific hist options
0411   for (size_t iDca = 0; iDca < NDca; iDca++) {
0412 
0413     // figure out dca vs. pt z-axis ranges
0414     const float minVsPtAll = arrDcaVsPtAll[iDca] -> GetMinimum(0.);
0415     const float minVsPtSel = arrDcaVsPtSel[iDca] -> GetMinimum(0.);
0416     const float maxVsPtAll = arrDcaVsPtAll[iDca] -> GetMaximum();
0417     const float maxVsPtSel = arrDcaVsPtSel[iDca] -> GetMaximum();
0418     const float minVsPtZ   = TMath::Min(minVsPtAll, minVsPtSel);
0419     const float maxVsPtZ   = TMath::Max(maxVsPtAll, maxVsPtSel);
0420 
0421     // set 1d hist options
0422     arrDcaWidth[iDca] -> SetMarkerColor(fCol);
0423     arrDcaWidth[iDca] -> SetMarkerStyle(fMar);
0424     arrDcaWidth[iDca] -> SetLineColor(fCol);
0425     arrDcaWidth[iDca] -> SetLineStyle(fLin);
0426     arrDcaWidth[iDca] -> SetLineWidth(fWid);
0427     arrDcaWidth[iDca] -> SetFillColor(fCol);
0428     arrDcaWidth[iDca] -> SetFillStyle(fFil);
0429     arrDcaWidth[iDca] -> SetTitleFont(fTxt);
0430     arrDcaWidth[iDca] -> SetTitle("");
0431     arrDcaWidth[iDca] -> GetXaxis() -> SetRangeUser(ptPlotRange.first, ptPlotRange.second);
0432     arrDcaWidth[iDca] -> GetXaxis() -> SetLabelSize(fLbl);
0433     arrDcaWidth[iDca] -> GetXaxis() -> SetTitle(sTitlePt.data());
0434     arrDcaWidth[iDca] -> GetXaxis() -> SetTitleFont(fTxt);
0435     arrDcaWidth[iDca] -> GetXaxis() -> SetTitleSize(fTtl);
0436     arrDcaWidth[iDca] -> GetXaxis() -> SetTitleOffset(fOffX);
0437     arrDcaWidth[iDca] -> GetXaxis() -> CenterTitle(fCnt);
0438     arrDcaWidth[iDca] -> GetYaxis() -> SetRangeUser(widthPlotRange.first, widthPlotRange.second);
0439     arrDcaWidth[iDca] -> GetYaxis() -> SetLabelSize(fLbl);
0440     arrDcaWidth[iDca] -> GetYaxis() -> SetTitle(sTitleWidth[iDca].data());
0441     arrDcaWidth[iDca] -> GetYaxis() -> SetTitleFont(fTxt);
0442     arrDcaWidth[iDca] -> GetYaxis() -> SetTitleSize(fTtl);
0443     arrDcaWidth[iDca] -> GetYaxis() -> SetTitleOffset(fOffY);
0444     arrDcaWidth[iDca] -> GetYaxis() -> CenterTitle(fCnt);
0445 
0446     // set dca vs. pt hist options
0447     arrDcaVsPtAll[iDca] -> SetMarkerColor(fCol);
0448     arrDcaVsPtAll[iDca] -> SetMarkerStyle(fMar);
0449     arrDcaVsPtAll[iDca] -> SetLineColor(fCol);
0450     arrDcaVsPtAll[iDca] -> SetLineStyle(fLin);
0451     arrDcaVsPtAll[iDca] -> SetLineWidth(fWid);
0452     arrDcaVsPtAll[iDca] -> SetFillColor(fCol);
0453     arrDcaVsPtAll[iDca] -> SetFillStyle(fFil);
0454     arrDcaVsPtAll[iDca] -> SetTitleFont(fTxt);
0455     arrDcaVsPtAll[iDca] -> GetXaxis() -> SetRangeUser(ptPlotRange.first, ptPlotRange.second);
0456     arrDcaVsPtAll[iDca] -> GetXaxis() -> SetLabelSize(fLbl);
0457     arrDcaVsPtAll[iDca] -> GetXaxis() -> SetTitle(sTitlePt.data());
0458     arrDcaVsPtAll[iDca] -> GetXaxis() -> SetTitleFont(fTxt);
0459     arrDcaVsPtAll[iDca] -> GetXaxis() -> SetTitleSize(fTtl);
0460     arrDcaVsPtAll[iDca] -> GetXaxis() -> SetTitleOffset(fOffX);
0461     arrDcaVsPtAll[iDca] -> GetXaxis() -> CenterTitle(fCnt);
0462     arrDcaVsPtAll[iDca] -> GetYaxis() -> SetRangeUser(dcaPlotRange.first, dcaPlotRange.second);
0463     arrDcaVsPtAll[iDca] -> GetYaxis() -> SetLabelSize(fLbl);
0464     arrDcaVsPtAll[iDca] -> GetYaxis() -> SetTitle(sTitleDca[iDca].data());
0465     arrDcaVsPtAll[iDca] -> GetYaxis() -> SetTitleFont(fTxt);
0466     arrDcaVsPtAll[iDca] -> GetYaxis() -> SetTitleSize(fTtl);
0467     arrDcaVsPtAll[iDca] -> GetYaxis() -> SetTitleOffset(fOffY);
0468     arrDcaVsPtAll[iDca] -> GetYaxis() -> CenterTitle(fCnt);
0469     arrDcaVsPtAll[iDca] -> GetZaxis() -> SetRangeUser(minVsPtZ, maxVsPtZ);
0470     arrDcaVsPtAll[iDca] -> GetZaxis() -> SetLabelSize(fLbl);
0471     arrDcaVsPtSel[iDca] -> SetMarkerColor(fCol);
0472     arrDcaVsPtSel[iDca] -> SetMarkerStyle(fMar);
0473     arrDcaVsPtSel[iDca] -> SetLineColor(fCol);
0474     arrDcaVsPtSel[iDca] -> SetLineStyle(fLin);
0475     arrDcaVsPtSel[iDca] -> SetLineWidth(fWid);
0476     arrDcaVsPtSel[iDca] -> SetFillColor(fCol);
0477     arrDcaVsPtSel[iDca] -> SetFillStyle(fFil);
0478     arrDcaVsPtSel[iDca] -> SetTitleFont(fTxt);
0479     arrDcaVsPtSel[iDca] -> GetXaxis() -> SetRangeUser(ptPlotRange.first, ptPlotRange.second);
0480     arrDcaVsPtSel[iDca] -> GetXaxis() -> SetLabelSize(fLbl);
0481     arrDcaVsPtSel[iDca] -> GetXaxis() -> SetTitle(sTitlePt.data());
0482     arrDcaVsPtSel[iDca] -> GetXaxis() -> SetTitleFont(fTxt);
0483     arrDcaVsPtSel[iDca] -> GetXaxis() -> SetTitleSize(fTtl);
0484     arrDcaVsPtSel[iDca] -> GetXaxis() -> SetTitleOffset(fOffX);
0485     arrDcaVsPtSel[iDca] -> GetXaxis() -> CenterTitle(fCnt);
0486     arrDcaVsPtSel[iDca] -> GetYaxis() -> SetRangeUser(dcaPlotRange.first, dcaPlotRange.second);
0487     arrDcaVsPtSel[iDca] -> GetYaxis() -> SetLabelSize(fLbl);
0488     arrDcaVsPtSel[iDca] -> GetYaxis() -> SetTitle(sTitleDca[iDca].data());
0489     arrDcaVsPtSel[iDca] -> GetYaxis() -> SetTitleFont(fTxt);
0490     arrDcaVsPtSel[iDca] -> GetYaxis() -> SetTitleSize(fTtl);
0491     arrDcaVsPtSel[iDca] -> GetYaxis() -> SetTitleOffset(fOffY);
0492     arrDcaVsPtSel[iDca] -> GetYaxis() -> CenterTitle(fCnt);
0493     arrDcaVsPtSel[iDca] -> GetZaxis() -> SetRangeUser(minVsPtZ, maxVsPtZ);
0494     arrDcaVsPtSel[iDca] -> GetZaxis() -> SetLabelSize(fLbl);
0495   }  // end variable loop
0496 
0497   // figure out dca xy vs. z z-axis ranges
0498   const float minVsDcaAll = hDcaXYvsZAll -> GetMinimum(0.);
0499   const float minVsDcaSel = hDcaXYvsZSel -> GetMinimum(0.);
0500   const float maxVsDcaAll = hDcaXYvsZAll -> GetMaximum();
0501   const float maxVsDcaSel = hDcaXYvsZSel -> GetMaximum();
0502   const float minVsDcaZ   = TMath::Min(minVsDcaAll, minVsDcaSel);
0503   const float maxVsDcaZ   = TMath::Max(maxVsDcaAll, maxVsDcaSel);
0504 
0505   // set dca xy vs. z hist options
0506   hDcaXYvsZAll -> SetMarkerColor(fCol);
0507   hDcaXYvsZAll -> SetMarkerStyle(fMar);
0508   hDcaXYvsZAll -> SetLineColor(fCol);
0509   hDcaXYvsZAll -> SetLineStyle(fLin);
0510   hDcaXYvsZAll -> SetLineWidth(fWid);
0511   hDcaXYvsZAll -> SetFillColor(fCol);
0512   hDcaXYvsZAll -> SetFillStyle(fFil);
0513   hDcaXYvsZAll -> SetTitleFont(fTxt);
0514   hDcaXYvsZAll -> GetXaxis() -> SetRangeUser(dcaPlotRange.first, dcaPlotRange.second);
0515   hDcaXYvsZAll -> GetXaxis() -> SetLabelSize(fLbl);
0516   hDcaXYvsZAll -> GetXaxis() -> SetTitle(sTitleDca[1].data());
0517   hDcaXYvsZAll -> GetXaxis() -> SetTitleFont(fTxt);
0518   hDcaXYvsZAll -> GetXaxis() -> SetTitleSize(fTtl);
0519   hDcaXYvsZAll -> GetXaxis() -> SetTitleOffset(fOffX);
0520   hDcaXYvsZAll -> GetXaxis() -> CenterTitle(fCnt);
0521   hDcaXYvsZAll -> GetYaxis() -> SetRangeUser(dcaPlotRange.first, dcaPlotRange.second);
0522   hDcaXYvsZAll -> GetYaxis() -> SetLabelSize(fLbl);
0523   hDcaXYvsZAll -> GetYaxis() -> SetTitle(sTitleDca[0].data());
0524   hDcaXYvsZAll -> GetYaxis() -> SetTitleFont(fTxt);
0525   hDcaXYvsZAll -> GetYaxis() -> SetTitleSize(fTtl);
0526   hDcaXYvsZAll -> GetYaxis() -> SetTitleOffset(fOffY);
0527   hDcaXYvsZAll -> GetYaxis() -> CenterTitle(fCnt);
0528   hDcaXYvsZAll -> GetZaxis() -> SetRangeUser(minVsDcaZ, maxVsDcaZ);
0529   hDcaXYvsZAll -> GetZaxis() -> SetLabelSize(fLbl);
0530   hDcaXYvsZSel -> SetMarkerColor(fCol);
0531   hDcaXYvsZSel -> SetMarkerStyle(fMar);
0532   hDcaXYvsZSel -> SetLineColor(fCol);
0533   hDcaXYvsZSel -> SetLineStyle(fLin);
0534   hDcaXYvsZSel -> SetLineWidth(fWid);
0535   hDcaXYvsZSel -> SetFillColor(fCol);
0536   hDcaXYvsZSel -> SetFillStyle(fFil);
0537   hDcaXYvsZSel -> SetTitleFont(fTxt);
0538   hDcaXYvsZSel -> GetXaxis() -> SetRangeUser(dcaPlotRange.first, dcaPlotRange.second);
0539   hDcaXYvsZSel -> GetXaxis() -> SetLabelSize(fLbl);
0540   hDcaXYvsZSel -> GetXaxis() -> SetTitle(sTitleDca[1].data());
0541   hDcaXYvsZSel -> GetXaxis() -> SetTitleFont(fTxt);
0542   hDcaXYvsZSel -> GetXaxis() -> SetTitleSize(fTtl);
0543   hDcaXYvsZSel -> GetXaxis() -> SetTitleOffset(fOffX);
0544   hDcaXYvsZSel -> GetXaxis() -> CenterTitle(fCnt);
0545   hDcaXYvsZSel -> GetYaxis() -> SetRangeUser(dcaPlotRange.first, dcaPlotRange.second);
0546   hDcaXYvsZSel -> GetYaxis() -> SetLabelSize(fLbl);
0547   hDcaXYvsZSel -> GetYaxis() -> SetTitle(sTitleDca[0].data());
0548   hDcaXYvsZSel -> GetYaxis() -> SetTitleFont(fTxt);
0549   hDcaXYvsZSel -> GetYaxis() -> SetTitleSize(fTtl);
0550   hDcaXYvsZSel -> GetYaxis() -> SetTitleOffset(fOffY);
0551   hDcaXYvsZSel -> GetYaxis() -> CenterTitle(fCnt);
0552   hDcaXYvsZSel -> GetZaxis() -> SetRangeUser(minVsDcaZ, maxVsDcaZ);
0553   hDcaXYvsZSel -> GetZaxis() -> SetLabelSize(fLbl);
0554   cout << "    Set histogram options." << endl;
0555 
0556   // text box options
0557   const uint16_t fAln      = 12;
0558   const uint16_t fColTxt   = 0;
0559   const uint16_t fFilTxt   = 0;
0560   const uint16_t fLinTxt   = 0;
0561   const size_t   nTxt      = sText.size();
0562   const float    yTxtStart = 0.1;
0563   const float    yTxtStop  = yTxtStart + (nTxt * 0.05);
0564 
0565   // text box dimensions
0566   const array<float, NVtx> xyTxt = {0.1, yTxtStart, 0.3, yTxtStop};
0567 
0568   // create text box
0569   TPaveText *ptInfo = new TPaveText(xyTxt[0], xyTxt[1], xyTxt[2], xyTxt[3], "NDC NB");
0570   ptInfo -> SetFillColor(fColTxt);
0571   ptInfo -> SetFillStyle(fFilTxt);
0572   ptInfo -> SetLineColor(fColTxt);
0573   ptInfo -> SetLineStyle(fLinTxt);
0574   ptInfo -> SetTextFont(fTxt);
0575   ptInfo -> SetTextAlign(fAln);
0576   for (const string text : sText) {
0577     ptInfo -> AddText(text.data());
0578   }
0579   cout << "    Made text box." << endl;
0580 
0581   // plot options
0582   const uint16_t fMode(0);
0583   const uint16_t fBord(2);
0584   const uint16_t fGrid(0);
0585   const uint16_t fTick(1);
0586   const uint16_t fLogZ(1);
0587   const uint16_t fFrame(0);
0588   const string   sPadAll("pAll");
0589   const string   sPadSel("pSelect");
0590 
0591   // plot margins
0592   const array<float, NVtx> xyMarginWidth = {0.02, 0.02, 0.15, 0.15};
0593   const array<float, NVtx> xyMarginPad   = {0.1,  0.15, 0.15, 0.15};
0594 
0595   // canvas & pad dimensions
0596   const pair<uint32_t, uint32_t> widthDim    = {750,  750};
0597   const pair<uint32_t, uint32_t> allVsSelDim = {1500, 750};
0598   const array<float, NVtx>       xyAllPad    = {0.0, 0.0, 0.5, 1.0};
0599   const array<float, NVtx>       xySelPad    = {0.5, 0.0, 1.0, 1.0};
0600 
0601   // make dca-specific plots
0602   array<TCanvas*, NDca> arrWidthPlots;
0603   array<TCanvas*, NDca> arrDcaVsPtPlots;
0604   array<TPad*,    NDca> arrDcaVsPtAllPad;
0605   array<TPad*,    NDca> arrDcaVsPtSelPad;
0606   for (size_t iDca = 0; iDca < NDca; iDca++) {
0607 
0608     // make width plots
0609     arrWidthPlots[iDca] = new TCanvas(sDcaWidthPlot[iDca].data(), "", widthDim.first, widthDim.second);
0610     arrWidthPlots[iDca] -> SetGrid(fGrid, fGrid);
0611     arrWidthPlots[iDca] -> SetTicks(fTick, fTick);
0612     arrWidthPlots[iDca] -> SetBorderMode(fMode);
0613     arrWidthPlots[iDca] -> SetBorderSize(fBord);
0614     arrWidthPlots[iDca] -> SetTopMargin(xyMarginWidth[0]);
0615     arrWidthPlots[iDca] -> SetRightMargin(xyMarginWidth[1]);
0616     arrWidthPlots[iDca] -> SetBottomMargin(xyMarginWidth[2]);
0617     arrWidthPlots[iDca] -> SetLeftMargin(xyMarginWidth[3]);
0618     arrWidthPlots[iDca] -> cd();
0619     arrDcaWidth[iDca]   -> Draw();
0620     ptInfo              -> Draw();
0621     fOutput             -> cd();
0622     arrWidthPlots[iDca] -> Write();
0623     arrWidthPlots[iDca] -> Close();
0624 
0625     // make dca vs. pt plots
0626     arrDcaVsPtPlots[iDca]  = new TCanvas(sDcaVsPtPlot[iDca].data(), "", allVsSelDim.first, allVsSelDim.second);
0627     arrDcaVsPtAllPad[iDca] = new TPad(sPadAll.data(), "", xyAllPad[0], xyAllPad[1], xyAllPad[2], xyAllPad[3]);
0628     arrDcaVsPtSelPad[iDca] = new TPad(sPadSel.data(), "", xySelPad[0], xySelPad[1], xySelPad[2], xySelPad[3]);
0629     arrDcaVsPtPlots[iDca]  -> SetGrid(fGrid, fGrid);
0630     arrDcaVsPtPlots[iDca]  -> SetTicks(fTick, fTick);
0631     arrDcaVsPtPlots[iDca]  -> SetBorderMode(fMode);
0632     arrDcaVsPtPlots[iDca]  -> SetBorderSize(fBord);
0633     arrDcaVsPtAllPad[iDca] -> SetGrid(fGrid, fGrid);
0634     arrDcaVsPtAllPad[iDca] -> SetTicks(fTick, fTick);
0635     arrDcaVsPtAllPad[iDca] -> SetBorderMode(fMode);
0636     arrDcaVsPtAllPad[iDca] -> SetBorderSize(fBord);
0637     arrDcaVsPtAllPad[iDca] -> SetLogz(fLogZ);
0638     arrDcaVsPtAllPad[iDca] -> SetTopMargin(xyMarginPad[0]);
0639     arrDcaVsPtAllPad[iDca] -> SetRightMargin(xyMarginPad[1]);
0640     arrDcaVsPtAllPad[iDca] -> SetBottomMargin(xyMarginPad[2]);
0641     arrDcaVsPtAllPad[iDca] -> SetLeftMargin(xyMarginPad[3]);
0642     arrDcaVsPtSelPad[iDca] -> SetGrid(fGrid, fGrid);
0643     arrDcaVsPtSelPad[iDca] -> SetTicks(fTick, fTick);
0644     arrDcaVsPtSelPad[iDca] -> SetBorderMode(fMode);
0645     arrDcaVsPtSelPad[iDca] -> SetBorderSize(fBord);
0646     arrDcaVsPtSelPad[iDca] -> SetLogz(fLogZ);
0647     arrDcaVsPtSelPad[iDca] -> SetTopMargin(xyMarginPad[0]);
0648     arrDcaVsPtSelPad[iDca] -> SetRightMargin(xyMarginPad[1]);
0649     arrDcaVsPtSelPad[iDca] -> SetBottomMargin(xyMarginPad[2]);
0650     arrDcaVsPtSelPad[iDca] -> SetLeftMargin(xyMarginPad[3]);
0651     arrDcaVsPtPlots[iDca]  -> cd();
0652     arrDcaVsPtAllPad[iDca] -> Draw();
0653     arrDcaVsPtSelPad[iDca] -> Draw();
0654     arrDcaVsPtAllPad[iDca] -> cd();
0655     arrDcaVsPtAll[iDca]    -> Draw("colz");
0656     arrFitsNeg[iDca]       -> Draw("same");
0657     arrFitsPos[iDca]       -> Draw("same");
0658     arrDcaVsPtSelPad[iDca] -> cd();
0659     arrDcaVsPtSel[iDca]    -> Draw("colz");
0660     ptInfo                 -> Draw();
0661     fOutput                -> cd();
0662     arrDcaVsPtPlots[iDca]  -> Write();
0663     arrDcaVsPtPlots[iDca]  -> Close();
0664   }  // end variable loop
0665 
0666   // make dca xy vs. z plot
0667   TCanvas* cDcaXYvsZ    = new TCanvas(sDcaXYvsZPlot.data(), "", allVsSelDim.first, allVsSelDim.second);
0668   TPad*    pDcaXYvsZAll = new TPad(sPadAll.data(), "", xyAllPad[0], xyAllPad[1], xyAllPad[2], xyAllPad[3]);
0669   TPad*    pDcaXYvsZSel = new TPad(sPadSel.data(), "", xySelPad[0], xySelPad[1], xySelPad[2], xySelPad[3]);
0670   cDcaXYvsZ    -> SetGrid(fGrid, fGrid);
0671   cDcaXYvsZ    -> SetTicks(fTick, fTick);
0672   cDcaXYvsZ    -> SetBorderMode(fMode);
0673   cDcaXYvsZ    -> SetBorderSize(fBord);
0674   pDcaXYvsZAll -> SetGrid(fGrid, fGrid);
0675   pDcaXYvsZAll -> SetTicks(fTick, fTick);
0676   pDcaXYvsZAll -> SetBorderMode(fMode);
0677   pDcaXYvsZAll -> SetBorderSize(fBord);
0678   pDcaXYvsZAll -> SetLogz(fLogZ);
0679   pDcaXYvsZAll -> SetTopMargin(xyMarginPad[0]);
0680   pDcaXYvsZAll -> SetRightMargin(xyMarginPad[1]);
0681   pDcaXYvsZAll -> SetBottomMargin(xyMarginPad[2]);
0682   pDcaXYvsZAll -> SetLeftMargin(xyMarginPad[3]);
0683   pDcaXYvsZSel -> SetGrid(fGrid, fGrid);
0684   pDcaXYvsZSel -> SetTicks(fTick, fTick);
0685   pDcaXYvsZSel -> SetBorderMode(fMode);
0686   pDcaXYvsZSel -> SetBorderSize(fBord);
0687   pDcaXYvsZSel -> SetLogz(fLogZ);
0688   pDcaXYvsZSel -> SetTopMargin(xyMarginPad[0]);
0689   pDcaXYvsZSel -> SetRightMargin(xyMarginPad[1]);
0690   pDcaXYvsZSel -> SetBottomMargin(xyMarginPad[2]);
0691   pDcaXYvsZSel -> SetLeftMargin(xyMarginPad[3]);
0692   cDcaXYvsZ    -> cd();
0693   pDcaXYvsZAll -> Draw();
0694   pDcaXYvsZSel -> Draw();
0695   pDcaXYvsZAll -> cd();
0696   hDcaXYvsZAll -> Draw("colz");
0697   pDcaXYvsZSel -> cd();
0698   hDcaXYvsZSel -> Draw("colz");
0699   ptInfo       -> Draw();
0700   fOutput      -> cd();
0701   cDcaXYvsZ    -> Write();
0702   cDcaXYvsZ    -> Close();
0703   cout << "    Made plots." << endl;
0704 
0705   // save output & close ------------------------------------------------------
0706 
0707   // save histograms
0708   fOutput -> cd();
0709   for (size_t iDca = 0; iDca < NDca; iDca++) {
0710     arrDcaWidth[iDca]   -> Write();
0711     arrWidthFits[iDca]  -> Write();
0712     arrDcaVsPtAll[iDca] -> Write();
0713     arrDcaVsPtSel[iDca] -> Write();
0714     arrFitsNeg[iDca]    -> Write();
0715     arrFitsPos[iDca]    -> Write();
0716   }
0717   hDcaXYvsZAll -> Write();
0718   hDcaXYvsZSel -> Write();
0719 
0720   // close flies
0721   fOutput -> cd();
0722   fOutput -> Close();
0723   fInput  -> cd();
0724   fInput  -> Close();
0725   cout << "  Finished with calculation!\n" << endl;
0726 
0727 }
0728 
0729 // end ------------------------------------------------------------------------