Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-21 23:59:02

0001 import pickle, os 
0002 import math 
0003 import ROOT 
0004 
0005 ss = ["shared25", "shared50","shared75","shared100"]
0006 samples = {"shared25":ROOT.kBlack, "shared50":ROOT.kRed, "shared75":ROOT.kBlue, "shared100":ROOT.kGreen+1}
0007 tags = {"shared25": "shared 25% hits", "shared50": "shared 50% hits", "shared75":"shared 75% hits" , "shared100":"shared 100% hits"}
0008 
0009 plots=[]
0010 titles={}  
0011 
0012 # Load histograms
0013 for st in ["MB1","MB2","MB3","MB4"]:
0014     for wh in ["Wh-2", "Wh-1", "Wh0", "Wh1", "Wh2"]:
0015         for var in ["Phi","PhiB","Chi2","Bx","Time"]:
0016             for q in ["q1","q3","q5","q8"]:
0017 
0018                 plots.append("h%sRes_%s_%s_%s" %(var, st, wh, q))
0019                 titlename = '; %s^{std}-%s^{bay};' %(var,var)
0020                 if "PhiB" in var: 
0021                     titlename = titlename.replace('PhiB','#phi_{B}')
0022                     titlename = titlename.replace('};','} (mrad);')
0023                 elif "Phi" in var:
0024                     titlename = titlename.replace('Phi','#phi')    
0025                     titlename = titlename.replace('} ;','} (mrad) ;')            
0026                 elif "Chi2" in var:
0027                     titlename = titlename.replace('Chi2','#chi^2')                
0028                 titles["h%sRes_%s_%s_%s" %(var, st, wh, q)] = titlename
0029 
0030                 
0031                 # Histograms inclusive in wheel number: do them just once
0032                 if wh == "Wh-2":
0033                     plots.append("h%sRes_%s_%s" %(var, st, q))
0034                     titlename = '; %s^{std}-%s^{bay};' %(var,var)
0035                     if "PhiB" in var: 
0036                         titlename = titlename.replace('PhiB','#phi_{B}')
0037                         titlename = titlename.replace('};','} (mrad);')
0038                     elif "Phi" in var:
0039                         titlename = titlename.replace('Phi','#phi')    
0040                         titlename = titlename.replace('} ;','} (mrad) ;')            
0041                     elif "Chi2" in var:
0042                         titlename = titlename.replace('Chi2','#chi^2')                
0043                     titles["h%sRes_%s_%s" %(var, st, q)] = titlename
0044 
0045         plots.append("hMatchingEff_%s_%s" %(st, wh))
0046         titles["hMatchingEff_%s_%s" %(st, wh)] = " ; muon quality ; Efficiency = N_{bayes}/N_{std}"  
0047 
0048         # Eff histogram inclusive in wheel number: do it just once
0049         if wh == "Wh-2":
0050             plots.append("hMatchingEff_%s" %(st))
0051             titles["hMatchingEff_%s" %(st)] = " ; muon quality ; Efficiency = N_{bayes}/N_{std}"  
0052 
0053 
0054 outpath = "../../../../Groupings/"
0055 if not os.path.exists(outpath):
0056     os.mkdir(outpath)
0057     print "cp /afs/cern.ch/user/n/ntrevisa/public/utils/index.php %s/" %outpath
0058     os.system("cp /afs/cern.ch/user/n/ntrevisa/public/utils/index.php %s/" %outpath)
0059 os.system("cp EventDumpList_StdToBayes.log %s/" %outpath)
0060 
0061 outpath = outpath + "StdToBayes/"
0062 if not os.path.exists(outpath):
0063     os.mkdir(outpath)
0064     print "cp /afs/cern.ch/user/n/ntrevisa/public/utils/index.php %s/" %outpath
0065     os.system("cp /afs/cern.ch/user/n/ntrevisa/public/utils/index.php %s/" %outpath)
0066 
0067 
0068 outFile = ROOT.TFile("GroupingComparison_StdToBayes.root","RECREATE")
0069 outFile.cd()
0070 
0071 ROOT.gROOT.ProcessLine('.L PlotTemplate.C+')
0072 ROOT.gROOT.SetBatch(True)
0073 ROOT.gStyle.SetOptStat(0)
0074 
0075 with open('GroupingComparison_StdToBayes.pickle', 'rb') as handle:
0076     b = pickle.load(handle)
0077 
0078 #leg = ROOT.TLegend(0.6,0.6,0.85,0.26);
0079 leg = ROOT.TLegend(0.6,0.6,0.88,0.4);
0080 leg.SetTextSize(0.03);
0081 
0082 for s in ss:        
0083     for plot in plots:
0084         print("s = {}, plot = {}".format(s, plot))
0085         b[s][plot].SetTitle(titles[plot])
0086         b[s][plot].Write()
0087         b[s][plot].SetLineColor(samples[s])
0088         b[s][plot].SetMarkerStyle(8)
0089         b[s][plot].SetMarkerColor(samples[s])
0090         b[s][plot].SetMarkerSize(0.8)
0091         b[s][plot].SetLineWidth(2)
0092 
0093     leg.AddEntry(b[s][plots[0]], tags[s],'l');
0094 
0095 canvas = ROOT.CreateCanvas('name', False, True)
0096 
0097 for plot in plots:
0098     drawn = False
0099     counts=0
0100     disp = ROOT.TLatex()
0101     disp.SetTextSize(0.025)
0102     for s in ss: 
0103         if not (drawn): 
0104             b[s][plot].Draw()
0105             drawn=True
0106         else:
0107             b[s][plot].Draw('same')            
0108         if (b[s][plot].InheritsFrom("TH1")):
0109             disp.DrawLatexNDC(0.13,0.87-counts*0.03,"#color[%d]{%s: %.1E (%.1E)}" %(samples[s],tags[s],b[s][plot].GetMean(),b[s][plot].GetRMS()))
0110         else :
0111             ROOT.gPad.Update()
0112             b[s][plot].GetPaintedGraph().SetMinimum(0.01)
0113             b[s][plot].GetPaintedGraph().SetMaximum(1.02)
0114             ROOT.gPad.Update()
0115         counts = counts+1
0116 
0117     disp.Draw("same")
0118     ROOT.DrawPrelimLabel(canvas)
0119     ROOT.DrawLumiLabel(canvas,'200 PU')
0120     leg.Draw("same")
0121     
0122     ROOT.SaveCanvas(canvas, outpath + plot)
0123 
0124 outFile.Close()
0125 
0126 
0127