Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:33:02

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 
0022 void makePlotsCalib(std::string fname="RelValDoubleEle200PU.root",
0023             std::string tag="All",
0024             std::string text="Double Electron",
0025             std::string dirnm="hgcalHitCalibration", 
0026             bool save=false) {
0027   std::string names[4] = {"h_EoP_CPene_100_calib_fraction_",
0028               "h_EoP_CPene_200_calib_fraction_",
0029               "h_EoP_CPene_300_calib_fraction_",
0030               "h_LayerOccupancy_"};
0031   std::string xname[4] = {"in 100#mum Silicon", "in 200#mum Silicon",
0032               "in 300#mum Silicon", "Occupancy"};
0033   std::string xtitl[4] = {"E/E_{True}", "E/E_{True}", "E/E_{True}", "Layer #"};
0034   std::string ytitl[4] = {"Clusters", "Clusters", "Clusters", "Clusters"}; 
0035   int         type1[4] = {0,0,0,0};
0036   int         type2[4] = {5,5,5,1};
0037 
0038   gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0039   gStyle->SetPadColor(kWhite);    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); pad->SetTopMargin(0.10);
0053           hist->GetYaxis()->SetTitle(ytitl[k].c_str());
0054           hist->GetXaxis()->SetTitle(xtitl[k].c_str());
0055       hist->SetTitle(""); hist->Rebin(type2[k]);
0056       hist->GetYaxis()->SetTitleOffset(1.5);
0057       if (type1[k] == 1) pad->SetLogy();
0058       hist->Draw();
0059       pad->Update();
0060       TPaveStats* st1 = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats");
0061       if (st1 != NULL) {
0062         st1->SetY1NDC(0.70); st1->SetY2NDC(0.90);
0063         st1->SetX1NDC(0.65); st1->SetX2NDC(0.90);
0064       }
0065       TPaveText *txt1 = new TPaveText(0.11,0.84,0.64,0.89,"blNDC");
0066       txt1->SetFillColor(0);
0067       char txt[200];
0068       sprintf (txt, "%s %s (%s)",tag.c_str(),xname[k].c_str(),text.c_str());
0069       txt1->AddText(txt);
0070       txt1->Draw("same");
0071       pad->Modified();
0072       pad->Update();
0073       if (save) {
0074         sprintf (name, "c_%s%s.gif", names[k].c_str(), tag.c_str());
0075         pad->Print(name);
0076       }
0077     }
0078       }
0079     }
0080   }
0081 }