1 #ifndef RecoBTag_IPProducer
2 #define RecoBTag_IPProducer
59 namespace IPProducerHelpers {
69 std::vector<reco::JTATagInfo> bases;
72 it != jetTracksAssociation->end();
87 maxDeltaR(iConfig.getParameter<double>(
"maxDeltaR")),
88 explicitJTA(iConfig.existsAs<bool>(
"explicitJTA") ? iConfig.getParameter<bool>(
"explicitJTA") :
false) {}
94 std::vector<reco::JetTagInfo> bases;
99 m_map.resize(jets->size());
106 for (
size_t j = 0;
j < it->numberOfDaughters(); ++
j) {
107 if (it->daughterPtr(
j)->bestTrack() !=
nullptr && it->daughterPtr(
j)->charge() != 0) {
108 m_map[
i].push_back(it->daughterPtr(
j));
112 for (
size_t j = 0;
j < cands->size(); ++
j) {
113 if ((*cands)[
j].bestTrack() !=
nullptr && (*cands)[
j].charge() != 0 && (*cands)[
j].pt() > 0 &&
115 m_map[
i].push_back(cands->ptrAt(j));
122 std::vector<std::vector<reco::CandidatePtr> >
m_map;
129 template <
class Container,
class Base,
class Helper>
132 typedef std::vector<reco::IPTagInfo<Container, Base> >
Product;
190 template <
class Container,
class Base,
class Helper>
192 : m_config(iConfig), m_helper(iConfig, consumesCollector()) {
198 esConsumes<TransientTrackBuilder, TransientTrackRecord>(
edm::ESInputTag(
"",
"TransientTrackBuilder"));
199 token_calib2D = esConsumes<TrackProbabilityCalibration, BTagTrackProbability2DRcd>();
200 token_calib3D = esConsumes<TrackProbabilityCalibration, BTagTrackProbability3DRcd>();
215 if (m_computeGhostTrack)
216 produces<reco::TrackCollection>(
"ghostTracks");
220 template <
class Container,
class Base,
class Helper>
227 template <
class Container,
class Base,
class Helper>
230 if (m_computeProbabilities)
231 checkEventSetup(iSetup);
234 iEvent.
getByToken(token_primaryVertex, primaryVertex);
240 auto result = std::make_unique<Product>();
242 std::unique_ptr<reco::TrackCollection> ghostTracks;
244 if (m_computeGhostTrack) {
245 ghostTracks = std::make_unique<reco::TrackCollection>();
253 if (!primaryVertex->empty()) {
254 pv = &*primaryVertex->begin();
259 e(0, 0) = 0.0015 * 0.0015;
260 e(1, 1) = 0.0015 * 0.0015;
266 std::vector<Base> baseTagInfos = m_helper.makeBaseVector(iEvent);
267 for (
typename std::vector<Base>::const_iterator it = baseTagInfos.begin(); it != baseTagInfos.end(); it++) {
271 if (m_directionWithTracks) {
273 for (
typename Container::const_iterator itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack)
275 jetMomentum += (*itTrack)->momentum();
279 std::vector<reco::TransientTrack> transientTracks;
281 for (
typename Container::const_iterator itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack) {
291 if (track.
pt() > m_cutMinPt &&
297 selectedTracks.push_back(*itTrack);
298 transientTracks.push_back(transientTrack);
302 GlobalVector direction(jetMomentum.x(), jetMomentum.y(), jetMomentum.z());
304 std::unique_ptr<reco::GhostTrack> ghostTrack;
306 if (m_computeGhostTrack) {
310 ghostTrack = std::make_unique<reco::GhostTrack>(
311 fitter.
fit(origin, error, direction, m_ghostTrackPriorDeltaR, transientTracks));
329 ghostTrackRef =
reco::TrackRef(ghostTrackRefProd, ghostTracks->size());
330 ghostTracks->push_back(*ghostTrack);
332 if (m_directionWithGhostTrack) {
334 double lambda = pred.
lambda(origin);
345 std::vector<float> prob2D, prob3D;
346 std::vector<reco::btag::TrackIPData> ipData;
348 for (
unsigned int ind = 0; ind < transientTracks.size(); ind++) {
364 if (ghostTrack.get()) {
365 const std::vector<reco::GhostTrackState>& states = ghostTrack->states();
366 std::vector<reco::GhostTrackState>::const_iterator pos =
367 std::find_if(states.begin(), states.end(), [&](
auto&
arg) {
return arg.track() == transientTrack; });
369 if (pos != states.end() && pos->isValid()) {
373 GlobalError e1 = pos->tsos().cartesianError().position();
388 ipData.push_back(trackIP);
390 if (m_computeProbabilities) {
392 std::pair<bool, double> probability = m_probabilityEstimator->probability(
393 m_useTrackQuality, 0, ipData.back().ip3d.significance(),
track, *(it->jet()), *pv);
394 prob3D.push_back(probability.first ? probability.second : -1.);
397 probability = m_probabilityEstimator->probability(
398 m_useTrackQuality, 1, ipData.back().ip2d.significance(),
track, *(it->jet()), *pv);
399 prob2D.push_back(probability.first ? probability.second : -1.);
404 typename Product::value_type(ipData, prob2D, prob3D, selectedTracks, *it, pvRef, direction, ghostTrackRef));
407 if (m_computeGhostTrack)
419 template <
class Container,
class Base,
class Helper>
424 unsigned long long cacheId3D = re3D.cacheIdentifier();
426 if (cacheId2D != m_calibrationCacheId2D || cacheId3D != m_calibrationCacheId3D)
435 m_probabilityEstimator = std::make_unique<HistogramProbabilityEstimator>(ca3D, ca2D);
437 m_calibrationCacheId3D = cacheId3D;
438 m_calibrationCacheId2D = cacheId2D;
447 desc.
add<
double>(
"maximumTransverseImpactParameter", 0.2);
448 desc.
add<
int>(
"minimumNumberOfHits", 8);
449 desc.
add<
double>(
"minimumTransverseMomentum", 1.0);
451 desc.
add<
double>(
"maximumLongitudinalImpactParameter", 17.0);
452 desc.
add<
bool>(
"computeGhostTrack",
true);
453 desc.
add<
double>(
"ghostTrackPriorDeltaR", 0.03);
455 desc.
add<
bool>(
"jetDirectionUsingGhostTrack",
false);
456 desc.
add<
int>(
"minimumNumberOfPixelHits", 2);
457 desc.
add<
bool>(
"jetDirectionUsingTracks",
false);
458 desc.
add<
bool>(
"computeProbabilities",
true);
459 desc.
add<
bool>(
"useTrackQuality",
false);
460 desc.
add<
double>(
"maximumChiSquared", 5.0);
469 desc.
add<
double>(
"maximumTransverseImpactParameter", 0.2);
470 desc.
add<
int>(
"minimumNumberOfHits", 8);
471 desc.
add<
double>(
"minimumTransverseMomentum", 1.0);
473 desc.
add<
double>(
"maximumLongitudinalImpactParameter", 17.0);
474 desc.
add<
bool>(
"computeGhostTrack",
true);
475 desc.
add<
double>(
"maxDeltaR", 0.4);
477 desc.
add<
bool>(
"jetDirectionUsingGhostTrack",
false);
478 desc.
add<
int>(
"minimumNumberOfPixelHits", 2);
479 desc.
add<
bool>(
"jetDirectionUsingTracks",
false);
480 desc.
add<
bool>(
"computeProbabilities",
true);
481 desc.
add<
bool>(
"useTrackQuality",
false);
483 desc.
add<
double>(
"ghostTrackPriorDeltaR", 0.03);
484 desc.
add<
double>(
"maximumChiSquared", 5.0);
reco::Vertex::Point convertPos(const GlobalPoint &p)
unsigned long long cacheIdentifier() const
double m_cutMaxChiSquared
std::vector< reco::JTATagInfo > makeBaseVector(const edm::Event &iEvent)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool m_directionWithGhostTrack
double lambda(const GlobalPoint &point) const
transient_vector_type::const_iterator const_iterator
unsigned long long m_calibrationCacheId3D
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
edm::ESGetToken< TrackProbabilityCalibration, BTagTrackProbability2DRcd > token_calib2D
bool getByToken(EDGetToken token, Handle< PROD > &result) const
int numberOfValidHits() const
JetTracksAssociation::Container JetTracksAssociationCollection
typedefs for backward compatibility
FromJetAndCands(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC, const std::string &jets="jets")
unsigned long long m_calibrationCacheId2D
reco::Vertex::Error convertError(const GlobalError &ge)
std::vector< Track > TrackCollection
collection of Tracks
TrackRefVector tracks(void) const override
returns a list of tracks associated to the jet
math::Error< dimension >::type Error
covariance error matrix (3x3)
GlobalPoint globalPosition() const
const MagneticField * field() const
auto const & tracks
cannot be loose
edm::ESGetToken< TrackProbabilityCalibration, BTagTrackProbability3DRcd > token_calib3D
const reco::Track * toTrack(const reco::TrackBaseRef &t)
const Point & position() const
position
double m_ghostTrackPriorDeltaR
GhostTrack fit(const GlobalPoint &priorPosition, const GlobalError &priorError, const GlobalVector &direction, double coneRadius, const std::vector< TransientTrack > &tracks) const
std::vector< std::vector< reco::CandidatePtr > > m_map
void checkEventSetup(const edm::EventSetup &iSetup)
std::unique_ptr< HistogramProbabilityEstimator > m_probabilityEstimator
const std::vector< reco::CandidatePtr > & tracks(const reco::JetTagInfo &it)
std::vector< reco::IPTagInfo< Container, Base > > Product
Container::value_type value_type
void addDefault(ParameterSetDescription const &psetDescription)
edm::RefToBase< Jet > jet(void) const override
returns a polymorphic reference to the tagged jet
Measurement1D distanceToGhostTrack
FromJTA(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
double pt() const
track transverse momentum
Abs< T >::type abs(const T &t)
edm::EDGetTokenT< reco::VertexCollection > token_primaryVertex
reco::TrackRefVector tracks(const reco::JTATagInfo &it)
math::XYZPoint Point
point in the space
unsigned short numberOfValidHits() const
number of valid hits found
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< reco::JetTracksAssociationCollection > token_associator
bool m_directionWithTracks
RefProd< PROD > getRefBeforePut()
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
const edm::ParameterSet & m_config
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
GlobalPoint closestToJetAxis
const Track & track() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
edm::EDGetTokenT< edm::View< reco::Jet > > token_jets
T const * product() const
T getParameter(std::string const &) const
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > token_trackBuilder
Error error() const
return SMatrix
Measurement1D distanceToJetAxis
void produce(edm::Event &, const edm::EventSetup &) override
const Vector & prediction() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
IPProducer(const edm::ParameterSet &)
GlobalPoint position(double lambda=0.) const
GlobalPoint closestToGhostTrack
edm::EDGetTokenT< edm::View< reco::Candidate > > token_cands
std::vector< reco::JetTagInfo > makeBaseVector(const edm::Event &iEvent)
int numberOfValidPixelHits() const
TrajectoryStateOnSurface impactPointState() const
bool m_computeProbabilities
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
edm::AssociationVector< reco::JetRefBaseProd, Values > Container
GlobalError positionError(double lambda=0.) const
const GlobalVector direction() const