Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "TH1.h"
0002 #include "TH2.h"
0003 #include "TLegend.h"
0004 #include "TCanvas.h"
0005 #include "TProfile.h"
0006 #include "TPaveStats.h"
0007 #include "TFile.h"
0008 #include "TString.h"
0009 #include "TList.h"
0010 #include "TStyle.h"
0011 #include "TClass.h"
0012 #include "TKey.h"
0013 #include "TDirectory.h"
0014 
0015 #include <cstdio>
0016 #include <string>
0017 #include <iostream>
0018 
0019 
0020 void PlotHGChitCalibration(const TString valfile, const TString reffile, std::string val_ver, std::string ref_ver) {
0021 
0022   TFile *f1 = new TFile(valfile);
0023   TFile *f2 = new TFile(reffile);
0024 
0025   //1D Histos
0026   const int type = 4;
0027   const int part = 6;
0028   const int NHist = type*part;
0029   std::string particle[part] = {"All", "Electron", "Muon", "Photon", "ChgHad",
0030                 "NeutHad"};
0031   std::string xtitl[type] = {"E/E_{True}", "E/E_{True}", "E/E_{True}",
0032                  "Layer #"};
0033   std::string ytitl[type] = {"Clusters", "Clusters", "Clusters", "Clusters"}; 
0034   std::string xname[type] = {"in 100#mum Silicon", "in 200#mum Silicon",
0035                  "in 300#mum Silicon", "Occupancy"};
0036   TH1* f1_hist[NHist];
0037   TH1* f2_hist[NHist];
0038   char name[64];
0039   std::vector<std::string>label;
0040   for (int i=0; i<part; ++i) {
0041     sprintf(name, "h_EoP_CPene_100_calib_fraction_%s",particle[i].c_str());
0042     label.push_back(name);
0043     sprintf(name,"h_EoP_CPene_200_calib_fraction_%s",particle[i].c_str());
0044     label.push_back(name);
0045     sprintf(name,"h_EoP_CPene_300_calib_fraction_%s",particle[i].c_str());
0046     label.push_back(name);
0047     sprintf(name,"h_LayerOccupancy_%s",particle[i].c_str());
0048     label.push_back(name);
0049   }
0050   for (int i=0; i<NHist; ++i) {
0051     int it = (i%type);
0052     int ip = (i - it)/type;
0053     sprintf(name, "hgcalHitCalibration/%s",label[i].c_str());
0054     
0055     //getting hist
0056     f1_hist[i] = (TH1*)f1->Get(name);
0057     f2_hist[i] = (TH1*)f2->Get(name);
0058 
0059     sprintf(name, "%s",label[i].c_str());
0060 
0061     //Drawing
0062     TCanvas *myc = new TCanvas("myc","",800,600);
0063     gStyle->SetOptStat(1111);
0064 
0065     f1_hist[i]->SetStats(kTRUE);   // stat box  
0066     f2_hist[i]->SetStats(kTRUE);  
0067 
0068     char txt[200];
0069     sprintf (txt, "%s %s",particle[ip].c_str(),xname[it].c_str());
0070     f1_hist[i]->SetTitle(txt);
0071     f2_hist[i]->SetTitle(txt);
0072      
0073     f1_hist[i]->SetLineWidth(2); 
0074     f2_hist[i]->SetLineWidth(2); 
0075      
0076     // diffferent histo colors and styles
0077     f1_hist[i]->SetLineColor(4);
0078     f1_hist[i]->SetLineStyle(1); 
0079     f1_hist[i]->GetYaxis()->SetTitle(ytitl[it].c_str());
0080     f1_hist[i]->GetXaxis()->SetTitle(xtitl[it].c_str());
0081      
0082     f2_hist[i]->SetLineColor(1);
0083     f2_hist[i]->SetLineStyle(2);  
0084     f2_hist[i]->GetYaxis()->SetTitle(ytitl[it].c_str());
0085     f2_hist[i]->GetXaxis()->SetTitle(xtitl[it].c_str());
0086 
0087     //Set maximum to the larger of the two
0088     if (f1_hist[i]->GetMaximum() < f2_hist[i]->GetMaximum()) f1_hist[i]->SetMaximum(1.05 * f2_hist[i]->GetMaximum());
0089 
0090     TLegend *leg = new TLegend(0.0, 0.91, 0.3, 0.99, "","brNDC");
0091 
0092     leg->SetBorderSize(2);
0093     //  leg->SetFillColor(51); 
0094     leg->SetFillStyle(1001); //
0095     leg->AddEntry(f1_hist[i],("CMSSW_"+val_ver).c_str(),"l");
0096     leg->AddEntry(f2_hist[i],("CMSSW_"+ref_ver).c_str(),"l"); 
0097 
0098     TPaveStats *ptstats = new TPaveStats(0.85,0.86,0.98,0.98,"brNDC");
0099     ptstats->SetTextColor(4);
0100     f1_hist[i]->GetListOfFunctions()->Add(ptstats);
0101     ptstats->SetParent(f1_hist[i]->GetListOfFunctions());
0102     TPaveStats *ptstats2 = new TPaveStats(0.85,0.74,0.98,0.86,"brNDC");
0103     ptstats2->SetTextColor(1);
0104     f2_hist[i]->GetListOfFunctions()->Add(ptstats2);
0105     ptstats2->SetParent(f2_hist[i]->GetListOfFunctions());
0106          
0107     f1_hist[i]->Draw(""); // "stat"   
0108     f2_hist[i]->Draw("histsames");   
0109      
0110     leg->Draw();   
0111     
0112     myc->SaveAs((std::string(name)+".png").c_str());
0113     if(myc) delete myc;
0114 
0115   }
0116 }