Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:08

0001 // -- c++ includes --
0002 #include <string>
0003 #include <iostream>
0004 #include <iomanip>
0005 #include <fstream>
0006 #include <regex>
0007 #include <unordered_map>
0008 
0009 // -- root includes --
0010 #include <TH1F.h>
0011 #include <TGraph.h>
0012 #include <TFile.h>
0013 #include <TLine.h>
0014 #include <TLegend.h>
0015 #include <TLatex.h>
0016 #include <TCanvas.h>
0017 
0018 // -- sPHENIX Style
0019 #include "sPhenixStyle.C"
0020 
0021 using std::cout;
0022 using std::cerr;
0023 using std::endl;
0024 using std::string;
0025 using std::to_string;
0026 using std::vector;
0027 using std::stringstream;
0028 using std::min;
0029 using std::max;
0030 using std::ofstream;
0031 using std::unordered_map;
0032 
0033 namespace myAnalysis
0034 {
0035   Int_t read(const string &inputFile);
0036   Int_t readZDCNS(const string &inputFile);
0037   void init();
0038   void write(const string &outputFile);
0039   void plot(const string &output);
0040 
0041   string extractNumberFromLastToken(const string &filename);
0042 
0043   struct RunInfo {
0044     string run;
0045     UInt_t evt_Jet6;
0046     UInt_t evt_Jet8;
0047     UInt_t evt_Jet10;
0048     UInt_t evt_Jet12;
0049     UInt_t evt_Jet6_mbdNS;
0050     UInt_t evt_Jet8_mbdNS;
0051     UInt_t evt_Jet10_mbdNS;
0052     UInt_t evt_Jet12_mbdNS;
0053     UInt_t evt_Jet6_bkg;
0054     UInt_t evt_Jet8_bkg;
0055     UInt_t evt_Jet10_bkg;
0056     UInt_t evt_Jet12_bkg;
0057     UInt_t evt_Jet6_mbdNS_bkg;
0058     UInt_t evt_Jet8_mbdNS_bkg;
0059     UInt_t evt_Jet10_mbdNS_bkg;
0060     UInt_t evt_Jet12_mbdNS_bkg;
0061     UInt_t evt_Jet6_bkgCEMC;
0062     UInt_t evt_Jet8_bkgCEMC;
0063     UInt_t evt_Jet10_bkgCEMC;
0064     UInt_t evt_Jet12_bkgCEMC;
0065 
0066     vector<TH1*> hEvents_JetX;
0067     vector<TH1*> hEvents_JetX_bkg;
0068   };
0069 
0070   enum class EventStatus {
0071     trigger = 0,
0072     trigger_bkg = 1,
0073     trigger_bkgCEMC = 2,
0074     trigger_mbdNS = 3,
0075     trigger_mbdNS_bkg = 4
0076   };
0077 
0078   vector<string> triggerIdx = {"Jet6", "Jet8", "Jet10", "Jet12"};
0079 
0080   vector<RunInfo> runs;
0081 
0082   unordered_map<string,Float_t> zdc_NS_vec;
0083 
0084   TGraph* hJet6_bkg;
0085   TGraph* hJet8_bkg;
0086   TGraph* hJet10_bkg;
0087   TGraph* hJet12_bkg;
0088 
0089   TGraph* hJet6_mbdNS_bkg;
0090   TGraph* hJet8_mbdNS_bkg;
0091   TGraph* hJet10_mbdNS_bkg;
0092   TGraph* hJet12_mbdNS_bkg;
0093 }
0094 
0095 string myAnalysis::extractNumberFromLastToken(const string &filename) {
0096     size_t lastSlashPos = filename.rfind('/');
0097     string lastToken = filename.substr(lastSlashPos + 1);
0098 
0099     std::regex numberRegex(R"(\d+)");
0100     std::smatch match;
0101 
0102     if (std::regex_search(lastToken, match, numberRegex)) {
0103         return match[0];
0104     }
0105 
0106     return "";
0107 }
0108 
0109 void myAnalysis::init() {
0110   cout << "init" << endl;
0111   hJet6_bkg  = new TGraph();
0112   hJet8_bkg  = new TGraph();
0113   hJet10_bkg = new TGraph();
0114   hJet12_bkg = new TGraph();
0115 
0116   hJet6_mbdNS_bkg  = new TGraph();
0117   hJet8_mbdNS_bkg  = new TGraph();
0118   hJet10_mbdNS_bkg = new TGraph();
0119   hJet12_mbdNS_bkg = new TGraph();
0120 }
0121 
0122 Int_t myAnalysis::readZDCNS(const string &inputFile) {
0123   // Create an input stream
0124   std::ifstream file(inputFile);
0125 
0126   // Check if the file was successfully opened
0127   if (!file.is_open()) {
0128         cerr << "Failed to open cuts file: " << inputFile << endl;
0129         return 1;
0130   }
0131 
0132   string line;
0133   // skip header
0134   std::getline(file, line);
0135   while (std::getline(file, line))
0136   {
0137         std::istringstream lineStream(line);
0138         string cell;
0139         char comma;
0140 
0141         UInt_t run;
0142         Float_t zdc_NS;
0143 
0144         if (lineStream >> run >> comma >> zdc_NS)
0145         {
0146           zdc_NS_vec[to_string(run)] = zdc_NS;
0147         }
0148         else
0149         {
0150           cerr << "Failed to parse line: " << line << endl;
0151           return 1;
0152         }
0153   }
0154 
0155   // Close the file
0156   file.close();
0157 
0158   return 0;
0159 }
0160 
0161 Int_t myAnalysis::read(const string &inputFile) {
0162   std::ifstream file(inputFile);
0163 
0164   // Check if the file was successfully opened
0165   if (!file.is_open()) {
0166       cerr << "Failed to open file: " << inputFile << endl;
0167       return 1;
0168   }
0169 
0170   string line;
0171 
0172   // sets a global switch disabling the referencing
0173   // allows histograms to be used even after file is closed
0174   TH1::AddDirectory(kFALSE);
0175   // loop over each run
0176   while (std::getline(file, line)) {
0177       std::istringstream lineStream(line);
0178 
0179       string rootFile;
0180       RunInfo info;
0181 
0182       if (lineStream >> rootFile) {
0183           TFile f(rootFile.c_str());
0184 
0185           auto hEvents_Jet6  = ((TH1F*)f.Get("hEvents_Jet6"));
0186           auto hEvents_Jet8  = ((TH1F*)f.Get("hEvents_Jet8"));
0187           auto hEvents_Jet10 = ((TH1F*)f.Get("hEvents_Jet10"));
0188           auto hEvents_Jet12 = ((TH1F*)f.Get("hEvents_Jet12"));
0189 
0190           UInt_t evt_Jet6  = hEvents_Jet6->GetBinContent((Int_t)EventStatus::trigger+1);
0191           UInt_t evt_Jet8  = hEvents_Jet8->GetBinContent((Int_t)EventStatus::trigger+1);
0192           UInt_t evt_Jet10 = hEvents_Jet10->GetBinContent((Int_t)EventStatus::trigger+1);
0193           UInt_t evt_Jet12 = hEvents_Jet12->GetBinContent((Int_t)EventStatus::trigger+1);
0194 
0195           UInt_t evt_Jet6_mbdNS  = hEvents_Jet6->GetBinContent((Int_t)EventStatus::trigger_mbdNS+1);
0196           UInt_t evt_Jet8_mbdNS  = hEvents_Jet8->GetBinContent((Int_t)EventStatus::trigger_mbdNS+1);
0197           UInt_t evt_Jet10_mbdNS = hEvents_Jet10->GetBinContent((Int_t)EventStatus::trigger_mbdNS+1);
0198           UInt_t evt_Jet12_mbdNS = hEvents_Jet12->GetBinContent((Int_t)EventStatus::trigger_mbdNS+1);
0199 
0200           UInt_t evt_Jet6_bkg  = hEvents_Jet6->GetBinContent((Int_t)EventStatus::trigger_bkg+1);
0201           UInt_t evt_Jet8_bkg  = hEvents_Jet8->GetBinContent((Int_t)EventStatus::trigger_bkg+1);
0202           UInt_t evt_Jet10_bkg = hEvents_Jet10->GetBinContent((Int_t)EventStatus::trigger_bkg+1);
0203           UInt_t evt_Jet12_bkg = hEvents_Jet12->GetBinContent((Int_t)EventStatus::trigger_bkg+1);
0204 
0205           UInt_t evt_Jet6_mbdNS_bkg  = hEvents_Jet6->GetBinContent((Int_t)EventStatus::trigger_mbdNS_bkg+1);
0206           UInt_t evt_Jet8_mbdNS_bkg  = hEvents_Jet8->GetBinContent((Int_t)EventStatus::trigger_mbdNS_bkg+1);
0207           UInt_t evt_Jet10_mbdNS_bkg = hEvents_Jet10->GetBinContent((Int_t)EventStatus::trigger_mbdNS_bkg+1);
0208           UInt_t evt_Jet12_mbdNS_bkg = hEvents_Jet12->GetBinContent((Int_t)EventStatus::trigger_mbdNS_bkg+1);
0209 
0210           UInt_t evt_Jet6_bkgCEMC  = hEvents_Jet6->GetBinContent((Int_t)EventStatus::trigger_bkgCEMC+1);
0211           UInt_t evt_Jet8_bkgCEMC  = hEvents_Jet8->GetBinContent((Int_t)EventStatus::trigger_bkgCEMC+1);
0212           UInt_t evt_Jet10_bkgCEMC = hEvents_Jet10->GetBinContent((Int_t)EventStatus::trigger_bkgCEMC+1);
0213           UInt_t evt_Jet12_bkgCEMC = hEvents_Jet12->GetBinContent((Int_t)EventStatus::trigger_bkgCEMC+1);
0214 
0215           info.run = extractNumberFromLastToken(rootFile);
0216 
0217           info.evt_Jet6 = evt_Jet6;
0218           info.evt_Jet8 = evt_Jet8;
0219           info.evt_Jet10 = evt_Jet10;
0220           info.evt_Jet12 = evt_Jet12;
0221 
0222           info.evt_Jet6_mbdNS = evt_Jet6_mbdNS;
0223           info.evt_Jet8_mbdNS = evt_Jet8_mbdNS;
0224           info.evt_Jet10_mbdNS = evt_Jet10_mbdNS;
0225           info.evt_Jet12_mbdNS = evt_Jet12_mbdNS;
0226 
0227           info.evt_Jet6_bkg = evt_Jet6_bkg;
0228           info.evt_Jet8_bkg = evt_Jet8_bkg;
0229           info.evt_Jet10_bkg = evt_Jet10_bkg;
0230           info.evt_Jet12_bkg = evt_Jet12_bkg;
0231 
0232           info.evt_Jet6_mbdNS_bkg = evt_Jet6_mbdNS_bkg;
0233           info.evt_Jet8_mbdNS_bkg = evt_Jet8_mbdNS_bkg;
0234           info.evt_Jet10_mbdNS_bkg = evt_Jet10_mbdNS_bkg;
0235           info.evt_Jet12_mbdNS_bkg = evt_Jet12_mbdNS_bkg;
0236 
0237           info.evt_Jet6_bkgCEMC = evt_Jet6_bkgCEMC;
0238           info.evt_Jet8_bkgCEMC = evt_Jet8_bkgCEMC;
0239           info.evt_Jet10_bkgCEMC = evt_Jet10_bkgCEMC;
0240           info.evt_Jet12_bkgCEMC = evt_Jet12_bkgCEMC;
0241 
0242           vector<TH1*> hEvents_JetX;
0243           vector<TH1*> hEvents_JetX_bkg;
0244           for(auto s : triggerIdx) {
0245             string name = "time/hEvents_"+s+"_A";
0246             hEvents_JetX.push_back((TH1F*)f.Get(name.c_str()));
0247 
0248             name = "time/hEvents_"+s+"_bkg_A";
0249             hEvents_JetX_bkg.push_back((TH1F*)f.Get(name.c_str()));
0250           }
0251 
0252           info.hEvents_JetX     = hEvents_JetX;
0253           info.hEvents_JetX_bkg = hEvents_JetX_bkg;
0254 
0255           runs.push_back(info);
0256 
0257           cout << "File: " << rootFile << ", Run: " << info.run << endl;
0258 
0259           f.Close();
0260       }
0261       else {
0262           cerr << "Failed to parse line: " << line << endl;
0263           return 1;
0264       }
0265   }
0266 
0267   // Close the file
0268   file.close();
0269   return 0;
0270 }
0271 
0272 void myAnalysis::write(const string &outputFile) {
0273    ofstream output(outputFile);
0274    output << "run,Events_Jet6,Events_Jet6_mbdNS,Events_Jet6_bkg,Events_Jet6_mbdNS_bkg,Events_Jet6_bkgCEMC,Jet6_bkg_fraction,Jet6_mbdNS_bkg_fraction,Jet6_bkgCEMC_fraction"
0275              << ",Events_Jet8,Events_Jet8_mbdNS,Events_Jet8_bkg,Events_Jet8_mbdNS_bkg,Events_Jet8_bkgCEMC,Jet8_bkg_fraction,Jet8_mbdNS_bkg_fraction,Jet8_bkgCEMC_fraction"
0276              << ",Events_Jet10,Events_Jet10_mbdNS,Events_Jet10_bkg,Events_Jet10_mbdNS_bkg,Events_Jet10_bkgCEMC,Jet10_bkg_fraction,Jet10_mbdNS_bkg_fraction,Jet10_bkgCEMC_fraction"
0277              << ",Events_Jet12,Events_Jet12_mbdNS,Events_Jet12_bkg,Events_Jet12_mbdNS_bkg,Events_Jet12_bkgCEMC,Jet12_bkg_fraction,Jet12_mbdNS_bkg_fraction,Jet12_bkgCEMC_fraction" << endl;
0278 
0279    stringstream s;
0280    Float_t max_frac = 0;
0281    for (auto info : runs) {
0282       // ensure that the run has a corresponding zdc rate recorded
0283       if (!zdc_NS_vec.count(info.run)) continue;
0284 
0285       s.str("");
0286       Float_t fraction_Jet6_bkg = (info.evt_Jet6) ? (Int_t) (info.evt_Jet6_bkg * 1e4 / info.evt_Jet6) / 100. : 0;
0287       Float_t fraction_Jet8_bkg = (info.evt_Jet8) ? (Int_t) (info.evt_Jet8_bkg * 1e4 / info.evt_Jet8) / 100. : 0;
0288       Float_t fraction_Jet10_bkg = (info.evt_Jet10) ? (Int_t) (info.evt_Jet10_bkg * 1e4 / info.evt_Jet10) / 100. : 0;
0289       Float_t fraction_Jet12_bkg = (info.evt_Jet12) ? (Int_t) (info.evt_Jet12_bkg * 1e4 / info.evt_Jet12) / 100. : 0;
0290 
0291       Float_t fraction_Jet6_mbdNS_bkg = (info.evt_Jet6_mbdNS) ? (Int_t) (info.evt_Jet6_mbdNS_bkg * 1e4 / info.evt_Jet6_mbdNS) / 100. : 0;
0292       Float_t fraction_Jet8_mbdNS_bkg = (info.evt_Jet8_mbdNS) ? (Int_t) (info.evt_Jet8_mbdNS_bkg * 1e4 / info.evt_Jet8_mbdNS) / 100. : 0;
0293       Float_t fraction_Jet10_mbdNS_bkg = (info.evt_Jet10_mbdNS) ? (Int_t) (info.evt_Jet10_mbdNS_bkg * 1e4 / info.evt_Jet10_mbdNS) / 100. : 0;
0294       Float_t fraction_Jet12_mbdNS_bkg = (info.evt_Jet12_mbdNS) ? (Int_t) (info.evt_Jet12_mbdNS_bkg * 1e4 / info.evt_Jet12_mbdNS) / 100. : 0;
0295 
0296       Float_t fraction_bkgCEMC_Jet6 = (info.evt_Jet6) ? (Int_t) (info.evt_Jet6_bkgCEMC * 1e4 / info.evt_Jet6) / 100. : 0;
0297       Float_t fraction_bkgCEMC_Jet8 = (info.evt_Jet8) ? (Int_t) (info.evt_Jet8_bkgCEMC * 1e4 / info.evt_Jet8) / 100. : 0;
0298       Float_t fraction_bkgCEMC_Jet10 = (info.evt_Jet10) ? (Int_t) (info.evt_Jet10_bkgCEMC * 1e4 / info.evt_Jet10) / 100. : 0;
0299       Float_t fraction_bkgCEMC_Jet12 = (info.evt_Jet12) ? (Int_t) (info.evt_Jet12_bkgCEMC * 1e4 / info.evt_Jet12) / 100. : 0;
0300 
0301       max_frac = max(max_frac, fraction_Jet6_bkg);
0302       max_frac = max(max_frac, fraction_Jet8_bkg);
0303       max_frac = max(max_frac, fraction_Jet10_bkg);
0304       max_frac = max(max_frac, fraction_Jet12_bkg);
0305 
0306       max_frac = max(max_frac, fraction_Jet6_mbdNS_bkg);
0307       max_frac = max(max_frac, fraction_Jet8_mbdNS_bkg);
0308       max_frac = max(max_frac, fraction_Jet10_mbdNS_bkg);
0309       max_frac = max(max_frac, fraction_Jet12_mbdNS_bkg);
0310 
0311       hJet6_bkg->AddPoint(zdc_NS_vec[info.run],fraction_Jet6_bkg);
0312       hJet8_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet8_bkg);
0313       hJet10_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet10_bkg);
0314       hJet12_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet12_bkg);
0315 
0316       hJet6_mbdNS_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet6_mbdNS_bkg);
0317       hJet8_mbdNS_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet8_mbdNS_bkg);
0318       hJet10_mbdNS_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet10_mbdNS_bkg);
0319       hJet12_mbdNS_bkg->AddPoint(zdc_NS_vec[info.run], fraction_Jet12_mbdNS_bkg);
0320 
0321       // print outlier
0322       if(zdc_NS_vec[info.run] < 3) cout << "Run: " << info.run << ", ZDC NS: " << zdc_NS_vec[info.run] << ", frac: " << fraction_Jet6_bkg << endl;
0323 
0324       if(zdc_NS_vec[info.run] >= 3 && fraction_Jet12_bkg > 15) cout << "Run: " << info.run << ", ZDC NS: " << zdc_NS_vec[info.run] << ", frac: " << fraction_Jet12_bkg << endl;
0325 
0326       s << info.run << "," << info.evt_Jet6 << "," << info.evt_Jet6_mbdNS << "," << info.evt_Jet6_bkg << "," << info.evt_Jet6_mbdNS_bkg << "," << info.evt_Jet6_bkgCEMC << "," << fraction_Jet6_bkg << "," << fraction_Jet6_mbdNS_bkg << "," << fraction_bkgCEMC_Jet6
0327         << "," << info.evt_Jet8 << "," << info.evt_Jet8_mbdNS << "," << info.evt_Jet8_bkg << "," << info.evt_Jet8_mbdNS_bkg << "," << info.evt_Jet8_bkgCEMC << "," << fraction_Jet8_bkg << "," << fraction_Jet8_mbdNS_bkg << "," << fraction_bkgCEMC_Jet8
0328         << "," << info.evt_Jet10 << "," << info.evt_Jet10_mbdNS << "," << info.evt_Jet10_bkg << "," << info.evt_Jet10_mbdNS_bkg << "," << info.evt_Jet10_bkgCEMC << "," << fraction_Jet10_bkg << "," << fraction_Jet10_mbdNS_bkg << "," << fraction_bkgCEMC_Jet10
0329         << "," << info.evt_Jet12 << "," << info.evt_Jet12_mbdNS << "," << info.evt_Jet12_bkg << "," << info.evt_Jet12_mbdNS_bkg << "," << info.evt_Jet12_bkgCEMC << "," << fraction_Jet12_bkg << "," << fraction_Jet12_mbdNS_bkg << "," << fraction_bkgCEMC_Jet12 << endl;
0330 
0331       output << s.str();
0332    }
0333 
0334    cout << "max frac: " << max_frac << endl;
0335 
0336    output.close();
0337 }
0338 
0339 void myAnalysis::plot(const string &output) {
0340     TCanvas* c1 = new TCanvas();
0341     c1->SetTickx();
0342     c1->SetTicky();
0343 
0344     c1->SetCanvasSize(1400, 1000);
0345     c1->SetLeftMargin(.08);
0346     c1->SetRightMargin(.02);
0347     c1->SetBottomMargin(.1);
0348 
0349     gPad->SetGrid(0,1);
0350 
0351     gStyle->SetTitleXOffset(0.9);
0352     gStyle->SetTitleYOffset(0.7);
0353 
0354     Float_t leg_x_low  = 0.15;
0355     Float_t leg_x_high = 0.25;
0356     Float_t leg_y_low  = 0.8;
0357     Float_t leg_y_high = 0.9;
0358 
0359     c1->Print((output + "[").c_str(), "pdf portrait");
0360 
0361     hJet6_mbdNS_bkg->SetMarkerColor(kRed);
0362     hJet8_mbdNS_bkg->SetMarkerColor(kRed);
0363     hJet10_mbdNS_bkg->SetMarkerColor(kRed);
0364     hJet12_mbdNS_bkg->SetMarkerColor(kRed);
0365 
0366     // gPad->SetLogy();
0367     hJet6_bkg->GetYaxis()->SetRangeUser(0,40);
0368     hJet6_bkg->GetXaxis()->SetLimits(3,9);
0369     hJet6_bkg->SetTitle("; #LT ZDC NS #GT [kHz]; Fraction of Background Events [%]");
0370     hJet6_bkg->Draw("AP");
0371     hJet6_mbdNS_bkg->Draw("same P");
0372 
0373     auto leg = new TLegend(leg_x_low, leg_y_low, leg_x_high, leg_y_high);
0374 
0375     leg->SetTextSize(0.05);
0376     leg->SetFillStyle(0);
0377     leg->AddEntry(hJet6_bkg, "Jet 6 GeV", "p");
0378     leg->AddEntry(hJet6_mbdNS_bkg, "Jet 6 GeV && MBD NS #geq 1", "p");
0379     leg->Draw("same");
0380 
0381     c1->Print("Jet6-bkg-vs-zdc-v1.png");
0382     c1->Print((output).c_str(), "pdf portrait");
0383 
0384     hJet6_bkg->GetYaxis()->SetRangeUser(0,12);
0385 
0386     c1->Print("Jet6-bkg-vs-zdc-v2.png");
0387     c1->Print((output).c_str(), "pdf portrait");
0388 
0389     hJet8_bkg->GetYaxis()->SetRangeUser(0,40);
0390     hJet8_bkg->GetXaxis()->SetLimits(3,9);
0391     hJet8_bkg->SetTitle("; #LT ZDC NS #GT [kHz]; Fraction of Background Events [%]");
0392     hJet8_bkg->Draw("AP");
0393     hJet8_mbdNS_bkg->Draw("same P");
0394 
0395     leg = new TLegend(leg_x_low, leg_y_low, leg_x_high, leg_y_high);
0396 
0397     leg->SetTextSize(0.05);
0398     leg->SetFillStyle(0);
0399     leg->AddEntry(hJet8_bkg, "Jet 8 GeV", "p");
0400     leg->AddEntry(hJet8_mbdNS_bkg, "Jet 8 GeV && MBD NS #geq 1", "p");
0401     leg->Draw("same");
0402 
0403     c1->Print("Jet8-bkg-vs-zdc-v1.png");
0404     c1->Print((output).c_str(), "pdf portrait");
0405 
0406     hJet8_bkg->GetYaxis()->SetRangeUser(0,25);
0407     c1->Print("Jet8-bkg-vs-zdc-v2.png");
0408     c1->Print((output).c_str(), "pdf portrait");
0409 
0410     hJet10_bkg->GetYaxis()->SetRangeUser(0,40);
0411     hJet10_bkg->GetXaxis()->SetLimits(3,9);
0412     hJet10_bkg->SetTitle("; #LT ZDC NS #GT [kHz]; Fraction of Background Events [%]");
0413     hJet10_bkg->Draw("AP");
0414     hJet10_mbdNS_bkg->Draw("same P");
0415 
0416     leg = new TLegend(leg_x_low, leg_y_low, leg_x_high, leg_y_high);
0417 
0418     leg->SetTextSize(0.05);
0419     leg->SetFillStyle(0);
0420     leg->AddEntry(hJet10_bkg, "Jet 10 GeV", "p");
0421     leg->AddEntry(hJet10_mbdNS_bkg, "Jet 10 GeV && MBD NS #geq 1", "p");
0422     leg->Draw("same");
0423 
0424     c1->Print("Jet10-bkg-vs-zdc-v1.png");
0425     c1->Print((output).c_str(), "pdf portrait");
0426 
0427     hJet12_bkg->GetYaxis()->SetRangeUser(0,40);
0428     hJet12_bkg->GetXaxis()->SetLimits(3,9);
0429     hJet12_bkg->SetTitle("; #LT ZDC NS #GT [kHz]; Fraction of Background Events [%]");
0430     hJet12_bkg->Draw("AP");
0431     hJet12_mbdNS_bkg->Draw("same P");
0432 
0433     leg = new TLegend(leg_x_low, leg_y_low, leg_x_high, leg_y_high);
0434 
0435     leg->SetTextSize(0.05);
0436     leg->SetFillStyle(0);
0437     leg->AddEntry(hJet12_bkg, "Jet 12 GeV", "p");
0438     leg->AddEntry(hJet12_mbdNS_bkg, "Jet 12 GeV && MBD NS #geq 1", "p");
0439     leg->Draw("same");
0440 
0441     c1->Print("Jet12-bkg-vs-zdc-v1.png");
0442     c1->Print((output).c_str(), "pdf portrait");
0443 
0444     c1->Print((output + "]").c_str(), "pdf portrait");
0445 }
0446 
0447 void event_stats(const string &inputFile, const string &inputZDCNSFile, const string &outputFile="stats.csv", const string &outputPlotFile="stats.pdf") {
0448     cout << "#############################" << endl;
0449     cout << "Run Parameters" << endl;
0450     cout << "input: "  << inputFile << endl;
0451     cout << "input ZDC: " << inputZDCNSFile << endl;
0452     cout << "output: " << outputFile << endl;
0453     cout << "output plots: " << outputPlotFile << endl;
0454     cout << "#############################" << endl;
0455 
0456     // set sPHENIX plotting style
0457     SetsPhenixStyle();
0458 
0459     if(myAnalysis::read(inputFile)) return;
0460     if(myAnalysis::readZDCNS(inputZDCNSFile)) return;
0461     myAnalysis::init();
0462     myAnalysis::write(outputFile);
0463     myAnalysis::plot(outputPlotFile);
0464 }
0465 
0466 # ifndef __CINT__
0467 Int_t main(Int_t argc, char* argv[]) {
0468 if(argc < 3 || argc > 5){
0469         cout << "usage: ./event-stats inputFile inputZDCNSFile [outputFile] [outputPlotFile]" << endl;
0470         cout << "inputFile: input list file" << endl;
0471         cout << "inputZDCNSFile: input csv file" << endl;
0472         cout << "outputFile: output csv file" << endl;
0473         cout << "outputPlotFile: output plot file" << endl;
0474         return 1;
0475     }
0476 
0477     string outputFile     = "stats.csv";
0478     string outputPlotFile = "stats.pdf";
0479 
0480     if(argc >= 4) {
0481         outputFile = argv[2];
0482     }
0483     if(argc >= 5) {
0484         outputPlotFile = argv[3];
0485     }
0486 
0487     event_stats(argv[1], argv[2], outputFile, outputPlotFile);
0488 
0489     cout << "======================================" << endl;
0490     cout << "done" << endl;
0491     return 0;
0492 }
0493 # endif