From 337515dd3c1ca8a1cdf10d1cad06e886ad760abb Mon Sep 17 00:00:00 2001 From: Vilius Cepaitis Date: Thu, 12 Nov 2020 18:27:55 +0100 Subject: [PATCH] Add second SV collection --- .../interface/ChargedCandidateFeatures.h | 1 + DataFormats/interface/XTagFeatures.h | 1 + NANOProducer/plugins/NANOProducer.cc | 84 +++++++++++-- NANOProducer/python/adaptedSV_cff.py | 14 ++- NANOProducer/test/produceNANO.py | 2 +- XTagInfoProducer/plugins/XTagInfoProducer.cc | 119 +++++++++++++----- 6 files changed, 174 insertions(+), 47 deletions(-) diff --git a/DataFormats/interface/ChargedCandidateFeatures.h b/DataFormats/interface/ChargedCandidateFeatures.h index e9f5ec7..9c89106 100644 --- a/DataFormats/interface/ChargedCandidateFeatures.h +++ b/DataFormats/interface/ChargedCandidateFeatures.h @@ -38,6 +38,7 @@ struct ChargedCandidateFeatures int cpf_matchedMuon; int cpf_matchedElectron; int cpf_matchedSV; + int cpf_matchedSV_adapted; int cpf_track_ndof; float cpf_dZmin; diff --git a/DataFormats/interface/XTagFeatures.h b/DataFormats/interface/XTagFeatures.h index 5379c9b..1eba843 100644 --- a/DataFormats/interface/XTagFeatures.h +++ b/DataFormats/interface/XTagFeatures.h @@ -17,6 +17,7 @@ class XTagFeatures { JetFeatures jet_features; ShallowTagInfoFeatures tag_info_features; std::vector sv_features; + std::vector sv_adapted_features; std::vector npf_features; std::vector cpf_features; std::vector mu_features; diff --git a/NANOProducer/plugins/NANOProducer.cc b/NANOProducer/plugins/NANOProducer.cc index 7c0dbbd..5376e3c 100644 --- a/NANOProducer/plugins/NANOProducer.cc +++ b/NANOProducer/plugins/NANOProducer.cc @@ -48,6 +48,7 @@ NANOProducer::NANOProducer(const edm::ParameterSet& iConfig) : produces("cpf"); produces("npf"); produces("sv"); + produces("svAdapted"); produces("length"); produces("muon") ; produces("electron") ; @@ -76,6 +77,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector cpf_jetIdx; std::vector npf_jetIdx; std::vector sv_jetIdx; + std::vector sv_adapted_jetIdx; std::vector mu_jetIdx; std::vector elec_jetIdx; @@ -83,6 +85,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector cpf_length; std::vector npf_length; std::vector sv_length; + std::vector sv_adapted_length; std::vector elec_length; std::vector mu_length; @@ -167,6 +170,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector cpf_matchedMuon; std::vector cpf_matchedElectron; std::vector cpf_matchedSV; + std::vector cpf_matchedSV_adapted; std::vector cpf_track_numberOfValidPixelHits; std::vector cpf_track_pixelLayersWithMeasurement; std::vector cpf_track_numberOfValidStripHits; @@ -198,12 +202,26 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector sv_costhetasvpv; std::vector sv_enratio; - std::vector mu_isGlobal ; - std::vector mu_isTight ; - std::vector mu_isMedium ; - std::vector mu_isLoose ; - std::vector mu_isStandAlone ; - + std::vector sv_adapted_ptrel; + std::vector sv_adapted_deta; + std::vector sv_adapted_dphi; + std::vector sv_adapted_deltaR; + std::vector sv_adapted_mass; + std::vector sv_adapted_ntracks; + std::vector sv_adapted_chi2; + std::vector sv_adapted_ndof; + std::vector sv_adapted_dxy; + std::vector sv_adapted_dxysig; + std::vector sv_adapted_d3d; + std::vector sv_adapted_d3dsig; + std::vector sv_adapted_costhetasvpv; + std::vector sv_adapted_enratio; + + std::vector mu_isGlobal; + std::vector mu_isTight; + std::vector mu_isMedium; + std::vector mu_isLoose; + std::vector mu_isStandAlone; std::vector mu_ptrel; std::vector mu_EtaRel; @@ -227,7 +245,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector mu_dzError; std::vector mu_numberOfValidPixelHits; std::vector mu_numberOfpixelLayersWithMeasurement; - std::vector mu_numberOfstripLayersWithMeasurement ; + std::vector mu_numberOfstripLayersWithMeasurement; std::vector mu_chi2; std::vector mu_ndof; @@ -246,8 +264,6 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector mu_Pfpileup03; std::vector mu_sumPfPhotonEt03; - - std::vector mu_timeAtIpInOut; std::vector mu_timeAtIpInOutErr; std::vector mu_timeAtIpOutIn; @@ -261,7 +277,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::vector elec_dphi; std::vector elec_charge; std::vector elec_energy; - std::vector elec_EtFromCaloEn ; + std::vector elec_EtFromCaloEn; std::vector elec_isEB; std::vector elec_isEE; std::vector elec_ecalEnergy; @@ -343,6 +359,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) unsigned int ncpf_total = 0; unsigned int nnpf_total = 0; unsigned int nsv_total = 0; + unsigned int nsv_total_adapted = 0; for (unsigned int itag= 0; itag < ntags; itag++){ const auto& features = tag_infos->at(itag).features(); @@ -353,14 +370,19 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) unsigned int ncpf = features.cpf_features.size(); unsigned int nnpf = features.npf_features.size(); unsigned int nsv = features.sv_features.size(); + unsigned int nsv_adapted = features.sv_adapted_features.size(); + nmu_total += nmu; nelec_total += nelec; ncpf_total += ncpf; nnpf_total += nnpf; nsv_total += nsv; + nsv_total_adapted += nsv_adapted; + cpf_length.push_back(ncpf); npf_length.push_back(nnpf); sv_length.push_back(nsv); + sv_adapted_length.push_back(nsv_adapted); elec_length.push_back(nelec); mu_length.push_back(nmu); @@ -435,6 +457,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) auto cpfTable = std::make_unique(ncpf_total, "cpf", false, false); auto npfTable = std::make_unique(nnpf_total, "npf", false, false); auto svTable = std::make_unique(nsv_total, "sv", false, false); + auto svTable_adapted = std::make_unique(nsv_total_adapted, "svAdapted", false, false); for (unsigned int itag= 0; itag < ntags; itag++) { @@ -444,12 +467,14 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) auto cpf = features.cpf_features; auto npf = features.npf_features; auto sv = features.sv_features; + auto sv_adapted = features.sv_adapted_features; unsigned int nmu = features.mu_features.size(); unsigned int nelec = features.elec_features.size(); unsigned int ncpf = features.cpf_features.size(); unsigned int nnpf = features.npf_features.size(); unsigned int nsv = features.sv_features.size(); + unsigned int nsv_adapted = features.sv_adapted_features.size(); int jetIdx = global_jetIdx[itag]; @@ -483,6 +508,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) cpf_matchedMuon.push_back(cpf_features.cpf_matchedMuon); cpf_matchedElectron.push_back(cpf_features.cpf_matchedElectron); cpf_matchedSV.push_back(cpf_features.cpf_matchedSV); + cpf_matchedSV_adapted.push_back(cpf_features.cpf_matchedSV_adapted); cpf_track_numberOfValidPixelHits.push_back(cpf_features.cpf_track_numberOfValidPixelHits); cpf_track_pixelLayersWithMeasurement.push_back(cpf_features.cpf_track_pixelLayersWithMeasurement); cpf_track_numberOfValidStripHits.push_back(cpf_features.cpf_track_numberOfValidStripHits); @@ -525,6 +551,26 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) sv_enratio.push_back(sv_features.sv_enratio); } + for (unsigned int i = 0; i < nsv_adapted; i++) + { + const auto& sv_adapted_features = sv_adapted.at(i); + sv_adapted_jetIdx.push_back(jetIdx); + sv_adapted_ptrel.push_back(sv_adapted_features.sv_ptrel); + sv_adapted_deta.push_back(sv_adapted_features.sv_deta); + sv_adapted_dphi.push_back(sv_adapted_features.sv_dphi); + sv_adapted_deltaR.push_back(sv_adapted_features.sv_deltaR); + sv_adapted_mass.push_back(sv_adapted_features.sv_mass); + sv_adapted_ntracks.push_back(sv_adapted_features.sv_ntracks); + sv_adapted_chi2.push_back(sv_adapted_features.sv_chi2); + sv_adapted_ndof.push_back(sv_adapted_features.sv_ndof); + sv_adapted_dxy.push_back(sv_adapted_features.sv_dxy); + sv_adapted_dxysig.push_back(sv_adapted_features.sv_dxysig); + sv_adapted_d3d.push_back(sv_adapted_features.sv_d3d); + sv_adapted_d3dsig.push_back(sv_adapted_features.sv_d3dsig); + sv_adapted_costhetasvpv.push_back(sv_adapted_features.sv_costhetasvpv); + sv_adapted_enratio.push_back(sv_adapted_features.sv_enratio); + } + for(unsigned int i = 0; i < nmu; i++) { @@ -752,6 +798,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) cpfTable->addColumn("matchedMuon", cpf_matchedMuon, "flag to specify whether the track is matched to a PF muon", nanoaod::FlatTable::IntColumn); cpfTable->addColumn("matchedElectron", cpf_matchedElectron, "flag to specify whether the track is matched to a PF electron", nanoaod::FlatTable::IntColumn); cpfTable->addColumn("matchedSV", cpf_matchedSV, "flag to specify whether the track is matched to a PF secondary vertex", nanoaod::FlatTable::IntColumn); + cpfTable->addColumn("matchedSV_adapted", cpf_matchedSV_adapted, "flag to specify whether the track is matched to a PF secondary vertex", nanoaod::FlatTable::IntColumn); cpfTable->addColumn("numberOfValidPixelHits", cpf_track_numberOfValidPixelHits , "number of valid pixel hits " , nanoaod::FlatTable::IntColumn); cpfTable->addColumn("pixelLayersWithMeasurement", cpf_track_pixelLayersWithMeasurement , "pixel layers with measurment ", nanoaod::FlatTable::IntColumn); cpfTable->addColumn("numberOfValidStripHits" , cpf_track_numberOfValidStripHits , "nb of valid strip hits " , nanoaod::FlatTable::IntColumn); @@ -788,6 +835,22 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) svTable->addColumn("costhetasvpv", sv_costhetasvpv, "cos(theta) of the secondary vertex (SV) with respect to the primary vertex (PV)", nanoaod::FlatTable::FloatColumn); svTable->addColumn("enratio", sv_enratio, "ratio of secondary vertex (SV) energy with respect to the jet", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("jetIdx", sv_adapted_jetIdx, "linked jet Id", nanoaod::FlatTable::IntColumn); + svTable_adapted->addColumn("ptrel", sv_adapted_ptrel, "secondary vertex (SV) transverse momentum relative to the uncorrected jet energy pt", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("deta", sv_adapted_deta, "absolute difference between the secondary vertex (SV) eta and jet eta", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("dphi", sv_adapted_dphi, "absolute difference between the secondary vertex (SV) phi and jet phi", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("deltaR", sv_adapted_deltaR, "pseudoangular distance (Delta R) between jet axis and SV flight direction", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("mass", sv_adapted_mass, "invariant mass of reconstructed secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("ntracks", sv_adapted_ntracks, "number of tracks associated to the secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("chi2", sv_adapted_chi2, "chi^2 of secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("ndof", sv_adapted_ndof, "number of degrees of freedom of secondary vertex (SV) fit", nanoaod::FlatTable::IntColumn); + svTable_adapted->addColumn("dxy", sv_adapted_dxy, "transverse impact parameter of the secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("dxysig", sv_adapted_dxysig, "transverse impact parameter significance of the secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("d3d", sv_adapted_d3d, "3D impact parameter of secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("d3dsig", sv_adapted_d3dsig, "3D impact parameter significance of secondary vertex (SV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("costhetasvpv", sv_adapted_costhetasvpv, "cos(theta) of the secondary vertex (SV) with respect to the primary vertex (PV)", nanoaod::FlatTable::FloatColumn); + svTable_adapted->addColumn("enratio", sv_adapted_enratio, "ratio of secondary vertex (SV) energy with respect to the jet", nanoaod::FlatTable::FloatColumn); + lengthTable->addColumn("cpf", cpf_length, "charged PF candidate track offset", nanoaod::FlatTable::IntColumn); lengthTable->addColumn("npf", npf_length, "neutral PF candidate offset", nanoaod::FlatTable::IntColumn); lengthTable->addColumn("sv", sv_length, "secondary vertex (SV) offset", nanoaod::FlatTable::IntColumn); @@ -939,6 +1002,7 @@ NANOProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) iEvent.put(std::move(cpfTable), "cpf"); iEvent.put(std::move(npfTable), "npf"); iEvent.put(std::move(svTable), "sv"); + iEvent.put(std::move(svTable_adapted), "svAdapted"); iEvent.put(std::move(lengthTable), "length"); iEvent.put(std::move(muonTable), "muon"); iEvent.put(std::move(electronTable), "electron"); diff --git a/NANOProducer/python/adaptedSV_cff.py b/NANOProducer/python/adaptedSV_cff.py index a747f66..c14445c 100644 --- a/NANOProducer/python/adaptedSV_cff.py +++ b/NANOProducer/python/adaptedSV_cff.py @@ -1,5 +1,7 @@ import FWCore.ParameterSet.Config as cms +# https://gist.github.com/daiktas/d3e0ed47b82e45502aaf787ae12934fd + adaptedInclusiveCandidateVertexFinder = cms.EDProducer("InclusiveCandidateVertexFinder", beamSpot = cms.InputTag("offlineBeamSpot"), clusterizer = cms.PSet( @@ -16,8 +18,8 @@ fitterSigmacut = cms.double(3), fitterTini = cms.double(256), maxNTracks = cms.uint32(30), - maximumLongitudinalImpactParameter = cms.double(3), # Default is 0.3->3 - minHits = cms.uint32(0), + maximumLongitudinalImpactParameter = cms.double(1), # Default is 0.3->20 (Ghent) -> 1 may be safer + minHits = cms.uint32(6), # 8 -> 6 minPt = cms.double(0.8), primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"), tracks = cms.InputTag("packedPFCandidates"), @@ -43,8 +45,8 @@ adaptedCandidateVertexArbitrator = cms.EDProducer("CandidateVertexArbitrator", beamSpot = cms.InputTag("offlineBeamSpot"), dLenFraction = cms.double(0.333), - dRCut = cms.double(0.4), - distCut = cms.double(0.04), + dRCut = cms.double(0.4), # 0.4 -> 1 # not sure good idea... + distCut = cms.double(0.04), # 0.04 -> 0.1 # check if safe fitterRatio = cms.double(0.25), fitterSigmacut = cms.double(3), fitterTini = cms.double(256), @@ -52,8 +54,8 @@ secondaryVertices = cms.InputTag("adaptedCandidateVertexMerger"), sigCut = cms.double(5), trackMinLayers = cms.int32(4), - trackMinPixels = cms.int32(0), # Default is 1->0 - trackMinPt = cms.double(0.4), + trackMinPixels = cms.int32(0), # 1->0 + trackMinPt = cms.double(0.8), tracks = cms.InputTag("packedPFCandidates") ) diff --git a/NANOProducer/test/produceNANO.py b/NANOProducer/test/produceNANO.py index 57b6009..fd4f278 100644 --- a/NANOProducer/test/produceNANO.py +++ b/NANOProducer/test/produceNANO.py @@ -224,7 +224,7 @@ electronSrc = cms.InputTag("slimmedElectrons"), shallow_tag_infos = cms.InputTag('pfDeepCSVTagInfosXTag'), vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), - #secondary_vertices = cms.InputTag("adaptedSlimmedSecondaryVertices") + secondary_vertices_adapted = cms.InputTag("adaptedSlimmedSecondaryVertices"), secondary_vertices = cms.InputTag("slimmedSecondaryVertices") ) diff --git a/XTagInfoProducer/plugins/XTagInfoProducer.cc b/XTagInfoProducer/plugins/XTagInfoProducer.cc index 2693590..32090e1 100644 --- a/XTagInfoProducer/plugins/XTagInfoProducer.cc +++ b/XTagInfoProducer/plugins/XTagInfoProducer.cc @@ -50,6 +50,48 @@ #include "TVector3.h" +llpdnnx::SecondaryVertexFeatures fillSVFeatures(const reco::VertexCompositePtrCandidate& sv, const reco::Vertex& pv, const pat::Jet& jet){ + float uncorrectedPt = jet.correctedP4("Uncorrected").pt(); + llpdnnx::SecondaryVertexFeatures sv_features; + + sv_features.sv_ptrel = sv.pt()/uncorrectedPt; + sv_features.sv_deta = sv.eta()-jet.eta(); + sv_features.sv_dphi = reco::deltaPhi(sv.phi(),jet.phi()); + sv_features.sv_deltaR = reco::deltaR(sv,jet); + sv_features.sv_mass = sv.mass(); + sv_features.sv_ntracks = sv.numberOfDaughters(); + sv_features.sv_chi2 = sv.vertexChi2(); + sv_features.sv_ndof = sv.vertexNdof(); + + + reco::Vertex::CovarianceMatrix covsv; + sv.fillVertexCovariance(covsv); + reco::Vertex svtx(sv.vertex(), covsv); + + VertexDistanceXY distXY; + Measurement1D distanceXY = distXY.distance(svtx, pv); + sv_features.sv_dxy = distanceXY.value(); + sv_features.sv_dxysig = distanceXY.value()/distanceXY.error(); + + VertexDistance3D dist3D; + Measurement1D distance3D = dist3D.distance(svtx, pv); + sv_features.sv_d3d = distance3D.value(); + sv_features.sv_d3dsig = distance3D.value()/distance3D.error(); + + if (std::isnan(sv_features.sv_dxysig) || std::isnan(sv_features.sv_d3dsig)) + { + sv_features.sv_dxysig = 0.; + sv_features.sv_d3dsig = 0.; + } + + reco::Candidate::Vector distance(sv.vx() - pv.x(), sv.vy() - pv.y(), sv.vz() - pv.z()); + sv_features.sv_costhetasvpv = sv.momentum().Unit().Dot(distance.Unit()); + sv_features.sv_enratio = sv.energy()/jet.pt(); + + return sv_features; +} + + class XTagInfoProducer : public edm::stream::EDProducer<> { public: explicit XTagInfoProducer(const edm::ParameterSet&); @@ -73,6 +115,7 @@ class XTagInfoProducer : public edm::stream::EDProducer<> { edm::EDGetTokenT> jet_token_; edm::EDGetTokenT vtx_token_; edm::EDGetTokenT sv_token_; + edm::EDGetTokenT sv_adapted_token_; edm::EDGetTokenT> shallow_tag_info_token_; edm::EDGetTokenT> candidateToken_; typedef std::vector XTagInfoCollection; @@ -85,6 +128,7 @@ XTagInfoProducer::XTagInfoProducer(const edm::ParameterSet& iConfig) : jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), sv_token_(consumes(iConfig.getParameter("secondary_vertices"))), + sv_adapted_token_(consumes(iConfig.getParameter("secondary_vertices_adapted"))), shallow_tag_info_token_(consumes>(iConfig.getParameter("shallow_tag_infos"))), muonsMiniAODToken_(consumes(iConfig.getParameter("muonSrc"))), electronsMiniAODToken_(consumes(iConfig.getParameter("electronSrc"))) @@ -121,6 +165,9 @@ XTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) edm::Handle svs; iEvent.getByToken(sv_token_, svs); + edm::Handle svs_adapted; + iEvent.getByToken(sv_adapted_token_, svs_adapted); + edm::Handle< pat::MuonCollection > muons; iEvent.getByToken(muonsMiniAODToken_, muons); @@ -150,6 +197,7 @@ XTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) for (std::size_t ijet = 0; ijet < jets->size(); ijet++) { const pat::Jet& jet = jets->at(ijet); + edm::RefToBase jet_ref(jets->refAt(ijet)); //upcast std::unordered_set jetConstituentSet; @@ -264,7 +312,10 @@ XTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) std::unordered_set candidatesMatchedToSV; - // fill features from secondary vertices + std::unordered_set candidatesMatchedToSVAdapted; + + // fill features from secondary vertices + for (unsigned int isv = 0; isv < svs->size(); ++isv) { const reco::VertexCompositePtrCandidate& sv = svs->at(isv); @@ -283,48 +334,47 @@ XTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) } } if (not matchingTrack) continue; - - llpdnnx::SecondaryVertexFeatures sv_features; - sv_features.sv_ptrel = sv.pt()/uncorrectedPt; - sv_features.sv_deta = sv.eta()-jet.eta(); - sv_features.sv_dphi = reco::deltaPhi(sv.phi(),jet.phi()); - sv_features.sv_deltaR = reco::deltaR(sv,jet); - sv_features.sv_mass = sv.mass(); - sv_features.sv_ntracks = sv.numberOfDaughters(); - sv_features.sv_chi2 = sv.vertexChi2(); - sv_features.sv_ndof = sv.vertexNdof(); + llpdnnx::SecondaryVertexFeatures sv_features = fillSVFeatures(sv, pv, jet); - reco::Vertex::CovarianceMatrix covsv; - sv.fillVertexCovariance(covsv); - reco::Vertex svtx(sv.vertex(), covsv); + features.sv_features.emplace_back(sv_features); + } - VertexDistanceXY distXY; - Measurement1D distanceXY = distXY.distance(svtx, pv); - sv_features.sv_dxy = distanceXY.value(); - sv_features.sv_dxysig = distanceXY.value()/distanceXY.error(); + std::stable_sort(features.sv_features.begin(),features.sv_features.end(),[](const auto& d1, const auto& d2) + { + return d1.sv_dxysig>d2.sv_dxysig; //sort decreasing + }); - VertexDistance3D dist3D; - Measurement1D distance3D = dist3D.distance(svtx, pv); - sv_features.sv_d3d = distance3D.value(); - sv_features.sv_d3dsig = distance3D.value()/distance3D.error(); - if (std::isnan(sv_features.sv_dxysig) || std::isnan(sv_features.sv_d3dsig)) + // fill features from secondary vertices + + for (unsigned int isv = 0; isv < svs_adapted->size(); ++isv) + { + const reco::VertexCompositePtrCandidate& sv_adapted = svs_adapted->at(isv); + + if (reco::deltaR(sv_adapted,jet)>0.4) + { + continue; + } + bool matchingTrack = false; + for (auto const& candidateFromVertex: sv_adapted.daughterPtrVector()) + { + if (jetConstituentSet.find(candidateFromVertex)!=jetConstituentSet.end()) { - sv_features.sv_dxysig = 0.; - sv_features.sv_d3dsig = 0.; + candidatesMatchedToSVAdapted.insert(candidateFromVertex); + matchingTrack = true; } + } + if (not matchingTrack) continue; - reco::Candidate::Vector distance(sv.vx() - pv.x(), sv.vy() - pv.y(), sv.vz() - pv.z()); - sv_features.sv_costhetasvpv = sv.momentum().Unit().Dot(distance.Unit()); - sv_features.sv_enratio = sv.energy()/jet.pt(); + llpdnnx::SecondaryVertexFeatures sv_adapted_features = fillSVFeatures(sv_adapted, pv, jet); - features.sv_features.emplace_back(sv_features); + features.sv_adapted_features.emplace_back(sv_adapted_features); } - std::stable_sort(features.sv_features.begin(),features.sv_features.end(),[](const auto& d1, const auto& d2) + std::stable_sort(features.sv_adapted_features.begin(),features.sv_adapted_features.end(),[](const auto& d1, const auto& d2) { return d1.sv_dxysig>d2.sv_dxysig; //sort decreasing }); @@ -435,6 +485,15 @@ XTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) cpf_features.cpf_matchedSV = 0; } + if (candidatesMatchedToSVAdapted.find(jet.daughterPtr(idaughter))!=candidatesMatchedToSVAdapted.end()) + { + cpf_features.cpf_matchedSV_adapted = 1; + } + else + { + cpf_features.cpf_matchedSV_adapted = 0; + } + //find matching muons llpdnnx::MuonCandidateFeatures mu_features;