File indexing completed on 2024-04-06 12:32:50
0001
0002
0003 """
0004 Copied from GEMCode/GEMValidation
0005 """
0006
0007 from ROOT import gStyle, TCanvas, gPad, TF1, TPaveText, TCanvas, TFile
0008
0009 import os
0010 import sys
0011
0012 import ROOT
0013 ROOT.gROOT.SetBatch(1)
0014
0015 import optparse
0016 def getEtaRange( station ) :
0017 etaRange = [1.55,2.15,1.65,2.45]
0018 if ( station ==1 or station==2 ) :
0019 return etaRange[ (station-1)*2], etaRange[ (station-1)*2+1 ]
0020 else :
0021 print "Something is wrong"
0022 return 1.5,2.6
0023
0024 def draw_occ(target_dir, h, ext =".png", opt = ""):
0025 gStyle.SetStatStyle(0)
0026 gStyle.SetOptStat(1110)
0027 c = TCanvas(h.GetTitle(),h.GetName(),600,600)
0028 c_title = c.GetTitle()
0029 c.Clear()
0030 if not h:
0031 sys.exit('h does not exist')
0032 h.SetLineWidth(2)
0033 h.SetLineColor(kBlue)
0034 h.Draw(opt)
0035 c.SaveAs(target_dir + c_title + ext)
0036
0037 def draw_bx(target_dir, h , ext = ".png", opt = ""):
0038 gStyle.SetStatStyle(0)
0039 gStyle.SetOptStat(1110)
0040 c = TCanvas(h.GetTitle(),h.GetName(),600,600)
0041 c_title = c.GetTitle()
0042 gPad.SetLogy()
0043 h.SetLineWidth(2)
0044 h.SetLineColor(kBlue)
0045 h.Draw(opt)
0046 h.SetMinimum(1.)
0047 c.SaveAs(target_dir + c_title + ext)
0048
0049 def draw_simple_zr(target_dir, h, ext =".png",opt="colz"):
0050 gStyle.SetOptStat(0)
0051 c = TCanvas(h.GetName(),h.GetName(),600,600)
0052 c.Divide(2,1)
0053 c_title = c.GetTitle()
0054
0055 if not h:
0056 sys.exit('h does not exist')
0057 h.SetLineWidth(2)
0058 h.SetLineColor(kBlue)
0059 c.cd(1)
0060 gPad.SetRightMargin(0)
0061 gPad.SetBorderMode(0)
0062 h1 = h.Clone()
0063 h1.SetAxisRange(564,572)
0064 h1.Draw("col")
0065 c.cd(2)
0066 h2 = h.Clone()
0067 gPad.SetLeftMargin(0)
0068 gPad.SetBorderMode(0)
0069 h2.SetAxisRange(793,800)
0070 h2.Draw(opt)
0071
0072
0073
0074 c.SaveAs(target_dir + c_title + ext)
0075
0076
0077 def draw_col_nostat(target_dir, h, ext =".png", opt = "colz"):
0078 gStyle.SetOptStat(0)
0079 c = TCanvas(h.GetTitle(),h.GetName(),800,600)
0080 c_title = c.GetTitle()
0081 c.Clear()
0082 if not h:
0083 sys.exit('h does not exist')
0084 h.SetLineWidth(2)
0085 h.SetLineColor(kBlue)
0086 h.Draw(opt)
0087 c.SaveAs(target_dir + c_title + ext)
0088
0089 def draw_col_eff(target_dir, h, ext =".png", opt = "colz"):
0090 gStyle.SetOptStat(0)
0091 c = TCanvas(h.GetTitle(),h.GetName(),800,600)
0092 c_title = c.GetTitle()
0093 c.Clear()
0094 if not h:
0095 sys.exit('h does not exist')
0096 h.SetLineWidth(2)
0097 h.SetLineColor(kBlue)
0098 h.SetMaximum(1.2)
0099 h.Draw(opt)
0100 c.SaveAs(target_dir + c_title + ext)
0101
0102
0103
0104 def draw_col(target_dir, h, ext =".png", opt = "col"):
0105 gStyle.SetStatStyle(0)
0106 gStyle.SetOptStat(1110)
0107 c = TCanvas(h.GetTitle(),h.GetName(),600,600)
0108 c_title = c.GetTitle()
0109 c.Clear()
0110 if not h:
0111 sys.exit('h does not exist')
0112 h.SetLineWidth(2)
0113 h.SetLineColor(kBlue)
0114 h.Draw(opt)
0115 c.SaveAs(target_dir + c_title + ext)
0116
0117 def draw_col_userRange( target_dir, h, ext =".png", opt = "col"):
0118 gStyle.SetStatStyle(0)
0119 c = TCanvas(h.GetTitle(),h.GetName(),1600,1600)
0120 c_title = c.GetTitle()
0121 c.Clear()
0122 if not h:
0123 sys.exit('h does not exist')
0124 h.SetLineWidth(2)
0125 h.SetLineColor(kBlue)
0126 h.SetLabelSize(0.02,"Y")
0127 h.SetLabelOffset(0,"Y")
0128 axis_title = h.GetXaxis().GetTitle()
0129 axis_title = axis_title+ "/"+str(h.GetXaxis().GetBinWidth(1))
0130 h.GetXaxis().SetTitle( axis_title)
0131 h.SetAxisRange(14.5,15.5)
0132 h.Draw(opt)
0133 c.SaveAs(target_dir + c_title + ext)
0134
0135
0136 def draw_col_overflow(target_dir, h, ext =".png", opt = "col"):
0137 gStyle.SetStatStyle(0)
0138 gStyle.SetOptStat(110200)
0139 c = TCanvas(h.GetTitle(),h.GetName(),600,600)
0140 c_title = c.GetTitle()
0141 c.Clear()
0142 if not h:
0143 sys.exit('h does not exist')
0144 h.SetLineWidth(2)
0145 h.SetLineColor(kBlue)
0146 h.Draw(opt)
0147 c.SaveAs(target_dir + c_title + ext)
0148
0149 def draw_eff(target_dir, h, ext = ".png", opt = ""):
0150 c = TCanvas(h.GetTitle(), h.GetName(),600,600)
0151 c_title = c.GetTitle()
0152 c.Clear()
0153 if not h:
0154 sys.exit('h does not exist')
0155 gPad.SetGrid(1)
0156 gStyle.SetStatStyle(0)
0157 gStyle.SetOptStat(0)
0158 gStyle.SetOptFit(0)
0159 h.GetYaxis().SetRangeUser(0,1.05)
0160 h.SetLineWidth(2)
0161 h.SetLineColor(kBlue)
0162 h.SetMarkerStyle(1)
0163 h.SetMarkerColor(kBlue)
0164 h.SetMarkerSize(1)
0165 h.Draw(opt);
0166 xmin=h.GetXaxis().GetXmin()
0167 xmax=h.GetXaxis().GetXmax()
0168 if ( h.GetName().find("eta") != -1) :
0169 if ( h.GetName().find("st1") != -1) :
0170 xmin,xmax = getEtaRange(1)
0171 elif ( h.GetName().find("st2") != -1 ) :
0172 xmin,xmax = getEtaRange(2)
0173 else :
0174 print "Use default setting."
0175
0176 f1 = TF1("fit1","pol0", xmin, xmax )
0177 r = h.Fit("fit1","RQS")
0178 ptstats = TPaveStats(0.25,0.35,0.75,0.55,"brNDC")
0179 ptstats.SetName("stats")
0180 ptstats.SetBorderSize(0)
0181 ptstats.SetLineWidth(0)
0182 ptstats.SetFillColor(0)
0183 ptstats.SetTextAlign(11)
0184 ptstats.SetTextFont(42)
0185 ptstats.SetTextSize(.05)
0186 ptstats.SetTextColor(kRed)
0187 ptstats.SetOptStat(0)
0188 ptstats.SetOptFit(1111)
0189 chi2 = int(r.Chi2())
0190 ndf = int(r.Ndf())
0191
0192 round(2.675, 2)
0193 p0 = f1.GetParameter(0)
0194 p0e = f1.GetParError(0)
0195 ptstats.AddText("#chi^{2} / ndf: %d/%d" %(chi2,ndf))
0196
0197 ptstats.AddText("Efficiency: %f #pm %f %%"%(p0,p0e))
0198 ptstats.Draw("same")
0199 pt = TPaveText(0.09899329,0.9178322,0.8993289,0.9737762,"blNDC")
0200 pt.SetName("title")
0201 pt.SetBorderSize(1)
0202 pt.SetFillColor(0)
0203 pt.SetFillStyle(0)
0204 pt.SetTextFont(42)
0205 pt.AddText(h.GetTitle())
0206 pt.Draw("same")
0207 c.SaveAs(target_dir + c_title + ext)
0208
0209
0210 def draw_plot( file, tDir,oDir ) :
0211 c = TCanvas("c","c",600,600)
0212 dqm_file = TFile( file)
0213 d1 = dqm_file.Get(tDir)
0214 key_list =[]
0215
0216 try :
0217 tlist = d1.GetListOfKeys()
0218 except :
0219 print oDir
0220 if ( oDir.find("Digi") != -1 ):
0221 tDir = "DQMData/Run 1/MuonGEMDigisV/Run summary/GEMDigiTask"
0222 d1 = dqm_file.Get(tDir)
0223 tlist = d1.GetListOfKeys()
0224 elif ( oDir.find("RecHit") != -1 ):
0225 tDir = "DQMData/Run 1/MuonGEMRecHitsV/Run summary/GEMRecHitTask"
0226 d1 = dqm_file.Get(tDir)
0227 tlist = d1.GetListOfKeys()
0228 else :
0229 print "error"
0230 exit(-1)
0231 for x in tlist :
0232 key_list.append(x.GetName())
0233 for hist in key_list :
0234 if hist.find("track_") != -1 :
0235 draw_occ( oDir,d1.Get(hist))
0236 elif (hist.find("dcEta") !=-1 ) :
0237 draw_col_nostat( oDir,d1.Get(hist))
0238 elif (hist.find("simple_zr")!= -1 ) :
0239 draw_simple_zr( oDir,d1.Get(hist))
0240 elif (hist.find("eff_DigiHit") != -1 ) :
0241 draw_col_eff( oDir, d1.Get(hist))
0242 elif (hist.find("lx") !=-1 or hist.find("ly") != -1 or hist.find("dphi") != -1 or hist.find("_phi_dist") != -1 ) :
0243 draw_occ( oDir,d1.Get(hist))
0244 elif ( hist.find("bx") != -1 ) :
0245 draw_bx( oDir, d1.Get(hist) )
0246 elif ( hist.find("xy") !=-1 or hist.find("zr") !=-1 or hist.find("roll_vs_strip")!= -1 or hist.find("phipad")!=-1 or hist.find("phistrip") != -1 or hist.find("sp")!=-1 or hist.find("sub")!=-1 ) :
0247 draw_col( oDir, d1.Get(hist) )
0248 elif ( hist.find("phiz") != -1 ) :
0249 draw_col_overflow( oDir, d1.Get(hist) )
0250 elif ( hist.find("eff") != -1 ) :
0251 draw_eff( oDir, d1.Get(hist) )
0252
0253 elif ( hist.find("geo_phi") != -1) :
0254 draw_col_userRange( oDir, d1.Get(hist))
0255 else :
0256 draw_occ( oDir, d1.Get(hist) )
0257
0258
0259
0260 if __name__ == '__main__' :
0261 usage = ": %prog [option] DQM_filename.root\negs) ./%prog -a DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root"
0262 parser = optparse.OptionParser(usage=usage)
0263
0264 parser.add_option("-o",dest='directory',help='Name of output directory(Default : temp_plot)',default="temp_plot")
0265 parser.add_option("-a",action='store_true',dest='all',help='Enable all step option.(-s -d -r)',default=False)
0266 parser.add_option("-s",action='store_true',dest='simhit',help='Run simhit plotter',default=False)
0267 parser.add_option("-d",action='store_true',dest='digi',help='Run digi plotter',default=False)
0268 parser.add_option("-r",action='store_true',dest='reco',help='Run reco plotter',default=False)
0269 options, args = parser.parse_args()
0270
0271 if len(sys.argv) ==1 :
0272 parser.print_help()
0273 exit()
0274
0275 if len(args)==0 :
0276 print "Input file name is None."
0277 print "Use default name."
0278 args.append("DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root")
0279
0280 if len(args) != 1 :
0281 print "Can not understand input argument"
0282 parser.print_help()
0283
0284 steps= []
0285 if ( options.all ) :
0286 options.simhit=True
0287 options.digi=True
0288 options.reco=True
0289
0290 if ( options.simhit) :
0291 steps.append("GEMHits")
0292 if ( options.digi) :
0293 steps.append("GEMDigis")
0294 if ( options.reco) :
0295 steps.append("GEMRecHits")
0296
0297 for step in steps :
0298 tDir = "DQMData/Run 1/Muon%sV/Run summary/%sTask"%(step,step)
0299 oDir = options.directory+"_%s"%(step)+'/'
0300 os.system("mkdir -p "+oDir )
0301 draw_plot(args[0],tDir,oDir)
0302
0303