diff --git a/ExampleInputFileList.txt b/ExampleInputFileList.txt new file mode 100644 index 0000000..2620325 --- /dev/null +++ b/ExampleInputFileList.txt @@ -0,0 +1 @@ +/store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/120000/3ED05633-EBB7-4A44-8F9D-CD956490BCFD.root diff --git a/ExampleInputFileList_data.txt b/ExampleInputFileList_data.txt new file mode 100644 index 0000000..10276de --- /dev/null +++ b/ExampleInputFileList_data.txt @@ -0,0 +1 @@ +/store/data/Run2018B/SingleMuon/NANOAOD/UL2018_MiniAODv2_NanoAODv9_GT36-v1/2430000/333071A2-4043-B340-BBDC-395EBF78EA33.root diff --git a/H4LCppModule.py b/H4LCppModule.py index 7a58940..813ff44 100644 --- a/H4LCppModule.py +++ b/H4LCppModule.py @@ -8,7 +8,7 @@ class HZZAnalysisCppProducer(Module): - def __init__(self,year,cfgFile,isMC): + def __init__(self,year,cfgFile,isMC,isFSR): base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" ROOT.gSystem.Load("%s/JHUGenMELA/MELA/data/slc7_amd64_gcc700/libJHUGenMELAMELA.so" % base) ROOT.gSystem.Load("%s/JHUGenMELA/MELA/data/slc7_amd64_gcc700/libjhugenmela.so" % base) @@ -53,6 +53,7 @@ def __init__(self,year,cfgFile,isMC): self.passZZEvts = 0 self.cfgFile = cfgFile self.isMC = isMC + self.worker.isFSR = isFSR pass def beginJob(self): pass @@ -275,10 +276,27 @@ def analyze(self, event): phij2 = self.worker.phij2 mj2 = self.worker.mj2 + if pTL2>pTL1: + pTL1, pTl2 = pTL2, pTL1 + etaL1, etaL2 = etaL2, etaL1 + phiL1, phiL2 = phiL2, phiL1 + massL1,massL2 = massL2, massL1 + if pTL4>pTL3: + pTL3, pTL4 = pTL4, pTL3 + etaL3, etaL4 = etaL4, etaL3 + phiL3, phiL4 = phiL4, phiL3 + massL3, massL4 = massL4, massL3 + + pT4l = self.worker.ZZsystem.Pt() eta4l = self.worker.ZZsystem.Eta() phi4l = self.worker.ZZsystem.Phi() mass4l = self.worker.ZZsystem.M() + if self.worker.isFSR==False: + pT4l = self.worker.ZZsystemnofsr.Pt() + eta4l = self.worker.ZZsystemnofsr.Eta() + phi4l = self.worker.ZZsystemnofsr.Phi() + mass4l = self.worker.ZZsystemnofsr.M() self.out.fillBranch("mass4l",mass4l) self.out.fillBranch("pT4l",pT4l) self.out.fillBranch("eta4l",eta4l) diff --git a/Utils b/Utils index 1901556..b06a036 160000 --- a/Utils +++ b/Utils @@ -1 +1 @@ -Subproject commit 19015568863964e49c13ada0ba36fbcfa4750df3 +Subproject commit b06a03675a56ff87d048d5a2bea987d719192809 diff --git a/condor_setup_lxplus.py b/condor_setup_lxplus.py index a536344..7851e4c 100644 --- a/condor_setup_lxplus.py +++ b/condor_setup_lxplus.py @@ -1,4 +1,8 @@ -import subprocess +""" +# How to run: +python3 condor_setup_lxplus.py +""" +import argparse import os import sys @@ -6,182 +10,209 @@ from color_style import style -# Variables to be changed by user -#StringToChange = "Run2016_v6_15June2020_MatteoWJetBinned" -#StringToChange = "Run2018_v6_DataReDoJEC" -StringToChange = "Run2017_v7_18Aug2020_Hadd" -customEOS = False -customEOS_cmd = 'eos root://cmseos.fnal.gov find -name "*.root" /store/group/lnujj/VVjj_aQGC/custom_nanoAOD' -#InputFileFromWhereReadDASNames = 'sample_list_v6_2016_campaign.dat' -#InputFileFromWhereReadDASNames = 'sample_list_v6_2017_campaign.dat' -#InputFileFromWhereReadDASNames = 'sample_list_v6_2018_campaign.dat' -#InputFileFromWhereReadDASNames = 'sample_list_v7_2016_campaign.dat' -#InputFileFromWhereReadDASNames = 'sample_list_v7_2017_eos_custom.dat' -InputFileFromWhereReadDASNames = 'sample_list_v7_2017_campaign.dat' - -Initial_path = '/eos/user/r/rasharma/post_doc_ihep/h2l2Q/' -Initial_path += StringToChange -condor_file_name = 'submit_condor_jobs_lnujj_'+StringToChange -condor_queue = "microcentury" -""" -Reference: https://twiki.cern.ch/twiki/bin/view/ABPComputing/LxbatchHTCondor#Queue_Flavours -Condor queue options -name Duration ------------------------- -espresso 20min -microcentury 1h -longlunch 2h -workday 8h 1nd -tomorrow 1d -testmatch 3d -nextweek 1w -""" - - -# Create log files -import infoCreaterGit -SumamryOfCurrentSubmission = raw_input("\n\nWrite summary for current job submission: ") -infoLogFiles = infoCreaterGit.BasicInfoCreater('summary.dat',SumamryOfCurrentSubmission) -infoLogFiles.GenerateGitPatchAndLog() - -# Get CMSSW directory path and name -cmsswDirPath = os.environ['CMSSW_BASE'] -CMSSWRel = cmsswDirPath.split("/")[-1] - -# Create directories for storing log files and output files at EOS. -import fileshelper -dirsToCreate = fileshelper.FileHelper('condor_logs/'+StringToChange, Initial_path) -output_log_path = dirsToCreate.CreateLogDirWithDate() -storeDir = dirsToCreate.CreateSotreArea(Initial_path) -dirName = dirsToCreate.dirName - -# create tarball of present working CMSSW base directory -os.system('rm -f CMSSW*.tgz') -import makeTarFile -makeTarFile.make_tarfile(cmsswDirPath, CMSSWRel+".tgz") -print "copying the "+CMSSWRel+".tgz file to eos path: "+storeDir+"\n" -os.system('cp ' + CMSSWRel+".tgz" + ' '+storeDir+'/' + CMSSWRel+".tgz") - -post_proc_to_run = "post_proc.py" -command = "python "+post_proc_to_run - -Transfer_Input_Files = ("Cert_271036-284044_13TeV_PromptReco_Collisions16_JSON.txt, " + - "Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt, " + - "Cert_314472-325175_13TeV_PromptReco_Collisions18_JSON.txt, " + - "keep_and_drop_data.txt") - -#with open('input_data_Files/sample_list_v6_2017_campaign.dat') as in_file: -with open('input_data_Files/'+InputFileFromWhereReadDASNames) as in_file: - outjdl_file = open(condor_file_name+".jdl","w") - outjdl_file.write("+JobFlavour = \""+condor_queue+"\"\n") - outjdl_file.write("Executable = "+condor_file_name+".sh\n") - outjdl_file.write("Universe = vanilla\n") - outjdl_file.write("Notification = ERROR\n") - outjdl_file.write("Should_Transfer_Files = YES\n") - outjdl_file.write("WhenToTransferOutput = ON_EXIT\n") - #outjdl_file.write("Transfer_Input_Files = "+Transfer_Input_Files + ", " + post_proc_to_run+"\n") - outjdl_file.write("x509userproxy = $ENV(X509_USER_PROXY)\n") - count = 0 - count_jobs = 0 - for lines in in_file: - if lines[0] == "#": continue - count = count +1 - #if count > 1: break - print(style.RED +"="*51+style.RESET+"\n") - print "==> Sample : ",count - sample_name = lines.split('/')[1] - campaign = lines.split('/')[2].split('-')[0] - print "==> sample_name = ",sample_name - print "==> campaign = ",campaign - ######################################## - # - # Create output directory - # - ######################################## - if sample_name.find("SingleMuon") != -1 or sample_name.find("SingleElectron") != -1 or sample_name.find("EGamma") != -1 or sample_name.find("DoubleMuon") != -1 or sample_name.find("MuonEG") != -1 or sample_name.find("DoubleEG") != -1: - output_string = sample_name + os.sep + campaign + os.sep + dirName - output_path = Initial_path + os.sep + output_string - os.system("mkdir "+Initial_path + os.sep + sample_name) - os.system("mkdir "+Initial_path + os.sep + sample_name + os.sep + campaign) - os.system("mkdir "+ Initial_path + os.sep + sample_name + os.sep + campaign + os.sep + dirName) - infoLogFiles.SendGitLogAndPatchToEos(Initial_path + os.sep + sample_name + os.sep + campaign + os.sep + dirName) - else: - output_string = sample_name+os.sep+dirName - output_path = Initial_path+ os.sep + output_string - os.system("mkdir "+Initial_path + os.sep + sample_name) - os.system("mkdir "+Initial_path + os.sep + sample_name+os.sep+dirName) - infoLogFiles.SendGitLogAndPatchToEos(Initial_path + os.sep + sample_name + os.sep + dirName) - print "==> output_path = ",output_path - - ######################################## - #print 'dasgoclient --query="file dataset='+lines.strip()+'"' - #print "..." - if customEOS: - xrd_redirector = 'root://cmseos.fnal.gov/' - output = os.popen(customEOS_cmd + lines.strip()).read() - else: - xrd_redirector = 'root://cms-xrd-global.cern.ch/' - output = os.popen('dasgoclient --query="file dataset='+lines.strip()+'"').read() - - count_root_files = 0 - for root_file in output.split(): - #print "=> ",root_file - count_root_files+=1 - count_jobs += 1 - outjdl_file.write("Output = "+output_log_path+"/"+sample_name+"_$(Process).stdout\n") - outjdl_file.write("Error = "+output_log_path+"/"+sample_name+"_$(Process).stdout\n") - outjdl_file.write("Log = "+output_log_path+"/"+sample_name+"_$(Process).log\n") - outjdl_file.write("Arguments = "+(xrd_redirector+root_file).replace('/','\/')+" "+output_path+" "+Initial_path+"\n") - outjdl_file.write("Queue \n") - print "Number of files: ",count_root_files - print "Number of jobs (till now): ",count_jobs - outjdl_file.close(); - - -outScript = open(condor_file_name+".sh","w"); -outScript.write('#!/bin/bash'); -outScript.write("\n"+'echo "Starting job on " `date`'); -outScript.write("\n"+'echo "Running on: `uname -a`"'); -outScript.write("\n"+'echo "System software: `cat /etc/redhat-release`"'); -outScript.write("\n"+'source /cvmfs/cms.cern.ch/cmsset_default.sh'); -outScript.write("\n"+'echo "copy cmssw tar file from store area"'); -outScript.write("\n"+'cp -s ${3}/'+CMSSWRel +'.tgz .'); -outScript.write("\n"+'tar -xf '+ CMSSWRel +'.tgz' ); -outScript.write("\n"+'rm '+ CMSSWRel +'.tgz' ); -outScript.write("\n"+'cd ' + CMSSWRel + '/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/' ); -#outScript.write("\n"+'echo "====> List files : " '); -#outScript.write("\n"+'ls -alh'); -outScript.write("\n"+'rm *.root'); -outScript.write("\n"+'scramv1 b ProjectRename'); -outScript.write("\n"+'eval `scram runtime -sh`'); -outScript.write("\n"+'sed -i "s/testfile = .*/testfile = \\"${1}\\"/g" '+post_proc_to_run); -outScript.write("\n"+'echo "========================================="'); -outScript.write("\n"+'echo "cat post_proc.py"'); -outScript.write("\n"+'echo "..."'); -outScript.write("\n"+'cat post_proc.py'); -outScript.write("\n"+'echo "..."'); -outScript.write("\n"+'echo "========================================="'); -outScript.write("\n"+command); -outScript.write("\n"+'echo "====> List root files : " '); -outScript.write("\n"+'ls *.root'); -outScript.write("\n"+'echo "====> copying *.root file to stores area..." '); -outScript.write("\n"+'if ls *_Skim.root 1> /dev/null 2>&1; then'); -outScript.write("\n"+' echo "File *_Skim.root exists. Copy this."'); -outScript.write("\n"+' echo "cp *_Skim.root ${2}"'); -outScript.write("\n"+' cp *_Skim.root ${2}'); -outScript.write("\n"+'else'); -outScript.write("\n"+' echo "file *_Skim.root does not exists, so copy *.root file."'); -outScript.write("\n"+' echo "cp *.root ${2}"'); -outScript.write("\n"+' cp *.root ${2}'); -outScript.write("\n"+'fi'); -outScript.write("\n"+'rm *.root'); -outScript.write("\n"+'cd ${_CONDOR_SCRATCH_DIR}'); -outScript.write("\n"+'rm -rf ' + CMSSWRel); -outScript.write("\n"); -outScript.close(); -os.system("chmod 777 "+condor_file_name+".sh"); - -print "===> Set Proxy Using:"; -print "\tvoms-proxy-init --voms cms --valid 168:00"; -print "\"condor_submit "+condor_file_name+".jdl\" to submit"; -#os.system("condor_submit "+condor_file_name+".jdl") +def main(args): + + # Variables from argparse + submission_name = args.submission_name + use_custom_eos = args.use_custom_eos + use_custom_eos_cmd = args.use_custom_eos_cmd + InputFileFromWhereReadDASNames = args.input_file + EOS_Output_path = args.eos_output_path + condor_file_name = args.condor_file_name + condor_queue = args.condor_queue + condor_log_path = args.condor_log_path + createTarFile = args.createTarFile + + # Get top-level directory name from PWD + TOP_LEVEL_DIR_NAME = os.path.basename(os.getcwd()) + + EOS_Output_path += submission_name + condor_file_name = 'submit_condor_jobs_lnujj_'+submission_name + + # Create log files + import infoCreaterGit + SumamryOfCurrentSubmission = input("\n\nWrite summary for current job submission: ") + infoLogFiles = infoCreaterGit.BasicInfoCreater('summary.dat',SumamryOfCurrentSubmission) + infoLogFiles.generate_git_patch_and_log() + + # Get CMSSW directory path and name + cmsswDirPath = os.environ['CMSSW_BASE'] + CMSSWRel = cmsswDirPath.split("/")[-1] + + # Create directories for storing log files and output files at EOS. + import fileshelper + dirsToCreate = fileshelper.FileHelper( (condor_log_path + '/condor_logs/'+submission_name).replace("//","/"), EOS_Output_path) + output_log_path = dirsToCreate.create_log_dir_with_date() + storeDir = dirsToCreate.create_store_area(EOS_Output_path) + dirName = dirsToCreate.dir_name + + # create tarball of present working CMSSW base directory + if createTarFile: os.system('rm -f CMSSW*.tgz') + import makeTarFile + if createTarFile: makeTarFile.make_tarfile(cmsswDirPath, CMSSWRel+".tgz") + print("copying the "+CMSSWRel+".tgz file to eos path: "+storeDir+"\n") + os.system('cp ' + CMSSWRel+".tgz" + ' '+storeDir+'/' + CMSSWRel+".tgz") + + post_proc_to_run = "post_proc.py" + command = "python "+post_proc_to_run + + Transfer_Input_Files = ("keep_and_drop.txt") # FIXME: Generalise this. + # Transfer_Input_Files = ("Cert_271036-284044_13TeV_PromptReco_Collisions16_JSON.txt, " + + # "Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt, " + + # "Cert_314472-325175_13TeV_PromptReco_Collisions18_JSON.txt, " + + # "keep_and_drop_data.txt") + + #with open('input_data_Files/sample_list_v6_2017_campaign.dat') as in_file: + with open('input_data_Files/'+InputFileFromWhereReadDASNames) as in_file: + outjdl_file = open(condor_file_name+".jdl","w") + outjdl_file.write("+JobFlavour = \""+condor_queue+"\"\n") + outjdl_file.write("Executable = "+condor_file_name+".sh\n") + outjdl_file.write("Universe = vanilla\n") + outjdl_file.write("Notification = ERROR\n") + outjdl_file.write("Should_Transfer_Files = YES\n") + outjdl_file.write("WhenToTransferOutput = ON_EXIT\n") + outjdl_file.write("Transfer_Input_Files = "+Transfer_Input_Files + ", " + post_proc_to_run+"\n") + outjdl_file.write("x509userproxy = $ENV(X509_USER_PROXY)\n") + count = 0 + count_jobs = 0 + for lines in in_file: + if lines[0] == "#": continue + count = count +1 + #if count > 1: break + print(style.RED +"="*51+style.RESET+"\n") + print ("==> Sample : ",count) + sample_name = lines.split('/')[1] + campaign = lines.split('/')[2].split('-')[0] + print("==> sample_name = ",sample_name) + print("==> campaign = ",campaign) + ######################################## + # + # Create output directory + # + ######################################## + if sample_name.find("SingleMuon") != -1 or sample_name.find("SingleElectron") != -1 or sample_name.find("EGamma") != -1 or sample_name.find("DoubleMuon") != -1 or sample_name.find("MuonEG") != -1 or sample_name.find("DoubleEG") != -1: + output_string = sample_name + os.sep + campaign + os.sep + dirName + output_path = EOS_Output_path + os.sep + output_string + os.system("mkdir "+EOS_Output_path + os.sep + sample_name) + os.system("mkdir "+EOS_Output_path + os.sep + sample_name + os.sep + campaign) + os.system("mkdir "+ EOS_Output_path + os.sep + sample_name + os.sep + campaign + os.sep + dirName) + infoLogFiles.send_git_log_and_patch_to_eos(EOS_Output_path + os.sep + sample_name + os.sep + campaign + os.sep + dirName) + else: + output_string = sample_name+os.sep+dirName + output_path = EOS_Output_path+ os.sep + output_string + os.system("mkdir "+EOS_Output_path + os.sep + sample_name) + os.system("mkdir "+EOS_Output_path + os.sep + sample_name+os.sep+dirName) + infoLogFiles.send_git_log_and_patch_to_eos(EOS_Output_path + os.sep + sample_name + os.sep + dirName) + # print "==> output_path = ",output_path + + ######################################## + #print 'dasgoclient --query="file dataset='+lines.strip()+'"' + #print "..." + if use_custom_eos: + xrd_redirector = 'root://cms-xrd-global.cern.ch/' + output = os.popen(use_custom_eos_cmd + lines.strip()).read() + else: + xrd_redirector = 'root://cms-xrd-global.cern.ch/' + output = os.popen('dasgoclient --query="file dataset='+lines.strip()+'"').read() + + count_root_files = 0 + for root_file in output.split(): + #print "=> ",root_file + count_root_files+=1 + count_jobs += 1 + outjdl_file.write("Output = "+output_log_path+"/"+sample_name+"_$(Process).stdout\n") + outjdl_file.write("Error = "+output_log_path+"/"+sample_name+"_$(Process).stdout\n") + outjdl_file.write("Log = "+output_log_path+"/"+sample_name+"_$(Process).log\n") + outjdl_file.write("Arguments = "+(xrd_redirector+root_file).replace('/','\/')+" "+output_path+" "+EOS_Output_path+"\n") + outjdl_file.write("Queue \n") + print("Number of files: ",count_root_files) + print("Number of jobs (till now): ",count_jobs) + outjdl_file.close(); + + + outScript = open(condor_file_name+".sh","w"); + outScript.write('#!/bin/bash'); + outScript.write("\n"+'echo "Starting job on " `date`'); + outScript.write("\n"+'echo "Running on: `uname -a`"'); + outScript.write("\n"+'echo "System software: `cat /etc/redhat-release`"'); + outScript.write("\n"+'source /cvmfs/cms.cern.ch/cmsset_default.sh'); + outScript.write("\n"+'echo "copy cmssw tar file from store area"'); + outScript.write("\n"+'cp -s ${3}/'+CMSSWRel +'.tgz .'); + outScript.write("\n"+'tar -xf '+ CMSSWRel +'.tgz' ); + outScript.write("\n"+'rm '+ CMSSWRel +'.tgz' ); + outScript.write("\n"+'cd ' + CMSSWRel + '/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/'+TOP_LEVEL_DIR_NAME+'/' ); + #outScript.write("\n"+'echo "====> List files : " '); + #outScript.write("\n"+'ls -alh'); + outScript.write("\n"+'rm *.root'); + outScript.write("\n"+'scramv1 b ProjectRename'); + outScript.write("\n"+'eval `scram runtime -sh`'); + outScript.write("\n"+'sed -i "s/ifRunningOnCondor = .*/ifRunningOnCondor = True/g" '+post_proc_to_run); + outScript.write("\n"+'sed -i "s/testfile = .*/testfile = \\"${1}\\"/g" '+post_proc_to_run); + outScript.write("\n"+'echo "========================================="'); + outScript.write("\n"+'echo "cat post_proc.py"'); + outScript.write("\n"+'echo "..."'); + outScript.write("\n"+'cat post_proc.py'); + outScript.write("\n"+'echo "..."'); + outScript.write("\n"+'echo "========================================="'); + outScript.write("\n"+command); + outScript.write("\n"+'echo "====> List root files : " '); + outScript.write("\n"+'ls *.root'); + outScript.write("\n"+'echo "====> copying *.root file to stores area..." '); + outScript.write("\n"+'if ls *_Skim.root 1> /dev/null 2>&1; then'); + outScript.write("\n"+' echo "File *_Skim.root exists. Copy this."'); + outScript.write("\n"+' echo "cp *_Skim.root ${2}"'); + outScript.write("\n"+' cp *_Skim.root ${2}'); + outScript.write("\n"+'else'); + outScript.write("\n"+' echo "file *_Skim.root does not exists, so copy *.root file."'); + outScript.write("\n"+' echo "cp *.root ${2}"'); + outScript.write("\n"+' cp *.root ${2}'); + outScript.write("\n"+'fi'); + outScript.write("\n"+'rm *.root'); + outScript.write("\n"+'cd ${_CONDOR_SCRATCH_DIR}'); + outScript.write("\n"+'rm -rf ' + CMSSWRel); + outScript.write("\n"); + outScript.close(); + os.system("chmod 777 "+condor_file_name+".sh"); + + print("\n#===> Set Proxy Using:") + print("voms-proxy-init --voms cms --valid 168:00") + print("\n# It is assumed that the proxy is created in file: /tmp/x509up_u48539. Update this in below two lines:") + print("cp /tmp/x509up_u48539 ~/") + print("export X509_USER_PROXY=~/x509up_u48539") + print("\n#Submit jobs:") + print("condor_submit "+condor_file_name+".jdl") + #os.system("condor_submit "+condor_file_name+".jdl") + +# Below patch is to format the help command as it is +class PreserveWhitespaceFormatter(argparse.RawTextHelpFormatter, argparse.ArgumentDefaultsHelpFormatter): + pass + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Condor Job Submission", formatter_class=PreserveWhitespaceFormatter) + parser.add_argument("--submission_name", default="Run2018_v9", help="String to be changed by user.") + parser.add_argument("--use_custom_eos", default=False, action='store_true', help="Use custom EOS.") + parser.add_argument("--createTarFile", default=True, action='store_false', help="Use custom EOS.") + parser.add_argument("--use_custom_eos_cmd", default='eos root://cmseos.fnal.gov find -name "*.root" /store/group/lnujj/VVjj_aQGC/custom_nanoAOD', help="Custom EOS command.") + parser.add_argument("--input_file", default='sample_list_v9_2018_campaign.dat', help="Input file from where to read DAS names.") + parser.add_argument("--eos_output_path", default='/eos/user/a/avijay/Higgs_020723', help="Initial path for operations.") + parser.add_argument("--condor_log_path", default='./', help="Path where condor log should be saved. By default is the current working directory") + parser.add_argument("--condor_file_name", default='submit_condor_jobs_lnujj_', help="Name for the condor file.") + parser.add_argument("--condor_queue", default="microcentury", help=""" + Condor queue options: (Reference: https://twiki.cern.ch/twiki/bin/view/ABPComputing/LxbatchHTCondor#Queue_Flavours) + + name Duration + ------------------------ + espresso 20min + microcentury 1h + longlunch 2h + workday 8h 1nd + tomorrow 1d + testmatch 3d + nextweek 1w + """) + + parser.add_argument("--post_proc", default="post_proc.py", help="Post process script to run.") + parser.add_argument("--transfer_input_files", default="keep_and_drop.txt", help="Files to be transferred as input.") + + args = parser.parse_args() + main(args) diff --git a/interface/H4LTools.h b/interface/H4LTools.h index b84eba6..6ef7f56 100644 --- a/interface/H4LTools.h +++ b/interface/H4LTools.h @@ -253,6 +253,7 @@ class H4LTools { FsrPhoton_dROverEt2.clear();FsrPhoton_phi.clear();FsrPhoton_eta.clear();FsrPhoton_pt.clear();FsrPhoton_relIso03.clear(); GenPart_pt.clear(); Zlist.clear(); + Zlistnofsr.clear(); Zflavor.clear(); Zlep1index.clear(); Zlep2index.clear(); @@ -279,7 +280,8 @@ class H4LTools { flag4e=false; flag4mu=false; flag2e2mu=false; } - + bool isFSR=true; + unsigned int Zsize=0; TSpline *spline_g4; TSpline *spline_g2; TSpline *spline_L1; diff --git a/post_proc.py b/post_proc.py index 51d4eea..c738598 100755 --- a/post_proc.py +++ b/post_proc.py @@ -7,56 +7,54 @@ from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import * from PhysicsTools.NanoAODTools.postprocessing.modules.btv.btagSFProducer import * -testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/120000/3ED05633-EBB7-4A44-8F9D-CD956490BCFD.root" -#testfile1 = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/270000/1B1D7372-F369-7C40-A85F-841308D42D2C.root" -#testfile2 = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/270000/2BA7CCC9-BA73-3C45-9844-474A92E58A28.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M120_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/270000/1D8ACDF9-FCA6-7649-95A4-487A132F318D.root" -#testfile1 = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M120_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/130000/6EA35A9B-C42E-0447-ACED-E3AC70A7AD7E.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M124_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/70000/1AAFFFBE-330D-EF42-B39E-BA70A7E90669.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M126_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/280000/8198816C-2B6D-CB41-9B96-6B02BD81CAAE.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/VBF_HToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/2430000/13F76A9B-76DD-144B-B328-A8C207376C08.root" -#testfile1 = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M130_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/70000/00305042-7CD7-2C46-8FD6-D1089E4C4163.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/FD91C4F0-7DE3-4947-817D-3EA957A0BC50.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/VBF_HToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/80000/3F65CE54-8477-C64E-B0BB-BD77E870AB54.root" -#testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo2L2Q_M1000_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/280000/7F817CD1-84C1-5347-AEEA-F069CAE84799.root" +ifRunningOnCondor = False + testfilelist = [] -testfilelist.append("root://cms-xrd-global.cern.ch//store/data/Run2018B/SingleMuon/NANOAOD/UL2018_MiniAODv2_NanoAODv9_GT36-v1/2430000/87FA9714-D8D3-1345-BFF5-3B417B1ADC64.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/130000/4743B911-1EA3-7E46-959B-93F466ED622F.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/130000/DE3F93DE-DAF6-DD4A-AC3B-13ACE92EAD68.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/2430000/336F0076-347C-AC40-B1B4-E31E14323B81.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/100D0E96-C700-5244-874F-38DB4B410228.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/28512C40-9C25-864A-98E9-4746C0471E63.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/2BAB6B06-FFE2-DC4F-A57F-3A33B3326A30.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/453FC70D-8164-1B4B-A756-81E7432C1D61.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/5C1E0BC2-F153-E946-9B61-470E8AF85C58.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/9DB74D60-0434-A04C-B430-173D6D6538C3.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/DB3B1648-246F-314E-9DD8-FACEA0AE62F6.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/260000/FD91C4F0-7DE3-4947-817D-3EA957A0BC50.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/270000/6021CDF7-AE6F-464D-81E2-AB75ABC4809D.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/270000/77B90DAA-35B9-004E-9C49-52E516FB15D6.root") -testfilelist.append("root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL17NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_mc2017_realistic_v9-v2/270000/C01084F4-328D-0146-B71E-B167AB6A7E86.root") - -entriesToRun = 0 # 0 if need to run over all entries else put number of entries to run -isMCTrueFalse = False + +if ifRunningOnCondor: + testfile = "root://cms-xrd-global.cern.ch//store/mc/RunIISummer20UL18NanoAODv9/GluGluHToZZTo4L_M125_TuneCP5_13TeV_powheg2_JHUGenV7011_pythia8/NANOAODSIM/106X_upgrade2018_realistic_v16_L1v1-v1/120000/3ED05633-EBB7-4A44-8F9D-CD956490BCFD.root" + testfilelist.append(testfile) + +else: + if len(sys.argv) > 1: + InputFileList = sys.argv[1] + else: + InputFileList = "ExampleInputFileList.txt" + with open(InputFileList, 'r') as file: + for line in file: + # Remove newline characters + line = line.strip() + # Append the line to the list with the "root://cms-xrd-global.cern.ch//" prefix + testfilelist.append("root://cms-xrd-global.cern.ch/" + line) + +# Set entriesToRun = 0 if need to run over all entries else put number of entries to run +entriesToRun = 0 if ifRunningOnCondor else 100 + +isMC = True +isFSR = False + +outputbranchsel = "keep_and_drop.txt" # Keep DownloadFileToLocalThenRun=True this should reduce the file read error from eos. DownloadFileToLocalThenRun=True -if testfilelist[0].find("2018") != -1: - year = 2018 - cfgFile = 'Input_2018.yml' -if testfilelist[0].find("2017") != -1: - year = 2017 - cfgFile = 'Input_2017.yml' -if testfilelist[0].find("UL18") != -1: + +if testfilelist[0].find("/data/") != -1: + isMC = False + outputbranchsel = "keep_and_drop_data.txt" + +if testfilelist[0].find("UL18") != -1 or testfilelist[0].find("UL2018") != -1: # UL2018 for identification of 2018 UL data and UL18 for identification of 2018 UL MC year = 2018 cfgFile = 'Input_2018.yml' -if testfilelist[0].find("UL17") != -1: + +if testfilelist[0].find("UL17") != -1 or testfilelist[0].find("UL2017") != -1: year = 2017 cfgFile = 'Input_2017.yml' -if testfilelist[0].find("pythia") != -1: - isMCTrueFalse = True -H4LCppModule = lambda: HZZAnalysisCppProducer(year,cfgFile,isMCTrueFalse) + +H4LCppModule = lambda: HZZAnalysisCppProducer(year,cfgFile, isMC, isFSR) +print("outputbranchsel = ",outputbranchsel) +print("isMC = ",isMC) +print("isFSR = ",isFSR) #p=PostProcessor(".",[testfile],"",None,[H4LCppModule()],provenance=True,fwkJobReport=False,haddFileName="nano_M125.root",maxEntries=entriesToRun,prefetch=DownloadFileToLocalThenRun,outputbranchsel="keep_and_drop.txt") -p=PostProcessor(".",testfilelist,"",None,[H4LCppModule()],provenance=True,fwkJobReport=False,haddFileName="nano_M125_cpp.root",maxEntries=entriesToRun,prefetch=DownloadFileToLocalThenRun,outputbranchsel="keep_and_drop.txt") +p=PostProcessor(".",testfilelist,"",None,[H4LCppModule()],provenance=True,fwkJobReport=False,haddFileName="nano_M125_cpp.root",maxEntries=entriesToRun,prefetch=DownloadFileToLocalThenRun,outputbranchsel=outputbranchsel) p.run() print "DONE" diff --git a/src/H4LTools.cc b/src/H4LTools.cc index 6130ce2..9e5fa63 100644 --- a/src/H4LTools.cc +++ b/src/H4LTools.cc @@ -150,11 +150,10 @@ unsigned H4LTools::doFsrRecovery(TLorentzVector Lep){ fsrcand.SetPtEtaPhiM(FsrPhoton_pt[BestFsrPhotons[i]],FsrPhoton_eta[BestFsrPhotons[i]],FsrPhoton_phi[BestFsrPhotons[i]],0); float dRlC,dRlOverPtC; dRlC = fsrcand.DeltaR(Lep); - dRlOverPtC = dRl/(fsrcand.Pt()*fsrcand.Pt()); - if ((dRlCkSmearMC(charge, pt, eta, phi, nLayers, u1); } } @@ -354,37 +354,44 @@ void H4LTools::LeptonSelection(){ ElelistFsr = BatchFsrRecovery(Elelist); MulistFsr = BatchFsrRecovery(Mulist); - + for(unsigned int ae=0; ae0.01){ - RelEleIsoNoFsr = RelEleIsoNoFsr - FsrPhoton_pt[FsrEleidx]/Elelist[ae].Pt(); - } + if (isFSR){ + unsigned int FsrEleidx; + FsrEleidx = doFsrRecovery(Elelist[ae]); + if(FsrEleidx<900){ + TLorentzVector fsrele; + fsrele.SetPtEtaPhiM(FsrPhoton_pt[FsrEleidx],FsrPhoton_eta[FsrEleidx],FsrPhoton_phi[FsrEleidx],0); + std::cout<<"Ele correction: "<< std::endl; + if(Elelist[ae].DeltaR(fsrele)>0.01){ + RelEleIsoNoFsr = RelEleIsoNoFsr - FsrPhoton_pt[FsrEleidx]/Elelist[ae].Pt(); + } + } } if((Eid[ae]==true)&&(RelEleIsoNoFsr<0.35)){ nTightEle++; TightEleindex.push_back(ae); nTightEleChgSum += Elechg[ae]; } + } for(unsigned int amu=0; amu0.01){ - RelIsoNoFsr = RelIsoNoFsr - FsrPhoton_pt[FsrMuonidx]/Mulist[amu].Pt(); - } + if (isFSR){ + unsigned int FsrMuonidx; + FsrMuonidx = doFsrRecovery(Mulist[amu]); + if(FsrMuonidx<900){ + TLorentzVector fsrmuon; + fsrmuon.SetPtEtaPhiM(FsrPhoton_pt[FsrMuonidx],FsrPhoton_eta[FsrMuonidx],FsrPhoton_phi[FsrMuonidx],0); + std::cout<<"muon FSR recovered"<0.01){ + RelIsoNoFsr = RelIsoNoFsr - FsrPhoton_pt[FsrMuonidx]/Mulist[amu].Pt(); + } + } } if((muid[amu]==true)&&(RelIsoNoFsr<0.35)){ nTightMu++; @@ -490,7 +497,9 @@ bool H4LTools::findZCandidate(){ Zlistnofsr.push_back(Zcannofsr); } - if (Zlist.size()>0){ + + Zsize = Zlist.size(); + if (Zsize>0){ return true; } else{ @@ -514,7 +523,7 @@ bool H4LTools::ZZSelection(){ if((abs(nTightEleChgSum)+abs(nTightMuChgSum))>(nTightMu+nTightEle-4)){ return foundZZCandidate; } - if(Zlist.size()<2){ + if(Zsize<2){ return foundZZCandidate; } @@ -676,11 +685,17 @@ bool H4LTools::ZZSelection(){ Z1nofsr = Zlistnofsr[Z1index]; Z2nofsr = Zlistnofsr[Z2index]; - ZZsystem = Z1+Z2; ZZsystemnofsr = Z1nofsr+Z2nofsr; + + /*if(abs(ZZsystemnofsr.M()-ZZsystem.M())>0.000001){ + std::cout<<"FSR works "<HiggscutDown)&&(massZZ