Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:12

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