Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:43

0001 #include <TFile.h>
0002 #include <TH1D.h>
0003 #include <TH1I.h>
0004 #include <TStyle.h>
0005 #include <TCanvas.h>
0006 #include <TLegend.h>
0007 #include <TPaveStats.h>
0008 #include <TPaveText.h>
0009 #include <vector>
0010 #include <string>
0011 #include <iomanip>
0012 #include <iostream>
0013 #include <fstream>
0014 #include <cstdlib>
0015 
0016 void PlotCollapse(const char* infile, std::string text, int tag=311,
0017           bool drawStatBox=true, bool save=false) {
0018   std::string name[6] = {"h_merge","h_size","h_depth","h_sfrac","h_frac",
0019              "h_balance"};
0020   int         type[6] = {0,0,0,0,1,1};       
0021   std::string xtitl[6]= {"Merged Hits", "Size of RecHit Collections",
0022              "Depth in DetId", 
0023              "Ratio of collection sizes #frac{RecHit}{PreRecHit}",
0024              "Energy fraction of collapsed hits",
0025              "Energy balance between pre- and post-collapse"};
0026   std::string ytitl[6]= {"Hits","Events","Hits","Events","Hits","Hits"};
0027 
0028   gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
0029   gStyle->SetPadColor(kWhite);    gStyle->SetFillColor(kWhite);
0030   gStyle->SetOptTitle(0);
0031   if (drawStatBox) {
0032     gStyle->SetOptStat(111110);  gStyle->SetOptFit(1);
0033   } else {
0034     gStyle->SetOptStat(0);       gStyle->SetOptFit(0);
0035   }
0036 
0037   TFile      *file = new TFile(infile);
0038   if (file) {
0039     for (unsigned int k=0; k<6; ++k) {
0040       TH1D* hist = (TH1D*)file->FindObjectAny(name[k].c_str());
0041       if (hist) {
0042     char namep[100];
0043     sprintf (namep, "c%s%d", name[k].c_str(), tag);
0044     TCanvas *pad = new TCanvas(namep, namep, 700, 500);
0045     pad->SetRightMargin(0.10);
0046     pad->SetTopMargin(0.10);
0047     if (type[k] == 1) pad->SetLogy();
0048     hist->GetXaxis()->SetTitleSize(0.04);
0049     hist->GetXaxis()->SetTitle(xtitl[k].c_str());
0050     hist->GetYaxis()->SetTitle(ytitl[k].c_str());
0051     hist->GetYaxis()->SetLabelOffset(0.005);
0052     hist->GetYaxis()->SetTitleSize(0.04);
0053     hist->GetYaxis()->SetLabelSize(0.035);
0054     hist->GetYaxis()->SetTitleOffset(1.10);
0055     hist->SetMarkerStyle(20);
0056     hist->SetMarkerColor(2);
0057     hist->SetLineColor(2);
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.25,0.91,0.90,0.96,"blNDC");
0066     txt1->SetFillColor(0);
0067     txt1->AddText(text.c_str());
0068     txt1->Draw("same");
0069     pad->Modified();
0070     pad->Update();
0071     if (save) {
0072       sprintf (namep, "%s.pdf", pad->GetName());
0073       pad->Print(namep);
0074     }
0075       }
0076     }
0077   }
0078 }