File indexing completed on 2023-03-17 10:57:59
0001
0002
0003 from __future__ import print_function
0004 import ROOT
0005 import sys,os,string,errno,shutil
0006 import code
0007 from ROOT import gROOT, gDirectory, gPad, gSystem, gRandom, gStyle
0008 from ROOT import TH1, TH1F, TCanvas, TFile
0009
0010 ROOT.gROOT.SetBatch()
0011 ROOT.gStyle.SetMarkerStyle(2)
0012 ROOT.gStyle.SetMarkerSize(0.6)
0013 ROOT.gStyle.SetMarkerColor(46)
0014 ROOT.gStyle.SetOptStat(0)
0015
0016 inputdir=sys.argv[1]
0017 outputdir=sys.argv[2]
0018
0019 print(str(inputdir))
0020 print(str(outputdir))
0021
0022 files = os.listdir(inputdir)
0023 print(files)
0024
0025 ROOT.gROOT.ProcessLine(".L ./plot_METDQM.C")
0026 ROOT.gROOT.ProcessLine(".L ./plot_jets_data_vs_MC.C")
0027 mettype = ['CaloMET','CaloMETNoHF''PfMET','TcMET','MuCorrMET']
0028
0029 rmscanvas = TCanvas("rmscanvas","rmsplots",1280,768)
0030 rmscanvas.Divide(2,2)
0031 meancanvas = TCanvas("meancanvas","meanplots",1280,768)
0032 meancanvas.Divide(2,2)
0033
0034 h_SumEt_rms = TH1F("h_SumEt_rms","", len(files),0,len(files))
0035 h_MET_rms = TH1F("h_MET_rms", "", len(files),0,len(files))
0036 h_MEx_rms = TH1F("h_MEx_rms", "", len(files),0,len(files))
0037 h_MEy_rms = TH1F("h_MEy_rms", "", len(files),0,len(files))
0038
0039 h_SumEt_mean = TH1F("h_SumEt_mean","", len(files),0,len(files))
0040 h_MET_mean = TH1F("h_MET_mean", "", len(files),0,len(files))
0041 h_MEx_mean = TH1F("h_MEx_mean", "", len(files),0,len(files))
0042 h_MEy_mean = TH1F("h_MEy_mean", "", len(files),0,len(files))
0043
0044 h_SumEt_rms.GetXaxis().SetTitle("Run #")
0045 h_SumEt_rms.GetYaxis().SetTitle("#sumE_{T} RMS")
0046 h_SumEt_rms.GetXaxis().SetTitleOffset(1.6)
0047 h_MET_rms.GetXaxis().SetTitle("Run #")
0048 h_MET_rms.GetYaxis().SetTitle("#slashE_{T} RMS")
0049 h_MET_rms.GetXaxis().SetTitleOffset(1.6)
0050 h_MEx_rms.GetXaxis().SetTitle("Run #")
0051 h_MEx_rms.GetYaxis().SetTitle("#slashE_{x} RMS")
0052 h_MEx_rms.GetXaxis().SetTitleOffset(1.6)
0053 h_MEy_rms.GetXaxis().SetTitle("Run #")
0054 h_MEy_rms.GetYaxis().SetTitle("#slashE_{y} RMS")
0055 h_MEy_rms.GetXaxis().SetTitleOffset(1.6)
0056
0057 h_SumEt_mean.GetXaxis().SetTitle("Run #")
0058 h_SumEt_mean.GetYaxis().SetTitle("#sumE_{T} Mean")
0059 h_SumEt_mean.GetXaxis().SetTitleOffset(1.6)
0060 h_MET_mean.GetXaxis().SetTitle("Run #")
0061 h_MET_mean.GetYaxis().SetTitle("#slashE_{T} Mean")
0062 h_MET_mean.GetXaxis().SetTitleOffset(1.6)
0063 h_MEx_mean.GetXaxis().SetTitle("Run #")
0064 h_MEx_mean.GetYaxis().SetTitle("#slashE_{x} Mean")
0065 h_MEx_mean.GetXaxis().SetTitleOffset(1.6)
0066 h_MEy_mean.GetXaxis().SetTitle("Run #")
0067 h_MEy_mean.GetYaxis().SetTitle("#slashE_{y} Mean")
0068 h_MEy_mean.GetXaxis().SetTitleOffset(1.6)
0069
0070
0071 for file in files:
0072 if (os.path.isfile(os.path.join(inputdir,file))):
0073 if ((file.find("R000000001")!=-1) or (file.find("MC")!=-1)):
0074 reference = os.path.join(inputdir,file)
0075 if (outputdir.find("afs")!=1):
0076 source = os.path.join(inputdir,file)
0077 destination = os.path.join(outputdir)
0078 try: shutil.copy2(source,destination)
0079 except IOError as err:
0080 print("cannot copy:\n%s\n to\n%s"%(source,destination))
0081 print("I/O error(%d): %s"%(err.errno,err.strerror))
0082 else:
0083 print("will not copy refernce root files to afs due to space restrictions")
0084 files.remove(file)
0085
0086
0087 for index,file in enumerate(files):
0088 if (os.path.isfile(os.path.join(inputdir,file))):
0089 if ((file.find("R000000001")==-1) and (file.find("MC")==-1)):
0090 infilename = os.path.join(inputdir,file)
0091 run = file[10:20]
0092 run = run.lstrip("R")
0093 run = run.lstrip("0")
0094
0095
0096 h_SumEt_rms.GetXaxis().SetBinLabel(index+1,run)
0097 h_SumEt_rms.GetXaxis().LabelsOption("v")
0098
0099 h_MET_rms.GetXaxis().SetBinLabel(index+1,run)
0100 h_MET_rms.GetXaxis().LabelsOption("v")
0101
0102 h_MEx_rms.GetXaxis().SetBinLabel(index+1,run)
0103 h_MEx_rms.GetXaxis().LabelsOption("v")
0104
0105 h_MEy_rms.GetXaxis().SetBinLabel(index+1,run)
0106 h_MEy_rms.GetXaxis().LabelsOption("v")
0107
0108 h_SumEt_mean.GetXaxis().SetBinLabel(index+1,run)
0109 h_SumEt_mean.GetXaxis().LabelsOption("v")
0110
0111 h_MET_mean.GetXaxis().SetBinLabel(index+1,run)
0112 h_MET_mean.GetXaxis().LabelsOption("v")
0113
0114 h_MEx_mean.GetXaxis().SetBinLabel(index+1,run)
0115 h_MEx_mean.GetXaxis().LabelsOption("v")
0116
0117 h_MEy_mean.GetXaxis().SetBinLabel(index+1,run)
0118 h_MEy_mean.GetXaxis().LabelsOption("v")
0119
0120
0121 try: os.makedirs(os.path.join(outputdir,run,"METDQM"))
0122 except OSError as err:
0123 if err.errno != errno.EEXIST: raise
0124
0125 for test in mettype:
0126 try: os.mkdir(os.path.join(outputdir,run,"METDQM",test))
0127 except OSError as err:
0128 if err.errno != errno.EEXIST: raise
0129
0130 rootfile = TFile(infilename)
0131
0132 if (test=="CaloMET"):
0133 try: os.mkdir(os.path.join(outputdir,run,"CaloTowers"))
0134 except OSError as err:
0135 if err.errno != errno.EEXIST: raise
0136
0137
0138 hist = "DQMData/Run %s/JetMET/Run summary/MET/%s/BasicCleanup/METTask_CaloSumET"%(run,test)
0139 rms = rootfile.Get(hist).GetRMS()
0140 mean = rootfile.Get(hist).GetMean()
0141 h_SumEt_rms.SetBinContent(index+1,rms)
0142 h_SumEt_mean.SetBinContent(index+1,mean)
0143
0144 hist = "DQMData/Run %s/JetMET/Run summary/MET/%s/BasicCleanup/METTask_CaloMET"%(run,test)
0145 rms = rootfile.Get(hist).GetRMS()
0146 mean = rootfile.Get(hist).GetMean()
0147 h_MET_rms.SetBinContent(index+1,rms)
0148 h_MET_mean.SetBinContent(index+1,mean)
0149
0150 hist = "DQMData/Run %s/JetMET/Run summary/MET/%s/BasicCleanup/METTask_CaloMEx"%(run,test)
0151 rms = rootfile.Get(hist).GetRMS()
0152 mean = rootfile.Get(hist).GetMean()
0153 h_MEx_rms.SetBinContent(index+1,rms)
0154 h_MEx_mean.SetBinContent(index+1,mean)
0155
0156 hist = "DQMData/Run %s/JetMET/Run summary/MET/%s/BasicCleanup/METTask_CaloMEy"%(run,test)
0157 rms = rootfile.Get(hist).GetRMS()
0158 mean = rootfile.Get(hist).GetMean()
0159 h_MEy_rms.SetBinContent(index+1,rms)
0160 h_MEy_mean.SetBinContent(index+1,mean)
0161
0162 plotdirectory = "DQMData/Run %s/JetMET/Run summary/MET/%s"%(run,test)
0163 if (rootfile.GetDirectory(plotdirectory)):
0164 metcmd = "plot_METDQM(\"%s\",\"%s\",%d,\"%s\",\"%s\")"%(infilename,reference,int(float(run)),outputdir,test)
0165 print(metcmd)
0166 ROOT.gROOT.ProcessLine(metcmd)
0167 else :
0168 print("Directory "+plotdirectory+" does not exist, not running creating plots.")
0169
0170
0171 try: os.makedirs(os.path.join(outputdir,run,"JetDQM","CaloJetAntiKt"))
0172 except OSError as err:
0173 if err.errno != errno.EEXIST: raise
0174
0175 jetcmd = "plot_jets_data_vs_MC(\"%s\",\"%s\",%d,\"%s\")"%(infilename,reference,int(float(run)),outputdir)
0176 print(jetcmd)
0177 ROOT.gROOT.ProcessLine(jetcmd)
0178 source = os.path.join(os.getcwd(),"result.root")
0179 destination = os.path.join(outputdir,run,"JetDQM")
0180 try: shutil.copy2(source,destination)
0181 except IOError as err:
0182 print("cannot copy:\n%s\n to\n%s"%(source,destination))
0183 print("I/O error(%d): %s"%(err.errno,err.strerror))
0184
0185
0186 if (outputdir.find("afs")!=1):
0187 source = os.path.join(inputdir,file)
0188 destination = os.path.join(outputdir,run)
0189 try: shutil.copy2(source,destination)
0190 except IOError as err:
0191 print("cannot copy:\n%s\n to\n%s"%(source,destination))
0192 print("I/O error(%d): %s"%(err.errno,err.strerror))
0193 else:
0194 print("will not copy source root files to afs due to space restrictions")
0195
0196 source = os.path.join(os.getcwd(),"UFAV.html")
0197 destination = os.path.join(outputdir,run)
0198 try: shutil.copy2(source,destination)
0199 except IOError as err:
0200 print("cannot copy:\n%s\n to\n%s"%(source,destination))
0201 print("I/O error(%d): %s"%(err.errno,err.strerror))
0202
0203 rmscanvas.cd(1)
0204 h_SumEt_rms.Draw("p")
0205 rmscanvas.cd(2)
0206 h_MET_rms.Draw("p")
0207 rmscanvas.cd(3)
0208 h_MEx_rms.Draw("p")
0209 rmscanvas.cd(4)
0210 h_MEy_rms.Draw("p")
0211
0212 meancanvas.cd(1)
0213 h_SumEt_mean.Draw("p")
0214 meancanvas.cd(2)
0215 h_MET_mean.Draw("p")
0216 meancanvas.cd(3)
0217 h_MEx_mean.Draw("p")
0218 meancanvas.cd(4)
0219 h_MEy_mean.Draw("p")
0220
0221 outfilename = "%s/rms.gif"%(outputdir)
0222 rmscanvas.SaveAs(outfilename)
0223 outfilename = "%s/mean.gif"%(outputdir)
0224 meancanvas.SaveAs(outfilename)