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  theTTopoToken(esConsumes()) {
24  iConfig, consumesCollector(), consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")));
25  setAlias(iConfig.getParameter<std::string>("@module_label"));
26 
27  if (iConfig.exists("clusterRemovalInfo")) {
28  edm::InputTag tag = iConfig.getParameter<edm::InputTag>("clusterRemovalInfo");
29  if (!(tag == edm::InputTag())) {
31  }
32  }
33 
34  //register your products
35  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
36  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
37  // TrackCollection refers to TrackingRechit and TrackExtra
38  // collections, need to declare its production after them to work
39  // around a rare race condition in framework scheduling
40  produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
41  produces<std::vector<Trajectory> >();
42  produces<std::vector<int> >();
43  produces<TrajTrackAssociationCollection>();
44 }
45 
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  //declare and get stuff to be retrieved from ES
59  //
63  edm::ESHandle<Propagator> thePropagator;
66  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
67 
68  TrackerTopology const& ttopo = setup.getData(theTTopoToken);
69 
70  //
71  //declare and get TrackColection to be retrieved from the event
72  //
73  AlgoProductCollection algoResults;
76  getFromEvt(theEvent, theTCCollection, bs);
77  //protect against missing product
78  if (theTCCollection.failedToGet()) {
79  edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
80  } else {
81  LogDebug("TrackProducer") << "run the algorithm"
82  << "\n";
83  try {
85  theMF.product(),
86  *theTCCollection,
87  theFitter.product(),
88  thePropagator.product(),
89  theBuilder.product(),
90  bs,
91  algoResults);
92  } catch (cms::Exception& e) {
93  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
94  << "\n"
95  << e << "\n";
96  throw;
97  }
98  }
99 
100  //put everything in the event
101  putInEvt(theEvent,
102  thePropagator.product(),
103  theMeasTk.product(),
104  outputRHColl,
105  outputTColl,
106  outputTEColl,
107  outputTrajectoryColl,
108  outputIndecesInputColl,
109  algoResults,
110  theBuilder.product(),
111  &ttopo);
112  LogDebug("TrackProducer") << "end"
113  << "\n";
114 }
115 
116 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup) {
117  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
118  //
119  // create empty output collections
120  //
121  std::vector<reco::TransientTrack> ttks;
122 
123  //
124  //declare and get stuff to be retrieved from ES
125  //
129  edm::ESHandle<Propagator> thePropagator;
132  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
133 
134  //
135  //declare and get TrackColection to be retrieved from the event
136  //
137  AlgoProductCollection algoResults;
140  getFromEvt(theEvent, theTCCollection, bs);
141  //protect against missing product
142  if (theTCCollection.failedToGet()) {
143  edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
144  } else {
145  LogDebug("TrackProducer") << "run the algorithm"
146  << "\n";
147  try {
149  theMF.product(),
150  *theTCCollection,
151  theFitter.product(),
152  thePropagator.product(),
153  theBuilder.product(),
154  bs,
155  algoResults);
156  } catch (cms::Exception& e) {
157  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
158  << "\n"
159  << e << "\n";
160  throw;
161  }
162  }
163  ttks.reserve(algoResults.size());
164  for (auto& prod : algoResults) {
165  ttks.push_back(reco::TransientTrack(*(prod.track), thePropagator.product()->magneticField()));
166  }
167 
168  LogDebug("TrackProducer") << "end"
169  << "\n";
170 
171  return ttks;
172 }
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackProducer.h:36
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual void getFromEvt(edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
Get TrackCandidateCollection from the Event (needed by TrackProducer)
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.
TrackProducer(const edm::ParameterSet &iConfig)
Constructor.
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void initTrackProducerBase(const edm::ParameterSet &conf, edm::ConsumesCollector cc, const edm::EDGetToken &src)
Call this method in inheriting class&#39; constructor.
Log< level::Error, false > LogError
void setAlias(std::string alias)
set the aliases of produced collections
bool failedToGet() const
Definition: HandleBase.h:72
T const * product() const
Definition: ESHandle.h:86
edm::EventID id() const
Definition: EventBase.h:59
void setClusterRemovalInfo(const edm::InputTag &clusterRemovalInfo)
Sets the information on cluster removal, and turns it on.
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
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.
std::vector< AlgoProduct > AlgoProductCollection
virtual const MagneticField * magneticField() const =0
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > theTTopoToken
Definition: TrackProducer.h:37
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.
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.
#define LogDebug(id)