Skip to content

Commit

Permalink
Merge pull request #4 from ram1123/HZZ_Analysis_2l2q_v2_devR
Browse files Browse the repository at this point in the history
Golden JSON, cuts to YAML
  • Loading branch information
Anusreevijay769 authored Sep 26, 2023
2 parents de85625 + 9d778d9 commit 9abc594
Show file tree
Hide file tree
Showing 31 changed files with 2,952 additions and 267 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 1 addition & 0 deletions ExampleInputFileList.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ExampleInputFileList_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/store/data/Run2018B/SingleMuon/NANOAOD/UL2018_MiniAODv2_NanoAODv9_GT36-v1/2430000/333071A2-4043-B340-BBDC-395EBF78EA33.root
58 changes: 50 additions & 8 deletions H4LCppModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class HZZAnalysisCppProducer(Module):
def __init__(self, isMC, year,cfgFile):
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)
Expand Down Expand Up @@ -40,11 +40,22 @@ def __init__(self, isMC, year,cfgFile):
with open(cfgFile, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
RoccoRPath = cfg['RoccoRPath']
self.worker = ROOT.H4LTools(self.year, RoccoRPath)
self.worker = ROOT.H4LTools(self.year, RoccoRPath)
self.worker.InitializeElecut(cfg['Electron']['pTcut'],cfg['Electron']['Etacut'],cfg['Electron']['Sip3dcut'],cfg['Electron']['Loosedxycut'],cfg['Electron']['Loosedzcut'],
cfg['Electron']['Isocut'],cfg['Electron']['BDTWP']['LowEta']['LowPT'],cfg['Electron']['BDTWP']['MedEta']['LowPT'],cfg['Electron']['BDTWP']['HighEta']['LowPT'],
cfg['Electron']['BDTWP']['LowEta']['HighPT'],cfg['Electron']['BDTWP']['MedEta']['HighPT'],cfg['Electron']['BDTWP']['HighEta']['HighPT'])
self.worker.InitializeMucut(cfg['Muon']['pTcut'],cfg['Muon']['Etacut'],cfg['Muon']['Sip3dcut'],cfg['Muon']['Loosedxycut'],cfg['Muon']['Loosedzcut'],cfg['Muon']['Isocut'],
cfg['Muon']['Tightdxycut'],cfg['Muon']['Tightdzcut'],cfg['Muon']['TightTrackerLayercut'],cfg['Muon']['TightpTErrorcut'],cfg['Muon']['HighPtBound'])
self.worker.InitializeFsrPhotonCut(cfg['FsrPhoton']['pTcut'],cfg['FsrPhoton']['Etacut'],cfg['FsrPhoton']['Isocut'],cfg['FsrPhoton']['dRlcut'],cfg['FsrPhoton']['dRlOverPtcut'])
self.worker.InitializeJetcut(cfg['Jet']['pTcut'],cfg['Jet']['Etacut'])
self.worker.InitializeEvtCut(cfg['MZ1cut'],cfg['MZZcut'],cfg['Higgscut']['down'],cfg['Higgscut']['up'],cfg['Zmass'],cfg['MZcut']['down'],cfg['MZcut']['up'])

self.passtrigEvts = 0
self.noCutsEvts = 0
self.passZZEvts = 0
self.cfgFile = cfgFile
self.isMC = isMC
self.worker.isFSR = isFSR
pass
def beginJob(self):
pass
Expand All @@ -54,12 +65,21 @@ def endJob(self):
print("{:27}:{:7} {}".format("Total: ", str(self.noCutsEvts), " Events"))
print("{:27}:{:7} {}".format("PassTrig: ", str(self.passtrigEvts), " Events"))
print("{:27}:{:7} {}".format("Pass4eCut: ", str(self.worker.cut4e), " Events"))
print("Pass4eGhostRemoval: "+str(self.worker.cutghost4e)+" Events")
print("Pass4eLepPtCut: "+str(self.worker.cutLepPt4e)+" Events")
print("Pass4eQCDSupress: "+str(self.worker.cutQCD4e)+" Events")
print("{:27}:{:7} {}".format("PassmZ1mZ2Cut_4e: ", str(self.worker.cutZZ4e), " Events"))
print("{:27}:{:7} {}".format("Passm4l_105_160_Cut_4e: ", str(self.worker.cutm4l4e), " Events"))
print("{:27}:{:7} {}".format("Pass4muCut: ", str(self.worker.cut4mu), " Events"))
print("Pass4muGhostRemoval: "+str(self.worker.cutghost4mu)+" Events")
print("Pass4muLepPtCut: "+str(self.worker.cutLepPt4mu)+" Events")
print("Pass4muQCDSupress: "+str(self.worker.cutQCD4mu)+" Events")
print("{:27}:{:7} {}".format("PassmZ1mZ2Cut_4mu: ", str(self.worker.cutZZ4mu), " Events"))
print("{:27}:{:7} {}".format("Passm4l_105_160_Cut_4mu: ", str(self.worker.cutm4l4mu), " Events"))
print("{:27}:{:7} {}".format("Pass2e2muCut: ", str(self.worker.cut2e2mu), " Events"))
print("Pass2e2muGhostRemoval: "+str(self.worker.cutghost2e2mu)+" Events")
print("Pass2e2muLepPtCut: "+str(self.worker.cutLepPt2e2mu)+" Events")
print("Pass2e2muQCDSupress: "+str(self.worker.cutQCD2e2mu)+" Events")
print("{:27}:{:7} {}".format("PassmZ1mZ2Cut_2e2mu: ", str(self.worker.cutZZ2e2mu), " Events"))
print("{:27}:{:7} {}".format("Passm4l_105_160_Cut_2e2mu: ", str(self.worker.cutm4l2e2mu), " Events"))
print("{:27}:{:7} {}".format("PassZZSelection: ", str(self.passZZEvts), " Events"))
Expand Down Expand Up @@ -167,8 +187,10 @@ def analyze(self, event):
# do NOT access other branches in python between the check/call to
# initReaders and the call to C++ worker code
self.worker.Initialize()
self.worker.SetObjectNum(event.nElectron,event.nMuon,event.nJet,event.nGenPart,event.nFsrPhoton)

isMC = self.isMC
self.worker.SetObjectNum(event.nElectron,event.nMuon,event.nJet,event.nFsrPhoton)
if isMC:
self.worker.SetObjectNumGen(event.nGenPart)
keepIt = False

passedTrig=False
Expand All @@ -192,22 +214,25 @@ def analyze(self, event):
fsrPhotons = Collection(event, "FsrPhoton")
jets = Collection(event, "Jet")
FatJets = Collection(event, "FatJet")
genparts = Collection(event, "GenPart")
if isMC:
genparts = Collection(event, "GenPart")
for xg in genparts:
self.worker.SetGenParts(xg.pt)
for xm in muons:
self.worker.SetMuonsGen(xm.genPartIdx)
for xe in electrons:
self.worker.SetElectrons(xe.pt, xe.eta, xe.phi, xe.mass, xe.dxy,
xe.dz, xe.sip3d, xe.mvaFall17V2Iso, xe.pdgId, xe.pfRelIso03_all)
for xm in muons:
self.worker.SetMuons(xm.pt, xm.eta, xm.phi, xm.mass, xm.isGlobal, xm.isTracker,
xm.dxy, xm.dz, xm.sip3d, xm.ptErr, xm.nTrackerLayers, xm.isPFcand,
xm.pdgId, xm.charge, xm.pfRelIso03_all, xm.genPartIdx)
xm.pdgId, xm.charge, xm.pfRelIso03_all)
for xf in fsrPhotons:
self.worker.SetFsrPhotons(xf.dROverEt2,xf.eta,xf.phi,xf.pt,xf.relIso03)
for xj in jets:
self.worker.SetJets(xj.pt,xj.eta,xj.phi,xj.mass,xj.jetId, xj.btagCSVV2, xj.puId)
for xj in FatJets:
self.worker.SetFatJets(xj.pt, xj.eta, xj.phi, xj.msoftdrop, xj.jetId, xj.btagDeepB, xj.particleNet_ZvsQCD)
for xg in genparts:
self.worker.SetGenParts(xg.pt)

