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 
0007 // -- root includes --
0008 #include <TH2F.h>
0009 #include <TF1.h>
0010 #include <TFile.h>
0011 #include <TLine.h>
0012 #include <TLegend.h>
0013 #include <TLatex.h>
0014 #include <TCanvas.h>
0015 
0016 // -- sPHENIX Style
0017 #include "sPhenixStyle.C"
0018 
0019 using std::cout;
0020 using std::cerr;
0021 using std::endl;
0022 using std::string;
0023 using std::to_string;
0024 using std::vector;
0025 using std::stringstream;
0026 using std::min;
0027 using std::max;
0028 using std::ofstream;
0029 
0030 namespace myAnalysis {
0031     void plots(const string& i_input, const string &output);
0032 }
0033 
0034 void myAnalysis::plots(const string& i_input, const string &output) {
0035 
0036     TFile input(i_input.c_str());
0037 
0038     TCanvas* c1 = new TCanvas();
0039     c1->SetTickx();
0040     c1->SetTicky();
0041 
0042     c1->SetCanvasSize(1400, 1000);
0043     c1->SetLeftMargin(.15);
0044     c1->SetRightMargin(.02);
0045     c1->SetBottomMargin(.11);
0046 
0047     c1->Print((output + "[").c_str(), "pdf portrait");
0048 
0049     gStyle->SetOptTitle();
0050     gStyle->SetTitleStyle(0);
0051     gStyle->SetTitleFontSize(0.08);
0052     gStyle->SetTitleW(1);
0053     gStyle->SetTitleH(0.05);
0054     gStyle->SetTitleFillColor(0);
0055     gStyle->SetTitleBorderSize(0);
0056     gStyle->SetTitleXOffset(1);
0057     gStyle->SetTitleYOffset(1.4);
0058 
0059 
0060     // ----------------------------------------------------------
0061     gPad->SetLogy();
0062 
0063     auto hEvents = (TH1F*)input.Get("event/hEvents");
0064 
0065     TLatex latex;
0066     latex.SetTextSize(0.05);
0067 
0068     hEvents->Draw();
0069 
0070     for(UInt_t i = 1; i < hEvents->GetNbinsX(); ++i) {
0071         string label = hEvents->GetXaxis()->GetBinLabel(i+1);
0072         hEvents->GetXaxis()->SetBinLabel(i+1,string(1,char('A'+i-1)).c_str());
0073 
0074         latex.DrawLatexNDC(0.3,0.89-0.07*(i-1),(string(1,char('A'+i-1)) + ": " + label).c_str());
0075     }
0076 
0077     hEvents->GetYaxis()->SetRangeUser(1,2e6);
0078     hEvents->GetXaxis()->SetLabelSize(0.1);
0079     hEvents->GetXaxis()->SetRangeUser(1,hEvents->GetNbinsX());
0080     c1->Print(output.c_str(), "pdf portrait");
0081     c1->Print((string(hEvents->GetName()) + ".png").c_str());
0082 
0083     // ----------------------------------------------------------
0084     gPad->SetLogy(0);
0085     c1->SetRightMargin(.15);
0086 
0087     auto h2ETVsFracCEMC      = (TH2F*)input.Get("bkg_checks/h2ETVsFracCEMC");
0088     auto h2ETVsFracCEMC_miss = (TH2F*)input.Get("bkg_checks/h2ETVsFracCEMC_miss");
0089 
0090     h2ETVsFracCEMC->SetTitle("Event");
0091     h2ETVsFracCEMC_miss->SetTitle("Event");
0092 
0093     auto cut_LoEmFracET1 = new TLine(0.1,10,0.1,200);
0094     auto cut_LoEmFracET2 = new TF1("cut_LoEmFracET2","50*x+20",-0.2,0.1);
0095 
0096     auto cut_HiEmFracET1 = new TLine(0.9,10,0.9,200);
0097     auto cut_HiEmFracET2 = new TF1("cut_LoEmFracET2","-50*x+70",0.9,1.2);
0098 
0099     cut_LoEmFracET1->SetLineColor(kRed);
0100     cut_LoEmFracET2->SetLineColor(kRed);
0101     cut_HiEmFracET1->SetLineColor(kRed);
0102     cut_HiEmFracET2->SetLineColor(kRed);
0103     cut_LoEmFracET2->SetLineWidth(1);
0104     cut_HiEmFracET2->SetLineWidth(1);
0105 
0106     h2ETVsFracCEMC->Draw("COLZ1");
0107     cut_LoEmFracET1->Draw("same");
0108     cut_LoEmFracET2->Draw("same");
0109     cut_HiEmFracET1->Draw("same");
0110     cut_HiEmFracET2->Draw("same");
0111     c1->Print(output.c_str(), "pdf portrait");
0112     c1->Print((string(h2ETVsFracCEMC->GetName()) + ".png").c_str());
0113 
0114     h2ETVsFracCEMC_miss->SetMaximum(5);
0115     h2ETVsFracCEMC_miss->Draw("COLZ1");
0116     cut_LoEmFracET1->Draw("same");
0117     cut_LoEmFracET2->Draw("same");
0118     cut_HiEmFracET1->Draw("same");
0119     cut_HiEmFracET2->Draw("same");
0120     c1->Print(output.c_str(), "pdf portrait");
0121     c1->Print((string(h2ETVsFracCEMC_miss->GetName()) + ".png").c_str());
0122 
0123     // ----------------------------------------------------------
0124 
0125     auto h2FracOHCalVsFracCEMC      = (TH2F*)input.Get("bkg_checks/h2FracOHCalVsFracCEMC");
0126     auto h2FracOHCalVsFracCEMC_miss = (TH2F*)input.Get("bkg_checks/h2FracOHCalVsFracCEMC_miss");
0127 
0128     h2FracOHCalVsFracCEMC->SetTitle("Event");
0129     h2FracOHCalVsFracCEMC_miss->SetTitle("Event");
0130 
0131     auto cut_IhFrac = new TF1("cut_IhFrac","0.65-x",-0.2,1.2);
0132     cut_IhFrac->SetLineColor(kRed);
0133     cut_IhFrac->SetLineWidth(1);
0134 
0135     h2FracOHCalVsFracCEMC->Draw("COLZ1");
0136     cut_IhFrac->Draw("same");
0137     c1->Print(output.c_str(), "pdf portrait");
0138     c1->Print((string(h2FracOHCalVsFracCEMC->GetName()) + ".png").c_str());
0139 
0140     h2FracOHCalVsFracCEMC_miss->Draw("COLZ1");
0141     cut_IhFrac->Draw("same");
0142     c1->Print(output.c_str(), "pdf portrait");
0143     c1->Print((string(h2FracOHCalVsFracCEMC_miss->GetName()) + ".png").c_str());
0144 
0145     // ----------------------------------------------------------
0146 
0147     c1->SetCanvasSize(2900, 1000);
0148     c1->SetLeftMargin(.06);
0149     c1->SetRightMargin(.1);
0150     c1->SetTopMargin(.1);
0151     c1->SetBottomMargin(.12);
0152 
0153     gStyle->SetOptTitle();
0154     gStyle->SetTitleStyle(0);
0155     gStyle->SetTitleFontSize(0.08);
0156     gStyle->SetTitleW(1);
0157     gStyle->SetTitleH(0.09);
0158     gStyle->SetTitleFillColor(0);
0159     gStyle->SetTitleBorderSize(0);
0160     gStyle->SetTitleXOffset(1);
0161     gStyle->SetTitleYOffset(0.5);
0162 
0163     auto hjetPhiEtaPt = (TH3*)input.Get("jets/hjetPhiEtaPt");
0164 
0165     hjetPhiEtaPt->GetZaxis()->SetRange(hjetPhiEtaPt->GetZaxis()->FindBin(10),hjetPhiEtaPt->GetNbinsZ());
0166     auto hyx = hjetPhiEtaPt->Project3D("yx");
0167     hyx->SetTitle("Jet: p_{T} #geq 10 GeV");
0168 
0169     hyx->Draw("COLZ1");
0170     c1->Print(output.c_str(), "pdf portrait");
0171     c1->Print((string(hjetPhiEtaPt->GetName()) + "-10.png").c_str());
0172 
0173     c1->SetCanvasSize(1400, 1000);
0174     c1->SetLeftMargin(.15);
0175     c1->SetRightMargin(.02);
0176     c1->SetBottomMargin(.11);
0177 
0178     auto hx = hjetPhiEtaPt->Project3D("x");
0179     hx->SetTitle("Jet: p_{T} #geq 10 GeV; #phi; Counts");
0180     hx->GetYaxis()->SetTitleOffset(1.4);
0181     hx->GetYaxis()->SetRangeUser(0,3e3);
0182 
0183     hx->Draw("COLZ1");
0184     c1->Print(output.c_str(), "pdf portrait");
0185     c1->Print((string(hjetPhiEtaPt->GetName()) + "-10-phi.png").c_str());
0186 
0187     auto hy = hjetPhiEtaPt->Project3D("y");
0188     hy->SetTitle("Jet: p_{T} #geq 10 GeV; #eta; Counts");
0189     hy->GetYaxis()->SetTitleOffset(1.4);
0190 
0191     hy->Draw("COLZ1");
0192     c1->Print(output.c_str(), "pdf portrait");
0193     c1->Print((string(hjetPhiEtaPt->GetName()) + "-10-eta.png").c_str());
0194 
0195     c1->SetCanvasSize(2900, 1000);
0196     c1->SetLeftMargin(.06);
0197     c1->SetRightMargin(.1);
0198     c1->SetTopMargin(.1);
0199     c1->SetBottomMargin(.12);
0200 
0201     hjetPhiEtaPt->GetZaxis()->SetRange(hjetPhiEtaPt->GetZaxis()->FindBin(60),hjetPhiEtaPt->GetNbinsZ());
0202     hyx = hjetPhiEtaPt->Project3D("yx");
0203     hyx->SetTitle("Jet: p_{T} #geq 60 GeV");
0204 
0205     hyx->Draw("COLZ1");
0206     c1->Print(output.c_str(), "pdf portrait");
0207     c1->Print((string(hjetPhiEtaPt->GetName()) + "-60.png").c_str());
0208 
0209     c1->SetCanvasSize(1400, 1000);
0210     c1->SetLeftMargin(.15);
0211     c1->SetRightMargin(.02);
0212     c1->SetBottomMargin(.11);
0213 
0214     hx = hjetPhiEtaPt->Project3D("x");
0215     hx->SetTitle("Jet: p_{T} #geq 60 GeV; #phi; Counts");
0216     hx->GetYaxis()->SetTitleOffset(1.4);
0217     hx->GetYaxis()->SetRangeUser(0,30);
0218 
0219     hx->Draw("COLZ1");
0220     c1->Print(output.c_str(), "pdf portrait");
0221     c1->Print((string(hjetPhiEtaPt->GetName()) + "-60-phi.png").c_str());
0222 
0223     hy = hjetPhiEtaPt->Project3D("y");
0224     hy->SetTitle("Jet: p_{T} #geq 60 GeV; #eta; Counts");
0225     hy->GetYaxis()->SetTitleOffset(1.4);
0226 
0227     hy->Draw("COLZ1");
0228     c1->Print(output.c_str(), "pdf portrait");
0229     c1->Print((string(hjetPhiEtaPt->GetName()) + "-60-eta.png").c_str());
0230 
0231     // ----------------------------------------------------------
0232 
0233     c1->SetCanvasSize(1400, 1000);
0234     c1->SetLeftMargin(.15);
0235     c1->SetRightMargin(.12);
0236     c1->SetBottomMargin(.12);
0237 
0238     auto hjetConstituentsVsPt = (TH2*)input.Get("jets/hjetConstituentsVsPt");
0239 
0240     gPad->SetLogz();
0241     hjetConstituentsVsPt->Draw("COLZ1");
0242     hjetConstituentsVsPt->GetXaxis()->SetRangeUser(10,200);
0243     hjetConstituentsVsPt->GetYaxis()->SetTitleOffset(1.4);
0244 
0245     c1->Print(output.c_str(), "pdf portrait");
0246     c1->Print((string(hjetConstituentsVsPt->GetName()) + ".png").c_str());
0247 
0248     // ----------------------------------------------------------
0249 
0250     auto hNJetsVsLeadPt = (TH2*)input.Get("jets/hNJetsVsLeadPt");
0251     hNJetsVsLeadPt->RebinX(2);
0252     hNJetsVsLeadPt->GetXaxis()->SetRangeUser(10,200);
0253     hNJetsVsLeadPt->GetYaxis()->SetRangeUser(0,50);
0254     hNJetsVsLeadPt->GetYaxis()->SetTitleOffset(1);
0255 
0256     hNJetsVsLeadPt->Draw("COLZ1");
0257     c1->Print(output.c_str(), "pdf portrait");
0258     c1->Print((string(hNJetsVsLeadPt->GetName()) + ".png").c_str());
0259 
0260     c1->Print((output + "]").c_str(), "pdf portrait");
0261 
0262     input.Close();
0263 }
0264 
0265 void display(const string &input, const string &output="plots.pdf") {
0266     cout << "#############################" << endl;
0267     cout << "Run Parameters" << endl;
0268     cout << "input: "  << input << endl;
0269     cout << "output: " << output << endl;
0270     cout << "#############################" << endl;
0271 
0272     // set sPHENIX plotting style
0273     SetsPhenixStyle();
0274 
0275     myAnalysis::plots(input, output);
0276 }
0277 
0278 # ifndef __CINT__
0279 Int_t main(Int_t argc, char* argv[]) {
0280 if(argc < 2 || argc > 3){
0281         cout << "usage: ./display input [output]" << endl;
0282         cout << "input: input root file" << endl;
0283         cout << "output: output pdf file" << endl;
0284         return 1;
0285     }
0286 
0287     string output  = "plots.pdf";
0288 
0289     if(argc >= 3) {
0290         output = argv[2];
0291     }
0292 
0293     display(argv[1], output);
0294 
0295     cout << "======================================" << endl;
0296     cout << "done" << endl;
0297     return 0;
0298 }
0299 # endif