CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TrackTimeValueMapProducer Class Reference
Inheritance diagram for TrackTimeValueMapProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 
 TrackTimeValueMapProducer (const edm::ParameterSet &)
 
 ~TrackTimeValueMapProducer ()
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void calculateTrackTimes (const edm::View< reco::Track > &, const std::vector< reco::RecoToSimCollection > &, std::vector< float > &) const
 
std::pair< float, float > extractTrackVertexTime (const std::vector< std::pair< TrackingParticleRef, double > > &) const
 

Private Attributes

const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associators_
 
const edm::EDGetTokenT< edm::View< reco::Track > > gsfTracks_
 
const edm::EDGetTokenT< edm::HepMCProducthepMCProduct_
 
std::vector< std::unique_ptr< const ResolutionModel > > resolutions_
 
const edm::EDGetTokenT< TrackingParticleCollectiontrackingParticles_
 
const edm::EDGetTokenT< TrackingVertexCollectiontrackingVertices_
 
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 41 of file TrackTimeValueMapProducer.cc.

Constructor & Destructor Documentation

TrackTimeValueMapProducer::TrackTimeValueMapProducer ( const edm::ParameterSet conf)

Definition at line 87 of file TrackTimeValueMapProducer.cc.

References Exception, reco::get(), dataset::name, ctppsDiamondLocalTracks_cfi::resolution, resolutions_, AlCaHLTBitMon_QueryRunRegistry::string, and GlobalPosition_Frontier_DevDB_cff::tag.

