Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:44

0001 #include <iostream>
0002 #include <TH1D.h>
0003 #include <TCanvas.h>
0004 #include <TFile.h>
0005 #include <TLegend.h>
0006 #include <TGraphAsymmErrors.h>
0007 
0008 void drawHisto(TString type, TFile * outputFile,
0009            const double & minX, const double & maxX,
0010            const double & minY, const double & maxY)
0011 {
0012   TFile * inputFile = new TFile("test.root", "READ");
0013   TCanvas * canvas = (TCanvas*)inputFile->Get("canvas"+type);
0014   TGraphAsymmErrors * graph = (TGraphAsymmErrors*)canvas->GetPrimitive("Graph_from_sigmaPtVs"+type);
0015 
0016   TFile * inputFile2 = new TFile("ComparedResol.root", "READ");
0017   TCanvas * canvas2 = (TCanvas*)inputFile2->Get("resolPtVS"+type);
0018   TH1D * histo = (TH1D*)canvas2->GetPrimitive("hResolPtGenVSMu_ResoVS"+type+"_resol_after");
0019 
0020   TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
0021   legend->SetTextSize(0.02);
0022   legend->SetFillColor(0); // Have a white background
0023   legend->AddEntry(histo, "resolution from MC comparison");
0024   legend->AddEntry(graph, "resolution from fitted function");
0025 
0026   graph->GetXaxis()->SetRangeUser(minX, maxX);
0027   graph->GetYaxis()->SetRangeUser(minY, maxY);
0028   canvas->Draw();
0029   histo->Draw("SAME");
0030   legend->Draw("SAME");
0031 
0032   outputFile->cd();
0033   canvas->Write();
0034 }
0035 
0036 void CompareErrorResol()
0037 {
0038   TFile * outputFile = new TFile("output.root", "RECREATE");
0039   drawHisto("Pt", outputFile, 0., 20., 0., 0.06);
0040   drawHisto("Eta", outputFile, -2.39, 2.39, 0., 0.06);
0041   outputFile->Write();
0042   outputFile->Close();
0043 }