Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:11

0001 #include <string>
0002 
0003 void plotMerge(char name[6]="Hits0", char rootfile[6]="ecHit", int files=5,
0004            int bin=1, bool logy=true, bool doprob=false, bool debug=false){
0005 
0006   char fname[20];
0007   sprintf (fname, "%s_1.root", rootfile);
0008   setTDRStyle();
0009   TFile *file = TFile::Open(fname);
0010   TDirectory *d1 = (TDirectory*)file->Get("analyzer");
0011   TH1F *h1 = (TH1F*)d1->Get(name);
0012   TH1F *hist(h1);
0013   std::cout << "Entries at loop 1: " << hist->GetEntries() << "\n";
0014 
0015   for (int i=2; i<=files; i++) {
0016     sprintf (fname, "%s_%d.root", rootfile, i); 
0017     TFile *file2 = TFile::Open(fname);
0018     TDirectory *d2 = (TDirectory*)file2->Get("analyzer");
0019     TH1F *h2 = (TH1F*)d2->Get(name);
0020     hist->Add(h2);
0021     if (debug) std::cout << "Entries at loop " << i << ": " << hist->GetEntries() << "\n";
0022     file2->Close();
0023   }
0024   TCanvas *myc = new TCanvas("name","",800,600);
0025   if (logy) gPad->SetLogy(1);
0026   hist->GetYaxis()->SetTitle("Events");
0027   hist->Rebin(bin);
0028   hist->Draw();
0029 
0030   if (doprob) {
0031     int    nbin = hist->GetXaxis()->GetNbins();
0032     double xmin = hist->GetXaxis()->GetXmin();
0033     double xmax = hist->GetXaxis()->GetXmax();
0034     double entry= hist->GetEntries();
0035     double scale= 1.0;
0036     if (entry > 0) scale = 1./entry;
0037     char title[60];
0038     std::string names(name), namx;
0039     namx.assign(names,0,4);
0040     char namx0[6];
0041     sprintf (namx0, "%s", namx.c_str());
0042     cout << name << " " << names << " " << namx << " " << namx0 << "\n";
0043     if      (namx == "E1T0") sprintf (title, "E1 (GeV)");
0044     else if (namx == "E1T1") sprintf (title, "E1 (GeV) (t < 400 ns)");
0045     else if (namx == "E9T0") sprintf (title, "E9 (GeV)");
0046     else if (namx == "E9T1") sprintf (title, "E9 (GeV) (t < 400 ns)");
0047     else                     sprintf (title, "Unknown X");
0048     TH1F *h0 = new TH1F("Prob", title, nbin, xmin, xmax);
0049     h0->GetXaxis()->SetTitle(title);
0050     h0->GetYaxis()->SetTitle("Probability");
0051     double sum = 0;
0052     for (int i=1; i<=nbin; i++) {
0053       double xb = hist->GetBinContent(i);
0054       sum += xb;
0055       double yb = (1.-scale*sum);
0056       double xc = ((i-0.5)*xmax+(nbin-i+0.5)*xmin)/((double)(nbin));
0057       h0->SetBinContent(i,yb);
0058       std::cout << i << " x " << xc << " prob " << yb << "\n";
0059     }
0060     myc = new TCanvas("Prob","",800,600);
0061     if (logy) gPad->SetLogy(1);
0062     h0->Draw();
0063   }
0064 }
0065 
0066 void setTDRStyle() {
0067   TStyle *tdrStyle = new TStyle("tdrStyle","Style for P-TDR");
0068 
0069 // For the canvas:
0070   tdrStyle->SetCanvasBorderMode(0);
0071   tdrStyle->SetCanvasColor(kWhite);
0072   tdrStyle->SetCanvasDefH(600); //Height of canvas
0073   tdrStyle->SetCanvasDefW(600); //Width of canvas
0074   tdrStyle->SetCanvasDefX(0);   //POsition on screen
0075   tdrStyle->SetCanvasDefY(0);
0076 
0077 // For the Pad:
0078   tdrStyle->SetPadBorderMode(0);
0079   tdrStyle->SetPadColor(kWhite);
0080   tdrStyle->SetPadGridX(false);
0081   tdrStyle->SetPadGridY(false);
0082   tdrStyle->SetGridColor(0);
0083   tdrStyle->SetGridStyle(3);
0084   tdrStyle->SetGridWidth(1);
0085 
0086 // For the frame:
0087   tdrStyle->SetFrameBorderMode(0);
0088   tdrStyle->SetFrameBorderSize(1);
0089   tdrStyle->SetFrameFillColor(0);
0090   tdrStyle->SetFrameFillStyle(0);
0091   tdrStyle->SetFrameLineColor(1);
0092   tdrStyle->SetFrameLineStyle(1);
0093   tdrStyle->SetFrameLineWidth(1);
0094 
0095 //For the date:
0096   tdrStyle->SetOptDate(0);
0097 
0098 // For the statistics box:
0099   tdrStyle->SetOptStat(1111111);
0100 
0101 // For the Global title:
0102 
0103   tdrStyle->SetOptTitle(0);
0104   tdrStyle->SetTitleFont(42);
0105   tdrStyle->SetTitleColor(1);
0106   tdrStyle->SetTitleTextColor(1);
0107   tdrStyle->SetTitleFillColor(10);
0108   tdrStyle->SetTitleFontSize(0.05);
0109 
0110 // For the axis titles:
0111 
0112   tdrStyle->SetTitleColor(1, "XYZ");
0113   tdrStyle->SetTitleFont(42, "XYZ");
0114   tdrStyle->SetTitleSize(0.04, "XYZ");
0115   tdrStyle->SetTitleXOffset(0.8);
0116   tdrStyle->SetTitleYOffset(0.8);
0117 
0118 // For the axis labels:
0119 
0120   tdrStyle->SetLabelColor(1, "XYZ");
0121   tdrStyle->SetLabelFont(42, "XYZ");
0122   tdrStyle->SetLabelOffset(0.007, "XYZ");
0123   tdrStyle->SetLabelSize(0.03, "XYZ");
0124 
0125 // For the axis:
0126 
0127   tdrStyle->SetAxisColor(1, "XYZ");
0128   tdrStyle->SetStripDecimals(kTRUE);
0129   tdrStyle->SetTickLength(0.03, "XYZ");
0130   tdrStyle->SetNdivisions(510, "XYZ");
0131   tdrStyle->SetPadTickX(1); 
0132   tdrStyle->SetPadTickY(1);
0133 
0134   tdrStyle->cd();
0135 
0136 }