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 70 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 74 of file PATLeptonTimeLifeInfoProducer.cc.

75  : leptonsToken_(consumes<std::vector<T>>(cfg.getParameter<edm::InputTag>("src"))),
76  pvToken_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("pvSource"))),
77  transTrackBuilderToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
78  selector_(cfg.getParameter<std::string>("selection")),
79  pvChoice_(cfg.getParameter<int>("pvChoice")) {
80  produces<TrackTimeLifeInfoMap>();
81 }
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 250 of file PATLeptonTimeLifeInfoProducer.cc.

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

250  {
251  // pat{Electron,Muon,Tau}TimeLifeInfoProducer
253 
254  std::string lepCollName;
255  if (typeid(T) == typeid(pat::Electron))
256  lepCollName = "slimmedElectrons";
257  else if (typeid(T) == typeid(pat::Muon))
258  lepCollName = "slimmedMuons";
259  else if (typeid(T) == typeid(pat::Tau))
260  lepCollName = "slimmedTaus";
261  desc.add<edm::InputTag>("src", edm::InputTag(lepCollName));
262  desc.add<edm::InputTag>("pvSource", edm::InputTag("offlineSlimmedPrimaryVertices"));
263  desc.add<std::string>("selection", "")->setComment("Selection required to produce and store time-life information");
264  desc.add<int>("pvChoice", useFront)
265  ->setComment(
266  "Define PV to compute IP: 0: first PV, 1: PV with the smallest dz of the tau leading track (default: " +
267  std::to_string(useFront) + ")");
268 
269  descriptions.addWithDefaultLabel(desc);
270 }
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 TransientVertex::hasRefittedTracks(), TransientVertex::refittedTracks(), and KalmanVertexFitter::vertex().

53  {
54  if (transTrk.size() < 2)
55  return false;
56  KalmanVertexFitter kvf(true);
57  transVtx = kvf.vertex(transTrk);
58  return transVtx.hasRefittedTracks() && transVtx.refittedTracks().size() == transTrk.size();
59  }
bool hasRefittedTracks() const
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 141 of file PATLeptonTimeLifeInfoProducer.cc.

References HPSPFTauProducerPuppi_cfi::electron.

141  {
142  return electron.gsfTrack().isNonnull() ? electron.gsfTrack().get() : nullptr;
143 }

◆ getTrack() [3/4]

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

Definition at line 146 of file PATLeptonTimeLifeInfoProducer.cc.

146  {
147  return muon.innerTrack().isNonnull() ? muon.innerTrack().get() : nullptr;
148 }

◆ getTrack() [4/4]

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

Definition at line 151 of file PATLeptonTimeLifeInfoProducer.cc.

References HLT_2024v12_cff::track.

151  {
152  const reco::Track* track = nullptr;
153  if (tau.leadChargedHadrCand().isNonnull())
154  track = tau.leadChargedHadrCand()->bestTrack();
155  return track;
156 }

◆ produce()

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

Definition at line 84 of file PATLeptonTimeLifeInfoProducer.cc.

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

84  {
85  // Get leptons
88 
89  // Get the vertices
92 
93  // Get transient track builder
94  const TransientTrackBuilder& transTrackBuilder = es.getData(transTrackBuilderToken_);
95 
96  std::vector<TrackTimeLifeInfo> infos;
97  infos.reserve(leptons->size());
98 
99  for (const auto& lepton : *leptons) {
101 
102  // Do nothing for lepton not passing selection
103  if (!selector_(lepton)) {
104  infos.push_back(info);
105  continue;
106  }
107  size_t pv_idx = 0;
108  if (pvChoice_ == useClosestInDz && getTrack(lepton) != nullptr) {
109  float dz_min = 999;
110  size_t vtx_idx = 0;
111  for (const auto& vtx : *vertices) {
112  float dz_tmp = std::abs(getTrack(lepton)->dz(vtx.position()));
113  if (dz_tmp < dz_min) {
114  dz_min = dz_tmp;
115  pv_idx = vtx_idx;
116  }
117  vtx_idx++;
118  }
119  }
120  const reco::Vertex& pv = !vertices->empty() ? (*vertices)[pv_idx] : reco::Vertex();
121 
122  // Obtain IP vector and set related info into lepton
123  produceAndFillIPInfo(lepton, transTrackBuilder, pv, info);
124 
125  // Fit SV and set related info for taus or do nothing for other lepton types
126  produceAndFillSVInfo(lepton, transTrackBuilder, pv, info);
127  infos.push_back(info);
128  } // end of lepton loop
129 
130  // Build the valuemap
131  auto infoMap = std::make_unique<TrackTimeLifeInfoMap>();
133  filler.insert(leptons, infos.begin(), infos.end());
134  filler.fill();
135 
136  // Store output into the event
137  evt.put(std::move(infoMap));
138 }
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:528
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 159 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_2024v12_cff::track, Measurement1D::value(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

162  {
163  const reco::Track* track = getTrack(lepton);
164  if (track != nullptr) {
165  // Extrapolate track to the point closest to PV
166  reco::TransientTrack transTrack = transTrackBuilder.build(track);
167  AnalyticalImpactPointExtrapolator extrapolator(transTrack.field());
168  TrajectoryStateOnSurface closestState =
169  extrapolator.extrapolate(transTrack.impactPointState(), RecoVertex::convertPos(pv.position()));
170  if (!closestState.isValid()) {
171  edm::LogError("PATLeptonTimeLifeInfoProducer")
172  << "closestState not valid! From:\n"
173  << "transTrack.impactPointState():\n"
174  << transTrack.impactPointState() << "RecoVertex::convertPos(pv.position()):\n"
175  << RecoVertex::convertPos(pv.position());
176  return;
177  }
178  GlobalPoint pca = closestState.globalPosition();
179  GlobalError pca_cov = closestState.cartesianError().position();
180  GlobalVector ip_vec = GlobalVector(pca.x() - pv.x(), pca.y() - pv.y(), pca.z() - pv.z());
181  GlobalError ip_cov = pca_cov + GlobalError(pv.covariance());
182  VertexDistance3D pca_dist;
183  Measurement1D ip_mes = pca_dist.distance(pv, VertexState(pca, pca_cov));
184  if (ip_vec.dot(GlobalVector(lepton.px(), lepton.py(), lepton.pz())) < 0)
185  ip_mes = Measurement1D(-1. * ip_mes.value(), ip_mes.error());
186 
187  // Store Track and PCA info
188  info.setTrack(track);
189  info.setBField_z(transTrackBuilder.field()->inInverseGeV(GlobalPoint(track->vx(), track->vy(), track->vz())).z());
190  info.setPCA(pca, pca_cov);
191  info.setIP(ip_vec, ip_cov);
192  info.setIPLength(ip_mes);
193  }
194 }
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 197 of file PATLeptonTimeLifeInfoProducer.cc.

200  {}

◆ 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 203 of file PATLeptonTimeLifeInfoProducer.cc.

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

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

◆ pvChoice_

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

Definition at line 66 of file PATLeptonTimeLifeInfoProducer.cc.

◆ pvToken_

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

Definition at line 63 of file PATLeptonTimeLifeInfoProducer.cc.

◆ selector_

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

Definition at line 65 of file PATLeptonTimeLifeInfoProducer.cc.

◆ transTrackBuilderToken_

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

Definition at line 64 of file PATLeptonTimeLifeInfoProducer.cc.