CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::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 
44  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
45  //
46  // create empty output collections
47  //
48  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
49  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
50  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
51  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
52  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
53 
54  //
55  //declare and get stuff to be retrieved from ES
56  //
60  edm::ESHandle<Propagator> thePropagator;
63  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
64 
65  TrackerTopology const& ttopo = setup.getData(theTTopoToken);
66 
67  //
68  //declare and get TrackColection to be retrieved from the event
69  //
70  AlgoProductCollection algoResults;
73  getFromEvt(theEvent, theTCCollection, bs);
74  //protect against missing product
75  if (theTCCollection.failedToGet()) {
76  edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
77  } else {
78  LogDebug("TrackProducer") << "run the algorithm"
79  << "\n";
80  try {
82  theMF.product(),
83  *theTCCollection,
84  theFitter.product(),
85  thePropagator.product(),
86  theBuilder.product(),
87  bs,
88  algoResults);
89  } catch (cms::Exception& e) {
90  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
91  << "\n"
92  << e << "\n";
93  throw;
94  }
95  }
96 
97  //put everything in the event
98  putInEvt(theEvent,
99  thePropagator.product(),
100  theMeasTk.product(),
101  outputRHColl,
102  outputTColl,
103  outputTEColl,
104  outputTrajectoryColl,
105  outputIndecesInputColl,
106  algoResults,
107  theBuilder.product(),
108  &ttopo);
109  LogDebug("TrackProducer") << "end"
110  << "\n";
111 }
112 
113 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup) {
114  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
115  //
116  // create empty output collections
117  //
118  std::vector<reco::TransientTrack> ttks;
119 
120  //
121  //declare and get stuff to be retrieved from ES
122  //
126  edm::ESHandle<Propagator> thePropagator;
129  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
130 
131  //
132  //declare and get TrackColection to be retrieved from the event
133  //
134  AlgoProductCollection algoResults;
137  getFromEvt(theEvent, theTCCollection, bs);
138  //protect against missing product
139  if (theTCCollection.failedToGet()) {
140  edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
141  } else {
142  LogDebug("TrackProducer") << "run the algorithm"
143  << "\n";
144  try {
146  theMF.product(),
147  *theTCCollection,
148  theFitter.product(),
149  thePropagator.product(),
150  theBuilder.product(),
151  bs,
152  algoResults);
153  } catch (cms::Exception& e) {
154  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
155  << "\n"
156  << e << "\n";
157  throw;
158  }
159  }
160  ttks.reserve(algoResults.size());
161  for (auto& prod : algoResults) {
162  ttks.push_back(reco::TransientTrack(*(prod.track), thePropagator.product()->magneticField()));
163  }
164 
165  LogDebug("TrackProducer") << "end"
166  << "\n";
167 
168  return ttks;
169 }
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackProducer.h:36
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.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
bool exists(std::string const &parameterName) const
checks if a parameter exists
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 getData(T &iHolder) const
Definition: EventSetup.h:128
void setClusterRemovalInfo(const edm::InputTag &clusterRemovalInfo)
Sets the information on cluster removal, and turns it on.
bool failedToGet() const
Definition: HandleBase.h:72
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
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EventID id() const
Definition: EventBase.h:59
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.
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
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)