Skip to content

BPHNano - Backport of https://github.com/cms-sw/cmssw/pull/48385 to CMSSW_15_0_X #48390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions PhysicsTools/BPHNano/plugins/BToTrkLLBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include "helper.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

class BToTrkLLBuilder : public edm::global::EDProducer<> {
// perhaps we need better structure here (begin run etc)
Expand Down Expand Up @@ -131,10 +132,15 @@ void BToTrkLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup co
if (!pre_vtx_selection_(cand))
continue;

KinVtxFitter fitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), kaons_ttracks->at(k_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA} // some small sigma for the lepton mass
);
KinVtxFitter fitter;
try {
fitter = KinVtxFitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), kaons_ttracks->at(k_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToKLL: Skipping candidate due to fit failure: " << e.what();
continue;
}

if (!fitter.success())
continue; // hardcoded, but do we need otherwise?
Expand Down Expand Up @@ -231,11 +237,18 @@ void BToTrkLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup co
// Mass constraint is applied to the first two particles in the
// "particles" vector Make sure that the first two particles are the
// ones you want to constrain
KinVtxFitter constraint_fitter(
{leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), kaons_ttracks->at(k_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA},
mass_constraint);
KinVtxFitter constraint_fitter;
try {
constraint_fitter =
KinVtxFitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), kaons_ttracks->at(k_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA},
mass_constraint);
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit")
<< "BToKLL - Constrained fit: Skipping candidate due to fit failure: " << e.what();
continue;
}
if (constraint_fitter.success()) {
auto constraint_p4 = constraint_fitter.fitted_p4();
constraint_sv_prob = constraint_fitter.prob();
Expand Down
125 changes: 87 additions & 38 deletions PhysicsTools/BPHNano/plugins/BToTrkTrkLLBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "helper.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

class BToTrkTrkLLBuilder : public edm::global::EDProducer<> {
// perhaps we need better structure here (begin run etc)
Expand Down Expand Up @@ -133,7 +134,10 @@ void BToTrkTrkLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup
cand.addUserInt("l2_idx", l2_idx);
cand.addUserInt("trk1_idx", trk1_idx);
cand.addUserInt("trk2_idx", trk2_idx);
cand.addUserInt("ditrack_idx", ditracks_idx);
// cand.addUserInt("ditrack_idx", ditracks_idx); this index corresponds to the ditrack collection.
// However, in order to refuce the event size, we do not store all the ditrack candidates but only those used to build a B candidate.
// So, now, index of B candidate is the same number for index of ditrack candidate
// This variable is not removed from the code in case we decide to store in the future all the ditrack candidates.
cand.addUserInt("ll_idx", ll_idx);

auto lep1_p4 = l1_ptr->polarP4();
Expand Down Expand Up @@ -162,28 +166,49 @@ void BToTrkTrkLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup
if (!pre_vtx_selection_(cand))
continue;

KinVtxFitter fitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA});
if (!fitter.success())
continue;
KinVtxFitter fitter_Kpi({leptons_ttracks->at(l1_idx),
KinVtxFitter fitter;
try {
fitter = KinVtxFitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::PI_MASS},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToTrkTrkLL - KK mass hypothesis: Skipping candidate due to fit failure: "
<< e.what();
continue;
}
if (!fitter.success())
continue;
KinVtxFitter fitter_Kpi;
try {
fitter_Kpi = KinVtxFitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::PI_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToTrkTrkLL - Kpi mass hypothesis: Skipping candidate due to fit failure: "
<< e.what();
continue;
}
if (!fitter_Kpi.success())
continue;
KinVtxFitter fitter_piK({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::PI_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA});
KinVtxFitter fitter_piK;
try {
fitter_piK = KinVtxFitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::PI_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToTrkTrkLL - piK mass hypothesis: Skipping candidate due to fit failure: "
<< e.what();
continue;
}
if (!fitter_piK.success())
continue;

Expand Down Expand Up @@ -310,31 +335,55 @@ void BToTrkTrkLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup
// "particles" vector Make sure that the first two particles are the
// ones you want to constrain

KinVtxFitter constraint_fitter_KK({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA},
mass_constraint);
KinVtxFitter constraint_fitter_KK;
try {
constraint_fitter_KK = KinVtxFitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA},
mass_constraint);
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit")
<< "BToTrkTrkLL - KK mass hypothesis constrained fit: Skipping candidate due to fit failure: "
<< e.what();
continue;
}
if (!constraint_fitter_KK.success())
continue;
KinVtxFitter constraint_fitter_Kpi({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::PI_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA},
mass_constraint);
KinVtxFitter constraint_fitter_Kpi;
try {
constraint_fitter_Kpi = KinVtxFitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::K_MASS, bph::PI_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA},
mass_constraint);
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit")
<< "BToTrkTrkLL - Kpi mass hypothesis constrained fit: Skipping candidate due to fit failure: "
<< e.what();
continue;
}
if (!constraint_fitter_Kpi.success())
continue;
KinVtxFitter constraint_fitter_piK({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::PI_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA},
mass_constraint);
KinVtxFitter constraint_fitter_piK;
try {
constraint_fitter_piK = KinVtxFitter({leptons_ttracks->at(l1_idx),
leptons_ttracks->at(l2_idx),
ditracks_ttracks->at(trk1_idx),
ditracks_ttracks->at(trk2_idx)},
{l1_ptr->mass(), l2_ptr->mass(), bph::PI_MASS, bph::K_MASS},
{bph::LEP_SIGMA, bph::LEP_SIGMA, bph::K_SIGMA, bph::K_SIGMA},
mass_constraint);
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit")
<< "BToTrkTrkLL - piK mass hypothesis constrained fit: Skipping candidate due to fit failure: "
<< e.what();
continue;
}
if (!constraint_fitter_piK.success())
continue;

