From 9463bdaf9d2a60b0680721778d80f5374522aa9e Mon Sep 17 00:00:00 2001 From: azaza Date: Tue, 8 Nov 2022 10:50:34 +0100 Subject: [PATCH 01/11] Added muon variables related to jets --- plugins/JetConstituentTableProducer.cc | 94 +++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/plugins/JetConstituentTableProducer.cc b/plugins/JetConstituentTableProducer.cc index 1fe8f5d..efe3dd7 100644 --- a/plugins/JetConstituentTableProducer.cc +++ b/plugins/JetConstituentTableProducer.cc @@ -48,8 +48,10 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { //const std::string name_; const std::string name_; const std::string nameSV_; + const std::string nameMu_; const std::string idx_name_; const std::string idx_nameSV_; + const std::string idx_nameMu_; const bool readBtag_; const double jet_radius_; @@ -57,10 +59,12 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { edm::EDGetTokenT vtx_token_; edm::EDGetTokenT cand_token_; edm::EDGetTokenT sv_token_; + edm::EDGetTokenT > muon_token_; edm::Handle vtxs_; edm::Handle cands_; edm::Handle svs_; + edm::Handle > muons_; edm::ESHandle track_builder_; edm::ESGetToken track_builder_token_; @@ -75,18 +79,22 @@ template< typename T> JetConstituentTableProducer::JetConstituentTableProducer(const edm::ParameterSet &iConfig) : name_(iConfig.getParameter("name")), nameSV_(iConfig.getParameter("nameSV")), + nameMu_(iConfig.getParameter("nameMu")), idx_name_(iConfig.getParameter("idx_name")), idx_nameSV_(iConfig.getParameter("idx_nameSV")), + idx_nameMu_(iConfig.getParameter("idx_nameMu")), readBtag_(iConfig.getParameter("readBtag")), jet_radius_(iConfig.getParameter("jet_radius")), jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), cand_token_(consumes(iConfig.getParameter("candidates"))), sv_token_(consumes(iConfig.getParameter("secondary_vertices"))), + muon_token_(consumes >(iConfig.getParameter("muons"))), track_builder_token_( esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))){ produces(name_); produces(nameSV_); + produces(nameMu_); produces>(); } @@ -98,24 +106,40 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even // elements in all these collections must have the same order! auto outCands = std::make_unique>(); auto outSVs = std::make_unique> (); - std::vector jetIdx_pf, jetIdx_sv, pfcandIdx, svIdx; + auto outMuons = std::make_unique>(); + std::vector jetIdx_pf, jetIdx_sv, jetIdx_mu, pfcandIdx, svIdx, muIdx; // PF Cands std::vector btagEtaRel, btagPtRatio, btagPParRatio, btagSip3dVal, btagSip3dSig, btagJetDistVal, cand_pt; // Secondary vertices std::vector sv_mass, sv_pt, sv_ntracks, sv_chi2, sv_normchi2, sv_dxy, sv_dxysig, sv_d3d, sv_d3dsig, sv_costhetasvpv; std::vector sv_ptrel, sv_phirel, sv_deltaR, sv_enratio; + // Muons + std::vector muon_pt, muon_eta, muon_phi, muon_ptrel; + std::vector muon_isGlobal, muon_chi2Tk, muon_chi2; + std::vector muon_nMuHit, muon_nMatched, muon_nTkHit, muon_nPixHit, muon_nOutHit; auto jets = iEvent.getHandle(jet_token_); iEvent.getByToken(vtx_token_, vtxs_); iEvent.getByToken(cand_token_, cands_); iEvent.getByToken(sv_token_, svs_); + iEvent.getByToken(muon_token_, muons_); if(readBtag_){ track_builder_ = iSetup.getHandle(track_builder_token_); } + /*outMuons->clear(); + jetIdx_mu.clear(); + muIdx.clear(); + muon_pt.clear(); + muon_eta.clear(); + muon_phi.clear(); + muon_ptrel.clear();*/ + + for (unsigned i_jet = 0; i_jet < jets->size(); ++i_jet) { const auto &jet = jets->at(i_jet); + std::cout<<"jet "<::produce(edm::Event &iEvent, const edm::Even } } } // end jet loop + + + //Muons + uint idx_mu=0; + for (const auto &mu : *muons_) { + if(reco::deltaR2(mu, jet) < jet_radius_ * jet_radius_){ + outMuons->push_back(mu); + jetIdx_mu.push_back(i_jet); + muIdx.push_back(idx_mu); + muon_pt.push_back(mu.pt()); + std::cout<<"muon pt: "<hitPattern().numberOfValidMuonHits()); + muon_nMatched.push_back(mu.numberOfMatchedStations()); + muon_nTkHit.push_back(mu.innerTrack()->hitPattern().numberOfValidHits()); + muon_nPixHit.push_back(mu.innerTrack()->hitPattern().numberOfValidPixelHits()); + muon_nOutHit.push_back(mu.innerTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_OUTER_HITS)); + muon_chi2.push_back(mu.globalTrack()->normalizedChi2()); + muon_chi2Tk.push_back(mu.innerTrack()->normalizedChi2()); + } + else{ + muon_nMuHit.push_back(-1); + muon_nMatched.push_back(-1); + muon_nTkHit.push_back(-1); + muon_nPixHit.push_back(-1); + muon_nOutHit.push_back(-1); + muon_chi2.push_back(-1); + muon_chi2Tk.push_back(-1); + + } + muon_isGlobal.push_back(mu.isGlobalMuon()); + + + + } + idx_mu++; + } } auto candTable = std::make_unique(outCands->size(), name_, false); @@ -256,6 +321,28 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even iEvent.put(std::move(svTable), nameSV_); iEvent.put(std::move(outCands)); + + + // Muon table + auto muonTable = std::make_unique(outMuons->size(), nameMu_, false); + // We fill from here only stuff that cannot be created with the SimpleFlatTnameableProducer + muonTable->addColumn("jetIdx", jetIdx_mu, "Index of the parent jet"); + muonTable->addColumn(idx_nameMu_, muIdx, "Index in the Muon list"); + if (readBtag_) { + muonTable->addColumn("pt", muon_pt, "pt", 20); + muonTable->addColumn("eta", muon_eta, "eta", 20); + muonTable->addColumn("phi", muon_pt, "phi", 20); + muonTable->addColumn("isGlobal", muon_isGlobal, "isGlobal", 20); + muonTable->addColumn("ptrel", muon_ptrel, "pt relative to parent jet", 20); + muonTable->addColumn("nMuHit", muon_nMuHit, "number of muon hits", 20); + muonTable->addColumn("nMatched", muon_nMatched, "number of matched stations", 20); + muonTable->addColumn("nTkHit", muon_nTkHit, "number of tracker hits", 20); + muonTable->addColumn("nPixHit", muon_nPixHit, "number of pixel hits", 20); + muonTable->addColumn("nOutHit", muon_nOutHit, "number of missing outer hits", 20); + muonTable->addColumn("chi2", muon_chi2, "chi2", 20); + muonTable->addColumn("chi2Tk", muon_chi2Tk, "chi2 inner track", 20); + } + iEvent.put(std::move(muonTable), nameMu_); } template< typename T> @@ -263,15 +350,18 @@ void JetConstituentTableProducer::fillDescriptions(edm::ConfigurationDescript edm::ParameterSetDescription desc; desc.add("name", "JetPFCands"); desc.add("nameSV", "JetSV"); + desc.add("nameMu", "JetMuons"); desc.add("idx_name", "candIdx"); desc.add("idx_nameSV", "svIdx"); + desc.add("idx_nameMu", "muIdx"); desc.add("jet_radius", true); desc.add("readBtag", true); desc.add("jets", edm::InputTag("slimmedJetsAK8")); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("candidates", edm::InputTag("packedPFCandidates")); desc.add("secondary_vertices", edm::InputTag("slimmedSecondaryVertices")); - descriptions.addWithDefaultLabel(desc); + desc.add("muons", edm::InputTag("slimmedMuons")); + descriptions.addWithDefaultLabel(desc); } typedef JetConstituentTableProducer PatJetConstituentTableProducer; From c7d40748b71dff478e10e680eb5f27cddac75a67 Mon Sep 17 00:00:00 2001 From: azaza Date: Tue, 8 Nov 2022 10:51:22 +0100 Subject: [PATCH 02/11] Added muon variables related to jets --- python/addPFCands_cff.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/addPFCands_cff.py b/python/addPFCands_cff.py index 1cb8602..37c2c48 100644 --- a/python/addPFCands_cff.py +++ b/python/addPFCands_cff.py @@ -62,6 +62,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_name = cms.string("pFCandsIdx"), nameSV = cms.string("FatJetSVs"), idx_nameSV = cms.string("sVIdx"), + nameMu = cms.string("FatJetMuons"), + idx_nameMu = cms.string("MuIdx"), ) process.customAK4ConstituentsTable = cms.EDProducer("PatJetConstituentTableProducer", candidates = candInput, @@ -71,6 +73,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_name = cms.string("pFCandsIdx"), nameSV = cms.string("JetSVs"), idx_nameSV = cms.string("sVIdx"), + #nameMu = cms.string("JetMuons"), + #idx_nameMu = cms.string("MuIdx"), ) if not allPF: process.customizedPFCandsTask.add(process.finalJetsConstituents) @@ -122,6 +126,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal nameSV = cms.string("GenFatJetSVs"), idx_name = cms.string("pFCandsIdx"), idx_nameSV = cms.string("sVIdx"), + nameMu = cms.string("GenFatJetMuons"), + idx_nameMu = cms.string("MuIdx"), readBtag = cms.bool(False)) process.genAK4ConstituentsTable = cms.EDProducer("GenJetConstituentTableProducer", candidates = genCandInput, @@ -130,6 +136,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal nameSV = cms.string("GenJetSVs"), idx_name = cms.string("pFCandsIdx"), idx_nameSV = cms.string("sVIdx"), + nameMu = cms.string("GenJetMuons"), + idx_nameMu = cms.string("MuIdx"), readBtag = cms.bool(False)) process.customizedPFCandsTask.add(process.genJetsAK4Constituents) #Note: For gen need to add jets to the process to keep pt cuts. process.customizedPFCandsTask.add(process.genJetsAK8Constituents) From a35ee2af1e44efebd2d4aaef632853fcf7f9ba64 Mon Sep 17 00:00:00 2001 From: azaza Date: Mon, 28 Nov 2022 17:12:56 +0100 Subject: [PATCH 03/11] add variables for track table --- plugins/JetConstituentTableProducer.cc | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/plugins/JetConstituentTableProducer.cc b/plugins/JetConstituentTableProducer.cc index efe3dd7..9e55c76 100644 --- a/plugins/JetConstituentTableProducer.cc +++ b/plugins/JetConstituentTableProducer.cc @@ -21,6 +21,9 @@ #include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h" #include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "TrackingTools/IPTools/interface/IPTools.h" + #include "DataFormats/BTauReco/interface/TrackIPTagInfo.h" #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h" #include "RecoBTag/FeatureTools/interface/deep_helpers.h" @@ -30,6 +33,7 @@ using namespace btagbtvdeep; #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "DataFormats/NanoAOD/interface/FlatTable.h" + template class JetConstituentTableProducer : public edm::stream::EDProducer<> { public: @@ -45,6 +49,10 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { //===== typedef reco::VertexCompositePtrCandidateCollection SVCollection; + typedef reco::TrackIPTagInfo IPTagInfo; + typedef typename reco::TrackIPTagInfo::input_container Tracks; + typedef typename reco::TrackIPTagInfo::input_container::value_type TrackRef; + //const std::string name_; const std::string name_; const std::string nameSV_; @@ -55,6 +63,8 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { const bool readBtag_; const double jet_radius_; + std::string ipTagInfos_; + edm::EDGetTokenT> jet_token_; edm::EDGetTokenT vtx_token_; edm::EDGetTokenT cand_token_; @@ -85,6 +95,7 @@ JetConstituentTableProducer::JetConstituentTableProducer(const edm::Parameter idx_nameMu_(iConfig.getParameter("idx_nameMu")), readBtag_(iConfig.getParameter("readBtag")), jet_radius_(iConfig.getParameter("jet_radius")), + ipTagInfos_(iConfig.getParameter("ipTagInfos")), jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), cand_token_(consumes(iConfig.getParameter("candidates"))), @@ -139,7 +150,7 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even for (unsigned i_jet = 0; i_jet < jets->size(); ++i_jet) { const auto &jet = jets->at(i_jet); - std::cout<<"jet "<::produce(edm::Event &iEvent, const edm::Even btagJetDistVal.push_back(0); } } - } // end jet loop + } // end daughters loop //Muons @@ -248,7 +259,7 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even jetIdx_mu.push_back(i_jet); muIdx.push_back(idx_mu); muon_pt.push_back(mu.pt()); - std::cout<<"muon pt: "<::produce(edm::Event &iEvent, const edm::Even } idx_mu++; } - } + + //tracks + if(readBtag_){ + const IPTagInfo *ipTagInfo = jet.tagInfoTrackIP(ipTagInfos_.c_str()); + } + + } //end jet loop auto candTable = std::make_unique(outCands->size(), name_, false); // We fill from here only stuff that cannot be created with the SimpleFlatTableProducer @@ -331,7 +348,7 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even if (readBtag_) { muonTable->addColumn("pt", muon_pt, "pt", 20); muonTable->addColumn("eta", muon_eta, "eta", 20); - muonTable->addColumn("phi", muon_pt, "phi", 20); + muonTable->addColumn("phi", muon_phi, "phi", 20); muonTable->addColumn("isGlobal", muon_isGlobal, "isGlobal", 20); muonTable->addColumn("ptrel", muon_ptrel, "pt relative to parent jet", 20); muonTable->addColumn("nMuHit", muon_nMuHit, "number of muon hits", 20); From 670c2d296d16670de04167f059fa8b671066e4d5 Mon Sep 17 00:00:00 2001 From: azaza Date: Wed, 14 Dec 2022 17:14:06 +0100 Subject: [PATCH 04/11] added variables for FatJet and SubJet --- plugins/JetConstituentTableProducer.cc | 21 +---- python/addBTV.py | 101 +++++++++++++++++++++++++ test/nano_mc_Run3_122X_NANO.py | 4 +- 3 files changed, 105 insertions(+), 21 deletions(-) diff --git a/plugins/JetConstituentTableProducer.cc b/plugins/JetConstituentTableProducer.cc index 9e55c76..e6e6eab 100644 --- a/plugins/JetConstituentTableProducer.cc +++ b/plugins/JetConstituentTableProducer.cc @@ -21,9 +21,6 @@ #include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h" #include "TrackingTools/Records/interface/TransientTrackRecord.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" -#include "TrackingTools/IPTools/interface/IPTools.h" - #include "DataFormats/BTauReco/interface/TrackIPTagInfo.h" #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h" #include "RecoBTag/FeatureTools/interface/deep_helpers.h" @@ -33,7 +30,6 @@ using namespace btagbtvdeep; #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "DataFormats/NanoAOD/interface/FlatTable.h" - template class JetConstituentTableProducer : public edm::stream::EDProducer<> { public: @@ -49,10 +45,6 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { //===== typedef reco::VertexCompositePtrCandidateCollection SVCollection; - typedef reco::TrackIPTagInfo IPTagInfo; - typedef typename reco::TrackIPTagInfo::input_container Tracks; - typedef typename reco::TrackIPTagInfo::input_container::value_type TrackRef; - //const std::string name_; const std::string name_; const std::string nameSV_; @@ -63,8 +55,6 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { const bool readBtag_; const double jet_radius_; - std::string ipTagInfos_; - edm::EDGetTokenT> jet_token_; edm::EDGetTokenT vtx_token_; edm::EDGetTokenT cand_token_; @@ -95,7 +85,6 @@ JetConstituentTableProducer::JetConstituentTableProducer(const edm::Parameter idx_nameMu_(iConfig.getParameter("idx_nameMu")), readBtag_(iConfig.getParameter("readBtag")), jet_radius_(iConfig.getParameter("jet_radius")), - ipTagInfos_(iConfig.getParameter("ipTagInfos")), jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), cand_token_(consumes(iConfig.getParameter("candidates"))), @@ -248,7 +237,7 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even btagJetDistVal.push_back(0); } } - } // end daughters loop + } // end jet loop //Muons @@ -290,13 +279,7 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even } idx_mu++; } - - //tracks - if(readBtag_){ - const IPTagInfo *ipTagInfo = jet.tagInfoTrackIP(ipTagInfos_.c_str()); - } - - } //end jet loop + } auto candTable = std::make_unique(outCands->size(), name_, false); // We fill from here only stuff that cannot be created with the SimpleFlatTableProducer diff --git a/python/addBTV.py b/python/addBTV.py index d24e4f3..9985b3f 100644 --- a/python/addBTV.py +++ b/python/addBTV.py @@ -299,6 +299,105 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D doc="DeepCSV light btag discriminator", precision=10), ) + + FatJetVars = cms.PSet( + uncorrpt=Var("?availableJECSets().size()>0?correctedJet('Uncorrected').pt():pt()", + float, + doc="Uncorrected pT", + precision=10), + residual=Var("?availableJECSets().size()>0 ? pt()/correctedJet('L3Absolute').pt() : 1. ", + float, + doc="residual", + precision=10), + jes=Var("?availableJECSets().size()>0 ? pt()/correctedJet('Uncorrected').pt() : 1.", + float, + doc="jes (jet substructure)", + precision=10), + CombIVF=Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')", + float, + doc="combinedIVF", + precision=10), + DeepCSVBDisc=Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')", + float, + doc="DeepCSVBDisc", + precision=10), + #DeepCSVb=Var("bDiscriminator('pfDeepCSVJetTags:probb')", + # float, + # doc="DeepCSVb", + # precision=10), + btagDeepB_c=Var("bDiscriminator('pfDeepCSVJetTags:probc')", + float, + doc="DeepCSV c tag discriminator", + precision=10), + # Jet_DeepCSVcc --> assente! + # btagDeepB_cc=Var("bDiscriminator('pfDeepCSVJetTags:probcc')", + # float, + # doc="DeepCSV cc tag discriminator", + # precision=10), + DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", + float, + doc="DeepCSV C vs L discriminator", + precision=10), + DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", + float, + doc="DeepCSV C vs B discriminator", + precision=10), + # SV_multi -> da rivedere + #SV_multi=Var("svTagInfo->nVertices()", + # int, + # doc="SV multiplicity", + # precision=10), + massSoftDrop=Var("? hasUserFloat('SoftDrop:Mass') ? userFloat('SoftDrop:Mass') : userFloat('ak8PFJetsPuppiSoftDropMass')", + float, + doc="mass SoftDrop", + precision=10), + DoubleSV=Var("bDiscriminator('doubleSVBJetTags')", + float, + doc="DoubleSV discriminator", + precision=10), + ) + + SubJetVars = cms.PSet( + uncorrpt=Var("?availableJECSets().size()>0?correctedJet('Uncorrected').pt():pt()", + float, + doc="Uncorrected pT", + precision=10), + residual=Var("?availableJECSets().size()>0 ? pt()/correctedJet('L3Absolute').pt() : 1. ", + float, + doc="residual", + precision=10), + jes=Var("?availableJECSets().size()>0 ? pt()/correctedJet('Uncorrected').pt() : 1.", + float, + doc="jes (jet substructure)", + precision=10), + CombIVF=Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')", + float, + doc="combinedIVF", + precision=10), + DeepCSVBDisc=Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')", + float, + doc="DeepCSVBDisc", + precision=10), + btagDeepB_c=Var("bDiscriminator('pfDeepCSVJetTags:probc')", + float, + doc="DeepCSV c tag discriminator", + precision=10), + DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", + float, + doc="DeepCSV C vs L discriminator", + precision=10), + DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", + float, + doc="DeepCSV C vs B discriminator", + precision=10), + # massSoftDrop=Var("? hasUserFloat('SoftDrop:Mass') ? userFloat('SoftDrop:Mass') : userFloat('ak8PFJetsPuppiSoftDropMass')", + # float, + # doc="mass SoftDrop", + # precision=10), + + ) + + # decouple these from CommonVars, not relevant for data HadronCountingVars = cms.PSet( @@ -348,6 +447,7 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D extension=cms.bool(True), # this is the extension table for FatJets variables=cms.PSet( CommonVars, + FatJetVars, #HadronCountingVars if runOnMC else cms.PSet(), # only necessary before 106x get_DDX_vars() if ('DDX' in keepInputs) else cms.PSet(), )) @@ -363,6 +463,7 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D extension=cms.bool(True), # this is the extension table for FatJets variables=cms.PSet( CommonVars, + SubJetVars, #HadronCountingVars if runOnMC else cms.PSet(), # only necessary before 106x )) diff --git a/test/nano_mc_Run3_122X_NANO.py b/test/nano_mc_Run3_122X_NANO.py index ef85edc..424a8bb 100644 --- a/test/nano_mc_Run3_122X_NANO.py +++ b/test/nano_mc_Run3_122X_NANO.py @@ -23,13 +23,13 @@ process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(-1), + input = cms.untracked.int32(1000), output = cms.optional.untracked.allowed(cms.int32,cms.PSet) ) # Input source process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring('/store/mc/Run3Winter22MiniAOD/TTTo2L2Nu_CP5_13p6TeV_powheg-pythia8/MINIAODSIM/122X_mcRun3_2021_realistic_v9-v2/2550000/0d44f6e9-6961-4d60-b2c1-0e21c1249100.root'), + fileNames = cms.untracked.vstring('/store/mc/Run3Winter22MiniAOD/ZprimeToTT_M3000_W30_TuneCP2_13p6TeV-madgraph-pythiaMLM-pythia8/MINIAODSIM/122X_mcRun3_2021_realistic_v9-v2/60000/0aca854d-fcdb-4523-834d-201c36e4a6ca.root'), secondaryFileNames = cms.untracked.vstring() ) From 002caef3ae7b0ca28f657964c596bdce03fe7457 Mon Sep 17 00:00:00 2001 From: azaza Date: Wed, 14 Dec 2022 18:46:53 +0100 Subject: [PATCH 05/11] New vars for FatJets and SubJets --- python/addBTV.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/python/addBTV.py b/python/addBTV.py index 9985b3f..023f79e 100644 --- a/python/addBTV.py +++ b/python/addBTV.py @@ -321,19 +321,10 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D float, doc="DeepCSVBDisc", precision=10), - #DeepCSVb=Var("bDiscriminator('pfDeepCSVJetTags:probb')", - # float, - # doc="DeepCSVb", - # precision=10), btagDeepB_c=Var("bDiscriminator('pfDeepCSVJetTags:probc')", float, doc="DeepCSV c tag discriminator", precision=10), - # Jet_DeepCSVcc --> assente! - # btagDeepB_cc=Var("bDiscriminator('pfDeepCSVJetTags:probcc')", - # float, - # doc="DeepCSV cc tag discriminator", - # precision=10), DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", float, doc="DeepCSV C vs L discriminator", @@ -342,15 +333,10 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D float, doc="DeepCSV C vs B discriminator", precision=10), - # SV_multi -> da rivedere - #SV_multi=Var("svTagInfo->nVertices()", - # int, - # doc="SV multiplicity", - # precision=10), - massSoftDrop=Var("? hasUserFloat('SoftDrop:Mass') ? userFloat('SoftDrop:Mass') : userFloat('ak8PFJetsPuppiSoftDropMass')", - float, - doc="mass SoftDrop", - precision=10), + #massSoftDrop=Var("? hasUserFloat('SoftDrop:Mass') ? userFloat('SoftDrop:Mass') : userFloat('ak8PFJetsPuppiSoftDropMass')", + # float, + # doc="mass SoftDrop", + # precision=10), DoubleSV=Var("bDiscriminator('doubleSVBJetTags')", float, doc="DoubleSV discriminator", From d42065e69d67d1bbc8437f464ba8be2516518919 Mon Sep 17 00:00:00 2001 From: azaza Date: Thu, 12 Jan 2023 13:30:31 +0100 Subject: [PATCH 06/11] adjust indentation --- plugins/JetConstituentTableProducer.cc | 91 ++++++++++++-------------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/plugins/JetConstituentTableProducer.cc b/plugins/JetConstituentTableProducer.cc index e6e6eab..0c52180 100644 --- a/plugins/JetConstituentTableProducer.cc +++ b/plugins/JetConstituentTableProducer.cc @@ -48,10 +48,10 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { //const std::string name_; const std::string name_; const std::string nameSV_; - const std::string nameMu_; + const std::string nameMu_; const std::string idx_name_; const std::string idx_nameSV_; - const std::string idx_nameMu_; + const std::string idx_nameMu_; const bool readBtag_; const double jet_radius_; @@ -59,12 +59,12 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { edm::EDGetTokenT vtx_token_; edm::EDGetTokenT cand_token_; edm::EDGetTokenT sv_token_; - edm::EDGetTokenT > muon_token_; + edm::EDGetTokenT > muon_token_; edm::Handle vtxs_; edm::Handle cands_; edm::Handle svs_; - edm::Handle > muons_; + edm::Handle > muons_; edm::ESHandle track_builder_; edm::ESGetToken track_builder_token_; @@ -79,22 +79,22 @@ template< typename T> JetConstituentTableProducer::JetConstituentTableProducer(const edm::ParameterSet &iConfig) : name_(iConfig.getParameter("name")), nameSV_(iConfig.getParameter("nameSV")), - nameMu_(iConfig.getParameter("nameMu")), + nameMu_(iConfig.getParameter("nameMu")), idx_name_(iConfig.getParameter("idx_name")), idx_nameSV_(iConfig.getParameter("idx_nameSV")), - idx_nameMu_(iConfig.getParameter("idx_nameMu")), + idx_nameMu_(iConfig.getParameter("idx_nameMu")), readBtag_(iConfig.getParameter("readBtag")), jet_radius_(iConfig.getParameter("jet_radius")), jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), cand_token_(consumes(iConfig.getParameter("candidates"))), sv_token_(consumes(iConfig.getParameter("secondary_vertices"))), - muon_token_(consumes >(iConfig.getParameter("muons"))), + muon_token_(consumes >(iConfig.getParameter("muons"))), track_builder_token_( esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))){ produces(name_); produces(nameSV_); - produces(nameMu_); + produces(nameMu_); produces>(); } @@ -107,34 +107,27 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even auto outCands = std::make_unique>(); auto outSVs = std::make_unique> (); auto outMuons = std::make_unique>(); - std::vector jetIdx_pf, jetIdx_sv, jetIdx_mu, pfcandIdx, svIdx, muIdx; + std::vector jetIdx_pf, jetIdx_sv, jetIdx_mu, pfcandIdx, svIdx, muIdx; // PF Cands std::vector btagEtaRel, btagPtRatio, btagPParRatio, btagSip3dVal, btagSip3dSig, btagJetDistVal, cand_pt; // Secondary vertices std::vector sv_mass, sv_pt, sv_ntracks, sv_chi2, sv_normchi2, sv_dxy, sv_dxysig, sv_d3d, sv_d3dsig, sv_costhetasvpv; std::vector sv_ptrel, sv_phirel, sv_deltaR, sv_enratio; - // Muons - std::vector muon_pt, muon_eta, muon_phi, muon_ptrel; - std::vector muon_isGlobal, muon_chi2Tk, muon_chi2; - std::vector muon_nMuHit, muon_nMatched, muon_nTkHit, muon_nPixHit, muon_nOutHit; + // Muons + std::vector muon_pt, muon_eta, muon_phi, muon_ptrel; + std::vector muon_isGlobal, muon_chi2Tk, muon_chi2; + std::vector muon_nMuHit, muon_nMatched, muon_nTkHit, muon_nPixHit, muon_nOutHit; auto jets = iEvent.getHandle(jet_token_); iEvent.getByToken(vtx_token_, vtxs_); iEvent.getByToken(cand_token_, cands_); iEvent.getByToken(sv_token_, svs_); - iEvent.getByToken(muon_token_, muons_); + iEvent.getByToken(muon_token_, muons_); if(readBtag_){ track_builder_ = iSetup.getHandle(track_builder_token_); } - /*outMuons->clear(); - jetIdx_mu.clear(); - muIdx.clear(); - muon_pt.clear(); - muon_eta.clear(); - muon_phi.clear(); - muon_ptrel.clear();*/ for (unsigned i_jet = 0; i_jet < jets->size(); ++i_jet) { @@ -240,20 +233,19 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even } // end jet loop - //Muons - uint idx_mu=0; - for (const auto &mu : *muons_) { - if(reco::deltaR2(mu, jet) < jet_radius_ * jet_radius_){ - outMuons->push_back(mu); + //Muons + uint idx_mu=0; + for (const auto &mu : *muons_) { + if(reco::deltaR2(mu, jet) < jet_radius_ * jet_radius_){ + outMuons->push_back(mu); jetIdx_mu.push_back(i_jet); muIdx.push_back(idx_mu); muon_pt.push_back(mu.pt()); - //std::cout<<"muon pt: "<hitPattern().numberOfValidMuonHits()); muon_nMatched.push_back(mu.numberOfMatchedStations()); muon_nTkHit.push_back(mu.innerTrack()->hitPattern().numberOfValidHits()); @@ -262,7 +254,7 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even muon_chi2.push_back(mu.globalTrack()->normalizedChi2()); muon_chi2Tk.push_back(mu.innerTrack()->normalizedChi2()); } - else{ + else{ muon_nMuHit.push_back(-1); muon_nMatched.push_back(-1); muon_nTkHit.push_back(-1); @@ -275,10 +267,9 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even muon_isGlobal.push_back(mu.isGlobalMuon()); - - } - idx_mu++; - } + } + idx_mu++; + } } auto candTable = std::make_unique(outCands->size(), name_, false); @@ -323,26 +314,26 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even iEvent.put(std::move(outCands)); - // Muon table - auto muonTable = std::make_unique(outMuons->size(), nameMu_, false); - // We fill from here only stuff that cannot be created with the SimpleFlatTnameableProducer - muonTable->addColumn("jetIdx", jetIdx_mu, "Index of the parent jet"); - muonTable->addColumn(idx_nameMu_, muIdx, "Index in the Muon list"); - if (readBtag_) { - muonTable->addColumn("pt", muon_pt, "pt", 20); - muonTable->addColumn("eta", muon_eta, "eta", 20); - muonTable->addColumn("phi", muon_phi, "phi", 20); - muonTable->addColumn("isGlobal", muon_isGlobal, "isGlobal", 20); - muonTable->addColumn("ptrel", muon_ptrel, "pt relative to parent jet", 20); - muonTable->addColumn("nMuHit", muon_nMuHit, "number of muon hits", 20); + // Muon table + auto muonTable = std::make_unique(outMuons->size(), nameMu_, false); + // We fill from here only stuff that cannot be created with the SimpleFlatTnameableProducer + muonTable->addColumn("jetIdx", jetIdx_mu, "Index of the parent jet"); + muonTable->addColumn(idx_nameMu_, muIdx, "Index in the Muon list"); + if (readBtag_) { + muonTable->addColumn("pt", muon_pt, "pt", 20); + muonTable->addColumn("eta", muon_eta, "eta", 20); + muonTable->addColumn("phi", muon_phi, "phi", 20); + muonTable->addColumn("isGlobal", muon_isGlobal, "isGlobal", 20); + muonTable->addColumn("ptrel", muon_ptrel, "pt relative to parent jet", 20); + muonTable->addColumn("nMuHit", muon_nMuHit, "number of muon hits", 20); muonTable->addColumn("nMatched", muon_nMatched, "number of matched stations", 20); muonTable->addColumn("nTkHit", muon_nTkHit, "number of tracker hits", 20); muonTable->addColumn("nPixHit", muon_nPixHit, "number of pixel hits", 20); muonTable->addColumn("nOutHit", muon_nOutHit, "number of missing outer hits", 20); muonTable->addColumn("chi2", muon_chi2, "chi2", 20); muonTable->addColumn("chi2Tk", muon_chi2Tk, "chi2 inner track", 20); - } - iEvent.put(std::move(muonTable), nameMu_); + } + iEvent.put(std::move(muonTable), nameMu_); } template< typename T> @@ -350,17 +341,17 @@ void JetConstituentTableProducer::fillDescriptions(edm::ConfigurationDescript edm::ParameterSetDescription desc; desc.add("name", "JetPFCands"); desc.add("nameSV", "JetSV"); - desc.add("nameMu", "JetMuons"); + desc.add("nameMu", "JetMuons"); desc.add("idx_name", "candIdx"); desc.add("idx_nameSV", "svIdx"); - desc.add("idx_nameMu", "muIdx"); + desc.add("idx_nameMu", "muIdx"); desc.add("jet_radius", true); desc.add("readBtag", true); desc.add("jets", edm::InputTag("slimmedJetsAK8")); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("candidates", edm::InputTag("packedPFCandidates")); desc.add("secondary_vertices", edm::InputTag("slimmedSecondaryVertices")); - desc.add("muons", edm::InputTag("slimmedMuons")); + desc.add("muons", edm::InputTag("slimmedMuons")); descriptions.addWithDefaultLabel(desc); } From 58c9d946bcfa738a7cb80f19cf8da30951eb4f53 Mon Sep 17 00:00:00 2001 From: azaza Date: Thu, 12 Jan 2023 13:33:53 +0100 Subject: [PATCH 07/11] adjust indentation --- python/addBTV.py | 81 ++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/python/addBTV.py b/python/addBTV.py index 023f79e..518f05c 100644 --- a/python/addBTV.py +++ b/python/addBTV.py @@ -312,36 +312,33 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D jes=Var("?availableJECSets().size()>0 ? pt()/correctedJet('Uncorrected').pt() : 1.", float, doc="jes (jet substructure)", - precision=10), - CombIVF=Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')", - float, - doc="combinedIVF", precision=10), + CombIVF=Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')", + float, + doc="combinedIVF", + precision=10), DeepCSVBDisc=Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')", - float, - doc="DeepCSVBDisc", - precision=10), + float, + doc="DeepCSVBDisc", + precision=10), btagDeepB_c=Var("bDiscriminator('pfDeepCSVJetTags:probc')", float, doc="DeepCSV c tag discriminator", precision=10), DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", - float, - doc="DeepCSV C vs L discriminator", - precision=10), + float, + doc="DeepCSV C vs L discriminator", + precision=10), DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", - float, - doc="DeepCSV C vs B discriminator", - precision=10), - #massSoftDrop=Var("? hasUserFloat('SoftDrop:Mass') ? userFloat('SoftDrop:Mass') : userFloat('ak8PFJetsPuppiSoftDropMass')", - # float, - # doc="mass SoftDrop", - # precision=10), + float, + doc="DeepCSV C vs B discriminator", + precision=10), + DoubleSV=Var("bDiscriminator('doubleSVBJetTags')", - float, - doc="DoubleSV discriminator", - precision=10), - ) + float, + doc="DoubleSV discriminator", + precision=10), + ) SubJetVars = cms.PSet( uncorrpt=Var("?availableJECSets().size()>0?correctedJet('Uncorrected').pt():pt()", @@ -353,33 +350,29 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D doc="residual", precision=10), jes=Var("?availableJECSets().size()>0 ? pt()/correctedJet('Uncorrected').pt() : 1.", - float, - doc="jes (jet substructure)", - precision=10), + float, + doc="jes (jet substructure)", + precision=10), CombIVF=Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')", - float, - doc="combinedIVF", - precision=10), + float, + doc="combinedIVF", + precision=10), DeepCSVBDisc=Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')", - float, - doc="DeepCSVBDisc", - precision=10), + float, + doc="DeepCSVBDisc", + precision=10), btagDeepB_c=Var("bDiscriminator('pfDeepCSVJetTags:probc')", - float, - doc="DeepCSV c tag discriminator", - precision=10), + float, + doc="DeepCSV c tag discriminator", + precision=10), DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", - float, - doc="DeepCSV C vs L discriminator", - precision=10), + float, + doc="DeepCSV C vs L discriminator", + precision=10), DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", - float, - doc="DeepCSV C vs B discriminator", - precision=10), - # massSoftDrop=Var("? hasUserFloat('SoftDrop:Mass') ? userFloat('SoftDrop:Mass') : userFloat('ak8PFJetsPuppiSoftDropMass')", - # float, - # doc="mass SoftDrop", - # precision=10), + float, + doc="DeepCSV C vs B discriminator", + precision=10), ) @@ -449,7 +442,7 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D extension=cms.bool(True), # this is the extension table for FatJets variables=cms.PSet( CommonVars, - SubJetVars, + SubJetVars, #HadronCountingVars if runOnMC else cms.PSet(), # only necessary before 106x )) From 9834793235dbf5564f29c8cc7d0fa4f827ee26cd Mon Sep 17 00:00:00 2001 From: azaza Date: Thu, 12 Jan 2023 13:34:33 +0100 Subject: [PATCH 08/11] adjust indentation --- python/addPFCands_cff.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/python/addPFCands_cff.py b/python/addPFCands_cff.py index 37c2c48..7e35dd0 100644 --- a/python/addPFCands_cff.py +++ b/python/addPFCands_cff.py @@ -62,7 +62,7 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_name = cms.string("pFCandsIdx"), nameSV = cms.string("FatJetSVs"), idx_nameSV = cms.string("sVIdx"), - nameMu = cms.string("FatJetMuons"), + nameMu = cms.string("FatJetMuons"), idx_nameMu = cms.string("MuIdx"), ) process.customAK4ConstituentsTable = cms.EDProducer("PatJetConstituentTableProducer", @@ -73,8 +73,6 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_name = cms.string("pFCandsIdx"), nameSV = cms.string("JetSVs"), idx_nameSV = cms.string("sVIdx"), - #nameMu = cms.string("JetMuons"), - #idx_nameMu = cms.string("MuIdx"), ) if not allPF: process.customizedPFCandsTask.add(process.finalJetsConstituents) @@ -126,8 +124,6 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal nameSV = cms.string("GenFatJetSVs"), idx_name = cms.string("pFCandsIdx"), idx_nameSV = cms.string("sVIdx"), - nameMu = cms.string("GenFatJetMuons"), - idx_nameMu = cms.string("MuIdx"), readBtag = cms.bool(False)) process.genAK4ConstituentsTable = cms.EDProducer("GenJetConstituentTableProducer", candidates = genCandInput, @@ -136,8 +132,6 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal nameSV = cms.string("GenJetSVs"), idx_name = cms.string("pFCandsIdx"), idx_nameSV = cms.string("sVIdx"), - nameMu = cms.string("GenJetMuons"), - idx_nameMu = cms.string("MuIdx"), readBtag = cms.bool(False)) process.customizedPFCandsTask.add(process.genJetsAK4Constituents) #Note: For gen need to add jets to the process to keep pt cuts. process.customizedPFCandsTask.add(process.genJetsAK8Constituents) From 1a8dac5d5ca394b90dcdb3b5f179d46c32d08e74 Mon Sep 17 00:00:00 2001 From: azaza Date: Fri, 13 Jan 2023 18:25:16 +0100 Subject: [PATCH 09/11] solve segmentation violation error --- python/addPFCands_cff.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/addPFCands_cff.py b/python/addPFCands_cff.py index 7e35dd0..83c3644 100644 --- a/python/addPFCands_cff.py +++ b/python/addPFCands_cff.py @@ -124,6 +124,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal nameSV = cms.string("GenFatJetSVs"), idx_name = cms.string("pFCandsIdx"), idx_nameSV = cms.string("sVIdx"), + nameMu = cms.string("GenFatJetMuons"), + idx_nameMu = cms.string("MuIdx"), readBtag = cms.bool(False)) process.genAK4ConstituentsTable = cms.EDProducer("GenJetConstituentTableProducer", candidates = genCandInput, @@ -132,6 +134,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal nameSV = cms.string("GenJetSVs"), idx_name = cms.string("pFCandsIdx"), idx_nameSV = cms.string("sVIdx"), + nameMu = cms.string("GenJetMuons"), + idx_nameMu = cms.string("MuIdx"), readBtag = cms.bool(False)) process.customizedPFCandsTask.add(process.genJetsAK4Constituents) #Note: For gen need to add jets to the process to keep pt cuts. process.customizedPFCandsTask.add(process.genJetsAK8Constituents) From 469e857e830a0a69f435e254ed7cf26d032307a9 Mon Sep 17 00:00:00 2001 From: azaza Date: Fri, 13 Jan 2023 18:38:18 +0100 Subject: [PATCH 10/11] improve variable implementation --- python/addBTV.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/addBTV.py b/python/addBTV.py index 518f05c..0eed8b3 100644 --- a/python/addBTV.py +++ b/python/addBTV.py @@ -317,7 +317,7 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D float, doc="combinedIVF", precision=10), - DeepCSVBDisc=Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')", + DeepCSVBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0 ? bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb') : -1", float, doc="DeepCSVBDisc", precision=10), @@ -325,11 +325,11 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D float, doc="DeepCSV c tag discriminator", precision=10), - DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", + DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))>=0 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", float, doc="DeepCSV C vs L discriminator", precision=10), - DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", + DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))>=0 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", float, doc="DeepCSV C vs B discriminator", precision=10), @@ -357,7 +357,7 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D float, doc="combinedIVF", precision=10), - DeepCSVBDisc=Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')", + DeepCSVBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0 ? bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb') : -1", float, doc="DeepCSVBDisc", precision=10), @@ -365,11 +365,11 @@ def add_BTV(process, runOnMC=False, onlyAK4=False, onlyAK8=False, keepInputs=['D float, doc="DeepCSV c tag discriminator", precision=10), - DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", + DeepCSVCvsLDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))>=0 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')) : -1", float, doc="DeepCSV C vs L discriminator", precision=10), - DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))!=-1 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", + DeepCSVCvsBDisc=Var("? (bDiscriminator('pfDeepCSVJetTags:probc'))>=0 ? bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')) : -1", float, doc="DeepCSV C vs B discriminator", precision=10), From b341310a199cf2e66e514992a77fe7047ee397c5 Mon Sep 17 00:00:00 2001 From: azaza Date: Thu, 16 Mar 2023 12:14:16 +0100 Subject: [PATCH 11/11] save muon table only for fat jets --- plugins/JetConstituentTableProducer.cc | 65 ++++++++++++++------------ python/addPFCands_cff.py | 12 +++-- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/plugins/JetConstituentTableProducer.cc b/plugins/JetConstituentTableProducer.cc index 0c52180..ae323e4 100644 --- a/plugins/JetConstituentTableProducer.cc +++ b/plugins/JetConstituentTableProducer.cc @@ -53,6 +53,7 @@ class JetConstituentTableProducer : public edm::stream::EDProducer<> { const std::string idx_nameSV_; const std::string idx_nameMu_; const bool readBtag_; + const bool addMuonTable_; const double jet_radius_; edm::EDGetTokenT> jet_token_; @@ -84,6 +85,7 @@ JetConstituentTableProducer::JetConstituentTableProducer(const edm::Parameter idx_nameSV_(iConfig.getParameter("idx_nameSV")), idx_nameMu_(iConfig.getParameter("idx_nameMu")), readBtag_(iConfig.getParameter("readBtag")), + addMuonTable_(iConfig.getParameter("addMuonTable")), jet_radius_(iConfig.getParameter("jet_radius")), jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), @@ -238,37 +240,39 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even for (const auto &mu : *muons_) { if(reco::deltaR2(mu, jet) < jet_radius_ * jet_radius_){ outMuons->push_back(mu); - jetIdx_mu.push_back(i_jet); - muIdx.push_back(idx_mu); - muon_pt.push_back(mu.pt()); - muon_eta.push_back(mu.eta()); - muon_phi.push_back(mu.phi()); - muon_ptrel.push_back(mu.pt()/jet.pt()); + if (readBtag_ && addMuonTable_) { + jetIdx_mu.push_back(i_jet); + muIdx.push_back(idx_mu); + muon_pt.push_back(mu.pt()); + muon_eta.push_back(mu.eta()); + muon_phi.push_back(mu.phi()); + muon_ptrel.push_back(mu.pt()/jet.pt()); - if(mu.isGlobalMuon()){ - muon_nMuHit.push_back(mu.outerTrack()->hitPattern().numberOfValidMuonHits()); - muon_nMatched.push_back(mu.numberOfMatchedStations()); - muon_nTkHit.push_back(mu.innerTrack()->hitPattern().numberOfValidHits()); - muon_nPixHit.push_back(mu.innerTrack()->hitPattern().numberOfValidPixelHits()); - muon_nOutHit.push_back(mu.innerTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_OUTER_HITS)); - muon_chi2.push_back(mu.globalTrack()->normalizedChi2()); - muon_chi2Tk.push_back(mu.innerTrack()->normalizedChi2()); - } - else{ - muon_nMuHit.push_back(-1); - muon_nMatched.push_back(-1); - muon_nTkHit.push_back(-1); - muon_nPixHit.push_back(-1); - muon_nOutHit.push_back(-1); - muon_chi2.push_back(-1); - muon_chi2Tk.push_back(-1); + if(mu.isGlobalMuon()){ + muon_nMuHit.push_back(mu.outerTrack()->hitPattern().numberOfValidMuonHits()); + muon_nMatched.push_back(mu.numberOfMatchedStations()); + muon_nTkHit.push_back(mu.innerTrack()->hitPattern().numberOfValidHits()); + muon_nPixHit.push_back(mu.innerTrack()->hitPattern().numberOfValidPixelHits()); + muon_nOutHit.push_back(mu.innerTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_OUTER_HITS)); + muon_chi2.push_back(mu.globalTrack()->normalizedChi2()); + muon_chi2Tk.push_back(mu.innerTrack()->normalizedChi2()); + } + else{ + muon_nMuHit.push_back(-1); + muon_nMatched.push_back(-1); + muon_nTkHit.push_back(-1); + muon_nPixHit.push_back(-1); + muon_nOutHit.push_back(-1); + muon_chi2.push_back(-1); + muon_chi2Tk.push_back(-1); + + } + muon_isGlobal.push_back(mu.isGlobalMuon()); } - muon_isGlobal.push_back(mu.isGlobalMuon()); - - + idx_mu++; } - idx_mu++; + } } @@ -317,9 +321,9 @@ void JetConstituentTableProducer::produce(edm::Event &iEvent, const edm::Even // Muon table auto muonTable = std::make_unique(outMuons->size(), nameMu_, false); // We fill from here only stuff that cannot be created with the SimpleFlatTnameableProducer - muonTable->addColumn("jetIdx", jetIdx_mu, "Index of the parent jet"); - muonTable->addColumn(idx_nameMu_, muIdx, "Index in the Muon list"); - if (readBtag_) { + if (readBtag_ && addMuonTable_) { + muonTable->addColumn("jetIdx", jetIdx_mu, "Index of the parent jet"); + muonTable->addColumn(idx_nameMu_, muIdx, "Index in the Muon list"); muonTable->addColumn("pt", muon_pt, "pt", 20); muonTable->addColumn("eta", muon_eta, "eta", 20); muonTable->addColumn("phi", muon_phi, "phi", 20); @@ -347,6 +351,7 @@ void JetConstituentTableProducer::fillDescriptions(edm::ConfigurationDescript desc.add("idx_nameMu", "muIdx"); desc.add("jet_radius", true); desc.add("readBtag", true); + desc.add("addMuonTable", false); desc.add("jets", edm::InputTag("slimmedJetsAK8")); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("candidates", edm::InputTag("packedPFCandidates")); diff --git a/python/addPFCands_cff.py b/python/addPFCands_cff.py index 83c3644..594e6dc 100644 --- a/python/addPFCands_cff.py +++ b/python/addPFCands_cff.py @@ -64,7 +64,8 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_nameSV = cms.string("sVIdx"), nameMu = cms.string("FatJetMuons"), idx_nameMu = cms.string("MuIdx"), - ) + addMuonTable = cms.bool(True), + ) process.customAK4ConstituentsTable = cms.EDProducer("PatJetConstituentTableProducer", candidates = candInput, jets = cms.InputTag("finalJetsPuppi"), # was finalJets before @@ -73,6 +74,7 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_name = cms.string("pFCandsIdx"), nameSV = cms.string("JetSVs"), idx_nameSV = cms.string("sVIdx"), + addMuonTable = cms.bool(False), ) if not allPF: process.customizedPFCandsTask.add(process.finalJetsConstituents) @@ -126,7 +128,9 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_nameSV = cms.string("sVIdx"), nameMu = cms.string("GenFatJetMuons"), idx_nameMu = cms.string("MuIdx"), - readBtag = cms.bool(False)) + readBtag = cms.bool(False), + addMuonTable = cms.bool(False), + ) process.genAK4ConstituentsTable = cms.EDProducer("GenJetConstituentTableProducer", candidates = genCandInput, jets = cms.InputTag("genJetsAK4Constituents"), # Note: The name has "Constituents" in it, but these are the jets @@ -136,7 +140,9 @@ def addPFCands(process, runOnMC=False, allPF = False, onlyAK4=False, onlyAK8=Fal idx_nameSV = cms.string("sVIdx"), nameMu = cms.string("GenJetMuons"), idx_nameMu = cms.string("MuIdx"), - readBtag = cms.bool(False)) + readBtag = cms.bool(False), + addMuonTable = cms.bool(False), + ) process.customizedPFCandsTask.add(process.genJetsAK4Constituents) #Note: For gen need to add jets to the process to keep pt cuts. process.customizedPFCandsTask.add(process.genJetsAK8Constituents) if not allPF: