Skip to content

Commit

Permalink
Merge pull request #29537 from cericeci/from-reco_include_InverseBeta…
Browse files Browse the repository at this point in the history
…_10_6_X_fixPatMuondXY_10_6_X

Backport of #28753 (fix the sign of pat::Muon dxy to take the one from the track)
  • Loading branch information
cmsbuild authored May 1, 2020
2 parents 1c34137 + 6025293 commit df33848
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 13 deletions.
14 changes: 13 additions & 1 deletion DataFormats/TrackReco/interface/TrackBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ class TrackBase

/// error on beta
double betaError() const;


/// error on dxy with respect to a user-given reference point + uncertainty (i.e. reco::Vertex position)
double dxyError(Point const &vtx, math::Error<3>::type const &vertexCov) const;

/// error on dxy with respect to a user-given beamspot
double dxyError(const BeamSpot &theBeamSpot) const;

/// fill SMatrix
CovarianceMatrix &fill(CovarianceMatrix &v) const;

Expand Down Expand Up @@ -885,6 +891,12 @@ inline double TrackBase::betaError() const
return std::sqrt(covbetabeta_);
}

// error on dxy with respect to a given beamspot
inline double TrackBase::dxyError(const BeamSpot &theBeamSpot) const
{
return dxyError(theBeamSpot.position(vz()), theBeamSpot.rotatedCovariance3D());
}

// number of valid hits found
inline unsigned short TrackBase::numberOfValidHits() const
{
Expand Down
13 changes: 13 additions & 0 deletions DataFormats/TrackReco/src/TrackBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ TrackBase::TrackAlgorithm TrackBase::algoByName(const std::string &name)
// cast
return TrackAlgorithm(index);
}