87  :
90  trackingParticles_(consumes<TrackingParticleCollection>( conf.getParameter<edm::InputTag>("trackingParticleSrc") ) ),
91  trackingVertices_(consumes<TrackingVertexCollection>( conf.getParameter<edm::InputTag>("trackingVertexSrc") ) ),
92  associators_( edm::vector_transform( conf.getParameter<std::vector<edm::InputTag> >("associators"), [this](const edm::InputTag& tag){ return this->consumes<reco::TrackToTrackingParticleAssociator>(tag); } ) )
93 {
94  // setup resolution models
95  const std::vector<edm::ParameterSet>& resos = conf.getParameterSetVector("resolutionModels");
96  for( const auto& reso : resos ) {
97  const std::string& name = reso.getParameter<std::string>("modelName");
98  ResolutionModel* resomod = ResolutionModelFactory::get()->create(name,reso);
99  resolutions_.emplace_back( resomod );
100 
101  // times and time resolutions for general tracks
102  produces<edm::ValueMap<float> >(generalTracksName+name);
103  produces<edm::ValueMap<float> >(generalTracksName+name+resolution);
104 
105  //for gsf tracks
106  produces<edm::ValueMap<float> >(gsfTracksName+name);
107  produces<edm::ValueMap<float> >(gsfTracksName+name+resolution);
108  }
109  // get RNG engine
111  if (!rng.isAvailable()){
112  throw cms::Exception("Configuration")
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.";
115  }
116 
117 }
T getParameter(std::string const &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
const edm::EDGetTokenT< TrackingVertexCollection > trackingVertices_
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 >
Definition: transform.h:11
std::vector< std::unique_ptr< const ResolutionModel > > resolutions_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< TrackingParticleCollection > trackingParticles_
const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associators_
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_
const edm::EDGetTokenT< edm::View< reco::Track > > gsfTracks_
T get(const Candidate &c)
Definition: component.h:55
TrackTimeValueMapProducer::~TrackTimeValueMapProducer ( )
inline

Definition at line 44 of file TrackTimeValueMapProducer.cc.

References produce().

44 { }

Member Function Documentation

void TrackTimeValueMapProducer::calculateTrackTimes ( const edm::View< reco::Track > &  tkcoll,
const std::vector< reco::RecoToSimCollection > &  assocs,
std::vector< float > &  tvals 
) const
private

Definition at line 200 of file TrackTimeValueMapProducer.cc.

References TrackValidation_cff::association, edm::AssociationMap< Tag >::const_iterator, constexpr, extractTrackVertexTime(), edm::View< T >::refAt(), and edm::View< T >::size().

Referenced by produce().

202  {
203  constexpr float flt_max = std::numeric_limits<float>::quiet_NaN();
204 
205  for( unsigned itk = 0; itk < tkcoll.size(); ++itk ) {
206  const auto tkref = tkcoll.refAt(itk);
207  reco::RecoToSimCollection::const_iterator track_tps = assocs.back().end();
208  for( const auto& association : assocs ) {
209  track_tps = association.find(tkref);
210  if( track_tps != association.end() ) break;
211  }
212  if( track_tps != assocs.back().end() ) {
213  if( !track_tps->val.size() ) {
214  tvals.push_back(flt_max);
215  } else {
216  const std::pair<float,float> time_info = extractTrackVertexTime(track_tps->val);
217  tvals.push_back(time_info.first);
218  }
219  } else {
220  tvals.push_back(flt_max);
221  }
222  }
223 }
friend struct const_iterator
size_type size() const
#define constexpr
RefToBase< value_type > refAt(size_type i) const
std::pair< float, float > extractTrackVertexTime(const std::vector< std::pair< TrackingParticleRef, double > > &) const
std::pair< float, float > TrackTimeValueMapProducer::extractTrackVertexTime ( const std::vector< std::pair< TrackingParticleRef, double > > &  tp_list) const
private

Definition at line 226 of file TrackTimeValueMapProducer.cc.

References LogDebug, mps_fire::result, and edm::second().

Referenced by calculateTrackTimes().

226  {
227  float result = 0.f;
228  float result_z = 0.f;
229  for( const auto& tpref : tp_list ) {
230  const auto& tvertex = tpref.first->parentVertex();
231  result = tvertex->position().T()*CLHEP::second; // convert into nano-seconds
232  result_z = tvertex->position().Z();
233  // account for secondary vertices...
234 
235  if( tvertex->nSourceTracks() ) {
236  auto pvertex = tvertex->sourceTracks()[0]->parentVertex();
237  result = pvertex->position().T()*CLHEP::second;
238  result_z = pvertex->position().Z();
239  while( pvertex->nSourceTracks() ) {
240  pvertex = pvertex->sourceTracks()[0]->parentVertex();
241  result = pvertex->position().T()*CLHEP::second;
242  result_z = pvertex->position().Z();
243  }
244  }
245  }
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);
248 }
#define LogDebug(id)
U second(std::pair< T, U > const &p)
void TrackTimeValueMapProducer::produce ( edm::StreamID  sid,
edm::Event evt,
const edm::EventSetup es 
) const
overridevirtual

Definition at line 119 of file TrackTimeValueMapProducer.cc.

References ctfWithMaterialTrackMCMatch_cfi::associator, simPFProducer_cfi::associators, associators_, calculateTrackTimes(), edm::Event::getByToken(), edm::RandomNumberGenerator::getEngine(), gsfTracks_, mps_fire::i, edm::isFinite(), dataset::name, ctppsDiamondLocalTracks_cfi::resolution, resolutions_, edm::View< T >::size(), AlCaHLTBitMon_QueryRunRegistry::string, create_public_lumi_plots::times, trackingParticles_, and tracks_.

Referenced by ~TrackTimeValueMapProducer().

