File indexing completed on 2024-07-22 23:31:30
0001 #include <TROOT.h>
0002 #include <TChain.h>
0003 #include <TFile.h>
0004 #include <TH1D.h>
0005 #include <TH2D.h>
0006 #include <TProfile.h>
0007 #include <TProfile2D.h>
0008 #include <TFitResult.h>
0009 #include <TFitResultPtr.h>
0010 #include <TStyle.h>
0011 #include <TCanvas.h>
0012 #include <TLegend.h>
0013 #include <TPaveStats.h>
0014 #include <TPaveText.h>
0015 #include <vector>
0016 #include <string>
0017 #include <iomanip>
0018 #include <iostream>
0019 #include <fstream>
0020
0021 void makePlotsCalib(std::string fname = "RelValDoubleEle200PU.root",
0022 std::string tag = "All",
0023 std::string text = "Double Electron",
0024 std::string dirnm = "hgcalHitCalibration",
0025 bool save = false) {
0026 std::string names[4] = {"h_EoP_CPene_100_calib_fraction_",
0027 "h_EoP_CPene_200_calib_fraction_",
0028 "h_EoP_CPene_300_calib_fraction_",
0029 "h_LayerOccupancy_"};
0030 std::string xname[4] = {"in 100#mum Silicon", "in 200#mum Silicon", "in 300#mum Silicon", "Occupancy"};
0031 std::string xtitl[4] = {"E/E_{True}", "E/E_{True}", "E/E_{True}", "Layer #"};
0032 std::string ytitl[4] = {"Clusters", "Clusters", "Clusters", "Clusters"};
0033 int type1[4] = {0, 0, 0, 0};
0034 int type2[4] = {5, 5, 5, 1};
0035
0036 gStyle->SetCanvasBorderMode(0);
0037 gStyle->SetCanvasColor(kWhite);
0038 gStyle->SetPadColor(kWhite);
0039 gStyle->SetFillColor(kWhite);
0040 gStyle->SetOptStat(111110);
0041 TFile *file = new TFile(fname.c_str());
0042 if (file) {
0043 TDirectory *dir = (TDirectory *)file->FindObjectAny(dirnm.c_str());
0044 if (dir) {
0045 char name[100];
0046 for (int k = 0; k < 4; ++k) {
0047 sprintf(name, "%s%s", names[k].c_str(), tag.c_str());
0048 TH1D *hist = (TH1D *)dir->FindObjectAny(name);
0049 std::cout << name << " read out at " << hist << std::endl;
0050 if (hist != 0) {
0051 TCanvas *pad = new TCanvas(name, name, 500, 500);
0052 pad->SetRightMargin(0.10);
0053 pad->SetTopMargin(0.10);
0054 hist->GetYaxis()->SetTitle(ytitl[k].c_str());
0055 hist->GetXaxis()->SetTitle(xtitl[k].c_str());
0056 hist->SetTitle("");
0057 hist->Rebin(type2[k]);
0058 hist->GetYaxis()->SetTitleOffset(1.5);
0059 if (type1[k] == 1)
0060 pad->SetLogy();
0061 hist->Draw();
0062 pad->Update();
0063 TPaveStats *st1 = (TPaveStats *)hist->GetListOfFunctions()->FindObject("stats");
0064 if (st1 != NULL) {
0065 st1->SetY1NDC(0.70);
0066 st1->SetY2NDC(0.90);
0067 st1->SetX1NDC(0.65);
0068 st1->SetX2NDC(0.90);
0069 }
0070 TPaveText *txt1 = new TPaveText(0.11, 0.84, 0.64, 0.89, "blNDC");
0071 txt1->SetFillColor(0);
0072 char txt[200];
0073 sprintf(txt, "%s %s (%s)", tag.c_str(), xname[k].c_str(), text.c_str());
0074 txt1->AddText(txt);
0075 txt1->Draw("same");
0076 pad->Modified();
0077 pad->Update();
0078 if (save) {
0079 sprintf(name, "c_%s%s.gif", names[k].c_str(), tag.c_str());
0080 pad->Print(name);
0081 }
0082 }
0083 }
0084 }
0085 }
0086 }