Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:30

0001 #include "TStyle.h"
0002 
0003 void plotCompare(char type[2]="HB", char hist[5]="h0", int bin1=2, int bin2=2,
0004          int logy=0, char header[20]="HCal Barrel", int save=0, 
0005          int mode=0, char vers1[20]="Current Release",
0006          char vers2[20]="Reference Version") {
0007 
0008   char file1[50], file2[50], title[100], fileps[50];
0009   sprintf (file1, "%s_new.root", type);
0010   sprintf (file2, "../data/%s_ref.root", type);
0011   // sprintf (file2, "orig/%s_new.root", type);
0012   sprintf (fileps, "%s%s.eps", type, hist);
0013   if (type == "HF") {
0014     switch (hist) {
0015     case "h0":   sprintf (title, "D(R) between Jet and its hits"); break;
0016     case "h1":   sprintf (title, "Time of hits in the Jets"); break;
0017     case "h2":   sprintf (title, "Energy of hits in the Jets"); break;
0018     case "h3":   sprintf (title, "Energy in ECal for the Jets"); break;
0019     case "h4":   sprintf (title, "Energy in HCal for the Jets"); break;
0020     case "h5":   sprintf (title, "Total energy   for the Jets"); break;
0021     case "h6":   sprintf (title, "Jet Energy"); break;
0022     case "h7":   sprintf (title, "Jet Eta"); break;
0023     case "h8":   sprintf (title, "Jet Phi"); break;
0024     case "h9":   sprintf (title, "Eta of hits"); break;          
0025     case "h10":  sprintf (title, "Phi of hits"); break;
0026     case "h11":  sprintf (title, "Energy of hits"); break;
0027     case "h12":  sprintf (title, "Time of hits"); break;
0028     case "h13":  sprintf (title, "Energy in Ecal"); break;
0029     case "h14":  sprintf (title, "Energy in Hcal"); break;
0030     case "h15":  sprintf (title, "Time of hits"); break;
0031     case "h16":  sprintf (title, "Time (energy weighted)"); break;
0032     case "h17":  sprintf (title, "Number of hits"); break;
0033     case "h18":  sprintf (title, "Energy in long fibre"); break;
0034     case "h19":  sprintf (title, "Energy in short fibre"); break;
0035     default:     sprintf (title, "Unknown"); break;
0036     }
0037   } else {
0038     switch (hist) {
0039     case "h0":   sprintf (title, "D(R) between Jet and its hits"); break;
0040     case "h1":   sprintf (title, "Time of hits in the Jets"); break;
0041     case "h2":   sprintf (title, "Energy of hits in the Jets"); break;
0042     case "h3":   sprintf (title, "Energy in ECal for the Jets"); break;
0043     case "h4":   sprintf (title, "Energy in HCal for the Jets"); break;
0044     case "h5":   sprintf (title, "Energy in HO   for the Jets"); break;
0045     case "h6":   sprintf (title, "Total energy   for the Jets"); break;
0046     case "h7":   sprintf (title, "D(eta) Jet"); break;
0047     case "h8":   sprintf (title, "D(phi) Jet"); break;
0048     case "h9":   sprintf (title, "D(r)   Jet"); break;
0049     case "h10":  sprintf (title, "Jet Energy"); break;
0050     case "h11":  sprintf (title, "Jet Eta"); break;
0051     case "h12":  sprintf (title, "Jet Phi"); break;
0052     case "h13":  sprintf (title, "Dijet Mass"); break;
0053     case "h14":  sprintf (title, "Energy in ECal NxN (DR Cone)"); break;
0054     case "h15":  sprintf (title, "Energy in HCal NxN (DR Cone)"); break;
0055     case "h16":  sprintf (title, "Energy in HO   NxN (DR Cone)"); break;
0056     case "h17":  sprintf (title, "Total energy   NxN (DR Cone)"); break;
0057     case "h18":  sprintf (title, "Energy in ECal NxN (eta/phi window)"); break;
0058     case "h19":  sprintf (title, "Energy in HCal NxN (eta/phi window)"); break;
0059     case "h20":  sprintf (title, "Energy in HO   NxN (eta/phi window)"); break;
0060     case "h21":  sprintf (title, "Total energy   NxN (eta/phi window)"); break;
0061     case "h22":  sprintf (title, "Layer number for hits"); break;
0062     case "h23":  sprintf (title, "Eta of hits"); break;          
0063     case "h24":  sprintf (title, "Phi of hits"); break;
0064     case "h25":  sprintf (title, "Energy of hits"); break;
0065     case "h26":  sprintf (title, "Time of hits"); break;
0066     case "h27":  sprintf (title, "ID of hits"); break;
0067     case "h28":  sprintf (title, "Jitter of hits"); break;
0068     case "h29":  sprintf (title, "Energy of hits in NxN"); break;
0069     case "h30":  sprintf (title, "Time   of hits in NxN"); break;
0070     case "h31":  sprintf (title, "Energy deposit in each layer"); break;
0071     case "h32":  sprintf (title, "Energy deposit in each depth"); break;
0072     case "h33":  sprintf (title, "Energy in HO"); break;
0073     case "h34":  sprintf (title, "Energy in HB/HE"); break;
0074     case "h35":  sprintf (title, "Energy in long HF fibre"); break;
0075     case "h36":  sprintf (title, "Energy in short HF fibre"); break;
0076     case "h37":  sprintf (title, "Energy in Ecal"); break;
0077     case "h38":  sprintf (title, "Energy in Hcal"); break;
0078     case "h39":  sprintf (title, "NxN trans fraction"); break; 
0079     case "h40":  sprintf (title, "Hit time 50ns"); break;   
0080     case "h41":  sprintf (title, "Hit time (energy weighted)"); break; 
0081     case "h42":  sprintf (title, "Number of hits in ECal"); break;
0082     case "h43":  sprintf (title, "Number of hits in HCal"); break;
0083     case "h44":  sprintf (title, "Number of hits"); break;
0084     case "h45":  sprintf (title, "Longitudinal Profile (E weighted)"); break;
0085     case "hl0":  sprintf (title, "Energy deposit in layer 0"); break; 
0086     case "hl1":  sprintf (title, "Energy deposit in layer 1"); break; 
0087     case "hl2":  sprintf (title, "Energy deposit in layer 2"); break; 
0088     case "hl3":  sprintf (title, "Energy deposit in layer 3"); break; 
0089     case "hl4":  sprintf (title, "Energy deposit in layer 4"); break; 
0090     case "hl5":  sprintf (title, "Energy deposit in layer 5"); break; 
0091     case "hl6":  sprintf (title, "Energy deposit in layer 6"); break; 
0092     case "hl7":  sprintf (title, "Energy deposit in layer 7"); break; 
0093     case "hl8":  sprintf (title, "Energy deposit in layer 8"); break; 
0094     case "hl9":  sprintf (title, "Energy deposit in layer 9"); break; 
0095     case "hl10": sprintf (title, "Energy deposit in layer 10"); break; 
0096     case "hl11": sprintf (title, "Energy deposit in layer 11"); break; 
0097     case "hl12": sprintf (title, "Energy deposit in layer 12"); break; 
0098     case "hl13": sprintf (title, "Energy deposit in layer 13"); break; 
0099     case "hl14": sprintf (title, "Energy deposit in layer 14"); break; 
0100     case "hl15": sprintf (title, "Energy deposit in layer 15"); break; 
0101     case "hl16": sprintf (title, "Energy deposit in layer 16"); break; 
0102     case "hl17": sprintf (title, "Energy deposit in layer 17"); break; 
0103     case "hl18": sprintf (title, "Energy deposit in layer 18"); break; 
0104     case "hl19": sprintf (title, "Energy deposit in layer 19"); break; 
0105     default:     sprintf (title, "Unknown"); break;
0106     }
0107   }
0108 
0109   cout << "New: " << file1 << " and Ref: " << file2 << " Title: " << title 
0110        << "\n";
0111 
0112   setTDRStyle();
0113 
0114   TFile *File1 = new TFile(file1);
0115   TH1F* new_hist = (TH1F*) File1->Get(hist) ;
0116 
0117   TFile *File2 = new TFile(file2);
0118   TH1F* ref_hist = (TH1F*) File2->Get(hist) ;
0119 
0120   TCanvas *myc = new TCanvas("myc","",800,600);
0121 
0122   new_hist->SetLineStyle(1);
0123   new_hist->SetLineWidth(3);
0124   new_hist->SetLineColor(2);
0125   new_hist->Rebin(bin1);
0126   new_hist->GetXaxis()->SetTitle(title);
0127   //  new_hist->GetYaxis()->SetTitle("Frequency");
0128   if (logy > 0) gPad->SetLogy(1);
0129 
0130   ref_hist->SetLineStyle(2);
0131   ref_hist->SetLineWidth(3);
0132   ref_hist->SetLineColor(4);
0133   ref_hist->Rebin(bin2);
0134   if (mode <= 1) {
0135     new_hist->Draw("HIST");
0136     ref_hist->Draw("HIST same");
0137   } else {
0138     ref_hist->Draw("HIST");
0139     new_hist->Draw("HIST same");
0140   }
0141 
0142   leg1 = new TLegend(0.55,0.15,0.85,0.25);
0143   leg1->AddEntry(new_hist,vers1,"F");
0144   leg1->AddEntry(ref_hist,vers2,"F");
0145   leg1->SetHeader(header);
0146   leg1->Draw();
0147 
0148   if (save > 0) myc->SaveAs(fileps);
0149 
0150   return;
0151 }
0152 
0153 void setTDRStyle() {
0154   TStyle *tdrStyle = new TStyle("tdrStyle","Style for P-TDR");
0155 
0156 // For the canvas:
0157   tdrStyle->SetCanvasBorderMode(0);
0158   tdrStyle->SetCanvasColor(kWhite);
0159   tdrStyle->SetCanvasDefH(600); //Height of canvas
0160   tdrStyle->SetCanvasDefW(600); //Width of canvas
0161   tdrStyle->SetCanvasDefX(0);   //POsition on screen
0162   tdrStyle->SetCanvasDefY(0);
0163 
0164 // For the Pad:
0165   tdrStyle->SetPadBorderMode(0);
0166   // tdrStyle->SetPadBorderSize(Width_t size = 1);
0167   tdrStyle->SetPadColor(kWhite);
0168   tdrStyle->SetPadGridX(false);
0169   tdrStyle->SetPadGridY(false);
0170   tdrStyle->SetGridColor(0);
0171   tdrStyle->SetGridStyle(3);
0172   tdrStyle->SetGridWidth(1);
0173 
0174 // For the frame:
0175   tdrStyle->SetFrameBorderMode(0);
0176   tdrStyle->SetFrameBorderSize(1);
0177   tdrStyle->SetFrameFillColor(0);
0178   tdrStyle->SetFrameFillStyle(0);
0179   tdrStyle->SetFrameLineColor(1);
0180   tdrStyle->SetFrameLineStyle(1);
0181   tdrStyle->SetFrameLineWidth(1);
0182 
0183 
0184 //For the date:
0185   tdrStyle->SetOptDate(0);
0186   // tdrStyle->SetDateX(Float_t x = 0.01);
0187   // tdrStyle->SetDateY(Float_t y = 0.01);
0188 
0189 // For the statistics box:
0190   tdrStyle->SetOptFile(0);
0191   tdrStyle->SetOptStat(0); // To display the mean and RMS:   SetOptStat("mr");
0192 
0193 // For the Global title:
0194 
0195   tdrStyle->SetOptTitle(0);
0196   tdrStyle->SetTitleFont(42);
0197   tdrStyle->SetTitleColor(1);
0198   tdrStyle->SetTitleTextColor(1);
0199   tdrStyle->SetTitleFillColor(10);
0200   tdrStyle->SetTitleFontSize(0.05);
0201 
0202 // For the axis titles:
0203 
0204   tdrStyle->SetTitleColor(1, "XYZ");
0205   tdrStyle->SetTitleFont(42, "XYZ");
0206   tdrStyle->SetTitleSize(0.06, "XYZ");
0207   // tdrStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
0208   // tdrStyle->SetTitleYSize(Float_t size = 0.02);
0209   tdrStyle->SetTitleXOffset(0.7);
0210   tdrStyle->SetTitleYOffset(0.7);
0211   // tdrStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
0212 
0213 // For the axis labels:
0214 
0215   tdrStyle->SetLabelColor(1, "XYZ");
0216   tdrStyle->SetLabelFont(42, "XYZ");
0217   tdrStyle->SetLabelOffset(0.007, "XYZ");
0218   tdrStyle->SetLabelSize(0.03, "XYZ");
0219 
0220 // For the axis:
0221 
0222   tdrStyle->SetAxisColor(1, "XYZ");
0223   tdrStyle->SetStripDecimals(kTRUE);
0224   tdrStyle->SetTickLength(0.03, "XYZ");
0225   tdrStyle->SetNdivisions(510, "XYZ");
0226   tdrStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0227   tdrStyle->SetPadTickY(1);
0228 
0229   tdrStyle->cd();
0230 
0231 }