Skip to content

Commit

Permalink
Merge pull request #13 from nurfikri89/eff_analysis_nano_run2
Browse files Browse the repository at this point in the history
Changes for production & analysis with JMEnanoV1 UL17 inputs
  • Loading branch information
nurfikri89 authored Nov 10, 2020
2 parents 3a5c375 + decc4a6 commit fcd560f
Show file tree
Hide file tree
Showing 31 changed files with 1,893 additions and 218 deletions.
1 change: 1 addition & 0 deletions Analyzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nbinnorj.cc
119 changes: 119 additions & 0 deletions Analyzer/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,125 @@ float DeltaPhiNorm(float dphi){
}
return _dphi/TMath::Pi();
}
//
// https://github.com/cms-sw/cmssw/blob/CMSSW_10_6_17/RecoJets/JetProducers/python/PileupJetIDCutParams_cfi.py#L44
//
bool PUJetID_106XUL17Cut_WPTight(float pt, float eta, float disc){

if (pt > 0.0 && pt < 10.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.77;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.38;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.31;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.21;
}
else if (pt >= 10.0 && pt < 20.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.77;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.38;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.31;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.21;
}
else if (pt >= 20.0 && pt < 30.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.90;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.60;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.12;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.13;
}
else if (pt >= 30.0 && pt < 40.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.96;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.82;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > 0.20;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > 0.09;
}
else if (pt >= 40.0 && pt < 50.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.98;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.92;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > 0.47;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > 0.29;
}
else return true;

return true;
}
//
// https://github.com/cms-sw/cmssw/blob/CMSSW_10_6_17/RecoJets/JetProducers/python/PileupJetIDCutParams_cfi.py#L44
//
bool PUJetID_106XUL17Cut_WPMedium(float pt, float eta, float disc){

if (pt > 0.0 && pt < 10.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.26;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.33;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.54;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.37;
}
else if (pt >= 10.0 && pt < 20.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.26;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.33;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.54;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.37;
}
else if (pt >= 20.0 && pt < 30.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.68;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.04;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.43;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.30;
}
else if (pt >= 30.0 && pt < 40.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.90;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.36;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.16;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.09;
}
else if (pt >= 40.0 && pt < 50.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > 0.96;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > 0.61;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > 0.14;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > 0.12;
}
else return true;

return true;
}
//
// https://github.com/cms-sw/cmssw/blob/CMSSW_10_6_17/RecoJets/JetProducers/python/PileupJetIDCutParams_cfi.py#L44
//
bool PUJetID_106XUL17Cut_WPLoose(float pt, float eta, float disc){

if (pt > 0.0 && pt < 10.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > -0.95;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.72;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.68;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.47;
}
else if (pt >= 10.0 && pt < 20.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > -0.95;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.72;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.68;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.47;
}
else if (pt >= 20.0 && pt < 30.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > -0.88;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.55;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.60;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.43;
}
else if (pt >= 30.0 && pt < 40.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > -0.63;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.18;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.43;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.24;
}
else if (pt >= 40.0 && pt < 50.0){
if (std::abs(eta) >= 0.00 && std::abs(eta) < 2.50) return disc > -0.19;
else if (std::abs(eta) >= 2.50 && std::abs(eta) < 2.75) return disc > -0.22;
else if (std::abs(eta) >= 2.75 && std::abs(eta) < 3.00) return disc > -0.13;
else if (std::abs(eta) >= 3.00 && std::abs(eta) < 5.00) return disc > -0.03;
}
else return true;

return true;
}


//
// https://github.com/cms-sw/cmssw/blob/CMSSW_10_2_22/RecoJets/JetProducers/python/PileupJetIDCutParams_cfi.py
//
Expand Down
73 changes: 49 additions & 24 deletions Analyzer/MakeHistograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ROOT
import VariableList
import SampleList
import SampleListUL

ROOT.gROOT.SetBatch()
ROOT.gROOT.LoadMacro("./Helpers.h")
Expand All @@ -20,19 +21,35 @@
]

def main(sample_name, useSkimNtuples, systStr, useNewTraining=False):

isUL=False

crabFiles = []
ntupleFiles = []

