File indexing completed on 2024-04-06 12:32:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "TCanvas.h"
0015 #include "TDirectory.h"
0016 #include "TF1.h"
0017 #include "TFile.h"
0018 #include "TFitResult.h"
0019 #include "TGraph.h"
0020 #include "TGraphAsymmErrors.h"
0021 #include "TH1D.h"
0022 #include "TH2D.h"
0023 #include "THStack.h"
0024 #include "TLegend.h"
0025 #include "TMath.h"
0026 #include "TProfile.h"
0027 #include "TPaveStats.h"
0028 #include "TPaveText.h"
0029 #include "TROOT.h"
0030 #include "TString.h"
0031 #include "TStyle.h"
0032
0033 #include <iostream>
0034 #include <iomanip>
0035 #include <vector>
0036 #include <string>
0037
0038 void setTDRStyle() {
0039 TStyle *tdrStyle = new TStyle("tdrStyle", "Style for P-TDR");
0040
0041
0042 tdrStyle->SetCanvasBorderMode(0);
0043 tdrStyle->SetCanvasColor(kWhite);
0044 tdrStyle->SetCanvasDefH(600);
0045 tdrStyle->SetCanvasDefW(600);
0046 tdrStyle->SetCanvasDefX(0);
0047 tdrStyle->SetCanvasDefY(0);
0048
0049
0050 tdrStyle->SetPadBorderMode(0);
0051
0052 tdrStyle->SetPadColor(kWhite);
0053 tdrStyle->SetPadGridX(false);
0054 tdrStyle->SetPadGridY(false);
0055 tdrStyle->SetGridColor(0);
0056 tdrStyle->SetGridStyle(3);
0057 tdrStyle->SetGridWidth(1);
0058
0059
0060 tdrStyle->SetFrameBorderMode(0);
0061 tdrStyle->SetFrameBorderSize(1);
0062 tdrStyle->SetFrameFillColor(0);
0063 tdrStyle->SetFrameFillStyle(0);
0064 tdrStyle->SetFrameLineColor(1);
0065 tdrStyle->SetFrameLineStyle(1);
0066 tdrStyle->SetFrameLineWidth(1);
0067
0068
0069 tdrStyle->SetOptDate(0);
0070
0071
0072
0073
0074 tdrStyle->SetOptFile(0);
0075 tdrStyle->SetOptStat("mr");
0076
0077
0078
0079 tdrStyle->SetOptTitle(0);
0080 tdrStyle->SetTitleFont(42);
0081 tdrStyle->SetTitleColor(1);
0082 tdrStyle->SetTitleTextColor(1);
0083 tdrStyle->SetTitleFillColor(10);
0084 tdrStyle->SetTitleFontSize(0.05);
0085
0086
0087 tdrStyle->SetTitleColor(1, "XYZ");
0088 tdrStyle->SetTitleFont(42, "XYZ");
0089 tdrStyle->SetTitleSize(0.06, "XYZ");
0090
0091
0092 tdrStyle->SetTitleXOffset(0.7);
0093 tdrStyle->SetTitleYOffset(0.7);
0094
0095
0096
0097 tdrStyle->SetLabelColor(1, "XYZ");
0098 tdrStyle->SetLabelFont(42, "XYZ");
0099 tdrStyle->SetLabelOffset(0.007, "XYZ");
0100 tdrStyle->SetLabelSize(0.03, "XYZ");
0101
0102
0103 tdrStyle->SetAxisColor(1, "XYZ");
0104 tdrStyle->SetStripDecimals(kTRUE);
0105 tdrStyle->SetTickLength(0.03, "XYZ");
0106 tdrStyle->SetNdivisions(510, "XYZ");
0107 tdrStyle->SetPadTickX(1);
0108 tdrStyle->SetPadTickY(1);
0109
0110 tdrStyle->cd();
0111 }
0112
0113 void plotCompare(std::string infile1, std::string infile2, std::string text1, std::string text2, int type, bool save) {
0114 const int ndets = 4;
0115 const int nhist = 5;
0116 std::string names[ndets][nhist] = {{"Hit05", "Hit17", "Hit21", "Hit25", "Hit29"},
0117 {"Hit06", "Hit18", "Hit22", "Hit26", "Hit30"},
0118 {"Hit07", "Hit19", "Hit23", "Hit27", "Hit31"},
0119 {"Hit08", "Hit20", "Hit24", "Hit28", "Hit32"}};
0120 std::string xtitl[nhist] = {"Hits", "Depth", "i#eta", "i#phi", "Energy (MeV)"};
0121 std::string dets[ndets] = {"HB", "HE", "HO", "HF"};
0122 int nbins[nhist] = {10, 1, 1, 1, 1};
0123 bool logs[nhist] = {0, 0, 0, 0, 1};
0124 double xmax[nhist] = {2000, -1, -1, -1, 2.0};
0125 int colors[2] = {2, 4};
0126 int style[2] = {1, 2};
0127
0128 if (type < 0 || type >= ndets)
0129 type = 0;
0130 setTDRStyle();
0131 TFile *file1 = new TFile(infile1.c_str());
0132 TFile *file2 = new TFile(infile2.c_str());
0133 if ((file1 != nullptr) && (file2 != nullptr)) {
0134 char name[20], cname[50];
0135 for (int k = 0; k < nhist; ++k) {
0136 sprintf(name, "%s", names[type][k].c_str());
0137 sprintf(cname, "c_%s", names[type][k].c_str());
0138 TH1D *hist[2];
0139 hist[0] = (TH1D *)(file1->FindObjectAny(name));
0140 hist[1] = (TH1D *)(file2->FindObjectAny(name));
0141 if ((hist[0] != nullptr) && (hist[1] != nullptr)) {
0142 TCanvas *pad = new TCanvas(cname, cname, 800, 600);
0143 pad->SetRightMargin(0.10);
0144 pad->SetTopMargin(0.10);
0145 if (logs[k] > 0)
0146 pad->SetLogy();
0147 TLegend *leg = new TLegend(0.65, 0.69, 0.89, 0.77);
0148 leg->SetFillColor(kWhite);
0149 double ymax(0.90);
0150 for (int i = 0; i < 2; ++i) {
0151 hist[i]->SetLineStyle(style[i]);
0152 hist[i]->SetLineColor(colors[i]);
0153 hist[i]->SetLineWidth(2);
0154 hist[i]->Rebin(nbins[k]);
0155 hist[i]->GetXaxis()->SetTitle(xtitl[k].c_str());
0156 if (xmax[k] > 0)
0157 hist[i]->GetXaxis()->SetRangeUser(0, xmax[k]);
0158 if (i == 0)
0159 hist[i]->Draw("HIST");
0160 else
0161 hist[i]->Draw("HIST sames");
0162 if (i == 0)
0163 sprintf(name, "%s", text1.c_str());
0164 else
0165 sprintf(name, "%s", text2.c_str());
0166 leg->AddEntry(hist[i], name, "lp");
0167 pad->Update();
0168 TPaveStats *st1 = (TPaveStats *)hist[i]->GetListOfFunctions()->FindObject("stats");
0169 if (st1 != nullptr) {
0170 double ymin = ymax - 0.06;
0171 st1->SetFillColor(kWhite);
0172 st1->SetLineColor(colors[i]);
0173 st1->SetTextColor(colors[i]);
0174 st1->SetY1NDC(ymin);
0175 st1->SetY2NDC(ymax);
0176 st1->SetX1NDC(0.70);
0177 st1->SetX2NDC(0.90);
0178 ymax = ymin;
0179 }
0180 }
0181 leg->Draw("same");
0182 pad->Update();
0183 TPaveText *txt1 = new TPaveText(0.65, 0.63, 0.89, 0.685, "blNDC");
0184 txt1->SetFillColor(kWhite);
0185 sprintf(name, "%s", dets[type].c_str());
0186 txt1->AddText(name);
0187 txt1->Draw("same");
0188 pad->Update();
0189 if (save) {
0190 sprintf(cname, "%s.pdf", pad->GetName());
0191 pad->Print(cname);
0192 }
0193 }
0194 }
0195 }
0196 }