Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-24 01:30:33

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // Usage:
0004 // .L MakeHitStudyPlots.C+g
0005 //
0006 //   To make plot of various quantities which are created by CaloSimHitStudy
0007 //   from one or two different settings
0008 //
0009 //     makeHitStudyPlots(file1, tag1, file2, tag2, todomin, todomax, gtitle,
0010 //                       ratio, save, dirnm)
0011 //
0012 //   To make plots of ratios of hits produced with identical geometry and
0013 //   generator level files created by HGCalHitCheck
0014 //
0015 //      makeDDDvsDD4hepPlots(dirnm, inType, geometry, layer, ratio, save)
0016 //
0017 //   To make plots of digitization variables from digitiasation campaigns
0018 //   with FullSim_Signal+FullSim_PU vs FasrSim_Signal+FastSim_PU vs
0019 //   FullSim_Signal+FastSim_PU
0020 //
0021 //      makeDigiStudyPlots(tag, todomin, todomax, save)
0022 //
0023 //   where (for makeHitStudyPlots)
0024 //     file1    std::string   Name of the first ROOT file [old/analRun3.root]
0025 //     file2    std::string   Name of the second ROOT file [new/analRun3.root]
0026 //     tag1     std::string   Tag for the first file [Bug]
0027 //     tag2     std::string   Tag for the second file [Fix]
0028 //     gtitle   std::string   Overall Titile [""]
0029 //     todomin  int           Minimum type # of histograms to be plotted [0]
0030 //     todomax  int           Maximum type # of histograms to be plotted [0]
0031 //     dirnm    std::string   Name of the directory [CaloSimHitStudy]
0032 //
0033 //   where (for makeHitStudyPlots)
0034 //     dirnm    std::string   Directory name (EE/HEF/HEB)
0035 //     inType   std::string   Name of the input data (Muon/MinBias)
0036 //     geometry std::string   Tag for the geometry (D98/D99)
0037 //     layer    int           Layer number (if 0; all layers combined)
0038 //     ratio    bool          if the ratio to be plotted [true]
0039 //                            (works when both files are active)
0040 //
0041 //   where (for makeHitStudyPlots)
0042 //     tag      std::string   Detectr type (EC/HC)
0043 //     todomin  int           Minimum type # of histograms to be plotted [0]
0044 //     todomax  int           Maximum type # of histograms to be plotted [0]
0045 //
0046 //   where (common to all macros)
0047 //     save     bool          If the canvas is to be saved as jpg file [false]
0048 //
0049 //////////////////////////////////////////////////////////////////////////////
0050 
0051 #include <TCanvas.h>
0052 #include <TChain.h>
0053 #include <TFile.h>
0054 #include <TFitResult.h>
0055 #include <TFitResultPtr.h>
0056 #include <TH1D.h>
0057 #include <TH2D.h>
0058 #include <TLegend.h>
0059 #include <TPaveStats.h>
0060 #include <TPaveText.h>
0061 #include <TProfile.h>
0062 #include <TROOT.h>
0063 #include <TStyle.h>
0064 #include <vector>
0065 #include <string>
0066 #include <iomanip>
0067 #include <iostream>
0068 #include <fstream>
0069 
0070 void makeHitStudyPlots(std::string file1 = "uncorr/analRun3.root",
0071                        std::string file2 = "corr/analRun3.root",
0072                        std::string tag1 = "Bug",
0073                        std::string tag2 = "Fix",
0074                        std::string gtitle = "",
0075                        int todomin = 0,
0076                        int todomax = 0,
0077                        bool ratio = true,
0078                        bool save = false,
0079                        std::string dirnm = "CaloSimHitStudy") {
0080   const int plots = 20;
0081   std::string names[plots] = {"Etot",   "Hit",     "EtotG",  "Time",    "EdepTk", "Edep", "HitHigh",
0082                               "HitLow", "HitMu",   "HitTk",  "TimeAll", "TimeTk", "eta",  "phi",
0083                               "EdepEM", "EdepHad", "EneInc", "EtaInc",  "PhiInc", "PtInc"};
0084   int numb[plots] = {9, 9, 9, 9, 16, 9, 1, 1, 1, 16, 9, 16, 9, 9, 9, 9, 1, 1, 1, 1};
0085   int rebin[plots] = {10, 10, 10, 10, 1, 10, 10, 10, 10, 10, 10, 10, 2, 4, 10, 10, 1, 1, 1, 1};
0086   bool debug(false);
0087 
0088   gStyle->SetCanvasBorderMode(0);
0089   gStyle->SetCanvasColor(kWhite);
0090   gStyle->SetPadColor(kWhite);
0091   gStyle->SetFillColor(kWhite);
0092   if (ratio)
0093     gStyle->SetOptStat(0);
0094   else
0095     gStyle->SetOptStat(1110);
0096   TFile* file[2];
0097   int nfile(0);
0098   std::string tag(""), tags[2];
0099   if (file1 != "") {
0100     file[nfile] = new TFile(file1.c_str());
0101     if (file[nfile]) {
0102       tags[nfile] = tag1;
0103       ++nfile;
0104       tag += tag1;
0105     }
0106   }
0107   if (file2 != "") {
0108     file[nfile] = new TFile(file2.c_str());
0109     if (file[nfile]) {
0110       tags[nfile] = tag2;
0111       ++nfile;
0112       tag += tag2;
0113     }
0114   }
0115   if ((todomin < 0) || (todomin >= plots))
0116     todomin = 0;
0117   if (todomax < todomin) {
0118     todomax = todomin;
0119   } else if (todomax >= plots) {
0120     todomax = plots - 1;
0121   }
0122   std::cout << "Use " << nfile << " files from " << file1 << " and " << file2 << " and look for " << todomin << ":"
0123             << todomax << std::endl;
0124   for (int todo = todomin; todo <= todomax; ++todo) {
0125     for (int i1 = 0; i1 < numb[todo]; ++i1) {
0126       double y1(0.90), dy(0.12);
0127       double y2 = y1 - dy * nfile - 0.01;
0128       TLegend* leg = (ratio) ? (new TLegend(0.10, 0.86, 0.90, 0.90)) : (new TLegend(0.65, y2 - nfile * 0.04, 0.90, y2));
0129       leg->SetBorderSize(1);
0130       leg->SetFillColor(10);
0131       TH1D* hist0[nfile];
0132       char name[100], namec[100];
0133       if (numb[todo] == 1) {
0134         sprintf(name, "%s", names[todo].c_str());
0135         sprintf(namec, "c_%s%s%s", names[todo].c_str(), tag.c_str(), gtitle.c_str());
0136       } else {
0137         sprintf(name, "%s%d", names[todo].c_str(), i1);
0138         sprintf(namec, "c_%s%d%s%s", names[todo].c_str(), i1, tag.c_str(), gtitle.c_str());
0139       }
0140       TCanvas* pad = new TCanvas(namec, namec, 500, 500);
0141       for (int ifile = 0; ifile < nfile; ++ifile) {
0142         TDirectory* dir = (TDirectory*)file[ifile]->FindObjectAny(dirnm.c_str());
0143         hist0[ifile] = static_cast<TH1D*>(dir->FindObjectAny(name));
0144         if (debug)
0145           std::cout << name << " read out at " << hist0[ifile] << " for " << tags[ifile] << std::endl;
0146       }
0147       if (!ratio) {
0148         int first(0);
0149         for (int ifile = 0; ifile < nfile; ++ifile) {
0150           TH1D* hist(hist0[ifile]);
0151           if (hist != nullptr) {
0152             hist->SetLineColor(first + 1);
0153             hist->SetLineStyle(first + 1);
0154             hist->GetYaxis()->SetTitleOffset(1.4);
0155             if (rebin[todo] > 1)
0156               hist->Rebin(rebin[todo]);
0157             hist->SetTitle(gtitle.c_str());
0158             if (first == 0) {
0159               pad = new TCanvas(namec, namec, 500, 500);
0160               pad->SetRightMargin(0.10);
0161               pad->SetTopMargin(0.10);
0162               pad->SetLogy();
0163               hist->Draw();
0164             } else {
0165               hist->Draw("sames");
0166             }
0167             leg->AddEntry(hist, tags[ifile].c_str(), "lp");
0168             pad->Update();
0169             ++first;
0170             TPaveStats* st = ((TPaveStats*)hist->GetListOfFunctions()->FindObject("stats"));
0171             if (st != NULL) {
0172               st->SetLineColor(first);
0173               st->SetTextColor(first);
0174               st->SetY1NDC(y1 - dy);
0175               st->SetY2NDC(y1);
0176               st->SetX1NDC(0.65);
0177               st->SetX2NDC(0.90);
0178               y1 -= dy;
0179             }
0180             pad->Modified();
0181             pad->Update();
0182             leg->Draw("same");
0183             pad->Update();
0184             if (save) {
0185               sprintf(name, "%s.pdf", pad->GetName());
0186               pad->Print(name);
0187             }
0188           }
0189         }
0190       } else {
0191         if (nfile == 2) {
0192           int nbin = hist0[0]->GetNbinsX();
0193           int nbinR = nbin / rebin[todo];
0194           double xlow = hist0[0]->GetXaxis()->GetBinLowEdge(1);
0195           double xhigh = hist0[0]->GetXaxis()->GetBinLowEdge(nbin) + hist0[0]->GetXaxis()->GetBinWidth(nbin);
0196           if (numb[todo] == 1) {
0197             sprintf(name, "%sRatio", names[todo].c_str());
0198             sprintf(namec, "c_%sRatio%s%s", names[todo].c_str(), tag.c_str(), gtitle.c_str());
0199           } else {
0200             sprintf(name, "%s%dRatio", names[todo].c_str(), i1);
0201             sprintf(namec, "c_%s%dRatio%s%s", names[todo].c_str(), i1, tag.c_str(), gtitle.c_str());
0202           }
0203           pad = new TCanvas(namec, namec, 500, 500);
0204           TH1D* histr = new TH1D(name, hist0[0]->GetTitle(), nbinR, xlow, xhigh);
0205           sprintf(name, "Ratio (%s/%s)", tags[0].c_str(), tags[1].c_str());
0206           histr->SetTitle(gtitle.c_str());
0207           histr->GetXaxis()->SetTitle(hist0[0]->GetXaxis()->GetTitle());
0208           histr->GetYaxis()->SetTitle(name);
0209           histr->GetXaxis()->SetLabelOffset(0.005);
0210           histr->GetXaxis()->SetTitleOffset(1.00);
0211           histr->GetYaxis()->SetLabelOffset(0.005);
0212           histr->GetYaxis()->SetTitleOffset(1.20);
0213           histr->GetYaxis()->SetRangeUser(0.0, 2.0);
0214           double sumNum(0), sumDen(0), maxDev(0);
0215           for (int j = 0; j < nbinR; ++j) {
0216             double tnum(0), tden(0), rnum(0), rden(0);
0217             for (int i = 0; i < rebin[todo]; ++i) {
0218               int ib = j * rebin[todo] + i + 1;
0219               tnum += hist0[0]->GetBinContent(ib);
0220               tden += hist0[1]->GetBinContent(ib);
0221               rnum += ((hist0[0]->GetBinError(ib)) * (hist0[0]->GetBinError(ib)));
0222               rden += ((hist0[1]->GetBinError(ib)) * (hist0[1]->GetBinError(ib)));
0223             }
0224             if (tden > 0 && tnum > 0) {
0225               double rat = tnum / tden;
0226               double err = rat * sqrt((rnum / (tnum * tnum)) + (rden / (tden * tden)));
0227               histr->SetBinContent(j + 1, rat);
0228               histr->SetBinError(j + 1, err);
0229               double temp1 = (rat > 1.0) ? 1.0 / rat : rat;
0230               double temp2 = (rat > 1.0) ? err / (rat * rat) : err;
0231               sumNum += (fabs(1 - temp1) / (temp2 * temp2));
0232               sumDen += (1.0 / (temp2 * temp2));
0233               if (fabs(1 - temp1) > maxDev)
0234                 maxDev = fabs(1 - temp1);
0235             }
0236           }
0237           histr->Draw();
0238           sprintf(name, "%s vs %s", tag1.c_str(), tag2.c_str());
0239           leg->AddEntry(histr, name, "lp");
0240           leg->Draw("same");
0241           pad->Update();
0242           TLine* line = new TLine(xlow, 1.0, xhigh, 1.0);
0243           line->SetLineColor(2);
0244           line->SetLineWidth(2);
0245           line->SetLineStyle(2);
0246           line->Draw("same");
0247           pad->Modified();
0248           pad->Update();
0249           sumNum = (sumDen > 0) ? (sumNum / sumDen) : 0;
0250           sumDen = (sumDen > 0) ? 1.0 / sqrt(sumDen) : 0;
0251           if (sumNum == 0)
0252             sumDen = 0;
0253           std::cout << tag1 << " vs " << tag2 << " " << hist0[0]->GetXaxis()->GetTitle() << " Mean deviation " << sumNum
0254                     << " +- " << sumDen << " maximum " << maxDev << std::endl;
0255           if (save) {
0256             sprintf(name, "%s.pdf", pad->GetName());
0257             pad->Print(name);
0258           }
0259         }
0260       }
0261     }
0262   }
0263 }
0264 
0265 void makeDDDvsDD4hepPlots(std::string dirnm = "EE",
0266                           std::string inType = "Muon",
0267                           std::string geometry = "D98",
0268                           int layer = 0,
0269                           bool ratio = true,
0270                           bool save = false) {
0271   const int plots = 3;
0272   std::string types[2] = {"DDD", "DD4hep"};
0273   std::string plotf[plots] = {"L", "F", "P"};
0274   std::string plotp[plots] = {"All", "Full|SiPM 2mm", "Partial|SiPM 4mm"};
0275   int rebins[2] = {4, 20};
0276   double xmaxs[2] = {1000, 5000};
0277   bool debug(false);
0278 
0279   gStyle->SetCanvasBorderMode(0);
0280   gStyle->SetCanvasColor(kWhite);
0281   gStyle->SetPadColor(kWhite);
0282   gStyle->SetFillColor(kWhite);
0283   if (ratio)
0284     gStyle->SetOptStat(0);
0285   else
0286     gStyle->SetOptStat(1110);
0287   TFile* file[2];
0288   int nfile(0);
0289   std::string tag(""), tags[2], filex[2];
0290   for (int i = 0; i < 2; ++i) {
0291     filex[i] = types[i] + geometry + inType + ".root";
0292     file[nfile] = new TFile(filex[i].c_str());
0293     if (file[nfile]) {
0294       tags[nfile] = types[i];
0295       ++nfile;
0296       tag += tags[nfile];
0297     }
0298   }
0299   char name[80], nameD[80], title[80];
0300   int rebin = (inType == "Muon") ? rebins[0] : rebins[1];
0301   double xmax = (inType == "Muon") ? xmaxs[0] : xmaxs[1];
0302   sprintf(nameD, "hgcalHitCheck%s", dirnm.c_str());
0303   sprintf(title, "%s vs %s for %s", types[0].c_str(), types[1].c_str(), inType.c_str());
0304   std::cout << "Use " << nfile << " files from " << filex[0] << " and " << filex[1] << " and look for " << plots
0305             << " plots in " << nameD << " with rebin " << rebin << " Max " << xmax << std::endl;
0306   for (int i = 0; i < plots; ++i) {
0307     if (layer == 0)
0308       sprintf(name, "Hits%s", plotf[i].c_str());
0309     else
0310       sprintf(name, "Hits%s%d", plotf[i].c_str(), layer);
0311     double y1(0.90), dy(0.12);
0312     double y2 = y1 - dy * nfile - 0.01;
0313     TLegend* leg = (ratio) ? (new TLegend(0.40, 0.86, 0.90, 0.90)) : (new TLegend(0.65, y2 - nfile * 0.04, 0.90, y2));
0314     leg->SetBorderSize(1);
0315     leg->SetFillColor(10);
0316     TH1D* hist0[nfile];
0317     for (int ifile = 0; ifile < nfile; ++ifile) {
0318       TDirectory* dir = (TDirectory*)file[ifile]->FindObjectAny(nameD);
0319       hist0[ifile] = static_cast<TH1D*>(dir->FindObjectAny(name));
0320       if (debug)
0321         std::cout << name << " read out at " << hist0[ifile] << " for " << tags[ifile] << std::endl;
0322     }
0323     char namec[160];
0324     if (!ratio) {
0325       sprintf(namec, "c_%s%s%s%s", geometry.c_str(), inType.c_str(), dirnm.c_str(), name);
0326       TCanvas* pad;
0327       int first(0);
0328       for (int ifile = 0; ifile < nfile; ++ifile) {
0329         TH1D* hist(hist0[ifile]);
0330         if (hist != nullptr) {
0331           if (rebin > 1)
0332             hist->Rebin(rebin);
0333           hist->SetTitle(title);
0334           hist->SetLineColor(first + 1);
0335           hist->SetLineStyle(first + 1);
0336           hist->GetYaxis()->SetTitleOffset(1.4);
0337           hist->GetXaxis()->SetRangeUser(0, xmax);
0338           hist->GetXaxis()->SetTitleSize(0.025);
0339           hist->GetXaxis()->SetTitleOffset(1.2);
0340           hist->SetMarkerStyle(first + 20);
0341           hist->SetMarkerColor(first + 1);
0342           hist->SetMarkerSize(0.7);
0343           if (first == 0) {
0344             pad = new TCanvas(namec, namec, 500, 500);
0345             pad->SetRightMargin(0.10);
0346             pad->SetTopMargin(0.10);
0347             pad->SetLogy();
0348             hist->Draw();
0349           } else {
0350             hist->Draw("sames");
0351           }
0352           leg->AddEntry(hist, tags[ifile].c_str(), "lp");
0353           pad->Update();
0354           ++first;
0355           TPaveStats* st = ((TPaveStats*)hist->GetListOfFunctions()->FindObject("stats"));
0356           if (st != NULL) {
0357             st->SetLineColor(first);
0358             st->SetTextColor(first);
0359             st->SetY1NDC(y1 - dy);
0360             st->SetY2NDC(y1);
0361             st->SetX1NDC(0.65);
0362             st->SetX2NDC(0.90);
0363             y1 -= dy;
0364           }
0365           pad->Modified();
0366           pad->Update();
0367           leg->Draw("same");
0368           pad->Update();
0369         }
0370         if (save) {
0371           sprintf(name, "%s.pdf", pad->GetName());
0372           pad->Print(name);
0373         }
0374       }
0375     } else if (nfile == 2) {
0376       sprintf(namec, "cR_%s%s%s%s", geometry.c_str(), inType.c_str(), dirnm.c_str(), name);
0377       TCanvas* pad = new TCanvas(namec, namec, 500, 500);
0378       int nbin = hist0[0]->GetNbinsX();
0379       int nbinR = nbin / rebin;
0380       double xlow = hist0[0]->GetXaxis()->GetBinLowEdge(1);
0381       double xhigh = xmax;
0382       TH1D* histr = new TH1D(name, hist0[0]->GetTitle(), nbinR, xlow, xhigh);
0383       histr->SetTitle(title);
0384       if (layer == 0)
0385         sprintf(name, "Number of hits (%s)", plotp[i].c_str());
0386       else
0387         sprintf(name, "Number of hits in Layer %d (%s)", layer, plotp[i].c_str());
0388       histr->GetXaxis()->SetTitle(name);
0389       sprintf(name, "Ratio (%s/%s)", tags[0].c_str(), tags[1].c_str());
0390       histr->GetYaxis()->SetTitle(name);
0391       histr->GetXaxis()->SetLabelOffset(0.005);
0392       histr->GetXaxis()->SetTitleOffset(1.30);
0393       histr->GetXaxis()->SetTitleSize(0.036);
0394       histr->GetYaxis()->SetLabelOffset(0.005);
0395       histr->GetYaxis()->SetTitleOffset(1.20);
0396       histr->GetYaxis()->SetTitleSize(0.036);
0397       histr->GetYaxis()->SetRangeUser(0.0, 5.0);
0398       histr->SetMarkerStyle(20);
0399       histr->SetMarkerColor(1);
0400       histr->SetMarkerSize(0.7);
0401       double sumNum(0), sumDen(0), maxDev(0);
0402       for (int j = 0; j < nbinR; ++j) {
0403         double tnum(0), tden(0), rnum(0), rden(0);
0404         for (int i = 0; i < rebin; ++i) {
0405           int ib = j * rebin + i + 1;
0406           tnum += hist0[0]->GetBinContent(ib);
0407           tden += hist0[1]->GetBinContent(ib);
0408           rnum += ((hist0[0]->GetBinError(ib)) * (hist0[0]->GetBinError(ib)));
0409           rden += ((hist0[1]->GetBinError(ib)) * (hist0[1]->GetBinError(ib)));
0410         }
0411         if (tden > 0 && tnum > 0) {
0412           double rat = tnum / tden;
0413           double err = rat * sqrt((rnum / (tnum * tnum)) + (rden / (tden * tden)));
0414           histr->SetBinContent(j + 1, rat);
0415           histr->SetBinError(j + 1, err);
0416           double temp1 = (rat > 1.0) ? 1.0 / rat : rat;
0417           double temp2 = (rat > 1.0) ? err / (rat * rat) : err;
0418           sumNum += (fabs(1 - temp1) / (temp2 * temp2));
0419           sumDen += (1.0 / (temp2 * temp2));
0420           if (fabs(1 - temp1) > maxDev)
0421             maxDev = fabs(1 - temp1);
0422         }
0423       }
0424       histr->Draw();
0425       if (layer == 0)
0426         sprintf(name, "%s %s", dirnm.c_str(), plotp[i].c_str());
0427       else
0428         sprintf(name, "%s (Layer %d) %s", dirnm.c_str(), layer, plotp[i].c_str());
0429       leg->AddEntry(histr, name, "lp");
0430       leg->Draw("same");
0431       pad->Update();
0432       TLine* line = new TLine(xlow, 1.0, xhigh, 1.0);
0433       line->SetLineColor(2);
0434       line->SetLineWidth(2);
0435       line->SetLineStyle(2);
0436       line->Draw("same");
0437       pad->Modified();
0438       pad->Update();
0439       sumNum = (sumDen > 0) ? (sumNum / sumDen) : 0;
0440       sumDen = (sumDen > 0) ? 1.0 / sqrt(sumDen) : 0;
0441       if (sumNum == 0)
0442         sumDen = 0;
0443       std::cout << tags[0] << " vs " << tags[1] << " " << hist0[0]->GetXaxis()->GetTitle() << " Mean deviation "
0444                 << sumNum << " +- " << sumDen << " maximum " << maxDev << std::endl;
0445       if (save) {
0446         sprintf(name, "%s.pdf", pad->GetName());
0447         pad->Print(name);
0448       }
0449     }
0450   }
0451 }
0452 
0453 void makeDigiStudyPlots(std::string tag = "HC", int todomin = 0, int todomax = 11, bool save = false) {
0454   const int nFiles = 3, ndetEC = 2, ndetHC = 3;
0455   std::string files[nFiles] = {
0456       "FullSimSignalwithFullSimPU", "FullSimSignalwithFastSimPU", "FastSimSignalwithFastSimPU"};
0457   std::string tags[nFiles] = {"Full+Full", "Ful+Fast", "Fast+Fast"};
0458   int color[nFiles] = {1, 2, 4};
0459   int lstyl[nFiles] = {1, 2, 4};
0460   std::string detsHC[ndetHC] = {"HB", "HE", "HF"};
0461   std::string detsEC[ndetEC] = {"Barrel", "Endcap"};
0462   std::string pretagEC = "EcalDigiTask";
0463   std::string pretagHC = "HcalDigiTask";
0464   const int plots = 16;
0465   std::string nameEC[plots] = {"ADC pulse 01 Gain 12",
0466                                "ADC pulse 02 Gain 12",
0467                                "ADC pulse 07 Gain 12",
0468                                "ADC pulse 04 Gain 12",
0469                                "ADC pulse 05 Gain 12",
0470                                "ADC pulse 06 Gain 12",
0471                                "ADC pulse 07 Gain 12",
0472                                "ADC pulse 08 Gain 12",
0473                                "analog pulse 01",
0474                                "analog pulse 02",
0475                                "analog pulse 03",
0476                                "analog pulse 04",
0477                                "analog pulse 05",
0478                                "analog pulse 06",
0479                                "analog pulse 07",
0480                                "analog pulse 08"};
0481   std::string nameHC[plots] = {"Ndigis",
0482                                "depths",
0483                                "post_SOI_frac",
0484                                "signal_amplitude",
0485                                "ADCO_adc_depth1",
0486                                "ADCO_adc_depth2",
0487                                "ADCO_adc_depth3",
0488                                "ADCO_adc_depth4",
0489                                "signal_amplitude_depth1",
0490                                "signal_amplitude_depth2",
0491                                "signal_amplitude_depth3",
0492                                "signal_amplitude_depth4",
0493                                "all_amplitudes_vs_bin_1D_depth1",
0494                                "all_amplitudes_vs_bin_1D_depth2",
0495                                "all_amplitudes_vs_bin_1D_depth3",
0496                                "all_amplitudes_vs_bin_1D_depth4"};
0497   int rebinEC[plots] = {10, 10, 10, 10, 10, 10, 10, 10, 2, 2, 2, 2, 2, 2, 2, 2};
0498   int rebinHC[plots] = {10, 1, 10, 10, 1, 1, 1, 1, 10, 10, 10, 10, 1, 1, 1, 1};
0499   double xlowEC[plots] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0500   double xlowHC[plots] = {3000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0501   double xhighEC[plots] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 50, 50, 50, 50, 50, 50, 50, 50};
0502   double xhighHC[plots] = {5000, 10, 2, 8000, 20, 20, 20, 20, 8000, 8000, 8000, 8000, 10, 10, 10, 10};
0503   bool debug(true);
0504 
0505   std::string dirnm = (tag == "EC") ? "ecalDigiStudy" : "hcalDigiStudy";
0506   gStyle->SetCanvasBorderMode(0);
0507   gStyle->SetCanvasColor(kWhite);
0508   gStyle->SetPadColor(kWhite);
0509   gStyle->SetFillColor(kWhite);
0510   gStyle->SetOptStat(1110);
0511   if ((todomin < 0) || (todomin >= plots))
0512     todomin = 0;
0513   if (todomax < todomin) {
0514     todomax = todomin;
0515   } else if (todomax >= plots) {
0516     todomax = plots - 1;
0517   }
0518   TFile* file[nFiles];
0519   char fname[100];
0520   int ok(0);
0521   for (int i = 0; i < nFiles; ++i) {
0522     sprintf(fname, "%s%s.root", tag.c_str(), files[i].c_str());
0523     file[i] = new TFile(fname);
0524     if (file[i]) {
0525       ++ok;
0526       std::cout << fname << " opened successfully" << std::endl;
0527     } else {
0528       std::cout << fname << " cannot be found" << std::endl;
0529     }
0530   }
0531   if (ok == nFiles) {
0532     int ndet = (tag == "EC") ? ndetEC : ndetHC;
0533     char name[100], namec[100];
0534     for (int i1 = todomin; i1 <= todomax; ++i1) {
0535       for (int i2 = 0; i2 < ndet; ++i2) {
0536         if (tag == "EC") {
0537           sprintf(name, "%s %s %s", pretagEC.c_str(), detsEC[i2].c_str(), nameEC[i1].c_str());
0538           sprintf(namec, "c_%s_%s_%s", pretagEC.c_str(), detsEC[i2].c_str(), nameEC[i1].c_str());
0539         } else {
0540           sprintf(name, "%s_%s_%s", pretagHC.c_str(), nameHC[i1].c_str(), detsHC[i2].c_str());
0541           sprintf(namec, "c_%s_%s_%s", pretagHC.c_str(), nameHC[i1].c_str(), detsHC[i2].c_str());
0542         }
0543         TH1D* hist0[nFiles];
0544         for (int i3 = 0; i3 < nFiles; ++i3) {
0545           TDirectory* dir = (TDirectory*)file[i3]->FindObjectAny(dirnm.c_str());
0546           hist0[i3] = static_cast<TH1D*>(dir->FindObjectAny(name));
0547           if (debug)
0548             std::cout << name << " read out at " << hist0[i3] << " for " << tags[i3] << std::endl;
0549         }
0550         TCanvas* pad = new TCanvas(namec, namec, 500, 500);
0551         int first(0);
0552         double y1(0.90), dy(0.12);
0553         double y2 = y1 - dy * nFiles - 0.01;
0554         TLegend* leg = new TLegend(0.65, y2 - nFiles * 0.04, 0.90, y2);
0555         for (int i3 = 0; i3 < nFiles; ++i3) {
0556           TH1D* hist(hist0[i3]);
0557           if (debug)
0558             std::cout << i3 << " Tag " << tags[i3] << " hiist " << hist << std::endl;
0559           if (hist != nullptr) {
0560             hist->SetLineColor(color[i3]);
0561             hist->SetLineStyle(lstyl[i3]);
0562             hist->GetYaxis()->SetTitleOffset(1.4);
0563             std::string title = hist->GetTitle();
0564             hist->GetXaxis()->SetTitle(title.c_str());
0565             hist->SetTitle("");
0566             if (tag == "EC") {
0567               if (rebinEC[i1] > 1)
0568                 hist->Rebin(rebinEC[i1]);
0569               hist->GetXaxis()->SetRangeUser(xlowEC[i1], xhighEC[i1]);
0570             } else {
0571               if (rebinHC[i1] > 1)
0572                 hist->Rebin(rebinHC[i1]);
0573               hist->GetXaxis()->SetRangeUser(xlowHC[i1], xhighHC[i1]);
0574             }
0575             if (first == 0) {
0576               pad = new TCanvas(namec, namec, 500, 500);
0577               pad->SetRightMargin(0.10);
0578               pad->SetTopMargin(0.10);
0579               /*
0580           if (tag == "EC") 
0581         pad->SetLogy();
0582           */
0583               hist->Draw();
0584             } else {
0585               hist->Draw("sames");
0586             }
0587             leg->AddEntry(hist, tags[i3].c_str(), "lp");
0588             pad->Update();
0589             ++first;
0590             TPaveStats* st = ((TPaveStats*)hist->GetListOfFunctions()->FindObject("stats"));
0591             if (st != NULL) {
0592               st->SetLineColor(color[i3]);
0593               st->SetTextColor(color[i3]);
0594               st->SetY1NDC(y1 - dy);
0595               st->SetY2NDC(y1);
0596               st->SetX1NDC(0.65);
0597               st->SetX2NDC(0.90);
0598               y1 -= dy;
0599             }
0600             pad->Modified();
0601             pad->Update();
0602             leg->Draw("same");
0603             pad->Update();
0604           }
0605         }
0606         if (save) {
0607           sprintf(name, "%s.pdf", pad->GetName());
0608           pad->Print(name);
0609         }
0610       }
0611     }
0612   }
0613 }