File indexing completed on 2024-04-06 12:30:26
0001 #include "TStyle.h"
0002
0003 void plot(char type[10]="TTBar", char hist0[2]="C", int bin=5, int mode=0,
0004 double xmax=-1., double ymax=-1., char fileps[40]="") {
0005
0006 char file[60], hist[30], codes[6], code;
0007
0008 sprintf (codes, "786519");
0009 sprintf (file, "fieldStudy%s.root", type);
0010 TFile* File = new TFile(file);
0011
0012 int nhist=6;
0013 if (mode==1) nhist=3;
0014 else if (mode==2) nhist=6;
0015
0016 TCanvas *myc = new TCanvas("myc","",800,600);
0017
0018 TH1F* hi[6];
0019 gPad->SetLogy(1);
0020
0021 for (int ih=0; ih<nhist; ih++) {
0022 if (mode == 1) {
0023 if (ih==1) sprintf (hist, "DQMData/StepC%s", hist0);
0024 else if (ih==2) sprintf (hist, "DQMData/StepN%s", hist0);
0025 else sprintf (hist, "DQMData/Step%s", hist0);
0026 } else if (mode == 2) {
0027 if (ih==1) sprintf (hist, "DQMData/StepE%s", hist0);
0028 else if (ih==2) sprintf (hist, "DQMData/StepG%s", hist0);
0029 else if (ih==3) sprintf (hist, "DQMData/StepCH%s", hist0);
0030 else if (ih==4) sprintf (hist, "DQMData/StepNH%s", hist0);
0031 else if (ih==5) sprintf (hist, "DQMData/StepMu%s", hist0);
0032 else sprintf (hist, "DQMData/Step%s", hist0);
0033 } else if (mode == 3) {
0034 code = codes[ih];
0035 sprintf (hist, "DQMData/Step%s%s", hist0, code);
0036 } else {
0037 code = codes[ih];
0038 sprintf (hist, "DQMData/Step%s", code);
0039 }
0040 hi[ih] = (TH1F*) File->Get(hist);
0041 hi[ih]->Rebin(bin);
0042 hi[ih]->SetLineStyle(ih+1);
0043 hi[ih]->SetLineWidth(2);
0044 hi[ih]->SetLineColor(ih+1);
0045 if (xmax > 0) hi[ih]->GetXaxis()->SetRangeUser(0.,xmax);
0046 if (ymax > 0) hi[ih]->SetMaximum(ymax);
0047 if (ih == 0) {
0048 hi[ih]->GetXaxis()->SetTitle("Step Size (mm)");
0049 hi[ih]->Draw("HIST");
0050 } else
0051 hi[ih]->Draw("HIST same");
0052 }
0053
0054 TLegend* leg = new TLegend(0.55,0.70,0.90,0.90);
0055 char det[20], header[30];
0056 if (hist0 == codes[1]) sprintf (det, "Tracker");
0057 else if (hist0 == codes[2]) sprintf (det, "Muon");
0058 else if (hist0 == codes[3]) sprintf (det, "BeamPipe");
0059 else if (hist0 == codes[4]) sprintf (det, "Forward");
0060 else if (hist0 == codes[5]) sprintf (det, "Others");
0061 else if (hist0 == codes[0]) sprintf (det, "Calo");
0062 else if (hist0 == "C") sprintf (det, "Charged");
0063 else if (hist0 == "N") sprintf (det, "Neutral");
0064 else if (hist0 == "E") sprintf (det, "Electron");
0065 else if (hist0 == "G") sprintf (det, "Photon");
0066 else if (hist0 == "CH") sprintf (det, "Charged Hadron");
0067 else if (hist0 == "NH") sprintf (det, "Neutral Hadron");
0068 else if (hist0 == "Mu") sprintf (det, "Muon");
0069 else if (hist0 == "0") sprintf (det, "All Volumes");
0070 else sprintf (det, "Unknown");
0071 if (mode > 0 && mode <= 3) sprintf (header, "%s Sample (%s)", type, det);
0072 else sprintf (header, "%s Sample", type);
0073 leg->SetHeader(header);
0074 for (int ih=0; ih<nhist; ih++) {
0075 if (mode == 1) {
0076 if (ih==1) sprintf (hist, "Charged");
0077 else if (ih==2) sprintf (hist, "Neutral");
0078 else sprintf (hist, "All");
0079 } else if (mode == 2) {
0080 if (ih==1) sprintf (hist, "Electron");
0081 else if (ih==2) sprintf (hist, "Photon");
0082 else if (ih==3) sprintf (hist, "Charged Hadron");
0083 else if (ih==4) sprintf (hist, "Neutral Hadron");
0084 else if (ih==5) sprintf (hist, "Muon");
0085 else sprintf (hist, "All");
0086 } else {
0087 if (ih==1) sprintf (hist, "Tracker");
0088 else if (ih==2) sprintf (hist, "Muon");
0089 else if (ih==3) sprintf (hist, "BeamPipe");
0090 else if (ih==4) sprintf (hist, "Forward");
0091 else if (ih==5) sprintf (hist, "Other");
0092 else sprintf (hist, "Calo");
0093 }
0094 leg->AddEntry(hi[ih],hist,"F");
0095 }
0096 leg->Draw();
0097
0098 if (fileps != "") myc->SaveAs(fileps);
0099 return;
0100 }