Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:21

0001 import re, sys, os
0002 
0003 file = open("output", "r")
0004 
0005 lines = file.readlines()
0006 file.close()
0007 
0008 variable = []
0009 eta1 = []
0010 eta2 = []
0011 mean = []
0012 error= []
0013 effS = []
0014 
0015 for line in lines:
0016     elements = re.split("\t", line)
0017     variable += [elements[1],]
0018     
0019     eta1 += [re.split(">", re.split("&&", elements[2])[0])[1],]
0020     eta2 += [re.split("<", elements[2])[1],]
0021 
0022     mean += [elements[3],]
0023     error+= [elements[4],]
0024     effS += [elements[5][:-1],]
0025 
0026 header = """void plot_MeanVsEta(){
0027    TCanvas *c1        = new TCanvas("c1","Mean vs Eta", 800, 600); 
0028    TH1F* h_em_et       = new TH1F("h_em_et",      "",150,0,1.5);
0029    TH1F* h_emCorr_et     = new TH1F("h_emCorr_et",    "",150,0,1.5);
0030    c1->cd();
0031 """
0032 file = open("plot_MeanVsEta.C", "w")
0033 file.write(header)
0034 
0035 for i in ("emCorr_et", "em_et"):
0036     for j in range(0, len(eta1)):
0037         if variable[j] != i:
0038             continue
0039         bin = str(int((float(eta1[j]) + float(eta2[j]))*50))
0040         file.write("  h_" + i + "->SetBinContent(" + bin + ", " + mean[j] + ");\n")
0041         file.write("  h_" + i + "->SetBinError  (" + bin + ", " + error[j] +");\n")
0042 
0043 file.write("  h_emCorr_et->SetMarkerStyle(23);\n")
0044 file.write("  h_em_et    ->SetMarkerStyle(20);\n")
0045 
0046 file.write("  h_emCorr_et->SetMarkerColor(4);\n")
0047 file.write("  h_em_et    ->SetMarkerColor(1);\n")
0048 
0049 file.write("  gStyle->SetOptStat(0);\n")
0050 
0051 file.write("  h_em_et    ->Draw();\n")
0052 file.write("  h_emCorr_et->Draw(\"SAME\");\n")
0053 
0054 header ="""  
0055 
0056   TAxis* ax = h_em_et->GetXaxis();
0057   ax->SetTitle("#eta");
0058   TAxis* ay = h_em_et->GetYaxis();
0059   ay->SetTitle("E_{T}^{RECO}/E_{T}^{MC}");
0060   ay->SetRangeUser(0.9,1.05);
0061   
0062   TLegend *leg = new TLegend(0.2, 0.2, 0.4, 0.4);
0063   leg->AddEntry(h_em_et, "Before correction");
0064   leg->AddEntry(h_emCorr_et, "After correction  ");
0065   leg->Draw();
0066   TLine* line = new TLine(0,1,1.5,1);
0067   line->SetLineWidth(2);
0068   line->SetLineColor(2); 
0069   line->Draw();
0070 
0071   c1->Print("MeadVsEta.ps");
0072   gROOT->ProcessLine(".q");
0073 
0074 """
0075 file.write(header)
0076 
0077 file.write("}\n")