From 2e907c427540cee4d1e6c284a1ede09e3c8307a4 Mon Sep 17 00:00:00 2001 From: yuji Date: Mon, 29 Jan 2024 11:16:08 +0100 Subject: [PATCH 1/6] GenAnalysis module added --- H4LCppModule.py | 25 ++- interface/GenAnalysis.h | 110 ++++++++++++ src/GenAnalysis.cc | 374 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 507 insertions(+), 2 deletions(-) create mode 100644 interface/GenAnalysis.h create mode 100644 src/GenAnalysis.cc diff --git a/H4LCppModule.py b/H4LCppModule.py index b8f3a58..3d6afe8 100644 --- a/H4LCppModule.py +++ b/H4LCppModule.py @@ -14,8 +14,19 @@ def __init__(self,year,cfgFile,isMC,isFSR): ROOT.gSystem.Load("%s/JHUGenMELA/MELA/data/slc7_amd64_gcc700/libjhugenmela.so" % base) ROOT.gSystem.Load("%s/JHUGenMELA/MELA/data/slc7_amd64_gcc700/libmcfm_707.so" % base) ROOT.gSystem.Load("%s/JHUGenMELA/MELA/data/slc7_amd64_gcc700/libcollier.so" % base) + if "/GenAnalysis_cc.so" not in ROOT.gSystem.GetLibraries(): + print("Load GenAnalysis C++ module") + base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" + if base: + ROOT.gROOT.ProcessLine( + ".L %s/src/GenAnalysis.cc+O" % base) + else: + base = "$CMSSW_BASE//src/PhysicsTools/NanoAODTools" + ROOT.gSystem.Load("libPhysicsToolsNanoAODTools.so") + ROOT.gROOT.ProcessLine( + ".L %s/interface/GenAnalysis.h" % base) if "/H4LTools_cc.so" not in ROOT.gSystem.GetLibraries(): - print("Load C++ module") + print("Load H4LTools C++ module") base = "$CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim" if base: ROOT.gROOT.ProcessLine( @@ -26,6 +37,7 @@ def __init__(self,year,cfgFile,isMC,isFSR): ROOT.gROOT.ProcessLine( ".L %s/interface/H4LTools.h" % base) self.year = year + self.genworker = ROOT.GenAnalysis() with open(cfgFile, 'r') as ymlfile: cfg = yaml.load(ymlfile) self.worker = ROOT.H4LTools(self.year) @@ -152,6 +164,8 @@ def analyze(self, event): self.worker.SetObjectNum(event.nElectron,event.nMuon,event.nJet,event.nFsrPhoton) if isMC: self.worker.SetObjectNumGen(event.nGenPart) + self.genworker.Initialize() + self.genworker.SetObjectNumGen(event.nGenPart, event.nGenJet) keepIt = False passedTrig=False @@ -175,8 +189,12 @@ def analyze(self, event): jets = Collection(event, "Jet") if isMC: genparts = Collection(event, "GenPart") + genjets = Collection(event, "GenJet") + for xj in genjets: + self.genworker.SetGenJets(xj.pt,xj.eta,xj.phi,xj.mass) for xg in genparts: self.worker.SetGenParts(xg.pt) + self.genworker.SetGenParts(xg.pt,xg.eta,xg.phi,xg.mass,xg.pdgId,xg.status,xg.statusFlags,xg.genPartIdxMother) for xm in muons: self.worker.SetMuonsGen(xm.genPartIdx) for xe in electrons: @@ -194,7 +212,10 @@ def analyze(self, event): self.worker.LeptonSelection() if ((self.worker.nTightEle<2)&(self.worker.nTightMu<2)): pass - + if isMC: + self.genworker.SetGenVariables() + + passedFiducialSelection = self.genworker.passedFiducialSelection Electron_Fsr_pt_vec = self.worker.ElectronFsrPt() Electron_Fsr_eta_vec = self.worker.ElectronFsrEta() diff --git a/interface/GenAnalysis.h b/interface/GenAnalysis.h new file mode 100644 index 0000000..4105f33 --- /dev/null +++ b/interface/GenAnalysis.h @@ -0,0 +1,110 @@ +#ifndef GenAnalysis_h +#define GenAnalysis_h + +#include +#include +#include +#include +#include +#include +#include "yaml-cpp/yaml.h" +#include "../JHUGenMELA/MELA/interface/Mela.h" + +class GenAnalysis{ + public: + GenAnalysis(); //Importing Ficducial Space cuts + std::vector GENlep_pt; + std::vector GENlep_eta; + std::vector GENlep_phi; + std::vector GENlep_mass; + std::vector GENZ_pt; + std::vector GENZ_eta; + std::vector GENZ_phi; + std::vector GENZ_mass; + std::vector GENZ_MomId; + std::vector GENH_pt; + std::vector GENH_eta; + std::vector GENH_phi; + std::vector GENH_mass; + std::vector GENjet_pt; + std::vector GENjet_eta; + std::vector GENjet_phi; + std::vector GENjet_mass; + std::vector GENlep_RelIso; + std::vector GENlep_id; + std::vector GENlep_status; + std::vector GENlep_MomId; + std::vector GENlep_MomMomId; + float GENMH, GENmassZZ, GENpTZZ; + float Zmass=91.1876; + double genIsoConeSizeEl, genIsoConeSizeMu; + float genIsoCutEl, genIsoCutMu; + float GENmass4l,GENmass4e,GENmass4mu, GENmass2e2mu; + float GENmassZ1,GENmassZ2,GENpT4l,GENeta4l,GENrapidity4l,GENphi4l; + float GENpt_leadingjet_pt30_eta4p7,GENpt_leadingjet_pt30_eta2p5; + float GENpT4lj, GENpT4ljj, GENmass4lj, GENmass4ljj; + float leadingPtCut,subleadingPtCut; + bool passedFiducialSelection; + int GENnjets_pt30_eta4p7,GENnjets_pt30_eta2p5; + unsigned int GENlep_Hindex[4]; + void SetGenParts(float GenPart_pt_, float GenPart_eta_,float GenPart_phi_,float GenPart_mass_,int GenPart_pdgId_,int GenPart_status_,int GenPart_statusFlags_,int GenPart_genPartIdxMother_){ + GenPart_pt.push_back(GenPart_pt_); + GenPart_eta.push_back(GenPart_eta_); + GenPart_phi.push_back(GenPart_phi_); + GenPart_mass.push_back(GenPart_mass_); + GenPart_pdgId.push_back(GenPart_pdgId_); + GenPart_statusFlags.push_back(GenPart_statusFlags_); + GenPart_status.push_back(GenPart_status_); + GenPart_genPartIdxMother.push_back(GenPart_genPartIdxMother_); + } + + void SetGenJets(float GenJet_pt_, float GenJet_eta_,float GenJet_phi_,float GenJet_mass_){ + GenJet_pt.push_back(GenJet_pt_); + GenJet_eta.push_back(GenJet_eta_); + GenJet_phi.push_back(GenJet_phi_); + GenJet_mass.push_back(GenJet_mass_); + } + void SetObjectNumGen(unsigned nGenPart_, unsigned nGenJet_){ + nGenPart = nGenPart_; + nGenJet = nGenJet_; + } + void Initialize(){ + passedFiducialSelection=false; + nGenPart = 0; nGenJet = 0; GENMH = 0; GENmassZZ= 0; GENpTZZ= 0; GENnjets_pt30_eta4p7=0;GENnjets_pt30_eta2p5=0; + GENpt_leadingjet_pt30_eta4p7=0; GENpt_leadingjet_pt30_eta2p5=0; + GenPart_pt.clear(); GenPart_eta.clear(); GenPart_phi.clear(); GenPart_mass.clear(); GenPart_pdgId.clear();GenPart_status.clear();GenPart_statusFlags.clear(); GenPart_genPartIdxMother.clear(); + GenJet_pt.clear(); GenJet_eta.clear(); GenJet_phi.clear(); GenJet_mass.clear(); + GENZ_phi.clear(); GENZ_pt.clear(); GENZ_eta.clear(); GENZ_mass.clear();GENZ_MomId.clear(); + GENH_phi.clear(); GENH_pt.clear(); GENH_eta.clear(); GENH_mass.clear(); + GENjet_pt.clear();GENjet_eta.clear();GENjet_phi.clear();GENjet_mass.clear(); + GENlep_eta.clear();GENlep_pt.clear();GENlep_phi.clear();GENlep_mass.clear();GENlep_id.clear();GENlep_status.clear();GENlep_MomMomId.clear();GENlep_MomId.clear();GENlep_RelIso.clear(); + } + int motherID(int Genidx); + int mothermotherID(int Genidx); + void SetGenVariables(); + bool mZ1_mZ2(unsigned int& L1, unsigned int& L2, unsigned int& L3, unsigned int& L4, bool makeCuts); + + + private: + std::vector GenPart_pt; + std::vector GenPart_eta; + std::vector GenPart_phi; + std::vector GenPart_mass; + std::vector GenPart_pdgId; + std::vector GenPart_status; + std::vector GenPart_statusFlags; + std::vector GenPart_genPartIdxMother; + + std::vector GenJet_pt; + std::vector GenJet_eta; + std::vector GenJet_phi; + std::vector GenJet_mass; + + unsigned nGenPart, nGenJet; +}; +GenAnalysis::GenAnalysis(){ + genIsoConeSizeEl=0.3; genIsoConeSizeMu=0.3; + genIsoCutEl=0.35; genIsoCutMu=0.35; + leadingPtCut=20;subleadingPtCut=10; +} +#endif \ No newline at end of file diff --git a/src/GenAnalysis.cc b/src/GenAnalysis.cc new file mode 100644 index 0000000..98a7e8b --- /dev/null +++ b/src/GenAnalysis.cc @@ -0,0 +1,374 @@ +#include "../interface/GenAnalysis.h" +#include +#include +#include +int GenAnalysis::motherID(int Genidx){ + int ID=0; + while(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=2212 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=21 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]>6){ + if(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=GenPart_pdgId[Genidx]){ + ID=GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]; return ID; + } + else{ + Genidx=GenPart_genPartIdxMother[Genidx]; + } + } + return 2212; +} +int GenAnalysis::mothermotherID(int Genidx){ + int ID=0; + while(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=2212 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=21 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]>6){ + if(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=GenPart_pdgId[Genidx] && GenPart_pdgId[GenPart_genPartIdxMother[GenPart_genPartIdxMother[Genidx]]]!=GenPart_pdgId[Genidx] && GenPart_pdgId[GenPart_genPartIdxMother[GenPart_genPartIdxMother[Genidx]]]!=GenPart_pdgId[GenPart_genPartIdxMother[Genidx]] ){ + ID=GenPart_pdgId[GenPart_genPartIdxMother[GenPart_genPartIdxMother[Genidx]]]; return ID; + } + else{ + Genidx=GenPart_genPartIdxMother[Genidx]; + } + } + return 2212; +} +void GenAnalysis::SetGenVariables(){ + int nGENLeptons=0; + TLorentzVector GENmom1, GENmom2; + TLorentzVector LS3_Z1_1, LS3_Z1_2, LS3_Z2_1, LS3_Z2_2, GEN_HVec; + int GENmom1_id=-999, GENmom2_id=-999; + int counter_initParticle=0; + for(unsigned int genpidx; genpidx gen_fsrset; + for(size_t k=0; k=20 && GenPart_status[genpidx]<30) ){ + GENZ_pt.push_back(GenPart_pt[genpidx]); + GENZ_eta.push_back(GenPart_eta[genpidx]); + GENZ_phi.push_back(GenPart_phi[genpidx]); + GENZ_mass.push_back(GenPart_mass[genpidx]); + GENZ_MomId.push_back(motherID(genpidx)); + } + } + if (GENlep_pt.size()>=4) { + + unsigned int L1_nocuts=99; unsigned int L2_nocuts=99; unsigned int L3_nocuts=99; unsigned int L4_nocuts=99; + bool passedFiducialSelectionNoCuts = mZ1_mZ2(L1_nocuts, L2_nocuts, L3_nocuts, L4_nocuts, false); + if (passedFiducialSelectionNoCuts) { + TLorentzVector Z1_1, Z1_2, Z2_1, Z2_2; + Z1_1.SetPtEtaPhiM(GENlep_pt[L1_nocuts],GENlep_eta[L1_nocuts],GENlep_phi[L1_nocuts],GENlep_mass[L1_nocuts]); + Z1_2.SetPtEtaPhiM(GENlep_pt[L2_nocuts],GENlep_eta[L2_nocuts],GENlep_phi[L2_nocuts],GENlep_mass[L2_nocuts]); + Z2_1.SetPtEtaPhiM(GENlep_pt[L3_nocuts],GENlep_eta[L3_nocuts],GENlep_phi[L3_nocuts],GENlep_mass[L3_nocuts]); + Z2_2.SetPtEtaPhiM(GENlep_pt[L4_nocuts],GENlep_eta[L4_nocuts],GENlep_phi[L4_nocuts],GENlep_mass[L4_nocuts]); + GENmassZZ = (Z1_1+Z1_2+Z2_1+Z2_2).M(); + GENpTZZ = (Z1_1+Z1_2+Z2_1+Z2_2).Pt(); + int genfs; + if (abs(GENlep_id[L1_nocuts])==abs(GENlep_id[L3_nocuts])) genfs=1; + else genfs=2; + } + + } + /////// DO THE FIDUCIAL VOLUME CALCULATION ////////////// + passedFiducialSelection=false; + int nFiducialLeptons = 0; + int nFiducialPtLead=0; + int nFiducialPtSublead=0; + + for (unsigned int i=0; i 5.0 && abs(thisLep.Eta()) < 2.4) + || (abs(GENlep_id[i]) == 11 && thisLep.Pt() > 7.0 && abs(thisLep.Eta()) < 2.5) ) + && GENlep_RelIso[i]<((abs(GENlep_id[i])==11)?genIsoCutEl:genIsoCutMu) ) { + nFiducialLeptons++; + if (thisLep.Pt()>leadingPtCut) nFiducialPtLead++; + if (thisLep.Pt()>subleadingPtCut) nFiducialPtSublead++; + } + } + if (nFiducialLeptons>=4 && nFiducialPtLead>=1 && nFiducialPtSublead>=2 ){ + // START FIDUCIAL EVENT TOPOLOGY CUTS + unsigned int L1=99; unsigned int L2=99; unsigned int L3=99; unsigned int L4=99; + GENmass4l = -1.0; GENmass4e = -1.0; GENmass4mu = -1.0; GENmass2e2mu = -1.0; + GENmassZ1 = -1.0; GENmassZ2 = -1.0; GENpT4l = -1.0; GENeta4l = 999.; GENrapidity4l = 999.; GENphi4l = 999.; + GENpT4lj = -1.0; GENpT4ljj=-1.0; GENmass4lj = -1.0; GENmass4ljj=-1.0; + + passedFiducialSelection = mZ1_mZ2(L1, L2, L3, L4, true); + + GENlep_Hindex[0] = L1; GENlep_Hindex[1] = L2; GENlep_Hindex[2] = L3; GENlep_Hindex[3] = L4; + if (passedFiducialSelection) { + + // TLorentzVector LS3_Z1_1, LS3_Z1_2, LS3_Z2_1, LS3_Z2_2; + LS3_Z1_1.SetPtEtaPhiM(GENlep_pt[L1],GENlep_eta[L1],GENlep_phi[L1],GENlep_mass[L1]); + LS3_Z1_2.SetPtEtaPhiM(GENlep_pt[L2],GENlep_eta[L2],GENlep_phi[L2],GENlep_mass[L2]); + LS3_Z2_1.SetPtEtaPhiM(GENlep_pt[L3],GENlep_eta[L3],GENlep_phi[L3],GENlep_mass[L3]); + LS3_Z2_2.SetPtEtaPhiM(GENlep_pt[L4],GENlep_eta[L4],GENlep_phi[L4],GENlep_mass[L4]); + GEN_HVec = LS3_Z1_1 + LS3_Z1_2 + LS3_Z2_1 + LS3_Z2_2; + + GENmass4l = (LS3_Z1_1+LS3_Z1_2+LS3_Z2_1+LS3_Z2_2).M(); + + if (abs(GENlep_id[L1])==11 && abs(GENlep_id[L3])==11) {GENmass4e = GENmass4l;}; + if (abs(GENlep_id[L1])==13 && abs(GENlep_id[L3])==13) {GENmass4mu = GENmass4l;}; + if ( (abs(GENlep_id[L1])==11 || abs(GENlep_id[L1])==13) && + (abs(GENlep_id[L3])==11 || abs(GENlep_id[L3])==13) && + (abs(GENlep_id[L1])!=abs(GENlep_id[L3]) ) ) {GENmass2e2mu = GENmass4l;}; + GENpT4l = (LS3_Z1_1+LS3_Z1_2+LS3_Z2_1+LS3_Z2_2).Pt(); + GENeta4l = (LS3_Z1_1+LS3_Z1_2+LS3_Z2_1+LS3_Z2_2).Eta(); + GENphi4l = (LS3_Z1_1+LS3_Z1_2+LS3_Z2_1+LS3_Z2_2).Phi(); + GENrapidity4l = (LS3_Z1_1+LS3_Z1_2+LS3_Z2_1+LS3_Z2_2).Rapidity(); + GENmassZ1 = (LS3_Z1_1+LS3_Z1_2).M(); + GENmassZ2 = (LS3_Z2_1+LS3_Z2_2).M(); + + int tmpIdL1,tmpIdL2,tmpIdL3,tmpIdL4; + TLorentzVector GENL11P4, GENL12P4, GENL21P4, GENL22P4; + if(GENlep_id[L1] < 0){ GENL11P4.SetPxPyPzE(LS3_Z1_1.Px(),LS3_Z1_1.Py(),LS3_Z1_1.Pz(),LS3_Z1_1.E()); tmpIdL1 = GENlep_id[L1];} + else{ GENL11P4.SetPxPyPzE(LS3_Z1_2.Px(),LS3_Z1_2.Py(),LS3_Z1_2.Pz(),LS3_Z1_2.E()); tmpIdL1 = GENlep_id[L2];} + if(GENlep_id[L2] > 0){ GENL12P4.SetPxPyPzE(LS3_Z1_2.Px(),LS3_Z1_2.Py(),LS3_Z1_2.Pz(),LS3_Z1_2.E()); tmpIdL2 = GENlep_id[L2];} + else{ GENL12P4.SetPxPyPzE(LS3_Z1_1.Px(),LS3_Z1_1.Py(),LS3_Z1_1.Pz(),LS3_Z1_1.E()); tmpIdL2 = GENlep_id[L1];} + if(GENlep_id[L3] < 0){ GENL21P4.SetPxPyPzE(LS3_Z2_1.Px(),LS3_Z2_1.Py(),LS3_Z2_1.Pz(),LS3_Z2_1.E()); tmpIdL3 = GENlep_id[L3];} + else{ GENL21P4.SetPxPyPzE(LS3_Z2_2.Px(),LS3_Z2_2.Py(),LS3_Z2_2.Pz(),LS3_Z2_2.E()); tmpIdL3 = GENlep_id[L4];} + if(GENlep_id[L4] > 0) { GENL22P4.SetPxPyPzE(LS3_Z2_2.Px(),LS3_Z2_2.Py(),LS3_Z2_2.Pz(),LS3_Z2_2.E()); tmpIdL4 = GENlep_id[L4];} + else{ GENL22P4.SetPxPyPzE(LS3_Z2_1.Px(),LS3_Z2_1.Py(),LS3_Z2_1.Pz(),LS3_Z2_1.E()); tmpIdL4 = GENlep_id[L3];} + + } + bool passedMassOS = true; bool passedElMuDeltaR = true; bool passedDeltaR = true; + unsigned int N=GENlep_pt.size(); + for(unsigned int i = 0; i GEN_goodJetsidx; + + for(unsigned genjetidx=0; genjetidx4.7) continue; + + bool inDR_pt30_eta4p7 = false; + unsigned int N=GENlep_pt.size(); + TLorentzVector thisJ; + thisJ.SetPtEtaPhiM(GenJet_pt[genjetidx],GenJet_eta[genjetidx],GenJet_phi[genjetidx],GenJet_mass[genjetidx]); + for(unsigned int i = 0; iGENpt_leadingjet_pt30_eta4p7) { + GENpt_leadingjet_pt30_eta4p7=pt; + } + if (abs(thisJ.Eta())<2.5) { + GENnjets_pt30_eta2p5++; + if (pt>GENpt_leadingjet_pt30_eta2p5) { + GENpt_leadingjet_pt30_eta2p5=pt; + } + } + } + }// loop over gen jets + + } + + } + return; +} +bool GenAnalysis::mZ1_mZ2(unsigned int& L1, unsigned int& L2, unsigned int& L3, unsigned int& L4, bool makeCuts) +{ + + double offshell = 999.0; bool findZ1 = false; bool passZ1 = false; + + L1 = 0; L2 = 0; + + unsigned int N = GENlep_pt.size(); + + for(unsigned int i=0; i 2.4)) continue; + if ( abs(GENlep_id[i]) == 11 && (li.Pt() < 7.0 || abs(li.Eta()) > 2.5)) continue; + if ( GENlep_RelIso[i]>((abs(GENlep_id[i])==11)?genIsoCutEl:genIsoCutMu)) continue; + + if ( abs(GENlep_id[j]) == 13 && (lj.Pt() < 5.0 || abs(lj.Eta()) > 2.4)) continue; + if ( abs(GENlep_id[j]) == 11 && (lj.Pt() < 7.0 || abs(lj.Eta()) > 2.5)) continue; + if ( GENlep_RelIso[j]>((abs(GENlep_id[i])==11)?genIsoCutEl:genIsoCutMu)) continue; + } + + TLorentzVector mll = li+lj; + + if(abs(mll.M()-Zmass)40 && ml1l2.M()<120 && findZ1) passZ1 = true; + if (!makeCuts) passZ1 = true; + + double pTL34 = 0.0; bool findZ2 = false; + //bool m4lwindow=false; double window_lo=70.0; double window_hi=140.0; + + //cout<<"findZ2"< 2.4)) continue; + if ( abs(GENlep_id[i]) == 11 && (li.Pt() < 7.0 || abs(li.Eta()) > 2.5)) continue; + if ( GENlep_RelIso[i]>((abs(GENlep_id[i])==11)?genIsoCutEl:genIsoCutMu)) continue; + + if ( abs(GENlep_id[j]) == 13 && (lj.Pt() < 5.0 || abs(lj.Eta()) > 2.4)) continue; + if ( abs(GENlep_id[j]) == 11 && (lj.Pt() < 7.0 || abs(lj.Eta()) > 2.5)) continue; + if ( GENlep_RelIso[j]>((abs(GENlep_id[i])==11)?genIsoCutEl:genIsoCutMu)) continue; + } + + if ( (li.Pt()+lj.Pt())>=pTL34 ) { + double mZ2 = Z2.M(); + if( (mZ2>12 && mZ2<120) || (!makeCuts) ) { + L3 = i; L4 = j; findZ2 = true; + pTL34 = li.Pt()+lj.Pt(); + //if (m4l>window_lo && m4l Date: Tue, 30 Jan 2024 17:21:37 +0100 Subject: [PATCH 2/6] naming convention --- H4LCppModule.py | 48 +++++++++++++++++++++++++++++++++++++++++++- interface/H4LTools.h | 2 ++ keep_and_drop.txt | 1 + src/GenAnalysis.cc | 6 +++--- src/H4LTools.cc | 2 +- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/H4LCppModule.py b/H4LCppModule.py index 3d6afe8..f6c50be 100644 --- a/H4LCppModule.py +++ b/H4LCppModule.py @@ -86,7 +86,16 @@ def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree): self.initReaders(inputTree) # initReaders must be called in beginFile self.out = wrappedOutputTree self.out.branch("mass4l", "F") + self.out.branch("GENmass4l", "F") + self.out.branch("mass4e", "F") + self.out.branch("mass4mu", "F") + self.out.branch("mass2e2mu", "F") self.out.branch("pT4l", "F") + self.out.branch("GENpT4l", "F") + self.out.branch("rapidity4l", "F") + self.out.branch("njets_pt30_eta4p7", "I") + self.out.branch("GENnjets_pt30_eta4p7", "I") + self.out.branch("GENrapidity4l", "F") self.out.branch("eta4l", "F") self.out.branch("phi4l", "F") self.out.branch("massZ1", "F") @@ -124,10 +133,13 @@ def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree): self.out.branch("pTj1", "F") self.out.branch("etaj1", "F") self.out.branch("phij1", "F") - self.out.branch("mj2", "F") self.out.branch("pTj2", "F") self.out.branch("etaj2", "F") self.out.branch("phij2", "F") + self.out.branch("mj2", "F") + self.out.branch("pileupWeight", "F") + self.out.branch("dataMCWeight_new", "F") + self.out.branch("prefiringWeight", "F") self.out.branch("Electron_Fsr_pt", "F", lenVar = "nElectron_Fsr") @@ -178,6 +190,16 @@ def analyze(self, event): passedZXCRSelection=False passedFiducialSelection=False nZXCRFailedLeptons=0 + prefiringWeight = 1 + dataMCWeight_new = 1 + pileupWeight = 1 + mass4e=0 + mass2e2mu=0 + mass4mu=0 + GENmass4l = -99 + GENpT4l = -99 + GENrapidity4l = -99 + GENnjets_pt30_eta4p7 = -1 passedTrig = PassTrig(event, self.cfgFile) if (passedTrig==True): self.passtrigEvts += 1 @@ -214,6 +236,10 @@ def analyze(self, event): pass if isMC: self.genworker.SetGenVariables() + GENmass4l = self.genworker.GENmass4l + GENpT4l = self.genworker.GENpT4l + GENrapidity4l = self.genworker.GENrapidity4l + GENnjets_pt30_eta4p7 = self.genworker.GENnjets_pt30_eta4p7 passedFiducialSelection = self.genworker.passedFiducialSelection @@ -303,13 +329,30 @@ def analyze(self, event): eta4l = self.worker.ZZsystem.Eta() phi4l = self.worker.ZZsystem.Phi() mass4l = self.worker.ZZsystem.M() + rapidity4l = self.worker.ZZsystem.Rapidity() + njets_pt30_eta4p7 = self.worker.njets_pt30_eta4p7 + if self.worker.flag4e: + mass4e = mass4l + if self.worker.flag2e2mu: + mass4e = mass4l + if self.worker.flag4mu: + mass4mu = mass4l 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("GENmass4l",GENmass4l) + self.out.fillBranch("mass4e",mass4e) + self.out.fillBranch("mass2e2mu",mass2e2mu) + self.out.fillBranch("mass4mu",mass4mu) self.out.fillBranch("pT4l",pT4l) + self.out.fillBranch("GENpT4l",GENpT4l) + self.out.fillBranch("rapidity4l",rapidity4l) + self.out.fillBranch("GENrapidity4l",GENrapidity4l) + self.out.fillBranch("njets_pt30_eta4p7",njets_pt30_eta4p7) + self.out.fillBranch("GENnjets_pt30_eta4p7",GENnjets_pt30_eta4p7) self.out.fillBranch("eta4l",eta4l) self.out.fillBranch("phi4l",phi4l) self.out.fillBranch("massZ1",massZ1) @@ -352,6 +395,9 @@ def analyze(self, event): self.out.fillBranch("pTj2",pTj2) self.out.fillBranch("etaj2",etaj2) self.out.fillBranch("phij2",phij2) + self.out.fillBranch("pileupWeight",pileupWeight) + self.out.fillBranch("dataMCWeight_new",dataMCWeight_new) + self.out.fillBranch("prefiringWeight",prefiringWeight) # self.out.fillBranch("nElectron_Fsr", len(electrons)) # self.out.fillBranch("nMuon_Fsr", len(muons)) diff --git a/interface/H4LTools.h b/interface/H4LTools.h index 7336cc3..edbc7da 100644 --- a/interface/H4LTools.h +++ b/interface/H4LTools.h @@ -218,6 +218,7 @@ class H4LTools { int nTightMu; int nTightEleChgSum; int nTightMuChgSum; + int njets_pt30_eta4p7; bool flag4e; bool flag4mu; @@ -275,6 +276,7 @@ class H4LTools { pTj1 = -99; etaj1 = -99; phij1 = -99; mj1 = -99; pTj2 = -99; etaj2 = -99; phij2 = -99; mj2 = -99; + njets_pt30_eta4p7 = -1; flag4e=false; flag4mu=false; flag2e2mu=false; } diff --git a/keep_and_drop.txt b/keep_and_drop.txt index 6e6d10a..fb9c991 100644 --- a/keep_and_drop.txt +++ b/keep_and_drop.txt @@ -84,5 +84,6 @@ keep SV* keep Electron_gen* keep FatJet_* keep Gen* +keep genWeight keep Jet_* keep Muon* diff --git a/src/GenAnalysis.cc b/src/GenAnalysis.cc index 98a7e8b..2862c67 100644 --- a/src/GenAnalysis.cc +++ b/src/GenAnalysis.cc @@ -4,7 +4,7 @@ #include int GenAnalysis::motherID(int Genidx){ int ID=0; - while(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=2212 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=21 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]>6){ + while(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=2212 || abs(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]])!=21 || abs(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]])>6){ if(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=GenPart_pdgId[Genidx]){ ID=GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]; return ID; } @@ -16,7 +16,7 @@ int GenAnalysis::motherID(int Genidx){ } int GenAnalysis::mothermotherID(int Genidx){ int ID=0; - while(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=2212 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=21 || GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]>6){ + while(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=2212 || abs(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]])!=21 || abs(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]])>6){ if(GenPart_pdgId[GenPart_genPartIdxMother[Genidx]]!=GenPart_pdgId[Genidx] && GenPart_pdgId[GenPart_genPartIdxMother[GenPart_genPartIdxMother[Genidx]]]!=GenPart_pdgId[Genidx] && GenPart_pdgId[GenPart_genPartIdxMother[GenPart_genPartIdxMother[Genidx]]]!=GenPart_pdgId[GenPart_genPartIdxMother[Genidx]] ){ ID=GenPart_pdgId[GenPart_genPartIdxMother[GenPart_genPartIdxMother[Genidx]]]; return ID; } @@ -32,7 +32,7 @@ void GenAnalysis::SetGenVariables(){ TLorentzVector LS3_Z1_1, LS3_Z1_2, LS3_Z2_1, LS3_Z2_2, GEN_HVec; int GENmom1_id=-999, GENmom2_id=-999; int counter_initParticle=0; - for(unsigned int genpidx; genpidx H4LTools::SelectedJets(std::vector ele, } } } - + njets_pt30_eta4p7 = goodJets.size(); return goodJets; } From 37f651fb1418150b834efa304f08fb4b01326e87 Mon Sep 17 00:00:00 2001 From: yuji Date: Wed, 31 Jan 2024 14:02:31 +0100 Subject: [PATCH 3/6] BranchName fixed --- GenAnalysis | 0 H4LCppModule.py | 96 +++++++++++++++++++++++++++++++++++++---- interface/GenAnalysis.h | 9 ++-- interface/H4LTools.h | 26 ++++++++--- src/GenAnalysis.cc | 4 +- src/H4LTools.cc | 17 +++++++- 6 files changed, 131 insertions(+), 21 deletions(-) create mode 100644 GenAnalysis diff --git a/GenAnalysis b/GenAnalysis new file mode 100644 index 0000000..e69de29 diff --git a/H4LCppModule.py b/H4LCppModule.py index f6c50be..ed6bc05 100644 --- a/H4LCppModule.py +++ b/H4LCppModule.py @@ -37,10 +37,11 @@ def __init__(self,year,cfgFile,isMC,isFSR): ROOT.gROOT.ProcessLine( ".L %s/interface/H4LTools.h" % base) self.year = year + self.isMC = isMC self.genworker = ROOT.GenAnalysis() with open(cfgFile, 'r') as ymlfile: cfg = yaml.load(ymlfile) - self.worker = ROOT.H4LTools(self.year) + self.worker = ROOT.H4LTools(self.year,self.isMC) 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']) @@ -53,7 +54,6 @@ def __init__(self,year,cfgFile,isMC,isFSR): self.passtrigEvts = 0 self.passZZEvts = 0 self.cfgFile = cfgFile - self.isMC = isMC self.worker.isFSR = isFSR pass def beginJob(self): @@ -140,8 +140,23 @@ def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree): self.out.branch("pileupWeight", "F") self.out.branch("dataMCWeight_new", "F") self.out.branch("prefiringWeight", "F") - - + self.out.branch("passedTrig", "O") + self.out.branch("passedFullSelection", "O") + self.out.branch("passedZ4lSelection", "O") + self.out.branch("passedZ4lZ1LSelection", "O") + self.out.branch("passedZ4lZXCRSelection", "O") + self.out.branch("passedZXCRSelection", "O") + self.out.branch("passedFiducialSelection", "O") + GENHlepNum = 4 + GENZNum = 2 + self.out.branch("GENlep_MomId", "I", lenVar = "nGENLeptons") + self.out.branch("GENlep_MomMomId", "I", lenVar = "nGENLeptons") + self.out.branch("GENZ_MomId", "I", lenVar = "nVECZ") + self.out.branch("GENZ_DaughtersId", "I", lenVar = "GENZNum") + self.out.branch("GENlep_Hindex", "I", lenVar = "GENHlepNum") + self.out.branch("lep_Hindex", "I", lenVar = "GENHlepNum") + self.out.branch("GENlep_id", "I", lenVar = "nGENLeptons") + self.out.branch("lep_genindex", "I", lenVar = "Lepointer") 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") @@ -198,8 +213,10 @@ def analyze(self, event): mass4mu=0 GENmass4l = -99 GENpT4l = -99 + nVECZ = 2 GENrapidity4l = -99 GENnjets_pt30_eta4p7 = -1 + nGENLeptons = 0 passedTrig = PassTrig(event, self.cfgFile) if (passedTrig==True): self.passtrigEvts += 1 @@ -219,6 +236,8 @@ def analyze(self, event): self.genworker.SetGenParts(xg.pt,xg.eta,xg.phi,xg.mass,xg.pdgId,xg.status,xg.statusFlags,xg.genPartIdxMother) for xm in muons: self.worker.SetMuonsGen(xm.genPartIdx) + for xe in electrons: + self.worker.SetElectronsGen(xe.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) @@ -240,9 +259,10 @@ def analyze(self, event): GENpT4l = self.genworker.GENpT4l GENrapidity4l = self.genworker.GENrapidity4l GENnjets_pt30_eta4p7 = self.genworker.GENnjets_pt30_eta4p7 + nGENLeptons = self.genworker.nGENLeptons passedFiducialSelection = self.genworker.passedFiducialSelection - + Electron_Fsr_pt_vec = self.worker.ElectronFsrPt() Electron_Fsr_eta_vec = self.worker.ElectronFsrEta() Electron_Fsr_phi_vec = self.worker.ElectronFsrPhi() @@ -250,13 +270,14 @@ def analyze(self, event): Muon_Fsr_eta_vec = self.worker.MuonFsrEta() Muon_Fsr_phi_vec = self.worker.MuonFsrPhi() - + Electron_Fsr_pt = [] Electron_Fsr_eta = [] Electron_Fsr_phi = [] Muon_Fsr_pt = [] Muon_Fsr_eta = [] Muon_Fsr_phi = [] + if len(Electron_Fsr_pt_vec)>0: for i in range(len(Electron_Fsr_pt_vec)): Electron_Fsr_pt.append(Electron_Fsr_pt_vec[i]) @@ -267,9 +288,53 @@ def analyze(self, event): 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]) - + GENlep_id = [] + GENlep_Hindex = [] + GENZ_DaughtersId = [] + GENZ_MomId = [] + GENlep_MomId = [] + GENlep_MomMomId = [] + if isMC: + GENlep_id_vec = self.genworker.GENlep_id + if len(GENlep_id_vec)>0: + for i in range(len(GENlep_id_vec)): + GENlep_id.append(GENlep_id_vec[i]) + GENlep_Hindex_vec = self.genworker.GENlep_Hindex + if len(GENlep_Hindex_vec)>0: + for i in range(len(GENlep_Hindex_vec)): + GENlep_Hindex.append(GENlep_Hindex_vec[i]) + GENZ_DaughtersId_vec = self.genworker.GENZ_DaughtersId + if len(GENZ_DaughtersId_vec)>0: + for i in range(len(GENZ_DaughtersId_vec)): + GENZ_DaughtersId.append(GENZ_DaughtersId_vec[i]) + nVECZ = self.genworker.nVECZ + GENZ_MomId_vec = self.genworker.GENZ_MomId + if len(GENZ_MomId_vec)>0: + for i in range(len(GENZ_MomId_vec)): + GENZ_MomId.append(GENZ_MomId_vec[i]) + GENlep_MomId_vec = self.genworker.GENlep_MomId + if len(GENlep_MomId_vec)>0: + for i in range(len(GENlep_MomId_vec)): + GENlep_MomId.append(GENlep_MomId_vec[i]) + GENlep_MomMomId_vec = self.genworker.GENlep_MomMomId + if len(GENlep_MomMomId_vec)>0: + for i in range(len(GENlep_MomMomId_vec)): + GENlep_MomMomId.append(GENlep_MomMomId_vec[i]) + + foundZZCandidate = self.worker.ZZSelection() - + Lepointer = self.worker.Lepointer + lep_Hindex = [] + lep_Hindex_vec = self.worker.lep_Hindex + if len(lep_Hindex_vec)>0: + for i in range(len(lep_Hindex_vec)): + lep_Hindex.append(lep_Hindex_vec[i]) + lep_genindex = [] + if isMC: + lep_genindex_vec = self.worker.lep_genindex + if len(lep_genindex_vec)>0: + for i in range(len(lep_genindex_vec)): + lep_genindex.append(lep_genindex_vec[i]) if (foundZZCandidate): keepIt = True self.passZZEvts += 1 @@ -369,6 +434,13 @@ def analyze(self, event): self.out.fillBranch("D_int",D_int) self.out.fillBranch("D_L1",D_L1) self.out.fillBranch("D_L1Zg",D_L1Zg) + self.out.fillBranch("passedTrig", passedTrig) + self.out.fillBranch("passedFullSelection", passedFullSelection) + self.out.fillBranch("passedZ4lSelection", passedZ4lSelection) + self.out.fillBranch("passedZ4lZ1LSelection", passedZ4lZ1LSelection) + self.out.fillBranch("passedZ4lZXCRSelection", passedZ4lZXCRSelection) + self.out.fillBranch("passedZXCRSelection", passedZXCRSelection) + self.out.fillBranch("passedFiducialSelection", passedFiducialSelection) self.out.fillBranch("massL1",massL1) self.out.fillBranch("pTL1",pTL1) @@ -401,7 +473,13 @@ def analyze(self, event): # self.out.fillBranch("nElectron_Fsr", len(electrons)) # self.out.fillBranch("nMuon_Fsr", len(muons)) - + + self.out.fillBranch("GENlep_id",GENlep_id) + self.out.fillBranch("GENlep_Hindex",GENlep_Hindex) + self.out.fillBranch("GENZ_DaughtersId",GENZ_DaughtersId) + self.out.fillBranch("GENZ_MomId",GENZ_MomId) + self.out.fillBranch("GENlep_MomId",GENlep_MomId) + self.out.fillBranch("GENlep_MomMomId",GENlep_MomMomId) 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) diff --git a/interface/GenAnalysis.h b/interface/GenAnalysis.h index 4105f33..2573810 100644 --- a/interface/GenAnalysis.h +++ b/interface/GenAnalysis.h @@ -45,7 +45,9 @@ class GenAnalysis{ float GENpT4lj, GENpT4ljj, GENmass4lj, GENmass4ljj; float leadingPtCut,subleadingPtCut; bool passedFiducialSelection; - int GENnjets_pt30_eta4p7,GENnjets_pt30_eta2p5; + int GENnjets_pt30_eta4p7,GENnjets_pt30_eta2p5,nGENLeptons; + int GENZ_DaughtersId[2]; + int nVECZ; unsigned int GENlep_Hindex[4]; void SetGenParts(float GenPart_pt_, float GenPart_eta_,float GenPart_phi_,float GenPart_mass_,int GenPart_pdgId_,int GenPart_status_,int GenPart_statusFlags_,int GenPart_genPartIdxMother_){ GenPart_pt.push_back(GenPart_pt_); @@ -70,8 +72,9 @@ class GenAnalysis{ } void Initialize(){ passedFiducialSelection=false; - nGenPart = 0; nGenJet = 0; GENMH = 0; GENmassZZ= 0; GENpTZZ= 0; GENnjets_pt30_eta4p7=0;GENnjets_pt30_eta2p5=0; - GENpt_leadingjet_pt30_eta4p7=0; GENpt_leadingjet_pt30_eta2p5=0; + nGenPart = 0; nGENLeptons=0;nGenJet = 0; GENMH = 0; GENmassZZ= 0; GENpTZZ= 0; GENnjets_pt30_eta4p7=0;GENnjets_pt30_eta2p5=0; + GENpt_leadingjet_pt30_eta4p7=0; GENpt_leadingjet_pt30_eta2p5=0;nVECZ=0; + GENZ_DaughtersId[0]=0;GENZ_DaughtersId[1]=0; GenPart_pt.clear(); GenPart_eta.clear(); GenPart_phi.clear(); GenPart_mass.clear(); GenPart_pdgId.clear();GenPart_status.clear();GenPart_statusFlags.clear(); GenPart_genPartIdxMother.clear(); GenJet_pt.clear(); GenJet_eta.clear(); GenJet_phi.clear(); GenJet_mass.clear(); GENZ_phi.clear(); GENZ_pt.clear(); GENZ_eta.clear(); GENZ_mass.clear();GENZ_MomId.clear(); diff --git a/interface/H4LTools.h b/interface/H4LTools.h index edbc7da..a91ff04 100644 --- a/interface/H4LTools.h +++ b/interface/H4LTools.h @@ -12,7 +12,7 @@ class H4LTools { public: - H4LTools(int year); + H4LTools(int year, bool isMC_); float elePtcut, MuPtcut, eleEtacut, MuEtacut, elesip3dCut, Musip3dCut,Zmass,MZ1cut,MZcutup,MZcutdown,MZZcut,HiggscutUp,HiggscutDown; float eleLoosedxycut,eleLoosedzcut,MuLoosedxycut,MuLoosedzcut,MuTightdxycut,MuTightdzcut,MuTightTrackerLayercut,MuTightpTErrorcut,MuHighPtBound,eleIsocut,MuIsocut; float fsrphotonPtcut,fsrphotonEtacut,fsrphotonIsocut,fsrphotondRlcut,fsrphotondRlOverPtcut, JetPtcut,JetEtacut; @@ -114,6 +114,9 @@ class H4LTools { void SetMuonsGen(int Muon_genPartIdx_){ Muon_genPartIdx.push_back(Muon_genPartIdx_); } + void SetElectronsGen(int Electron_genPartIdx_){ + Electron_genPartIdx.push_back(Electron_genPartIdx_); + } /*void SetMuons(TTreeReaderArray *Muon_pt_, TTreeReaderArray *Muon_eta_, TTreeReaderArray *Muon_phi_, TTreeReaderArray *Muon_mass_, TTreeReaderArray *Muon_isGlobal_, TTreeReaderArray *Muon_isTracker_, TTreeReaderArray *Muon_dxy_, TTreeReaderArray *Muon_dz_,TTreeReaderArray *Muon_sip3d_, TTreeReaderArray *Muon_ptErr_, @@ -169,7 +172,7 @@ class H4LTools { void SetObjectNumGen(unsigned nGenPart_){ nGenPart = nGenPart_; } - + bool isMC; std::vector goodLooseElectrons2012(); std::vector goodLooseMuons2012(); std::vector goodMuons2015_noIso_noPf(std::vector Muonindex); @@ -194,6 +197,8 @@ class H4LTools { std::vector Zflavor; //mu->13, e->11 std::vector Zlep1index; std::vector Zlep2index; + std::vector Zlep1lepindex; + std::vector Zlep2lepindex; std::vector Zlep1pt; std::vector Zlep1eta; std::vector Zlep1phi; @@ -213,12 +218,12 @@ class H4LTools { std::vector Zlep2phiNoFsr; std::vector Zlep2massNoFsr; std::vector jetidx; - int nTightEle; int nTightMu; int nTightEleChgSum; int nTightMuChgSum; int njets_pt30_eta4p7; + int Lepointer; bool flag4e; bool flag4mu; @@ -239,12 +244,16 @@ class H4LTools { std::vector Muiso,Eiso; std::vector Eid; std::vector muid; + std::vector lep_genindex; + std::vector TightElelep_index; + std::vector TightMulep_index; + int lep_Hindex[4]; std::vector TightEleindex; std::vector TightMuindex; void Initialize(){ Electron_pt.clear();Electron_phi.clear();Electron_eta.clear();Electron_mass.clear();Electron_dxy.clear();Electron_dz.clear();Electron_sip3d.clear(); - Electron_mvaFall17V2Iso.clear();Electron_pdgId.clear();Electron_pfRelIso03_all.clear(); + Electron_mvaFall17V2Iso.clear();Electron_pdgId.clear();Electron_genPartIdx.clear();Electron_pfRelIso03_all.clear(); Muon_pt.clear();Muon_phi.clear();Muon_eta.clear();Muon_mass.clear();Muon_dxy.clear();Muon_dz.clear();Muon_sip3d.clear();Muon_ptErr.clear();Muon_pfRelIso03_all.clear(); Muon_nTrackerLayers.clear();Muon_genPartIdx.clear();Muon_pdgId.clear();Muon_charge.clear(); Muon_isTracker.clear();Muon_isGlobal.clear();Muon_isPFcand.clear(); @@ -262,12 +271,14 @@ class H4LTools { Zlep1chg.clear(); Zlep2chg.clear(); Zlep1ptNoFsr.clear(); Zlep1etaNoFsr.clear(); Zlep1phiNoFsr.clear(); Zlep1massNoFsr.clear(); Zlep2ptNoFsr.clear(); Zlep2etaNoFsr.clear(); Zlep2phiNoFsr.clear(); Zlep2massNoFsr.clear(); - jetidx.clear(); + jetidx.clear(); lep_genindex.clear(); TightElelep_index.clear();TightMulep_index.clear(); looseEle.clear(); looseMu.clear(); bestEle.clear(); bestMu.clear(); tighteleforjetidx.clear(); tightmuforjetidx.clear(); Electronindex.clear(); Muonindex.clear(); AllEid.clear(); AllMuid.clear(); Elelist.clear(); Mulist.clear(); ElelistFsr.clear(); Mulist.clear(); Elechg.clear(); Muchg.clear(); Muiso.clear();Eiso.clear(); Eid.clear(); muid.clear(); TightEleindex.clear(); TightMuindex.clear(); + nElectron = 0; nMuon = 0; nJet = 0; nFsrPhoton = 0; nGenPart = 0; nTightEle = 0; nTightMu = 0; nTightEleChgSum = 0; nTightMuChgSum = 0; + Lepointer = 0; pTL1 = -999; etaL1 = -999; phiL1 = -999; massL1 = -999; pTL2 = -999; etaL2 = -999; phiL2 = -999; massL2 = -999; @@ -315,7 +326,7 @@ class H4LTools { private: std::vector Electron_pt,Electron_phi,Electron_eta,Electron_mass,Electron_dxy,Electron_dz,Electron_sip3d; std::vector Electron_mvaFall17V2Iso,Electron_pfRelIso03_all; - std::vector Electron_pdgId; + std::vector Electron_pdgId,Electron_genPartIdx; std::vector Jet_pt,Jet_phi,Jet_eta,Jet_mass,Jet_btagDeepC; std::vector Jet_jetId,Jet_puId; @@ -335,7 +346,8 @@ class H4LTools { }; -H4LTools::H4LTools(int year){ +H4LTools::H4LTools(int year, bool isMC_){ + isMC = isMC_; std::cout<<"year"<<" "<setCandidateDecayMode(TVar::CandidateDecay_ZZ); diff --git a/src/GenAnalysis.cc b/src/GenAnalysis.cc index 2862c67..00fde19 100644 --- a/src/GenAnalysis.cc +++ b/src/GenAnalysis.cc @@ -27,7 +27,6 @@ int GenAnalysis::mothermotherID(int Genidx){ return 2212; } void GenAnalysis::SetGenVariables(){ - int nGENLeptons=0; TLorentzVector GENmom1, GENmom2; TLorentzVector LS3_Z1_1, LS3_Z1_2, LS3_Z2_1, LS3_Z2_2, GEN_HVec; int GENmom1_id=-999, GENmom2_id=-999; @@ -114,6 +113,7 @@ void GenAnalysis::SetGenVariables(){ GENZ_phi.push_back(GenPart_phi[genpidx]); GENZ_mass.push_back(GenPart_mass[genpidx]); GENZ_MomId.push_back(motherID(genpidx)); + nVECZ++; } } if (GENlep_pt.size()>=4) { @@ -224,6 +224,8 @@ void GenAnalysis::SetGenVariables(){ if(deltaRll<=0.02) { passedDeltaR = false; break; } } } + GENZ_DaughtersId[0] = abs(GENlep_id[GENlep_Hindex[0]]); + GENZ_DaughtersId[1] = abs(GENlep_id[GENlep_Hindex[2]]);//Fix me: maybe not correct! if(passedMassOS==false || passedElMuDeltaR==false || passedDeltaR==false) passedFiducialSelection=false; if (passedFiducialSelection) { // DO GEN JETS diff --git a/src/H4LTools.cc b/src/H4LTools.cc index 746dfaa..996130d 100644 --- a/src/H4LTools.cc +++ b/src/H4LTools.cc @@ -335,6 +335,10 @@ void H4LTools::LeptonSelection(){ nTightEle++; TightEleindex.push_back(ae); nTightEleChgSum += Elechg[ae]; + TightElelep_index.push_back(Lepointer); + Lepointer++; + if (isMC) lep_genindex.push_back(Electron_genPartIdx[Electronindex[ae]]); + else lep_genindex.push_back(-1); } } @@ -358,6 +362,10 @@ void H4LTools::LeptonSelection(){ nTightMu++; TightMuindex.push_back(amu); nTightMuChgSum += Muchg[amu]; + TightMulep_index.push_back(Lepointer); + Lepointer++; + if (isMC) lep_genindex.push_back(Muon_genPartIdx[Muonindex[amu]]); + else lep_genindex.push_back(-1); } } @@ -391,6 +399,8 @@ bool H4LTools::findZCandidate(){ Zlist.push_back(Zcan); Zlep1index.push_back(TightEleindex[ke]); Zlep2index.push_back(TightEleindex[je]); + Zlep1lepindex.push_back(TightElelep_index[ke]); + Zlep2lepindex.push_back(TightElelep_index[je]); Zflavor.push_back(11); Zlep1pt.push_back(ElelistFsr[TightEleindex[ke]].Pt()); Zlep2pt.push_back(ElelistFsr[TightEleindex[je]].Pt()); @@ -426,6 +436,8 @@ bool H4LTools::findZCandidate(){ Zlist.push_back(Zcan); Zlep1index.push_back(TightMuindex[kmu]); Zlep2index.push_back(TightMuindex[jmu]); + Zlep1lepindex.push_back(TightMulep_index[kmu]); + Zlep2lepindex.push_back(TightMulep_index[jmu]); Zflavor.push_back(13); Zlep1pt.push_back(MulistFsr[TightMuindex[kmu]].Pt()); Zlep2pt.push_back(MulistFsr[TightMuindex[jmu]].Pt()); @@ -730,7 +742,10 @@ bool H4LTools::ZZSelection(){ Lep3.SetPtEtaPhiM(Zlep1pt[Z2index],Zlep1eta[Z2index],Zlep1phi[Z2index],Zlep1mass[Z2index]); Lep4.SetPtEtaPhiM(Zlep2pt[Z2index],Zlep2eta[Z2index],Zlep2phi[Z2index],Zlep2mass[Z2index]); - + lep_Hindex[0] = Zlep1lepindex[Z1index]; + lep_Hindex[1] = Zlep2lepindex[Z1index]; + lep_Hindex[2] = Zlep1lepindex[Z2index]; + lep_Hindex[3] = Zlep2lepindex[Z2index]; pTL1 = Lep1.Pt(); etaL1 = Lep1.Eta(); phiL1 = Lep1.Phi(); From 77974034cbbc5b0f420b093e861f05d7cb07c9a7 Mon Sep 17 00:00:00 2001 From: yuji Date: Thu, 1 Feb 2024 16:10:04 +0100 Subject: [PATCH 4/6] add 2022 dataset --- input_data_Files/sample_list_v12_2022.dat | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 input_data_Files/sample_list_v12_2022.dat diff --git a/input_data_Files/sample_list_v12_2022.dat b/input_data_Files/sample_list_v12_2022.dat new file mode 100644 index 0000000..dabf1c8 --- /dev/null +++ b/input_data_Files/sample_list_v12_2022.dat @@ -0,0 +1,32 @@ +# Data +/SingleMuon/Run2022C-16Dec2023-v1/NANOAOD +/DoubleMuon/Run2022C-16Dec2023-v1/NANOAOD +/Muon/Run2022C-16Dec2023-v1/NANOAOD +/Muon/Run2022D-16Dec2023-v1/NANOAOD +/Muon/Run2022E-16Dec2023-v1/NANOAOD +/Muon/Run2022F-16Dec2023-v1/NANOAOD +/Muon/Run2022G-19Dec2023-v2/NANOAOD +/MuonEG/Run2022C-22Sep2023-v1/NANOAOD +/MuonEG/Run2022D-22Sep2023-v1/NANOAOD +/MuonEG/Run2022E-22Sep2023-v1/NANOAOD +/MuonEG/Run2022F-22Sep2023-v1/NANOAOD +/MuonEG/Run2022G-22Sep2023-v1/NANOAOD +/EGamma/Run2022C-16Dec2023-v1/NANOAOD +/EGamma/Run2022D-16Dec2023-v1/NANOAOD +/EGamma/Run2022E-16Dec2023-v1/NANOAOD +/EGamma/Run2022F-16Dec2023-v1/NANOAOD +/EGamma/Run2022G-16Dec2023-v1/NANOAOD +# +# MC +/GluGluHtoZZto4L_M-125_TuneCP5_13p6TeV_powheg2-JHUGenV752-pythia8/Run3Summer22NanoAODv12-130X_mcRun3_2022_realistic_v5-v2/NANOAODSIM +/GluGluHtoZZto4L_M-125_TuneCP5_13p6TeV_powheg2-JHUGenV752-pythia8/Run3Summer22EENanoAODv12-130X_mcRun3_2022_realistic_postEE_v6-v2/NANOAODSIM +/VBFHto2Zto4L_M125_TuneCP5_13p6TeV_powheg-jhugenv752-pythia8/Run3Summer22NanoAODv12-130X_mcRun3_2022_realistic_v5-v2/NANOAODSIM +/VBFHto2Zto4L_M125_TuneCP5_13p6TeV_powheg-jhugenv752-pythia8/Run3Summer22EENanoAODv12-130X_mcRun3_2022_realistic_postEE_v6-v2/NANOAODSIM +/WminusH_Hto2Zto4L_M-125_TuneCP5_13p6TeV_powheg2-minlo-HWJ-JHUGenV752-pythia8/Run3Summer22NanoAODv12-130X_mcRun3_2022_realistic_v5-v2/NANOAODSIM +/WminusH_Hto2Zto4L_M-125_TuneCP5_13p6TeV_powheg2-minlo-HWJ-JHUGenV752-pythia8/Run3Summer22EENanoAODv12-130X_mcRun3_2022_realistic_postEE_v6-v2/NANOAODSIM +/WplusH_Hto2Zto4L_M-125_TuneCP5_13p6TeV_powheg2-minlo-HWJ-JHUGenV752-pythia8/Run3Summer22NanoAODv12-130X_mcRun3_2022_realistic_v5-v2/NANOAODSIM +/WplusH_Hto2Zto4L_M-125_TuneCP5_13p6TeV_powheg2-minlo-HWJ-JHUGenV752-pythia8/Run3Summer22EENanoAODv12-130X_mcRun3_2022_realistic_postEE_v6-v2/NANOAODSIM +/ZHto2Zto4L_M125_TuneCP5_13p6TeV_powheg2-minlo-HZJ-JHUGenV752-pythia8/Run3Summer22NanoAODv12-130X_mcRun3_2022_realistic_v5-v2/NANOAODSIM +/ZHto2Zto4L_M125_TuneCP5_13p6TeV_powheg2-minlo-HZJ-JHUGenV752-pythia8/Run3Summer22EENanoAODv12-130X_mcRun3_2022_realistic_postEE_v6-v2/NANOAODSIM +/TTH_Hto2Z_M-125_4LFilter_TuneCP5_13p6TeV_powheg2-JHUGenV752-pythia8/Run3Summer22NanoAODv12-130X_mcRun3_2022_realistic_v5-v2/NANOAODSIM +/TTH_Hto2Z_M-125_4LFilter_TuneCP5_13p6TeV_powheg2-JHUGenV752-pythia8/Run3Summer22EENanoAODv12-130X_mcRun3_2022_realistic_postEE_v6-v2/NANOAODSIM From ae8cd2e2e55941285beb8bb19766f78baf1e95a3 Mon Sep 17 00:00:00 2001 From: yuji Date: Thu, 1 Feb 2024 17:03:11 +0100 Subject: [PATCH 5/6] update keep_and_drop.txt --- keep_and_drop.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/keep_and_drop.txt b/keep_and_drop.txt index fb9c991..a130d81 100644 --- a/keep_and_drop.txt +++ b/keep_and_drop.txt @@ -23,6 +23,9 @@ keep *L3 keep *L4 keep *j1 keep *j2 +keep pass* +keep GEN* +keep njet* keep D_* # keep nPhoton # keep Photon* From 1f6bcda6858399d8527a75887fa67774a544f067 Mon Sep 17 00:00:00 2001 From: yuji Date: Fri, 2 Feb 2024 09:11:50 +0100 Subject: [PATCH 6/6] add 2022 option --- post_proc.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/post_proc.py b/post_proc.py index c708eb0..1d8b575 100755 --- a/post_proc.py +++ b/post_proc.py @@ -61,7 +61,15 @@ def main(): # Determine the year and type (MC or Data) first_file = testfilelist[0] isMC = "/data/" not in first_file - + + if "22" in first_file or "postEE" in first_file: + """UL2018 for identification of 2018 UL data and UL18 for identification of 2018 UL MC + """ + year = 2018 + cfgFile = "Input_2018.yml" + jsonFileName = "golden_Json/Cert_314472-325175_13TeV_Legacy2018_Collisions18_JSON.txt" + sfFileName = "DeepCSV_102XSF_V2.csv" + modulesToRun.extend([muonScaleRes2018()]) if "UL18" in first_file or "UL2018" in first_file: """UL2018 for identification of 2018 UL data and UL18 for identification of 2018 UL MC """