36 #include "CLHEP/Units/SystemOfUnits.h"
57 const std::vector<edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator>>
associators_;
69 constexpr
float m_pion = 139.57061e-3;
72 template <
typename ParticleType,
typename T>
75 const std::vector<T> &
values,
79 filler.insert(
handle, values.begin(), values.end());
86 : tracks_(consumes<edm::
View<
reco::Track>>(conf.getParameter<edm::
InputTag>(
"trackSrc"))),
87 tracksName_(conf.getParameter<edm::
InputTag>(
"trackSrc").label()),
95 [this](
const edm::
InputTag &
tag) {
return this->consumes<reco::TrackToTrackingParticleAssociator>(
tag); })),
96 etaMin_(conf.getParameter<
double>(
"etaMin")),
97 etaMax_(conf.getParameter<
double>(
"etaMax")),
98 ptMin_(conf.getParameter<
double>(
"ptMin")),
99 pMin_(conf.getParameter<
double>(
"pMin")),
102 const std::vector<edm::ParameterSet> &resos = conf.getParameterSetVector(
"resolutionModels");
103 for (
const auto &reso : resos) {
108 produces<edm::ValueMap<float>>(tracksName_ +
name);
109 produces<edm::ValueMap<float>>(tracksName_ + name +
resolution);
115 std::vector<edm::Handle<reco::TrackToTrackingParticleAssociator>> associators;
117 associators.emplace_back();
118 auto &back = associators.back();
122 std::vector<float> generalTrackTimes;
140 std::vector<reco::RecoToSimCollection> associatedTracks;
141 associatedTracks.reserve(associators.size());
142 for (
const auto &associator : associators) {
143 associatedTracks.emplace_back(associator->associateRecoToSim(TrackCollectionH, TPCollectionH));
146 double sumSimTime = 0.;
147 double sumSimTimeSq = 0.;
150 if (puinfo.getBunchCrossing() == 0) {
151 for (
const float &time : puinfo.getPU_times()) {
152 double simtime = time;
153 sumSimTime += simtime;
154 sumSimTimeSq += simtime * simtime;
161 double meanSimTime = sumSimTime / double(nsim);
162 double varSimTime = sumSimTimeSq / double(nsim) - meanSimTime * meanSimTime;
164 std::normal_distribution<float> gausSimTime(meanSimTime, rmsSimTime);
167 unsigned int runNum_uint =
static_cast<unsigned int>(evt.
id().
run());
168 unsigned int lumiNum_uint =
static_cast<unsigned int>(evt.
id().
luminosityBlock());
169 unsigned int evNum_uint =
static_cast<unsigned int>(evt.
id().
event());
170 unsigned int tkChi2_uint = uint32_t(TrackCollection.
empty() ? 0 : TrackCollection.
refAt(0)->chi2() / 0.01);
171 std::uint32_t
seed = tkChi2_uint + (lumiNum_uint << 10) + (runNum_uint << 20) + evNum_uint;
172 std::mt19937 rng(seed);
174 for (
unsigned itk = 0; itk < TrackCollection.
size(); ++itk) {
175 const auto tkref = TrackCollection.
refAt(itk);
184 if (track_tps != associatedTracks.back().end() && track_tps->val.size() == 1) {
187 generalTrackTimes.push_back(time);
189 float rndtime = gausSimTime(rng);
190 generalTrackTimes.push_back(rndtime);
191 if (track_tps != associatedTracks.back().end() && track_tps->val.size() > 1) {
192 LogDebug(
"TooManyTracks") <<
"track matched to " << track_tps->val.size() <<
" tracking particles!"
200 std::vector<float> times, resos;
202 times.reserve(TrackCollection.
size());
203 resos.reserve(TrackCollection.
size());
205 for (
unsigned i = 0;
i < TrackCollection.
size(); ++
i) {
208 bool inAcceptance = absEta < etaMax_ && absEta >=
etaMin_ && tk.
p() >
pMin_ &&
211 const float resolution = reso->getTimeResolution(tk);
212 std::normal_distribution<float> gausGeneralTime(generalTrackTimes[
i], resolution);
213 times.push_back(gausGeneralTime(rng));
214 resos.push_back(resolution);
216 times.push_back(0.0
f);
217 resos.push_back(-1.);
221 writeValueMap(evt, TrackCollectionH, times,
tracksName_ + name);
228 int pdgid = tp.
pdgId();
233 if (tvertex->nSourceTracks() && tvertex->sourceTracks()[0]->pdgId() == pdgid) {
234 auto pvertex = tvertex->sourceTracks()[0]->parentVertex();
235 result = pvertex->position();
236 while (pvertex->nSourceTracks() && pvertex->sourceTracks()[0]->pdgId() == pdgid) {
237 pvertex = pvertex->sourceTracks()[0]->parentVertex();
238 result = pvertex->position();
244 GlobalPoint result_pos(result.x(), result.y(), result.z());
247 float tkz = tkstate.position().z();
254 float pathlength =
std::sqrt(pathlengthrphi * pathlengthrphi + dz * dz);
257 float speed =
std::sqrt(1. / (1. + m_pion / p)) * CLHEP::c_light / CLHEP::cm;
constexpr double deltaPhi(double phi1, double phi2)
double p() const
momentum vector magnitude
EventNumber_t event() const
const edm::EDGetTokenT< TrackingVertexCollection > trackingVertices_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
etaMaxForPtThreshold_(conf.getParameter< double >("etaMaxForPtThreshold"))
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
friend struct const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
#define DEFINE_FWK_MODULE(type)
int pdgId() const
PDG ID.
Geom::Phi< T > phi() const
Global3DPoint GlobalPoint
std::vector< Track > TrackCollection
collection of Tracks
double phi() const
azimuthal angle of momentum vector
const MagneticField * field() const
const std::string tracksName_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
etaMax_(conf.getParameter< double >("etaMax"))
LuminosityBlockNumber_t luminosityBlock() const
std::vector< std::unique_ptr< const ResolutionModel > > resolutions_
RefToBase< value_type > refAt(size_type i) const
bool getData(T &iHolder) const
U second(std::pair< T, U > const &p)
ptMin_(conf.getParameter< double >("ptMin"))
double eta() const
pseudorapidity of momentum vector
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
pMin_(conf.getParameter< double >("pMin"))
~TrackTimeValueMapProducer() override
double pt() const
track transverse momentum
Abs< T >::type abs(const T &t)
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > builderToken_
float extractTrackVertexTime(const TrackingParticle &, const reco::TransientTrack &) const
const TrackingVertexRef & parentVertex() const
TrackTimeValueMapProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< TrackingParticleCollection > trackingParticles_
double vz() const
z coordinate of the reference point on track
const float etaMaxForPtThreshold_
const Track & track() const
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
std::vector< TrackingVertex > TrackingVertexCollection
const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associators_
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_
Monte Carlo truth information used for tracking validation.
int charge() const
track electric charge
std::vector< TrackingParticle > TrackingParticleCollection
etaMin_(conf.getParameter< double >("etaMin"))
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupSummaryInfo_
GlobalVector momentum() const
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override