CMS 3D CMS Logo

TrackProducer.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
10 
12 
14 
17 
19  KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
20  iConfig.getParameter<bool>("useHitsSplitting")),
21  theAlgo(iConfig)
22 {
23  setConf(iConfig);
24  setSrc( consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
25  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )),
26  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>( "MeasurementTrackerEvent") ));
27  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
28 
29  if ( iConfig.exists("clusterRemovalInfo") ) {
30  edm::InputTag tag = iConfig.getParameter<edm::InputTag>("clusterRemovalInfo");
31  if (!(tag == edm::InputTag())) { setClusterRemovalInfo( tag ); }
32  }
33 
34  //register your products
35  produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
36  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
37  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
38  produces<std::vector<Trajectory> >() ;
39  produces<std::vector<int> >() ;
40  produces<TrajTrackAssociationCollection>();
41 
42 }
43 
44 
46 {
47  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
48  //
49  // create empty output collections
50  //
51  std::unique_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
52  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
53  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
54  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
55  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
56 
57 
58  //
59  //declare and get stuff to be retrieved from ES
60  //
64  edm::ESHandle<Propagator> thePropagator;
67  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
68 
70  setup.get<TrackerTopologyRcd>().get(httopo);
71 
72  //
73  //declare and get TrackColection to be retrieved from the event
74  //
75  AlgoProductCollection algoResults;
77  reco::BeamSpot bs;
78  getFromEvt(theEvent,theTCCollection,bs);
79  //protect against missing product
80  if (theTCCollection.failedToGet()){
81  edm::LogError("TrackProducer") <<"could not get the TrackCandidateCollection.";}
82  else{
83  LogDebug("TrackProducer") << "run the algorithm" << "\n";
84  try{
85  theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection,
86  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
87  } catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate." << "\n" << e << "\n"; throw;}
88  }
89 
90  //put everything in the event
91  putInEvt(theEvent, thePropagator.product(),theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, outputIndecesInputColl, algoResults, theBuilder.product(), httopo.product());
92  LogDebug("TrackProducer") << "end" << "\n";
93 }
94 
95 
96 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup)
97 {
98  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
99  //
100  // create empty output collections
101  //
102  std::vector<reco::TransientTrack> ttks;
103 
104  //
105  //declare and get stuff to be retrieved from ES
106  //
110  edm::ESHandle<Propagator> thePropagator;
113  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
114 
115  //
116  //declare and get TrackColection to be retrieved from the event
117  //
118  AlgoProductCollection algoResults;
120  reco::BeamSpot bs;
121  getFromEvt(theEvent,theTCCollection,bs);
122  //protect against missing product
123  if (theTCCollection.failedToGet()){
124  edm::LogError("TrackProducer") <<"could not get the TrackCandidateCollection.";}
125  else{
126  LogDebug("TrackProducer") << "run the algorithm" << "\n";
127  try{
128  theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection,
129  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
130  }
131  catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate." << "\n" << e << "\n"; throw; }
132  }
133  ttks.reserve(algoResults.size());
134  for (auto & prod : algoResults){
135  ttks.push_back( reco::TransientTrack(*(prod.track),thePropagator.product()->magneticField() ));
136  }
137 
138  LogDebug("TrackProducer") << "end" << "\n";
139 
140  return ttks;
141 }
142 
143 
#define LogDebug(id)
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackProducer.h:37
T getParameter(std::string const &) const
virtual void getFromEvt(edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
Get TrackCandidateCollection from the Event (needed by TrackProducer)
TrackProducer(const edm::ParameterSet &iConfig)
Constructor.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::unique_ptr< TrackingRecHitCollection > &, std::unique_ptr< reco::TrackCollection > &, std::unique_ptr< reco::TrackExtraCollection > &, std::unique_ptr< std::vector< Trajectory > > &, std::unique_ptr< std::vector< int > > &, AlgoProductCollection &, TransientTrackingRecHitBuilder const *, const TrackerTopology *ttopo, int BeforeOrAfter=0)
Put produced collections in the event.
void setClusterRemovalInfo(const edm::InputTag &clusterRemovalInfo)
Sets the information on cluster removal, and turns it on.
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
void setAlias(std::string alias)
set the aliases of produced collections
void setConf(const edm::ParameterSet &conf)
Set parameter set.
virtual const MagneticField * magneticField() const =0
void setSrc(const edm::EDGetToken &src, const edm::EDGetTokenT< reco::BeamSpot > &bsSrc, const edm::EDGetTokenT< MeasurementTrackerEvent > &mteSrc)
set label of source collection
bool failedToGet() const
Definition: HandleBase.h:78
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
virtual void produce(edm::Event &, const edm::EventSetup &) override
Implementation of produce method.
std::vector< reco::TransientTrack > getTransient(edm::Event &, const edm::EventSetup &)
Get Transient Tracks.
const T & get() const
Definition: EventSetup.h:56
std::vector< AlgoProduct > AlgoProductCollection
edm::EventID id() const
Definition: EventBase.h:58
void runWithCandidate(const TrackingGeometry *, const MagneticField *, const TrackCandidateCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
Run the Final Fit taking TrackCandidates as input.
T const * product() const
Definition: ESHandle.h:86
virtual void getFromES(const edm::EventSetup &, edm::ESHandle< TrackerGeometry > &, edm::ESHandle< MagneticField > &, edm::ESHandle< TrajectoryFitter > &, edm::ESHandle< Propagator > &, edm::ESHandle< MeasurementTracker > &, edm::ESHandle< TransientTrackingRecHitBuilder > &)
Get needed services from the Event Setup.