self.worker.MuonPtCorrection(self.isMC)
self.worker.LeptonSelection()
Expand Down Expand Up @@ -305,10 +330,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)
Expand Down
88 changes: 87 additions & 1 deletion Input_2017.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Triggers:
- event.HLT_Mu8_DiEle12_CaloIdL_TrackIdL_DZ
- event.HLT_Mu8_DiEle12_CaloIdL_TrackIdL
- event.HLT_Ele35_WPTight_Gsf
- event.HLT_Ele35_WPTight_Gsf_L1EGMT
- event.HLT_Ele38_WPTight_Gsf
- event.HLT_Ele40_WPTight_Gsf
- event.HLT_IsoMu27
Expand All @@ -39,3 +38,90 @@ Triggers_2l2q:
- event.HLT_DiMu9_Ele9_CaloIdL_TrackIdL_DZ
- event.HLT_Mu8_DiEle12_CaloIdL_TrackIdL
- event.HLT_Mu8_DiEle12_CaloIdL_TrackIdL_DZ
Zmass:
91.1876
MZ1cut:
40
MZcut:
down:
12
up:
120
MZZcut:
70
Higgscut:
up:
160
down:
105

Electron:
pTcut:
7
Etacut:
2.5
Sip3dcut:
4
Loosedxycut:
0.5
Loosedzcut:
1
BDTWP:
LowEta:
LowPT:
0.9128577458
HighPT:
0.1559788054
MedEta:
LowPT:
0.9056792368
HighPT:
0.0273863727
HighEta:
LowPT:
0.9439440575
HighPT:
-0.5532483665
Isocut:
0.35
Muon:
pTcut:
5
Etacut:
2.4
Sip3dcut:
4
Loosedxycut:
0.5
Loosedzcut:
1
Tightdxycut:
0.2
Tightdzcut:
0.5
TightTrackerLayercut:
5
TightpTErrorcut:
0.3
HighPtBound:
200
Isocut:
0.35