if "DataUL" in sample_name or "MCUL" in sample_name:
EOSURL = SampleListUL.EOSURL
crabFiles = SampleListUL.Samples[sample_name].crabFiles
ntupleFiles = SampleListUL.Samples[sample_name].ntupleFiles
isUL=True
else:
EOSURL = SampleList.EOSURL
crabFiles = SampleList.Samples[sample_name].crabFiles
ntupleFiles = SampleList.Samples[sample_name].ntupleFiles


FileList = []

if useSkimNtuples:
print "Globbing File Paths:"
for files in SampleList.Samples[sample_name].ntupleFiles:
for files in ntupleFiles:
print files
FileList += [SampleList.EOSURL+f for f in glob.glob(files)]
FileList += [EOSURL+f for f in glob.glob(files)]
else:
print "Globbing File Paths:"
for files in SampleList.Samples[sample_name].crabFiles:
for files in crabFiles:
print files
FileList += [SampleList.EOSURL+f for f in glob.glob(files)]
FileList += [EOSURL+f for f in glob.glob(files)]

# Creating std::vector as filelist holder to be plugged into RDataFrame
vec = ROOT.vector('string')()
Expand Down Expand Up @@ -92,33 +109,42 @@ def main(sample_name, useSkimNtuples, systStr, useNewTraining=False):
df = df.Define("probeJet_dilep_dphi", probeJetStr+"_dilep_dphi")
if isMC:
df = df.Define("probeJet_passGenMatch",probeJetStr+"_gen_match")
if isUL:
df = df.Define("probeJet_puIdDiscOTF", probeJetStr+"_puIdDiscOTF")
#
#
#
df = df.Define("probeJet_dilep_dphi_norm","DeltaPhiNorm(probeJet_dilep_dphi)")
df = df.Define("probeJet_dilep_ptbalance","dilep_pt/probeJet_pt")
#
# Define pileup ID cuts
#
# Guide on how to read the pileup ID bitmap variable:
# https://twiki.cern.ch/twiki/bin/viewauth/CMS/PileupJetID#miniAOD_and_nanoAOD
# NOTE: The pileup ID decision flag stored in NanoAOD (v7 and earlier) is based on
# the 80X BDT training and working point (as in the parent MiniAOD).
#
if not useNewTraining:
df = df.Define("probeJet_puIdLoose_pass", "probeJet_puIdFlag_Loose")
df = df.Define("probeJet_puIdMedium_pass", "probeJet_puIdFlag_Medium")
df = df.Define("probeJet_puIdTight_pass", "probeJet_puIdFlag_Tight")
#
# Starting from NanoAODv7, the pileup ID BDT discriminant value is stored for each jet.
# The discriminant is calculated based on the appropriate training for each Run-2 year.
# i.e 80X for 2016, 94X for 2017 and 102X for 2018
#
else:
argStr = "probeJet_pt,probeJet_eta,probeJet_puIdDisc"
df = df.Define("probeJet_puIdLoose_pass", "PUJetID_80XCut_WPLoose("+argStr+")")
df = df.Define("probeJet_puIdMedium_pass", "PUJetID_80XCut_WPMedium("+argStr+")")
df = df.Define("probeJet_puIdTight_pass", "PUJetID_80XCut_WPTight("+argStr+")")
if not isUL: #EOY
#
# Guide on how to read the pileup ID bitmap variable:
# https://twiki.cern.ch/twiki/bin/viewauth/CMS/PileupJetID#miniAOD_and_nanoAOD
# NOTE: The pileup ID decision flag stored in NanoAOD (v7 and earlier) is based on
# the 80X BDT training and working point (as in the parent MiniAOD).
#
if not useNewTraining:
df = df.Define("probeJet_puIdLoose_pass", "probeJet_puIdFlag_Loose")
df = df.Define("probeJet_puIdMedium_pass", "probeJet_puIdFlag_Medium")
df = df.Define("probeJet_puIdTight_pass", "probeJet_puIdFlag_Tight")
#
# Starting from NanoAODv7, the pileup ID BDT discriminant value is stored for each jet.
# The discriminant is calculated based on the appropriate training for each Run-2 year.
# i.e 80X for 2016, 94X for 2017 and 102X for 2018
#
else:
argStr = "probeJet_pt,probeJet_eta,probeJet_puIdDisc"
df = df.Define("probeJet_puIdLoose_pass", "PUJetID_80XCut_WPLoose("+argStr+")")
df = df.Define("probeJet_puIdMedium_pass", "PUJetID_80XCut_WPMedium("+argStr+")")
df = df.Define("probeJet_puIdTight_pass", "PUJetID_80XCut_WPTight("+argStr+")")
else: #UL
argStr = "probeJet_pt,probeJet_eta,probeJet_puIdDiscOTF"
df = df.Define("probeJet_puIdLoose_pass", "PUJetID_106XUL17Cut_WPLoose("+argStr+")")
df = df.Define("probeJet_puIdMedium_pass", "PUJetID_106XUL17Cut_WPMedium("+argStr+")")
df = df.Define("probeJet_puIdTight_pass", "PUJetID_106XUL17Cut_WPTight("+argStr+")")
#
#
#
Expand Down Expand Up @@ -354,4 +380,3 @@ def main(sample_name, useSkimNtuples, systStr, useNewTraining=False):
elapsed = time_end - time_start
elapsed_str = str(datetime.timedelta(seconds=elapsed.seconds))
print("MakeHistograms.py::DONE::Sample("+args.sample+")::Time("+str(time_end)+")::Elapsed("+elapsed_str+")")

