File indexing completed on 2024-04-06 12:32:50
0001
0002
0003 """
0004 Copied from GEMCode/GEMValidation
0005 """
0006
0007 from ROOT import TFile, gStyle, TCanvas, gPad, TH1F
0008
0009 import os
0010 import sys
0011 import ROOT
0012 ROOT.gROOT.SetBatch(1)
0013
0014 import optparse
0015
0016 output = TFile("output.root","RECREATE")
0017
0018
0019 def draw_occ(target_dir, h1,h2, ext =".png", opt = ""):
0020 gStyle.SetStatStyle(0)
0021 gStyle.SetOptStat(1110)
0022 c = TCanvas(h1.GetTitle(),h1.GetName(),600,600)
0023 c_title = c.GetTitle()
0024 c.Clear()
0025 if not h1 or not h2:
0026 sys.exit('h1 or h2 does not exist')
0027 h1.SetLineWidth(2)
0028 h1.SetLineColor(kBlue)
0029 h1.SetMarkerColor(kBlue)
0030 h1.SetTitle(args[0])
0031 h1.Draw(opt)
0032 h2.SetLineWidth(2)
0033 h2.SetLineColor(kRed)
0034 h2.SetMarkerColor(kRed)
0035 h2.SetTitle(args[1])
0036 h2.Draw("same"+opt)
0037 gPad.SetTitle(c_title)
0038 leg = gPad.BuildLegend()
0039 h1.SetTitle(c_title)
0040 c.Update()
0041 c.SaveAs(target_dir + c_title + ext)
0042
0043
0044 def draw_diff_strip(target_dir, h1,h2, ext =".png", opt = ""):
0045 gStyle.SetStatStyle(0)
0046 gStyle.SetOptStat(0)
0047 c = TCanvas("c1",("strip_diff_%s")%(h1.GetName()),600,600)
0048 c_title = c.GetTitle()
0049 c.Clear()
0050 if not h1 or not h2:
0051 sys.exit('h1 or h2 does not exist')
0052 xbin = h1.GetXaxis().GetNbins()
0053 xmin = h1.GetXaxis().GetXmin()
0054 xmax = h1.GetXaxis().GetXmax()
0055 title = ("Difference of strip phi between %s and %s")%(h1.GetName(),h2.GetName())
0056 h = TH1F("strip_diff",title,xbin,xmin,xmax)
0057 for x in range( xbin ) :
0058 value1 = h1.GetBinContent( x + 1 )
0059 value2 = h2.GetBinContent( x + 1 )
0060 h.SetBinContent( x+1, value1 - value2)
0061 h.Draw(opt)
0062 gPad.SetTitle(c_title)
0063
0064 c.Update()
0065 c.SaveAs(target_dir + c_title + ext)
0066 output.ReOpen("UPDATE")
0067 h.Write()
0068
0069 def draw_plot( file1, file2, tDir,oDir ) :
0070 c = TCanvas("c","c",600,600)
0071 dqm_file1 = TFile( file1)
0072 dqm_file2 = TFile( file2)
0073 d1 = dqm_file1.Get(tDir)
0074 d2 = dqm_file2.Get(tDir)
0075 key_list =[]
0076
0077 tlist1 = d1.GetListOfKeys()
0078 for x in tlist1 :
0079 key_list.append(x.GetName())
0080
0081 for hist in key_list :
0082 if ( hist.find("_phiz_") != -1 ) :
0083 draw_occ( oDir,d1.Get(hist), d2.Get(hist),".png","col");
0084 elif ( hist.find("strip_phi_dist") != -1 ) :
0085 draw_diff_strip( oDir, d1.Get(hist), d2.Get(hist) )
0086 elif ( hist.find("sp") != -1) :
0087 draw_occ( oDir, d1.Get(hist), d2.Get(hist))
0088
0089 if __name__ == '__main__' :
0090 usage = ": %prog DQM_file1.root file2.root \negs) ./%prog -o c_temp_plot DQM_v6.root DQM_v7.root"
0091 parser = optparse.OptionParser(usage=usage)
0092 parser.add_option("-o",dest='directory',help='Name of output directory(Default : c_temp_plot)',default="c_temp_plot")
0093 options, args = parser.parse_args()
0094
0095 if len(args)==0 :
0096 print "Input file name is None."
0097 print "Use default name.[ DQM_v6.root and DQM_v7.root]"
0098 args.append("DQM_v6.root")
0099 args.append("DQM_v7.root")
0100
0101 tDir = "DQMData/Run 1/MuonGEMDigisV/Run summary/GEMDigisTask"
0102 oDir = options.directory+"_GEMDigis/"
0103 os.system("mkdir -p "+oDir )
0104 draw_plot(args[0],args[1],tDir,oDir)