Expand Down
29 changes: 21 additions & 8 deletions PhysicsTools/BPHNano/plugins/BToV0LLBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include "helper.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

class BToV0LLBuilder : public edm::global::EDProducer<> {
// perhaps we need better structure here (begin run etc)
Expand Down Expand Up @@ -130,9 +131,15 @@ void BToV0LLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup con
if (!pre_vtx_selection_(cand))
continue;

KinVtxFitter fitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), v0_ttracks->at(v0_idx)},
{l1_ptr->mass(), l2_ptr->mass(), v0_ptr->mass()},
{bph::LEP_SIGMA, bph::LEP_SIGMA, v0_ptr->userFloat("massErr")});
KinVtxFitter fitter;
try {
fitter = KinVtxFitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), v0_ttracks->at(v0_idx)},
{l1_ptr->mass(), l2_ptr->mass(), v0_ptr->mass()},
{bph::LEP_SIGMA, bph::LEP_SIGMA, v0_ptr->userFloat("massErr")});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToV0LL: Skipping candidate due to fit failure: " << e.what();
continue;
}

if (!fitter.success())
continue;
Expand Down Expand Up @@ -246,11 +253,17 @@ void BToV0LLBuilder::produce(edm::StreamID, edm::Event &evt, edm::EventSetup con
// Mass constraint is applied to the first two particles in the
// "particles" vector Make sure that the first two particles are the
// ones you want to constrain
KinVtxFitter constraint_fitter(
{leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), v0_ttracks->at(v0_idx)},
{l1_ptr->mass(), l2_ptr->mass(), v0_ptr->mass()},
{bph::LEP_SIGMA, bph::LEP_SIGMA, v0_ptr->userFloat("massErr")},
mass_constraint);
KinVtxFitter constraint_fitter;
try {
constraint_fitter =
KinVtxFitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), v0_ttracks->at(v0_idx)},
{l1_ptr->mass(), l2_ptr->mass(), v0_ptr->mass()},
{bph::LEP_SIGMA, bph::LEP_SIGMA, v0_ptr->userFloat("massErr")},
mass_constraint);
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToV0LL: Skipping candidate due to fit failure: " << e.what();
continue;
}
if (constraint_fitter.success()) {
auto constraint_p4 = constraint_fitter.fitted_p4();
cstr_vtx_x = constraint_fitter.fitted_vtx().x();
Expand Down
41 changes: 30 additions & 11 deletions PhysicsTools/BPHNano/plugins/BToV0TrkDisplacedLLBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <limits>
#include <algorithm>
#include "KinVtxFitter.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

using namespace std;

Expand Down Expand Up @@ -171,9 +172,15 @@ void BToV0TrkDisplacedLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::Ev
if (!pre_vtx_selection_(cand))
continue;

KinVtxFitter xifitter({pions_ttracks->at(pi_idx), V0s_ttracks->at(V0_idx)},
{bph::PI_MASS, V0_ptr->mass()},
{bph::PI_SIGMA, V0_ptr->userFloat("massErr")});
KinVtxFitter xifitter;
try {
xifitter = KinVtxFitter({pions_ttracks->at(pi_idx), V0s_ttracks->at(V0_idx)},
{bph::PI_MASS, V0_ptr->mass()},
{bph::PI_SIGMA, V0_ptr->userFloat("massErr")});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "Xi Builder: Skipping candidate due to fit failure: " << e.what();
continue;
}
if (!xifitter.success())
continue;
const auto &XiTT = xifitter.fitted_candidate_ttrk();
Expand All @@ -196,9 +203,15 @@ void BToV0TrkDisplacedLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::Ev
cand.addUserFloat("Xi_mass", ximass);
cand.addUserFloat("Xi_massErr", ximassErr);

KinVtxFitter fitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), XiTT},
{l1_ptr->mass(), l2_ptr->mass(), ximass},
{bph::LEP_SIGMA, bph::LEP_SIGMA, ximassErr});
KinVtxFitter fitter;
try {
fitter = KinVtxFitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), XiTT},
{l1_ptr->mass(), l2_ptr->mass(), ximass},
{bph::LEP_SIGMA, bph::LEP_SIGMA, ximassErr});
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToXiLL Builder: Skipping candidate due to fit failure: " << e.what();
continue;
}
if (!fitter.success())
continue;
cand.setVertex(
Expand Down Expand Up @@ -319,12 +332,18 @@ void BToV0TrkDisplacedLLBuilder::produce(edm::StreamID, edm::Event &evt, edm::Ev
ParticleMass mass_constraint = (dilepton_mass < jpsi_bin[1]) ? JPsi_mass : Psi2S_mass;
// Mass constraint is applied to the first two particles in the "particles" vector
// Make sure that the first two particles are the ones you want to constrain
KinVtxFitter constrained_fitter(

{leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), XiTT},
{l1_ptr->mass(), l2_ptr->mass(), ximass},
{bph::LEP_SIGMA, bph::LEP_SIGMA, ximassErr},
mass_constraint); //K_SIGMA==PI_SIGMA
KinVtxFitter constrained_fitter;
try {
constrained_fitter = KinVtxFitter({leptons_ttracks->at(l1_idx), leptons_ttracks->at(l2_idx), XiTT},
{l1_ptr->mass(), l2_ptr->mass(), ximass},
{bph::LEP_SIGMA, bph::LEP_SIGMA, ximassErr},
mass_constraint);
} catch (const VertexException &e) {
edm::LogWarning("KinematicFit") << "BToXiLL Builder: Skipping candidate due to fit failure: " << e.what();
continue;
}

if (!constrained_fitter.success()) {
// Save default values and continue
cand.addUserInt("sv_OK_withMC", sv_OK_withMC);
Expand Down
Loading