CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
PATLeptonTimeLifeInfoProducer< T > Class Template Reference

Produces lepton life-time information. More...

Inheritance diagram for PATLeptonTimeLifeInfoProducer< T >:
edm::stream::EDProducer<>

Public Member Functions

 PATLeptonTimeLifeInfoProducer (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PATLeptonTimeLifeInfoProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

enum  PVChoice { useFront = 0, useClosestInDz }
 
using TrackTimeLifeInfoMap = edm::ValueMap< TrackTimeLifeInfo >
 

Private Member Functions

const reco::TrackgetTrack (const T &)
 
template<>
const reco::TrackgetTrack (const pat::Electron &electron)
 
template<>
const reco::TrackgetTrack (const pat::Muon &muon)
 
template<>
const reco::TrackgetTrack (const pat::Tau &tau)
 
void produceAndFillIPInfo (const T &, const TransientTrackBuilder &, const reco::Vertex &, TrackTimeLifeInfo &)
 
void produceAndFillSVInfo (const T &, const TransientTrackBuilder &, const reco::Vertex &, TrackTimeLifeInfo &)
 
template<>
void produceAndFillSVInfo (const pat::Tau &tau, const TransientTrackBuilder &transTrackBuilder, const reco::Vertex &pv, TrackTimeLifeInfo &info)
 

Static Private Member Functions

static bool fitVertex (const std::vector< reco::TransientTrack > &transTrk, TransientVertex &transVtx)
 

Private Attributes

edm::EDGetTokenT< std::vector< T > > leptonsToken_
 
int pvChoice_
 
edm::EDGetTokenT< reco::VertexCollectionpvToken_
 
const StringCutObjectSelector< Tselector_
 
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecordtransTrackBuilderToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

template<typename T>
class PATLeptonTimeLifeInfoProducer< T >

Produces lepton life-time information.

Author
Michal Bluj, NCBJ, Warsaw

Definition at line 40 of file PATLeptonTimeLifeInfoProducer.cc.

Member Typedef Documentation

◆ TrackTimeLifeInfoMap

Definition at line 75 of file PATLeptonTimeLifeInfoProducer.cc.

Member Enumeration Documentation

◆ PVChoice

template<typename T >
enum PATLeptonTimeLifeInfoProducer::PVChoice
private

Constructor & Destructor Documentation

◆ PATLeptonTimeLifeInfoProducer()

template<typename T >
PATLeptonTimeLifeInfoProducer< T >::PATLeptonTimeLifeInfoProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 79 of file PATLeptonTimeLifeInfoProducer.cc.

80  : leptonsToken_(consumes<std::vector<T>>(cfg.getParameter<edm::InputTag>("src"))),
81  pvToken_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("pvSource"))),
82  transTrackBuilderToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
83  selector_(cfg.getParameter<std::string>("selection")),
84  pvChoice_(cfg.getParameter<int>("pvChoice")) {
85  produces<TrackTimeLifeInfoMap>();
86 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDGetTokenT< reco::VertexCollection > pvToken_
edm::EDGetTokenT< std::vector< T > > leptonsToken_
const StringCutObjectSelector< T > selector_
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_

◆ ~PATLeptonTimeLifeInfoProducer()

template<typename T >
PATLeptonTimeLifeInfoProducer< T >::~PATLeptonTimeLifeInfoProducer ( )
inlineoverride

Definition at line 43 of file PATLeptonTimeLifeInfoProducer.cc.

43 {};

Member Function Documentation

◆ fillDescriptions()

template<typename T >
void PATLeptonTimeLifeInfoProducer< T >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 255 of file PATLeptonTimeLifeInfoProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, AlCaHLTBitMon_QueryRunRegistry::string, and to_string().

255  {
256  // pat{Electron,Muon,Tau}TimeLifeInfoProducer
258 
259  std::string lepCollName;
260  if (typeid(T) == typeid(pat::Electron))
261  lepCollName = "slimmedElectrons";
262  else if (typeid(T) == typeid(pat::Muon))
263  lepCollName = "slimmedMuons";
264  else if (typeid(T) == typeid(pat::Tau))
265  lepCollName = "slimmedTaus";
266  desc.add<edm::InputTag>("src", edm::InputTag(lepCollName));
267  desc.add<edm::InputTag>("pvSource", edm::InputTag("offlineSlimmedPrimaryVertices"));
268  desc.add<std::string>("selection", "")->setComment("Selection required to produce and store time-life information");
269  desc.add<int>("pvChoice", useFront)
270  ->setComment(
271  "Define PV to compute IP: 0: first PV, 1: PV with the smallest dz of the tau leading track (default: " +
272  std::to_string(useFront) + ")");
273 
274  descriptions.addWithDefaultLabel(desc);
275 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static std::string to_string(const XMLCh *ch)
Analysis-level tau class.
Definition: Tau.h:53
Analysis-level electron class.
Definition: Electron.h:51
long double T
Analysis-level muon class.
Definition: Muon.h:51

◆ fitVertex()

template<typename T >
static bool PATLeptonTimeLifeInfoProducer< T >::fitVertex ( const std::vector< reco::TransientTrack > &  transTrk,
TransientVertex transVtx 
)
inlinestaticprivate

Definition at line 53 of file PATLeptonTimeLifeInfoProducer.cc.

References MillePedeFileConverter_cfg::e, TransientVertex::hasRefittedTracks(), TransientVertex::refittedTracks(), and KalmanVertexFitter::vertex().

53  {
54  if (transTrk.size() < 2)
55  return false;
56  try {
57  KalmanVertexFitter kvf(true);
58  transVtx = kvf.vertex(transTrk);
59  return transVtx.hasRefittedTracks() && transVtx.refittedTracks().size() == transTrk.size();
60  } catch (VertexException& e) {
61  edm::LogWarning("PATLeptonTimeLifeInfoProducer") << " fitVertex failed: " << e.what();
62  return false;
63  }
64  }
Common base class.
bool hasRefittedTracks() const
Log< level::Warning, false > LogWarning
std::vector< reco::TransientTrack > const & refittedTracks() const

◆ getTrack() [1/4]

template<typename T >
const reco::Track* PATLeptonTimeLifeInfoProducer< T >::getTrack ( const T )
private

◆ getTrack() [2/4]

template<>
const reco::Track * PATLeptonTimeLifeInfoProducer< pat::Electron >::getTrack ( const pat::Electron electron)
private

Definition at line 146 of file PATLeptonTimeLifeInfoProducer.cc.

References HPSPFTauProducerPuppi_cfi::electron.

146  {
147  return electron.gsfTrack().isNonnull() ? electron.gsfTrack().get() : nullptr;
148 }

◆ getTrack() [3/4]

template<>
const reco::Track * PATLeptonTimeLifeInfoProducer< pat::Muon >::getTrack ( const pat::Muon muon)
private

Definition at line 151 of file PATLeptonTimeLifeInfoProducer.cc.

151  {
152  return muon.innerTrack().isNonnull() ? muon.innerTrack().get() : nullptr;
153 }

◆ getTrack() [4/4]

template<>
const reco::Track * PATLeptonTimeLifeInfoProducer< pat::Tau >::getTrack ( const pat::Tau tau)
private

Definition at line 156 of file PATLeptonTimeLifeInfoProducer.cc.

References HLT_2024v14_cff::track.

156  {
157  const reco::Track* track = nullptr;
158  if (tau.leadChargedHadrCand().isNonnull())
159  track = tau.leadChargedHadrCand()->bestTrack();
160  return track;
161 }

◆ produce()

template<typename T >
void PATLeptonTimeLifeInfoProducer< T >::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 89 of file PATLeptonTimeLifeInfoProducer.cc.

References funct::abs(), PVValHelper::dz, trigObjTnPSource_cfi::filler, edm::Event::getByToken(), edm::EventSetup::getData(), getTrack(), info(), submitPVValidationJobs::infos, HLT_2024v14_cff::leptons, eostools::move(), edm::Event::put(), HltBtagValidation_cff::Vertex, AlignmentTracksFromVertexSelector_cfi::vertices, and L1BJetProducer_cff::vtx.

89  {
90  // Get leptons
93 
94  // Get the vertices
97 
98  // Get transient track builder
99  const TransientTrackBuilder& transTrackBuilder = es.getData(transTrackBuilderToken_);
100 
101  std::vector<TrackTimeLifeInfo> infos;
102  infos.reserve(leptons->size());
103 
104  for (const auto& lepton : *leptons) {
106 
107  // Do nothing for lepton not passing selection
108  if (!selector_(lepton)) {
109  infos.push_back(info);
110  continue;
111  }
112  size_t pv_idx = 0;
113  if (pvChoice_ == useClosestInDz && getTrack(lepton) != nullptr) {
114  float dz_min = 999;
115  size_t vtx_idx = 0;
116  for (const auto& vtx : *vertices) {
117  float dz_tmp = std::abs(getTrack(lepton)->dz(vtx.position()));
118  if (dz_tmp < dz_min) {
119  dz_min = dz_tmp;
120  pv_idx = vtx_idx;
121  }
122  vtx_idx++;
123  }
124  }
125  const reco::Vertex& pv = !vertices->empty() ? (*vertices)[pv_idx] : reco::Vertex();
126 
127  // Obtain IP vector and set related info into lepton
128  produceAndFillIPInfo(lepton, transTrackBuilder, pv, info);
129 
130  // Fit SV and set related info for taus or do nothing for other lepton types
131  produceAndFillSVInfo(lepton, transTrackBuilder, pv, info);
132  infos.push_back(info);
133  } // end of lepton loop
134 
135  // Build the valuemap
136  auto infoMap = std::make_unique<TrackTimeLifeInfoMap>();
138  filler.insert(leptons, infos.begin(), infos.end());
139  filler.fill();
140 
141  // Store output into the event
142  evt.put(std::move(infoMap));
143 }
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void produceAndFillSVInfo(const T &, const TransientTrackBuilder &, const reco::Vertex &, TrackTimeLifeInfo &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
edm::EDGetTokenT< reco::VertexCollection > pvToken_
edm::EDGetTokenT< std::vector< T > > leptonsToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
helper::Filler< ValueMap< T > > Filler
Definition: ValueMap.h:162
const StringCutObjectSelector< T > selector_
void produceAndFillIPInfo(const T &, const TransientTrackBuilder &, const reco::Vertex &, TrackTimeLifeInfo &)
const reco::Track * getTrack(const T &)
Structure to hold time-life information.
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transTrackBuilderToken_
def move(src, dest)
Definition: eostools.py:511

◆ produceAndFillIPInfo()

template<typename T >
void PATLeptonTimeLifeInfoProducer< T >::produceAndFillIPInfo ( const T lepton,
const TransientTrackBuilder transTrackBuilder,
const reco::Vertex pv,
TrackTimeLifeInfo info 
)
private

Definition at line 164 of file PATLeptonTimeLifeInfoProducer.cc.

References TransientTrackBuilder::build(), RecoVertex::convertPos(), Vector3DBase< T, FrameTag >::dot(), Measurement1D::error(), TransientTrackBuilder::field(), reco::TransientTrack::field(), getTrack(), reco::TransientTrack::impactPointState(), info(), MagneticField::inInverseGeV(), HLT_2024v14_cff::track, Measurement1D::value(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

167  {
168  const reco::Track* track = getTrack(lepton);
169  if (track != nullptr) {
170  // Extrapolate track to the point closest to PV
171  reco::TransientTrack transTrack = transTrackBuilder.build(track);
172  AnalyticalImpactPointExtrapolator extrapolator(transTrack.field());
173  TrajectoryStateOnSurface closestState =
174  extrapolator.extrapolate(transTrack.impactPointState(), RecoVertex::convertPos(pv.position()));
175  if (!closestState.isValid()) {
176  edm::LogError("PATLeptonTimeLifeInfoProducer")
177  << "closestState not valid! From:\n"
178  << "transTrack.impactPointState():\n"
179  << transTrack.impactPointState() << "RecoVertex::convertPos(pv.position()):\n"
180  << RecoVertex::convertPos(pv.position());
181  return;
182  }
183  GlobalPoint pca = closestState.globalPosition();
184  GlobalError pca_cov = closestState.cartesianError().position();
185  GlobalVector ip_vec = GlobalVector(pca.x() - pv.x(), pca.y() - pv.y(), pca.z() - pv.z());
186  GlobalError ip_cov = pca_cov + GlobalError(pv.covariance());
187  VertexDistance3D pca_dist;
188  Measurement1D ip_mes = pca_dist.distance(pv, VertexState(pca, pca_cov));
189  if (ip_vec.dot(GlobalVector(lepton.px(), lepton.py(), lepton.pz())) < 0)
190  ip_mes = Measurement1D(-1. * ip_mes.value(), ip_mes.error());
191 
192  // Store Track and PCA info
193  info.setTrack(track);
194  info.setBField_z(transTrackBuilder.field()->inInverseGeV(GlobalPoint(track->vx(), track->vy(), track->vz())).z());
195  info.setPCA(pca, pca_cov);
196  info.setIP(ip_vec, ip_cov);
197  info.setIPLength(ip_mes);
198  }
199 }
reco::Vertex::Point convertPos(const GlobalPoint &p)
static const TGPicture * info(bool iBackgroundIsBlack)
T z() const
Definition: PV3DBase.h:61
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:99
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalVector inInverseGeV(const GlobalPoint &gp) const
Field value ad specified global point, in 1/Gev.
Definition: MagneticField.h:36
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
Log< level::Error, false > LogError
reco::TransientTrack build(const reco::Track *p) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
const MagneticField * field() const
const MagneticField * field() const
double value() const
Definition: Measurement1D.h:25
const reco::Track * getTrack(const T &)
double error() const
Definition: Measurement1D.h:27
TrajectoryStateOnSurface impactPointState() const
Global3DVector GlobalVector
Definition: GlobalVector.h:10

◆ produceAndFillSVInfo() [1/2]

template<typename T >
void PATLeptonTimeLifeInfoProducer< T >::produceAndFillSVInfo ( const T lepton,
const TransientTrackBuilder transTrackBuilder,
const reco::Vertex pv,
TrackTimeLifeInfo info 
)
private

Definition at line 202 of file PATLeptonTimeLifeInfoProducer.cc.

205  {}

◆ produceAndFillSVInfo() [2/2]

template<>
void PATLeptonTimeLifeInfoProducer< pat::Tau >::produceAndFillSVInfo ( const pat::Tau tau,
const TransientTrackBuilder transTrackBuilder,
const reco::Vertex pv,
TrackTimeLifeInfo info 
)
private

Definition at line 208 of file PATLeptonTimeLifeInfoProducer.cc.

References TransientTrackBuilder::build(), info(), TransientVertex::positionError(), pfDeepBoostedJetPreprocessParams_cfi::sv, and HLT_2024v14_cff::track.

211  {
212  // Fit SV with tracks of charged tau decay products
213  int fitOK = 0;
214  if (tau.signalChargedHadrCands().size() + tau.signalLostTracks().size() > 1) {
215  // Get tracks from tau signal charged candidates
216  std::vector<reco::TransientTrack> transTrks;
217  TransientVertex transVtx;
218  for (const auto& cand : tau.signalChargedHadrCands()) {
219  if (cand.isNull())
220  continue;
221  const reco::Track* track = cand->bestTrack();
222  if (track != nullptr)
223  transTrks.push_back(transTrackBuilder.build(track));
224  }
225  for (const auto& cand : tau.signalLostTracks()) {
226  if (cand.isNull())
227  continue;
228  const reco::Track* track = cand->bestTrack();
229  if (track != nullptr)
230  transTrks.push_back(transTrackBuilder.build(track));
231  }
232  // Fit SV with KalmanVertexFitter
233  fitOK = fitVertex(transTrks, transVtx) ? 1 : -1;
234  if (fitOK > 0) {
235  reco::Vertex sv = transVtx;
236  // Get flight-length
237  // Full PV->SV flight vector with its covariance
238  GlobalVector flight_vec = GlobalVector(sv.x() - pv.x(), sv.y() - pv.y(), sv.z() - pv.z());
239  GlobalError flight_cov = transVtx.positionError() + GlobalError(pv.covariance());
240  //MB: can be taken from tau itself (but with different fit of PV and SV) as follows:
241  //tau.flightLength().mag2());
242  //tau.flightLengthSig();
243  VertexDistance3D sv_dist;
244  Measurement1D flightLength_mes = sv_dist.signedDistance(pv, sv, GlobalVector(tau.px(), tau.py(), tau.pz()));
245 
246  // Store SV info
247  info.setSV(sv);
248  info.setFlightVector(flight_vec, flight_cov);
249  info.setFlightLength(flightLength_mes);
250  }
251  }
252 }
static const TGPicture * info(bool iBackgroundIsBlack)
GlobalError positionError() const
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
reco::TransientTrack build(const reco::Track *p) const
static bool fitVertex(const std::vector< reco::TransientTrack > &transTrk, TransientVertex &transVtx)
Global3DVector GlobalVector
Definition: GlobalVector.h:10

Member Data Documentation

◆ leptonsToken_

template<typename T >
edm::EDGetTokenT<std::vector<T> > PATLeptonTimeLifeInfoProducer< T >::leptonsToken_
private

Definition at line 67 of file PATLeptonTimeLifeInfoProducer.cc.

◆ pvChoice_

template<typename T >
int PATLeptonTimeLifeInfoProducer< T >::pvChoice_
private

Definition at line 71 of file PATLeptonTimeLifeInfoProducer.cc.

◆ pvToken_

template<typename T >
edm::EDGetTokenT<reco::VertexCollection> PATLeptonTimeLifeInfoProducer< T >::pvToken_
private

Definition at line 68 of file PATLeptonTimeLifeInfoProducer.cc.

◆ selector_

template<typename T >
const StringCutObjectSelector<T> PATLeptonTimeLifeInfoProducer< T >::selector_
private

Definition at line 70 of file PATLeptonTimeLifeInfoProducer.cc.

◆ transTrackBuilderToken_

template<typename T >
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> PATLeptonTimeLifeInfoProducer< T >::transTrackBuilderToken_
private

Definition at line 69 of file PATLeptonTimeLifeInfoProducer.cc.