32 #include "CLHEP/Units/SystemOfUnits.h" 34 #include "CLHEP/Random/RandGauss.h" 56 const std::vector<edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> >
associators_;
61 const std::vector<reco::RecoToSimCollection>&,
62 std::vector<float>& )
const;
63 std::pair<float,float>
extractTrackVertexTime(
const std::vector<std::pair<TrackingParticleRef, double> >&)
const;
69 constexpr float fakeBeamSpotTimeWidth = 0.175f;
70 static const std::string generalTracksName(
"generalTracks");
71 static const std::string gsfTracksName(
"gsfTracks");
74 template<
typename ParticleType,
typename T>
77 const std::vector<T> &
values,
95 const std::vector<edm::ParameterSet>& resos = conf.getParameterSetVector(
"resolutionModels");
96 for(
const auto& reso : resos ) {
102 produces<edm::ValueMap<float> >(generalTracksName+
name);
103 produces<edm::ValueMap<float> >(generalTracksName+name+
resolution);
106 produces<edm::ValueMap<float> >(gsfTracksName+
name);
107 produces<edm::ValueMap<float> >(gsfTracksName+name+
resolution);
111 if (!rng.isAvailable()){
113 <<
"TrackTimeValueMapProducer::TrackTimeValueMapProducer() - RandomNumberGeneratorService is not present in configuration file.\n" 114 <<
"Add the service in the configuration file or remove the modules that require it.";
122 auto rng_engine = &(rng->
getEngine(sid));
125 std::vector<edm::Handle<reco::TrackToTrackingParticleAssociator> >
associators;
127 associators.emplace_back();
128 auto& back = associators.back();
132 std::vector<float> generalTrackTimes, gsfTrackTimes;
149 std::vector<reco::RecoToSimCollection> associatedTracks, associatedTracksGsf;
151 associatedTracks.emplace_back(
associator->associateRecoToSim(TrackCollectionH, TPCollectionH));
152 associatedTracksGsf.emplace_back(
associator->associateRecoToSim(GsfTrackCollectionH, TPCollectionH));
161 std::vector<float>
times, resos;
162 std::vector<float> gsf_times, gsf_resos;
164 times.reserve(TrackCollection.
size());
165 resos.reserve(TrackCollection.
size());
166 gsf_times.reserve(GsfTrackCollection.
size());
167 gsf_resos.reserve(GsfTrackCollection.
size());
169 for(
unsigned i = 0;
i < TrackCollection.
size(); ++
i ) {
171 if(
edm::isFinite( generalTrackTimes[
i] ) && generalTrackTimes[
i] != 0.f) {
172 const float resolution = reso->getTimeResolution(tk);
173 times.push_back( CLHEP::RandGauss::shoot(rng_engine, generalTrackTimes[i], resolution) );
174 resos.push_back( resolution );
176 times.push_back( generalTrackTimes[i] );
177 resos.push_back( fakeBeamSpotTimeWidth );
181 for(
unsigned i = 0;
i < GsfTrackCollection.
size(); ++
i ) {
184 const float resolution = reso->getTimeResolution(tk);
185 gsf_times.push_back( CLHEP::RandGauss::shoot(rng_engine, gsfTrackTimes[i], resolution) );
186 gsf_resos.push_back( resolution );
188 gsf_times.push_back( gsfTrackTimes[i] );
189 gsf_resos.push_back( fakeBeamSpotTimeWidth );
193 writeValueMap( evt, TrackCollectionH, times, generalTracksName+name );
194 writeValueMap( evt, TrackCollectionH, resos, generalTracksName+name+
resolution );
195 writeValueMap( evt, GsfTrackCollectionH, gsf_times, gsfTracksName+name );
196 writeValueMap( evt, GsfTrackCollectionH, gsf_resos, gsfTracksName+name+
resolution );
201 const std::vector<reco::RecoToSimCollection>& assocs,
202 std::vector<float>& tvals )
const {
203 constexpr float flt_max = std::numeric_limits<float>::quiet_NaN();
205 for(
unsigned itk = 0; itk < tkcoll.
size(); ++itk ) {
206 const auto tkref = tkcoll.
refAt(itk);
212 if( track_tps != assocs.back().end() ) {
213 if( !track_tps->val.size() ) {
214 tvals.push_back(flt_max);
217 tvals.push_back(time_info.first);
220 tvals.push_back(flt_max);
228 float result_z = 0.f;
229 for(
const auto& tpref : tp_list ) {
230 const auto& tvertex = tpref.first->parentVertex();
232 result_z = tvertex->position().Z();
235 if( tvertex->nSourceTracks() ) {
236 auto pvertex = tvertex->sourceTracks()[0]->parentVertex();
238 result_z = pvertex->position().Z();
239 while( pvertex->nSourceTracks() ) {
240 pvertex = pvertex->sourceTracks()[0]->parentVertex();
242 result_z = pvertex->position().Z();
246 if( tp_list.size() > 1 )
LogDebug(
"TooManyTracks") <<
"track matched to " << tp_list.size() <<
" tracking particles!" << std::endl;
247 return std::make_pair(result,result_z);
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const edm::EDGetTokenT< TrackingVertexCollection > trackingVertices_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< TrackingParticle > TrackingParticleCollection
friend struct const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
std::vector< Track > TrackCollection
collection of Tracks
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 >
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::vector< std::unique_ptr< const ResolutionModel > > resolutions_
~TrackTimeValueMapProducer()
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
RefToBase< value_type > refAt(size_type i) const
U second(std::pair< T, U > const &p)
std::pair< float, float > extractTrackVertexTime(const std::vector< std::pair< TrackingParticleRef, double > > &) const
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
const edm::EDGetTokenT< edm::HepMCProduct > hepMCProduct_
TrackTimeValueMapProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< TrackingParticleCollection > trackingParticles_
std::vector< TrackingVertex > TrackingVertexCollection
const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associators_
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_
const edm::EDGetTokenT< edm::View< reco::Track > > gsfTracks_
void calculateTrackTimes(const edm::View< reco::Track > &, const std::vector< reco::RecoToSimCollection > &, std::vector< float > &) const
T get(const Candidate &c)