FsrPhoton:
pTcut:
2
Etacut:
2.4
Isocut:
0.8
dRlcut:
0.5
dRlOverPtcut:
0.012

Jet:
pTcut:
30
Etacut:
4.7
88 changes: 88 additions & 0 deletions Input_2018.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,91 @@ Triggers:

RoccoRPath:
KalmanMuonCalibrationsProducer/data/roccor.Run2.v5/RoccoR2018UL.txt

Zmass:
91.1876
MZ1cut:
40
MZcut:
down:
12
up:
120
MZZcut:
70
Higgscut:
up:
160
down:
105

Electron:
pTcut:
7
Etacut:
2.5
Sip3dcut:
4
Loosedxycut:
0.5
Loosedzcut:
1
BDTWP:
LowEta:
LowPT:
0.9044286167
HighPT:
0.1968600840
MedEta:
LowPT:
0.9094166886
HighPT:
0.0759172100
HighEta:
LowPT:
0.9443653660
HighPT:
-0.5169136775
Isocut:
0.35
Muon:
pTcut:
5
Etacut:
2.4
Sip3dcut:
4
Loosedxycut:
0.5
Loosedzcut:
1
Tightdxycut:
0.2
Tightdzcut:
0.5
TightTrackerLayercut:
5
TightpTErrorcut:
0.3
HighPtBound:
200
Isocut:
0.35

FsrPhoton:
pTcut:
2
Etacut:
2.4
Isocut:
0.8
dRlcut:
0.5
dRlOverPtcut:
0.012

Jet:
pTcut:
30
Etacut:
4.7
20 changes: 10 additions & 10 deletions JetSFMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ROOT

from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection

class JetSFMaker(Module):
#----------------------------------------------------------------------------
Expand All @@ -13,11 +13,11 @@ class JetSFMaker(Module):
#weight. Same for up/down variations (weights).
#----------------------------------------------------------------------------

def __init__(self, cmssw, puid_sf_config='PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/data/JetPUID_cfg.py'):
def __init__(self, cmssw, puid_sf_config='PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim/data/JetPUID_cfg.py'):
cmssw_base = os.getenv('CMSSW_BASE')
with open(cmssw_base + '/src/' + puid_sf_config) as src:
exec(src)

puid_sf_cfg = jet_puid_sf[cmssw]

source = ROOT.TFile.Open(cmssw_base + '/src/' + puid_sf_cfg['source'])
Expand Down Expand Up @@ -77,7 +77,7 @@ def analyze(self, event):
up = 1 + abs(sf-1)
down = 1 - abs(sf-1)
puid_upjw = up
puid_downjw = down
puid_downjw = down
else:
puid_jw = (1.-sf*eff)/(1.-eff)
if (jtype == 'real') or (jtype == 'pu' and abs(jet.eta)>=2.5):
Expand All @@ -87,28 +87,28 @@ def analyze(self, event):
up = 1 + abs(sf-1)
down = 1 - abs(sf-1)
puid_upjw = (1.-up*eff)/(1.-eff)
puid_downjw = (1.-down*eff)/(1.-eff)
puid_downjw = (1.-down*eff)/(1.-eff)

#store per jet weights and variations
sfs[wp].append(puid_jw)
sfs_up[wp].append(puid_upjw)
sfs_down[wp].append(puid_downjw)

for wp in ['loose', 'medium', 'tight']:
self.out.fillBranch('Jet_PUIDSF_%s' % wp, sfs[wp])
self.out.fillBranch('Jet_PUIDSF_%s' % wp, sfs[wp])
self.out.fillBranch('Jet_PUIDSF_%s_up' % wp, sfs_up[wp])
self.out.fillBranch('Jet_PUIDSF_%s_down' % wp, sfs_down[wp])

return True

def get_sf_and_eff(self, jtype, wp, jet):
sf_map = self.sf_maps['%s_%s' % (jtype, wp)]
sf_uncty_map = self.sf_uncty_maps['%s_%s_uncty' % (jtype, wp)]
sf_uncty_map = self.sf_uncty_maps['%s_%s_uncty' % (jtype, wp)]
eff_map = self.eff_maps['%s_mc_%s' % (jtype, wp)]

if jet.pt < 30. or jet.pt > 50. or abs(jet.eta) > 4.7:
#do not apply SF outside CleanJet region and where PUID was not applied
return 1.,0.,0.,0.
if jet.pt < 30. or jet.pt > 50. or abs(jet.eta) > 4.7:
#do not apply SF outside CleanJet region and where PUID was not applied
return 1.,0.,0.,0.

ix = min(max(1, sf_map.GetXaxis().FindFixBin(jet.pt)), sf_map.GetNbinsX())
iy = min(max(1, sf_map.GetYaxis().FindFixBin(jet.eta)), sf_map.GetNbinsY())
Expand Down
Loading

0 comments on commit 9abc594

Please sign in to comment.