76 changes: 51 additions & 25 deletions Analyzer/MakeHistogramsHisto3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import array
import ROOT
import SampleList
import SampleListUL

ROOT.gROOT.SetBatch()
ROOT.gROOT.LoadMacro("./Helpers.h")
Expand Down Expand Up @@ -85,18 +86,33 @@

def main(sample_name, useSkimNtuples, systStr, useNewTraining=False):

isUL=False

crabFiles = []
ntupleFiles = []

if "DataUL" in sample_name or "MCUL" in sample_name:
EOSURL = SampleListUL.EOSURL
crabFiles = SampleListUL.Samples[sample_name].crabFiles
ntupleFiles = SampleListUL.Samples[sample_name].ntupleFiles
isUL=True
else:
EOSURL = SampleList.EOSURL
crabFiles = SampleList.Samples[sample_name].crabFiles
ntupleFiles = SampleList.Samples[sample_name].ntupleFiles

FileList = []

if useSkimNtuples:
print "Globbing File Paths:"
for files in SampleList.Samples[sample_name].ntupleFiles:
for files in ntupleFiles:
print files
FileList += [SampleList.EOSURL+f for f in glob.glob(files)]
FileList += [EOSURL+f for f in glob.glob(files)]
else:
print "Globbing File Paths:"
for files in SampleList.Samples[sample_name].crabFiles:
for files in crabFiles:
print files
FileList += [SampleList.EOSURL+f for f in glob.glob(files)]
FileList += [EOSURL+f for f in glob.glob(files)]

