From e010717e350dd4635c2719535881ec43196f2523 Mon Sep 17 00:00:00 2001 From: Ramkrishna Sharma Date: Mon, 20 Nov 2023 14:50:16 +0100 Subject: [PATCH] Fix the empty lepton branch issue (#24) --- H4LCppModule.py | 53 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/H4LCppModule.py b/H4LCppModule.py index 813ff44..14b3ece 100644 --- a/H4LCppModule.py +++ b/H4LCppModule.py @@ -16,22 +16,22 @@ def __init__(self,year,cfgFile,isMC,isFSR): ROOT.gSystem.Load("%s/JHUGenMELA/MELA/data/slc7_amd64_gcc700/libcollier.so" % base) if "/H4LTools_cc.so" not in ROOT.gSystem.GetLibraries(): print("Load C++ module") - base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" + base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" if base: ROOT.gROOT.ProcessLine( ".L %s/src/H4LTools.cc+O" % base) else: - base = "$CMSSW_BASE//src/PhysicsTools/NanoAODTools" + base = "$CMSSW_BASE//src/PhysicsTools/NanoAODTools" ROOT.gSystem.Load("libPhysicsToolsNanoAODTools.so") ROOT.gROOT.ProcessLine( ".L %s/interface/H4LTools.h" % base) if "/RoccoR_cc.so" not in ROOT.gSystem.GetLibraries(): - base = "$CMSSW_BASE//src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" + base = "$CMSSW_BASE//src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" if base: ROOT.gROOT.ProcessLine( ".L %s/src/RoccoR.cc+O" % base) else: - base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools" + base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools" ROOT.gSystem.Load("libPhysicsToolsNanoAODTools.so") ROOT.gROOT.ProcessLine( ".L %s/interface/RoccoR.h" % base) @@ -48,7 +48,7 @@ def __init__(self,year,cfgFile,isMC,isFSR): 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.passZZEvts = 0 self.cfgFile = cfgFile @@ -129,12 +129,12 @@ def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree): self.out.branch("phij2", "F") - self.out.branch("Electron_Fsr_pt", "F", lenVar = "nElectron") - self.out.branch("Electron_Fsr_eta", "F", lenVar = "nElectron") - self.out.branch("Electron_Fsr_phi", "F", lenVar = "nElectron") - self.out.branch("Muon_Fsr_pt", "F", lenVar = "nMuon") - self.out.branch("Muon_Fsr_eta", "F", lenVar = "nMuon") - self.out.branch("Muon_Fsr_phi", "F", lenVar = "nMuon") + self.out.branch("Electron_Fsr_pt", "F", lenVar = "nElectron_Fsr") + self.out.branch("Electron_Fsr_eta", "F", lenVar = "nElectron_Fsr") + self.out.branch("Electron_Fsr_phi", "F", lenVar = "nElectron_Fsr") + self.out.branch("Muon_Fsr_pt", "F", lenVar = "nMuon_Fsr") + self.out.branch("Muon_Fsr_eta", "F", lenVar = "nMuon_Fsr") + self.out.branch("Muon_Fsr_phi", "F", lenVar = "nMuon_Fsr") with open("SyncLepton2018GGH.txt", 'w') as f: f.write("Sync data list:"+"\n") @@ -164,7 +164,7 @@ def analyze(self, event): if isMC: self.worker.SetObjectNumGen(event.nGenPart) keepIt = False - + passedTrig=False passedFullSelection=False passedZ4lSelection=False @@ -195,27 +195,27 @@ def analyze(self, event): 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.dxy, xm.dz, xm.sip3d, xm.ptErr, xm.nTrackerLayers, xm.isPFcand, 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) - + self.worker.MuonPtCorrection(isMC) self.worker.LeptonSelection() if ((self.worker.nTightEle<2)&(self.worker.nTightMu<2)): pass - """Electron_Fsr_pt_vec = self.worker.ElectronFsrPt() + Electron_Fsr_pt_vec = self.worker.ElectronFsrPt() Electron_Fsr_eta_vec = self.worker.ElectronFsrEta() Electron_Fsr_phi_vec = self.worker.ElectronFsrPhi() Muon_Fsr_pt_vec = self.worker.MuonFsrPt() Muon_Fsr_eta_vec = self.worker.MuonFsrEta() Muon_Fsr_phi_vec = self.worker.MuonFsrPhi() - - + + Electron_Fsr_pt = [] Electron_Fsr_eta = [] Electron_Fsr_phi = [] @@ -231,8 +231,10 @@ def analyze(self, event): for i in range(len(Muon_Fsr_pt_vec)): Muon_Fsr_pt.append(Muon_Fsr_pt_vec[i]) Muon_Fsr_eta.append(Muon_Fsr_eta_vec[i]) - Muon_Fsr_phi.append(Muon_Fsr_phi_vec[i])""" + Muon_Fsr_phi.append(Muon_Fsr_phi_vec[i]) + foundZZCandidate = self.worker.ZZSelection() + if (foundZZCandidate): keepIt = True self.passZZEvts += 1 @@ -286,7 +288,7 @@ def analyze(self, event): etaL3, etaL4 = etaL4, etaL3 phiL3, phiL4 = phiL4, phiL3 massL3, massL4 = massL4, massL3 - + pT4l = self.worker.ZZsystem.Pt() eta4l = self.worker.ZZsystem.Eta() @@ -342,14 +344,17 @@ def analyze(self, event): self.out.fillBranch("etaj2",etaj2) self.out.fillBranch("phij2",phij2) - """self.out.fillBranch("Electron_Fsr_pt",Electron_Fsr_pt) + # self.out.fillBranch("nElectron_Fsr", len(electrons)) + # self.out.fillBranch("nMuon_Fsr", len(muons)) + + self.out.fillBranch("Electron_Fsr_pt",Electron_Fsr_pt) self.out.fillBranch("Electron_Fsr_eta",Electron_Fsr_eta) self.out.fillBranch("Electron_Fsr_phi",Electron_Fsr_phi) self.out.fillBranch("Muon_Fsr_pt",Muon_Fsr_pt) self.out.fillBranch("Muon_Fsr_eta",Muon_Fsr_eta) - self.out.fillBranch("Muon_Fsr_phi",Muon_Fsr_phi)""" - + self.out.fillBranch("Muon_Fsr_phi",Muon_Fsr_phi) + """with open("SyncLepton2018GGH.txt", 'a') as f: if(foundZZCandidate): f.write(str('%.4f' % event.run)+":"+str('%.4f' % event.luminosityBlock)+":"+str('%.4f' % event.event)+":" \ @@ -365,8 +370,8 @@ def analyze(self, event): +str('%.4f'%-1.0000)+":"+str('%.4f'%-1.0000)+":"+str('%.4f'%-1.0000)+":"+str('%.4f'%-1.0000)+"\n")""" - - + + return keepIt