double TrackBase::dxyError(Point const &vtx, math::Error<3>::type const &vertexCov) const {
// Gradient of TrackBase::dxy(const Point &myBeamSpot) with respect to track parameters. Using unrolled expressions to avoid calling for higher dimension matrices
// ( 0, 0, x_vert * cos(phi) + y_vert * sin(phi), 1, 0 )
// Gradient with respect to point parameters
// ( sin(phi), -cos(phi))
// Propagate covariance assuming cross-terms of the covariance between track and vertex parameters are 0
return std::sqrt((vtx.x() * px() + vtx.y() * py()) * (vtx.x() * px() + vtx.y() * py()) / (pt() * pt()) *
covariance(i_phi, i_phi) +
2 * (vtx.x() * px() + vtx.y() * py()) / pt() * covariance(i_phi, i_dxy) + covariance(i_dxy, i_dxy) +
py() * py() / (pt() * pt()) * vertexCov(0, 0) - 2 * py() * px() / (pt() * pt()) * vertexCov(0, 1) +
px() * px() / (pt() * pt()) * vertexCov(1, 1));
}
40 changes: 30 additions & 10 deletions PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ PATMuonProducer::PATMuonProducer(const edm::ParameterSet& iConfig, PATMuonHeavyO
muonTimeExtraToken_ =
consumes<edm::ValueMap<reco::MuonTimeExtra>>(iConfig.getParameter<edm::InputTag>("sourceMuonTimeExtra"));
}
// Switch to get the dB from the track instead of using IPTools
getdBFromTrack_ = iConfig.getParameter<bool>("getdBFromTrack");
// Monte Carlo matching
addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
if (addGenMatch_) {
Expand Down Expand Up @@ -982,6 +984,9 @@ void PATMuonProducer::fillDescriptions(edm::ConfigurationDescriptions& descripti
iDesc.add<edm::InputTag>("sourceInverseBeta", edm::InputTag("muons", "combined"))
->setComment("source of inverse beta values");

// switch to get the IP from the best track instead of running IPTools
iDesc.add<bool>("getdBFromTrack", false)->setComment("switch IP2D computation to use the best track one");

// MC matching configurables
iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
Expand Down Expand Up @@ -1094,14 +1099,25 @@ void PATMuonProducer::embedHighLevel(pat::Muon& aMuon,
bool primaryVertexIsValid,
reco::BeamSpot& beamspot,
bool beamspotIsValid) {
// Generic variable to store measurements
std::pair<bool,Measurement1D> result;
double d0_corr;
double d0_err;

// Correct to PV

// PV2D
std::pair<bool, Measurement1D> result =
if (getdBFromTrack_){
aMuon.setDB(track->dxy(primaryVertex.position()),
track->dxyError(primaryVertex.position(), primaryVertex.covariance()),
pat::Muon::PV2D);
} else{
result =
IPTools::signedTransverseImpactParameter(tt, GlobalVector(track->px(), track->py(), track->pz()), primaryVertex);
double d0_corr = result.second.value();
double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
aMuon.setDB(d0_corr, d0_err, pat::Muon::PV2D);
d0_corr = result.second.value();
d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
aMuon.setDB( d0_corr, d0_err, pat::Muon::PV2D);
}

// PV3D
result = IPTools::signedImpactParameter3D(tt, GlobalVector(track->px(), track->py(), track->pz()), primaryVertex);
Expand All @@ -1110,14 +1126,18 @@ void PATMuonProducer::embedHighLevel(pat::Muon& aMuon,
aMuon.setDB(d0_corr, d0_err, pat::Muon::PV3D);

// Correct to beam spot
// make a fake vertex out of beam spot
reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());

// BS2D
result = IPTools::signedTransverseImpactParameter(tt, GlobalVector(track->px(), track->py(), track->pz()), vBeamspot);
d0_corr = result.second.value();
d0_err = beamspotIsValid ? result.second.error() : -1.0;
aMuon.setDB(d0_corr, d0_err, pat::Muon::BS2D);
// make a fake vertex out of beam spot
reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
if (getdBFromTrack_){
aMuon.setDB(track->dxy(beamspot), track->dxyError(beamspot), pat::Muon::BS2D);
} else{
result = IPTools::signedTransverseImpactParameter(tt, GlobalVector(track->px(), track->py(), track->pz()), vBeamspot);
d0_corr = result.second.value();
d0_err = beamspotIsValid ? result.second.error() : -1.0;
aMuon.setDB( d0_corr, d0_err, pat::Muon::BS2D);
}

// BS3D
result = IPTools::signedImpactParameter3D(tt, GlobalVector(track->px(), track->py(), track->pz()), vBeamspot);
Expand Down
2 changes: 2 additions & 0 deletions PhysicsTools/PatAlgos/plugins/PATMuonProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ namespace pat {
bool embedDytMuon_;
/// add combined inverse beta measurement into the muon
bool addInverseBeta_;
/// switch on reading the dB information from the track
bool getdBFromTrack_;
/// input tag for reading inverse beta
edm::EDGetTokenT<edm::ValueMap<reco::MuonTimeExtra>> muonTimeExtraToken_;
/// add generator match information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
# Read and store combined inverse beta
addInverseBeta = cms.bool(True),
sourceMuonTimeExtra = cms.InputTag("muons","combined"), #Use combined info, not only csc or dt

# Get 2D-IP from the best track instead of using IPTools
getdBFromTrack = cms.bool(False),

# mc matching
addGenMatch = cms.bool(True),
embedGenMatch = cms.bool(True),
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ def miniAOD_customizeCommon(process):
process.patMuons.computeSoftMuonMVA = True

process.patMuons.addTriggerMatching = True
from Configuration.Eras.Modifier_run2_miniAOD_devel_cff import run2_miniAOD_devel
from Configuration.Eras.Modifier_run2_muon_2016_cff import run2_muon_2016
from Configuration.Eras.Modifier_run2_muon_2017_cff import run2_muon_2017
from Configuration.Eras.Modifier_run2_muon_2018_cff import run2_muon_2018
run2_muon_2016.toModify( process.patMuons, effectiveAreaVec = [0.0735,0.0619,0.0465,0.0433,0.0577])
run2_muon_2017.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
run2_muon_2018.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
run2_muon_2016.toModify( process.patMuons, mvaTrainingFile = "RecoMuon/MuonIdentification/data/mu_2016_BDTG.weights.xml")

run2_miniAOD_devel.toModify( process.patMuons, getdBFromTrack = True)
process.patMuons.computePuppiCombinedIso = True
#
# disable embedding of electron and photon associated objects already stored by the ReducedEGProducer
Expand Down Expand Up @@ -373,7 +374,6 @@ def miniAOD_customizeCommon(process):
process.deepTau2017v2p1.taus = _noUpdatedTauName
deepTauIDTaskNew_ = cms.Task(process.deepTau2017v2p1,process.slimmedTaus)

from Configuration.Eras.Modifier_run2_miniAOD_devel_cff import run2_miniAOD_devel
from Configuration.Eras.Modifier_run2_tau_ul_2016_cff import run2_tau_ul_2016
from Configuration.Eras.Modifier_run2_tau_ul_2018_cff import run2_tau_ul_2018
for era in [run2_miniAOD_devel,run2_tau_ul_2016,run2_tau_ul_2018]:
Expand Down

0 comments on commit df33848

Please sign in to comment.