Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 void gctAnalyzerMergePlotter2()
0002 {
0003 
0004   //set the style
0005   setStyle();
0006 
0007   //Create the file you want to write the output canvasses to
0008   TFile *output = new TFile("SUSY_pattern_results_rawgctAnalyzer.root", "RECREATE");
0009 
0010   //Open the file
0011   TFile *input = new TFile("raw_gctAnalyzer.root");
0012 
0013   //Canvas
0014   //TCanvas *c1 = new TCanvas("c1","c1",800,700);
0015 
0016   //Set the output folder
0017   TString outfolder = "/afs/cern.ch/user/j/jad/scratch0/SUSY_pattern_results010410/";
0018   TString basedata = "gctErrorAnalyzer/DataHistograms/";
0019   TString baseemu = "gctErrorAnalyzer/EmulatorHistograms/";
0020   TString baseerrorhist = "gctErrorAnalyzer/ErrorHistograms_Flags/";
0021   TString isoem = "IsoEm/";
0022   TString nisoem = "NonIsoEM/";
0023   TString cenjet = "CenJets/";
0024   TString taujet = "TauJets/";
0025   TString forjet = "ForJets/";
0026   TString hfrings = "HFRingSums/";
0027   TString hfringb = "HFBitCounts/";
0028   TString totale = "TotalESums/";
0029   TString missinge = "MissingESums/";
0030 
0031   //Iso e/gamma
0032   PlotWrite(input,output,outfolder,TString("isoEgRank"),TString(basedata+isoem+"isoEgD_Rank"),TString(baseemu+isoem+"isoEgE_Rank"),"E_{T}","Iso EM candidates",0,0);
0033   PlotWrite(input,output,outfolder,TString("isoEgEta"),TString(basedata+isoem+"isoEgD_EtEtaPhi"),TString(baseemu+isoem+"isoEgE_EtEtaPhi"),"#eta","Iso EM candidates",0,0,"eta");
0034   PlotWrite(input,output,outfolder,TString("isoEgPhi"),TString(basedata+isoem+"isoEgD_EtEtaPhi"),TString(baseemu+isoem+"isoEgE_EtEtaPhi"),"#phi","Iso EM candidates",0,0,"phi");
0035   PlotWriteErrors(input,output,outfolder,TString("isoEg_errorFlag"),TString(baseerrorhist+"isoEg_errorFlag"));
0036 
0037   //Non Iso e/gamma
0038   PlotWrite(input,output,outfolder,TString("nonIsoEgRank"),TString(basedata+nisoem+"nonIsoEgD_Rank"),TString(baseemu+nisoem+"nonIsoEgE_Rank"),"E_{T}","Non-Iso EM candidates",0,0);
0039   PlotWrite(input,output,outfolder,TString("nonIsoEgEta"),TString(basedata+nisoem+"nonIsoEgD_EtEtaPhi"),TString(baseemu+nisoem+"nonIsoEgE_EtEtaPhi"),"#eta","Non-Iso EM candidates",0,0,"eta");
0040   PlotWrite(input,output,outfolder,TString("nonIsoEgPhi"),TString(basedata+nisoem+"nonIsoEgD_EtEtaPhi"),TString(baseemu+nisoem+"nonIsoEgE_EtEtaPhi"),"#phi","Non-Iso EM candidates",0,0,"phi");
0041   PlotWriteErrors(input,output,outfolder,TString("nonIsoEg_errorFlag"),TString(baseerrorhist+"nonIsoEg_errorFlag"));
0042 
0043   //Central Jets
0044   PlotWrite(input,output,outfolder,TString("cenJetsRank"),TString(basedata+cenjet+"cenJetD_Rank"),TString(baseemu+cenjet+"cenJetE_Rank"),"E_{T}","Central Jet candidates",0,0);
0045   PlotWrite(input,output,outfolder,TString("cenJetsEta"),TString(basedata+cenjet+"cenJetD_EtEtaPhi"),TString(baseemu+cenjet+"cenJetE_EtEtaPhi"),"#eta","Central Jet candidates",0,0,"eta");
0046   PlotWrite(input,output,outfolder,TString("cenJetsPhi"),TString(basedata+cenjet+"cenJetD_EtEtaPhi"),TString(baseemu+cenjet+"cenJetE_EtEtaPhi"),"#phi","Central Jet candidates",0,0,"phi");
0047   PlotWriteErrors(input,output,outfolder,TString("cenJet_errorFlag"),TString(baseerrorhist+"cenJet_errorFlag"));
0048 
0049   //Tau Jets
0050   PlotWrite(input,output,outfolder,TString("tauJetsRank"),TString(basedata+taujet+"tauJetD_Rank"),TString(baseemu+taujet+"tauJetE_Rank"),"E_{T}","Tau-Jet candidates",0,0);
0051   PlotWrite(input,output,outfolder,TString("tauJetsEta"),TString(basedata+taujet+"tauJetD_EtEtaPhi"),TString(baseemu+taujet+"tauJetE_EtEtaPhi"),"#eta","Tau-Jet candidates",0,0,"eta");
0052   PlotWrite(input,output,outfolder,TString("tauJetsPhi"),TString(basedata+taujet+"tauJetD_EtEtaPhi"),TString(baseemu+taujet+"tauJetE_EtEtaPhi"),"#phi","Tau-Jet candidates",0,0,"phi");
0053   PlotWriteErrors(input,output,outfolder,TString("tauJet_errorFlag"),TString(baseerrorhist+"tauJet_errorFlag"));
0054 
0055   //Forward Jets
0056   PlotWrite(input,output,outfolder,TString("forJetsRank"),TString(basedata+forjet+"forJetD_Rank"),TString(baseemu+forjet+"forJetE_Rank"),"E_{T}","Forward Jet candidates",0,0);
0057   PlotWrite(input,output,outfolder,TString("forJetsEta"),TString(basedata+forjet+"forJetD_EtEtaPhi"),TString(baseemu+forjet+"forJetE_EtEtaPhi"),"#eta","Forward Jet candidates",0,0,"eta");
0058   PlotWrite(input,output,outfolder,TString("forJetsPhi"),TString(basedata+forjet+"forJetD_EtEtaPhi"),TString(baseemu+forjet+"forJetE_EtEtaPhi"),"#phi","Forward Jet candidates",0,0,"phi");
0059   PlotWriteErrors(input,output,outfolder,TString("forJet_errorFlag"),TString(baseerrorhist+"forJet_errorFlag"));
0060 
0061   //HF Ring Sums
0062   PlotWrite(input,output,outfolder,TString("hfRingSum1+"),TString(basedata+hfrings+"hfRingSumD_1+"),TString(baseemu+hfrings+"hfRingSumE_1+"),"Ring 1+ E_{T} Sum","Events",0,0);
0063   PlotWrite(input,output,outfolder,TString("hfRingSum1-"),TString(basedata+hfrings+"hfRingSumD_1-"),TString(baseemu+hfrings+"hfRingSumE_1-"),"Ring 1- E_{T} Sum","Events",0,0);
0064   PlotWrite(input,output,outfolder,TString("hfRingSum2+"),TString(basedata+hfrings+"hfRingSumD_2+"),TString(baseemu+hfrings+"hfRingSumE_2+"),"Ring 2+ E_{T} Sum","Events",0,0);
0065   PlotWrite(input,output,outfolder,TString("hfRingSum2-"),TString(basedata+hfrings+"hfRingSumD_2-"),TString(baseemu+hfrings+"hfRingSumE_2-"),"Ring 2- E_{T} Sum","Events",0,0);
0066   PlotWriteErrors(input,output,outfolder,TString("hfRingSum_errorFlag"),TString(baseerrorhist+"hfRingSum_errorFlag"));
0067   
0068   //HF Bit Counts
0069   PlotWrite(input,output,outfolder,TString("hfBitCount1+"),TString(basedata+hfringb+"hfBitCountD_1+"),TString(baseemu+hfringb+"hfBitCountE_1+"),"Ring 1+ Bit Counts","Events",0,0);
0070   PlotWrite(input,output,outfolder,TString("hfBitCount1-"),TString(basedata+hfringb+"hfBitCountD_1-"),TString(baseemu+hfringb+"hfBitCountE_1-"),"Ring 1- Bit Counts","Events",0,0);
0071   PlotWrite(input,output,outfolder,TString("hfBitCount2+"),TString(basedata+hfringb+"hfBitCountD_2+"),TString(baseemu+hfringb+"hfBitCountE_2+"),"Ring 2+ Bit Counts","Events",0,0);
0072   PlotWrite(input,output,outfolder,TString("hfBitCount2-"),TString(basedata+hfringb+"hfBitCountD_2-"),TString(baseemu+hfringb+"hfBitCountE_2-"),"Ring 2- Bit Counts","Events",0,0);
0073   PlotWriteErrors(input,output,outfolder,TString("hfBitCount_errorFlag"),TString(baseerrorhist+"hfBitCount_errorFlag"));
0074 
0075   //Total ET
0076   PlotWrite(input,output,outfolder,TString("totalEt"),TString(basedata+totale+"totalEtD"),TString(baseemu+totale+"totalEtE"),"E_{T}","Events",32,0);
0077   PlotWriteErrors(input,output,outfolder,TString("totalEt_errorFlag"),TString(baseerrorhist+"totalEt_errorFlag"));
0078 
0079   //Total HT
0080   PlotWrite(input,output,outfolder,TString("totalHt"),TString(basedata+totale+"totalHtD"),TString(baseemu+totale+"totalHtE"),"H_{T}","Events",32,0);
0081   PlotWriteErrors(input,output,outfolder,TString("totalHt_errorFlag"),TString(baseerrorhist+"totalHt_errorFlag"));
0082 
0083   //Missing ET
0084   PlotWrite(input,output,outfolder,TString("missingEt"),TString(basedata+missinge+"missingEtD"),TString(baseemu+missinge+"missingEtE"),"|E_{T}^{miss}|","Events",32,0);
0085   PlotWrite(input,output,outfolder,TString("missingEt_phi"),TString(basedata+missinge+"missingEtD_Phi"),TString(baseemu+missinge+"missingEtE_Phi"),"E_{T}^{miss} #phi","Events",0,0);
0086   PlotWriteErrors(input,output,outfolder,TString("missingEt_errorFlag"),TString(baseerrorhist+"missingEt_errorFlag"));
0087 
0088   //Missing HT
0089   PlotWrite(input,output,outfolder,TString("missingHt"),TString(basedata+missinge+"missingHtD"),TString(baseemu+missinge+"missingHtE"),"|H_{T}^{miss}|","Events",2,128);
0090   PlotWrite(input,output,outfolder,TString("missingHt_phi"),TString(basedata+missinge+"missingHtD_Phi"),TString(baseemu+missinge+"missingHtE_Phi"),"H_{T}^{miss} #phi","Events",0,17);
0091   PlotWriteErrors(input,output,outfolder,TString("missingHt_errorFlag"),TString(baseerrorhist+"missingHt_errorFlag"));
0092 
0093   input->Close();
0094   output->Close();
0095 
0096   return;
0097   
0098 }
0099 
0100 void PlotWrite(TFile* input, TFile* output, TString output_folder, TString canvas, TString Hist_data, TString Hist_emu, TString XAxisLabel, TString YAxisLabel="Events", int rebin, int xAxisRange, TString Opt="")
0101 {
0102 
0103   // Setup the canvas
0104   TCanvas *c1= new TCanvas(canvas,canvas,800,700);
0105   c1->SetLogy(1);
0106 
0107   // Get the histograms from the files
0108   if(Opt == "eta" || Opt == "phi")
0109   {
0110     if(Opt == "eta") {
0111     TH2F *Data2 = (TH2F*)input->Get(Hist_data);
0112     TH1D *Data = Data2->ProjectionX();
0113     if(rebin>0) Data->Rebin(rebin);
0114     if(xAxisRange>0) Data->GetXaxis()->SetRangeUser(0,xAxisRange);
0115 
0116     TH2F *Emu2 = (TH2F*)input->Get(Hist_emu);
0117     TH1D *Emu = Emu2->ProjectionX();
0118     if(rebin>0) Emu->Rebin(rebin);
0119     if(xAxisRange>0) Emu->GetXaxis()->SetRangeUser(0,xAxisRange);
0120     }
0121     if(Opt == "phi") {
0122     TH2F *Data2 = (TH2F*)input->Get(Hist_data); 
0123     TH1D *Data = Data2->ProjectionY();
0124     if(rebin>0) Data->Rebin(rebin);
0125     if(xAxisRange>0) Data->GetXaxis()->SetRangeUser(0,xAxisRange);
0126 
0127     TH2F *Emu2 = (TH2F*)input->Get(Hist_emu);
0128     TH1D *Emu = Emu2->ProjectionY();
0129     if(rebin>0) Emu->Rebin(rebin);
0130     if(xAxisRange>0) Emu->GetXaxis()->SetRangeUser(0,xAxisRange);
0131     }
0132   }
0133   else
0134   {
0135     TH1D *Data = (TH1D*)input->Get(Hist_data);
0136     if(rebin>0) Data->Rebin(rebin);
0137     if(xAxisRange>0) Data->GetXaxis()->SetRangeUser(0,xAxisRange);
0138 
0139     TH1D *Emu = (TH1D*)input->Get(Hist_emu);
0140     if(rebin>0) Emu->Rebin(rebin);
0141     if(xAxisRange>0) Emu->GetXaxis()->SetRangeUser(0,xAxisRange);
0142   }
0143 
0144   // Add the X axis label
0145   Emu->GetXaxis()->SetTitle(XAxisLabel);
0146   Emu->GetYaxis()->SetTitle(YAxisLabel);
0147   Emu->GetYaxis()->SetTitleSize(0.06);
0148   Emu->GetXaxis()->SetTitleSize(0.06);
0149   Emu->SetLineWidth(2);
0150   Emu->SetTitleOffset(1.10,"y");
0151   Emu->SetTitleOffset(0.80,"x");
0152 
0153   // Marker type for data
0154   Data->SetMarkerStyle(20);
0155   Data->SetMarkerColor(kRed);
0156 
0157   // plot them
0158   if (gPad->GetLogy()){
0159     Emu->SetMaximum(TMath::Max(Emu->GetMaximum(),Data->GetMaximum())*5);
0160   } else {
0161     Emu->SetMaximum(TMath::Max(Emu->GetMaximum(),Data->GetMaximum())*1.75);
0162   }
0163   Emu->DrawCopy("hist");
0164   Data->DrawCopy("psame");
0165 
0166   //make Legend
0167   TLegend * aLegend = new TLegend(0.646,0.768,0.746,0.868,NULL,"brNDC");
0168   aLegend->SetFillColor(0);
0169   aLegend->SetLineColor(0);
0170   aLegend->SetTextSize(0.05);
0171   aLegend->AddEntry(Emu,TString("Emulator"), "L");
0172   aLegend->AddEntry(Data,TString("Hardware"), "P");
0173   aLegend->DrawClone("same");
0174   gPad->RedrawAxis();
0175 
0176   //write canvas as png
0177   c1->Print(TString(output_folder+canvas+".png"));  
0178 
0179   //write canvas to output file
0180   output->cd();
0181   c1->Write();
0182   return;
0183 }
0184 
0185 void PlotWriteErrors(TFile* input, TFile* output, TString output_folder, TString canvas, TString Hist, TString Opt="")
0186 {
0187 
0188   // Setup the canvas
0189   TCanvas *c1= new TCanvas(canvas,canvas,800,700);
0190 
0191   // Get the histograms from the files
0192   TH1D *Data = (TH1D*)input->Get(Hist);
0193 
0194   //check to make sure there are some events before setting the log scale
0195   if(Data->Integral() == 0 ) c1->SetLogy(0);
0196   else  c1->SetLogy(1);
0197 
0198   // Fill for histogram
0199   Data->SetFillColor(kBlue);
0200   Data->GetXaxis()->SetTitleSize(0.06);
0201   Data->GetXaxis()->SetTitleOffset(0.75);
0202   Data->GetYaxis()->SetTitleSize(0.05);
0203   Data->GetYaxis()->SetTitleOffset(1.00);
0204 
0205   // plot them
0206   Data->DrawCopy("hist");
0207 
0208   gPad->RedrawAxis();
0209 
0210   //write canvas as png
0211   c1->Print(TString(output_folder+canvas+".png"));  
0212 
0213   //write canvas to output file
0214   output->cd();
0215   c1->Write();
0216   return;
0217 }
0218 
0219 void setStyle() {
0220 
0221   TStyle *setStyle = new TStyle("setStyle","Style for GCT Analyzer");
0222 
0223   // Stuff from plain style
0224   setStyle->SetCanvasColor(kWhite);
0225   setStyle->SetFrameBorderMode(0);
0226   setStyle->SetCanvasBorderMode(0);
0227   setStyle->SetFrameFillColor(0);
0228   setStyle->SetPadBorderMode(0);
0229   setStyle->SetPadColor(kWhite); 
0230 
0231   setStyle->SetOptStat(0);
0232   setStyle->SetOptTitle(0);
0233   setStyle->SetOptFit(0);
0234   setStyle->SetOptDate(0);
0235 
0236   // Labels and borders
0237   
0238   setStyle->SetLabelSize(0.055,"x");
0239   setStyle->SetLabelSize(0.06,"y");
0240   setStyle->SetLabelOffset(0.00,"x");
0241   setStyle->SetLabelOffset(0.00,"y");
0242   setStyle->SetTitleOffset(0.05,"x");
0243   setStyle->SetTitleOffset(0.50,"y");
0244   //setStyle->SetLabelFont(22,"x");
0245   //setStyle->SetLabelFont(22,"y");
0246   //setStyle->SetErrorX(0.0000);
0247   //setStyle->SetTickLength(0.05,"x");
0248   //setStyle->SetTickLength(0.05,"y");
0249   //setStyle->SetLineWidth(0.8);
0250   //setStyle->SetPadTickX(1);
0251   //setStyle->SetPadTickY(1);
0252   setStyle->SetPadLeftMargin(0.15);
0253   setStyle->SetPadTopMargin(0.077);
0254   setStyle->SetPadBottomMargin(0.123);
0255   
0256   setStyle->cd();
0257 }