File indexing completed on 2024-04-06 12:32:14
0001
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <fstream>
0005 #include <cmath>
0006 #include <vector>
0007
0008 #include "TCanvas.h"
0009 #include "TDirectory.h"
0010 #include "TFile.h"
0011 #include "TLegend.h"
0012 #include "TPaveText.h"
0013 #include "TProfile.h"
0014 #include "TStyle.h"
0015
0016
0017 int colorLayer[6] = { 2, 7, 6, 3, 4, 1};
0018 std::string dets[6] = {"BeamPipe", "Tracker", "EM Calorimeter",
0019 "Hadron Calorimeter", "Muon System", "Forward Shield"};
0020
0021 void etaPhiPlot(TString fileName="matbdg_Calo.root", TString plot="IntLen",
0022 int ifirst=0, int ilast=5, int drawLeg=1, bool ifEta=true,
0023 double maxEta=-1, bool debug=false);
0024 void etaPhiDiff(TString fileName1="matbdg_Calo1.root",
0025 TString fileName2="matbdg_Calo2.root", TString plot="IntLen",
0026 int itype=2, int drawLeg=1, bool ifEta=true, double maxEta=-1);
0027 void setStyle();
0028
0029 void etaPhiPlot(TString fileName, TString plot, int ifirst, int ilast,
0030 int drawLeg, bool ifEta, double maxEta, bool debug) {
0031
0032 TFile* hcalFile = new TFile(fileName);
0033 hcalFile->cd("g4SimHits");
0034 setStyle();
0035
0036 TString xtit = TString("#eta");
0037 TString ytit = "none";
0038 int ymin = 0, ymax = 20, istart = 200;
0039 double xh = 0.90;
0040 if (plot.CompareTo("RadLen") == 0) {
0041 ytit = TString("Material Budget (X_{0})");
0042 ymin = 0; ymax = 200; istart = 100;
0043 } else if (plot.CompareTo("StepLen") == 0) {
0044 ytit = TString("Material Budget (Step Length)");
0045 ymin = 0; ymax = 15000; istart = 300; xh = 0.70;
0046 } else {
0047 ytit = TString("Material Budget (#lambda)");
0048 ymin = 0; ymax = 20; istart = 200;
0049 }
0050 if (!ifEta) {
0051 istart += 300;
0052 xtit = TString("#phi");
0053 }
0054
0055 TLegend *leg = new TLegend(xh-0.25, 0.75, xh, 0.90);
0056 leg->SetBorderSize(1); leg->SetFillColor(10); leg->SetMargin(0.25);
0057 leg->SetTextSize(0.018);
0058
0059 int nplots=0;
0060 TProfile *prof[6];
0061 for (int ii=ilast; ii>=ifirst; ii--) {
0062 char hname[10], title[50];
0063 sprintf(hname, "%i", istart+ii);
0064 gDirectory->GetObject(hname,prof[nplots]);
0065 prof[nplots]->GetXaxis()->SetTitle(xtit);
0066 prof[nplots]->GetYaxis()->SetTitle(ytit);
0067 prof[nplots]->GetYaxis()->SetRangeUser(ymin, ymax);
0068 prof[nplots]->SetLineColor(colorLayer[ii]);
0069 prof[nplots]->SetFillColor(colorLayer[ii]);
0070 if (ifEta && maxEta > 0)
0071 prof[nplots]->GetXaxis()->SetRangeUser(-maxEta,maxEta);
0072 if (xh < 0.8)
0073 prof[nplots]->GetYaxis()->SetTitleOffset(1.7);
0074 sprintf(title, "%s", dets[ii].c_str());
0075 leg->AddEntry(prof[nplots], title, "lf");
0076 nplots++;
0077 if (ii == ilast && debug) {
0078 int nbinX = prof[0]->GetNbinsX();
0079 double xmin = prof[0]->GetXaxis()->GetXmin();
0080 double xmax = prof[0]->GetXaxis()->GetXmax();
0081 double dx = (xmax - xmin)/nbinX;
0082 std::cout << "Hist " << ii;
0083 for (int ibx=0; ibx<nbinX; ibx++) {
0084 double xx1 = xmin + ibx*dx;
0085 double cont = prof[0]->GetBinContent(ibx+1);
0086 std::cout << " | " << ibx << "(" << xx1 << ":" << (xx1+dx) << ") "
0087 << cont;
0088 }
0089 std::cout << "\n";
0090 }
0091 }
0092
0093 TString cname = "c_" + plot + xtit;
0094 TCanvas *cc1 = new TCanvas(cname, cname, 700, 600);
0095 if (xh < 0.8) {
0096 cc1->SetLeftMargin(0.15); cc1->SetRightMargin(0.05);
0097 }
0098
0099 prof[0]->Draw("h");
0100 for(int i=1; i<nplots; i++)
0101 prof[i]->Draw("h sames");
0102 if (drawLeg > 0) leg->Draw("sames");
0103 }
0104
0105 void etaPhiDiff(TString fileName1, TString fileName2, TString plot,
0106 int itype, int drawLeg, bool ifEta, double maxEta) {
0107
0108 setStyle();
0109
0110 TString xtit = TString("#eta");
0111 TString ytit = "none";
0112 double xh = 0.90, ymin = -0.5, ymax = 0.5;
0113 int ihist = 200 + itype;
0114 if (plot.CompareTo("RadLen") == 0) {
0115 ytit = TString("Material Budget Difference (X_{0})");
0116 ymin = -1; ymax = 1; ihist = 100 + itype;
0117 } else if (plot.CompareTo("StepLen") == 0) {
0118 ytit = TString("Material Budget Difference (Step Length)");
0119 ymin = -20; ymax = 20; ihist = 300 + itype; xh = 0.70;
0120 } else {
0121 ytit = TString("Material Budget Difference (#lambda)");
0122 }
0123 if (!ifEta) {
0124 ihist += 300;
0125 xtit = TString("#phi");
0126 }
0127
0128 TLegend *leg = new TLegend(xh-0.25, 0.84, xh, 0.90);
0129 leg->SetBorderSize(1); leg->SetFillColor(10); leg->SetMargin(0.25);
0130 leg->SetTextSize(0.022);
0131
0132 TProfile *prof1, *prof2;
0133 char hname[10], title[50];
0134 sprintf(hname, "%i", ihist);
0135 TFile* file1 = new TFile(fileName1);
0136 file1->cd("g4SimHits");
0137 gDirectory->GetObject(hname,prof1);
0138 TFile* file2 = new TFile(fileName2);
0139 file2->cd("g4SimHits");
0140 gDirectory->GetObject(hname,prof2);
0141 TH1D *prof = (TH1D*) prof1->Clone();
0142 prof->Add(prof2,-1);
0143 prof->GetXaxis()->SetTitle(xtit);
0144 prof->GetYaxis()->SetTitle(ytit);
0145 prof->GetYaxis()->SetRangeUser(ymin, ymax);
0146 prof->SetLineColor(colorLayer[itype]);
0147 for (int k=1; k<=prof->GetNbinsX(); ++k)
0148 prof->SetBinError(k,0);
0149 if (ifEta && maxEta > 0)
0150 prof->GetXaxis()->SetRangeUser(-maxEta,maxEta);
0151 if (xh < 0.8)
0152 prof->GetYaxis()->SetTitleOffset(1.7);
0153 sprintf(title, "%s", dets[itype].c_str());
0154 leg->AddEntry(prof, title, "lf");
0155
0156 TString cname = "c_dif" + plot + xtit;
0157 TCanvas *cc1 = new TCanvas(cname, cname, 700, 600);
0158 if (xh < 0.8) {
0159 cc1->SetLeftMargin(0.15); cc1->SetRightMargin(0.05);
0160 }
0161
0162 prof->Draw("h");
0163 if (drawLeg > 0) leg->Draw("sames");
0164 }
0165
0166 void setStyle () {
0167
0168 gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0169 gStyle->SetPadColor(kWhite); gStyle->SetFrameBorderMode(0);
0170 gStyle->SetFrameBorderSize(1); gStyle->SetFrameFillColor(0);
0171 gStyle->SetFrameFillStyle(0); gStyle->SetFrameLineColor(1);
0172 gStyle->SetFrameLineStyle(1); gStyle->SetFrameLineWidth(1);
0173 gStyle->SetOptStat(0); gStyle->SetLegendBorderSize(1);
0174 gStyle->SetOptTitle(0); gStyle->SetTitleOffset(2.5,"Y");
0175
0176 }
0177