# Creating std::vector as filelist holder to be plugged into RDataFrame
vec = ROOT.vector('string')()
Expand Down Expand Up @@ -157,6 +173,8 @@ def main(sample_name, useSkimNtuples, systStr, useNewTraining=False):
df = df.Define("probeJet_dilep_dphi", probeJetStr+"_dilep_dphi")
if isMC:
df = df.Define("probeJet_passGenMatch", probeJetStr+"_gen_match")
if isUL:
df = df.Define("probeJet_puIdDiscOTF", probeJetStr+"_puIdDiscOTF")
#
#
#
Expand All @@ -165,25 +183,33 @@ def main(sample_name, useSkimNtuples, systStr, useNewTraining=False):
#
# Define pileup ID cuts
#
# Guide on how to read the pileup ID bitmap variable:
# https://twiki.cern.ch/twiki/bin/viewauth/CMS/PileupJetID#miniAOD_and_nanoAOD
# NOTE: The pileup ID decision flag stored in NanoAOD (v7 and earlier) is based on
# the 80X BDT training and working point (as in the parent MiniAOD).
#
if not useNewTraining:
df = df.Define("probeJet_puIdLoose_pass", "probeJet_puIdFlag_Loose")
df = df.Define("probeJet_puIdMedium_pass", "probeJet_puIdFlag_Medium")
df = df.Define("probeJet_puIdTight_pass", "probeJet_puIdFlag_Tight")
#
# Starting from NanoAODv7, the pileup ID BDT discriminant value is stored for each jet.
# The discriminant is calculated based on the appropriate training for each Run-2 year.
# i.e 80X for 2016, 94X for 2017 and 102X for 2018
#
else:
argStr = "probeJet_pt,probeJet_eta,probeJet_puIdDisc"
df = df.Define("probeJet_puIdLoose_pass", "PUJetID_80XCut_WPLoose("+argStr+")")
df = df.Define("probeJet_puIdMedium_pass", "PUJetID_80XCut_WPMedium("+argStr+")")
df = df.Define("probeJet_puIdTight_pass", "PUJetID_80XCut_WPTight("+argStr+")")
if not isUL: #EOY
#
# Guide on how to read the pileup ID bitmap variable:
# https://twiki.cern.ch/twiki/bin/viewauth/CMS/PileupJetID#miniAOD_and_nanoAOD
# NOTE: The pileup ID decision flag stored in NanoAOD (v7 and earlier) is based on
# the 80X BDT training and working point (as in the parent MiniAOD).
#
if not useNewTraining:
df = df.Define("probeJet_puIdLoose_pass", "probeJet_puIdFlag_Loose")
df = df.Define("probeJet_puIdMedium_pass", "probeJet_puIdFlag_Medium")
df = df.Define("probeJet_puIdTight_pass", "probeJet_puIdFlag_Tight")
#
# Starting from NanoAODv7, the pileup ID BDT discriminant value is stored for each jet.
# The discriminant is calculated based on the appropriate training for each Run-2 year.
# i.e 80X for 2016, 94X for 2017 and 102X for 2018
#
else:
argStr = "probeJet_pt,probeJet_eta,probeJet_puIdDisc"
df = df.Define("probeJet_puIdLoose_pass", "PUJetID_80XCut_WPLoose("+argStr+")")
df = df.Define("probeJet_puIdMedium_pass", "PUJetID_80XCut_WPMedium("+argStr+")")
df = df.Define("probeJet_puIdTight_pass", "PUJetID_80XCut_WPTight("+argStr+")")
else: #UL
if useNewTraining:
argStr = "probeJet_pt,probeJet_eta,probeJet_puIdDiscOTF"
df = df.Define("probeJet_puIdLoose_pass", "PUJetID_106XUL17Cut_WPLoose("+argStr+")")
df = df.Define("probeJet_puIdMedium_pass", "PUJetID_106XUL17Cut_WPMedium("+argStr+")")
df = df.Define("probeJet_puIdTight_pass", "PUJetID_106XUL17Cut_WPTight("+argStr+")")
#
#
#
Expand Down Expand Up @@ -335,7 +361,7 @@ def ProjectTH3(h3, HistoDict, systStrPost):
for hist3DName in Histograms3D:
Histograms3D[hist3DName].Write()

# Loop over the Histograms1D dictionary and store TH3 in ROOT file
# Loop over the Histograms1D dictionary and store TH1 in ROOT file
for histName in Histograms:
Histograms[histName].Write()

Expand All @@ -361,6 +387,7 @@ def ProjectTH3(h3, HistoDict, systStrPost):
isMC = False
if "MC" in args.sample:
isMC = True

#
# List all jet energy scale and resolution systematics
#
Expand All @@ -377,7 +404,6 @@ def ProjectTH3(h3, HistoDict, systStrPost):
if "AMCNLO" in args.sample: ak4Systematics=[]

ROOT.ROOT.EnableImplicitMT(args.cores)

#
# Do Nominal
#
Expand Down
10 changes: 10 additions & 0 deletions Analyzer/RunLocal_MakeHistograms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ SAMPLES=(
# Data18C_EGamma
# Data18D_EGamma
)
SAMPLES=(
# MCUL17_DY_MG
# MCUL17_DY_AMCNLO
# DataUL17B_DoubleMuon
# DataUL17C_DoubleMuon
# DataUL17D_DoubleMuon
# DataUL17E_DoubleMuon
# DataUL17F_DoubleMuon
)

#
# Make histograms from ntuples
#
Expand Down
Loading

0 comments on commit fcd560f

Please sign in to comment.