119  {
120  // get RNG engine
122  auto rng_engine = &(rng->getEngine(sid));
123 
124  // get sim track associators
125  std::vector<edm::Handle<reco::TrackToTrackingParticleAssociator> > associators;
126  for( const auto& token : associators_ ) {
127  associators.emplace_back();
128  auto& back = associators.back();
129  evt.getByToken(token,back);
130  }
131 
132  std::vector<float> generalTrackTimes, gsfTrackTimes;
133 
134  //get track collections
135  edm::Handle<edm::View<reco::Track> > TrackCollectionH;
136  evt.getByToken(tracks_, TrackCollectionH);
137  const edm::View<reco::Track>& TrackCollection = *TrackCollectionH;
138 
139  edm::Handle<edm::View<reco::Track> > GsfTrackCollectionH;
140  evt.getByToken(gsfTracks_, GsfTrackCollectionH);
141  const edm::View<reco::Track>& GsfTrackCollection = *GsfTrackCollectionH;
142 
143  //get tracking particle collections
145  evt.getByToken(trackingParticles_, TPCollectionH);
146  //const TrackingParticleCollection& TPCollection = *TPCollectionH;
147 
148  // associate the reco tracks / gsf Tracks
149  std::vector<reco::RecoToSimCollection> associatedTracks, associatedTracksGsf;
150  for( auto associator : associators ) {
151  associatedTracks.emplace_back(associator->associateRecoToSim(TrackCollectionH, TPCollectionH));
152  associatedTracksGsf.emplace_back(associator->associateRecoToSim(GsfTrackCollectionH, TPCollectionH));
153  }
154 
155 
156  calculateTrackTimes(TrackCollection, associatedTracks, generalTrackTimes);
157  calculateTrackTimes(GsfTrackCollection, associatedTracksGsf, gsfTrackTimes);
158 
159  for( const auto& reso : resolutions_ ) {
160  const std::string& name = reso->name();
161  std::vector<float> times, resos;
162  std::vector<float> gsf_times, gsf_resos;
163 
164  times.reserve(TrackCollection.size());
165  resos.reserve(TrackCollection.size());
166  gsf_times.reserve(GsfTrackCollection.size());
167  gsf_resos.reserve(GsfTrackCollection.size());
168 
169  for( unsigned i = 0; i < TrackCollection.size(); ++i ) {
170  const reco::Track& tk = TrackCollection[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 );
175  } else {
176  times.push_back( generalTrackTimes[i] );
177  resos.push_back( fakeBeamSpotTimeWidth );
178  }
179  }
180 
181  for( unsigned i = 0; i < GsfTrackCollection.size(); ++i ) {
182  const reco::Track& tk = GsfTrackCollection[i];
183  if( edm::isFinite( gsfTrackTimes[i] ) && gsfTrackTimes[i] != 0.f ) {
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 );
187  } else {
188  gsf_times.push_back( gsfTrackTimes[i] );
189  gsf_resos.push_back( fakeBeamSpotTimeWidth );
190  }
191  }
192 
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 );
197  }
198 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
size_type size() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::vector< std::unique_ptr< const ResolutionModel > > resolutions_
bool isFinite(T x)
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
const edm::EDGetTokenT< TrackingParticleCollection > trackingParticles_
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

Member Data Documentation

const std::vector<edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> > TrackTimeValueMapProducer::associators_
private

Definition at line 56 of file TrackTimeValueMapProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::View<reco::Track> > TrackTimeValueMapProducer::gsfTracks_
private

Definition at line 51 of file TrackTimeValueMapProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::HepMCProduct> TrackTimeValueMapProducer::hepMCProduct_
private

Definition at line 54 of file TrackTimeValueMapProducer.cc.

std::vector<std::unique_ptr<const ResolutionModel> > TrackTimeValueMapProducer::resolutions_
private

Definition at line 58 of file TrackTimeValueMapProducer.cc.

Referenced by produce(), and TrackTimeValueMapProducer().

const edm::EDGetTokenT<TrackingParticleCollection> TrackTimeValueMapProducer::trackingParticles_
private

Definition at line 52 of file TrackTimeValueMapProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<TrackingVertexCollection> TrackTimeValueMapProducer::trackingVertices_
private

Definition at line 53 of file TrackTimeValueMapProducer.cc.

const edm::EDGetTokenT<edm::View<reco::Track> > TrackTimeValueMapProducer::tracks_
private

Definition at line 50 of file TrackTimeValueMapProducer.cc.

Referenced by produce().