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  setConf(iConfig);
23  setSrc(consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")),
24  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot")),
25  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent")));
26  setAlias(iConfig.getParameter<std::string>("@module_label"));
27 
28  if (iConfig.exists("clusterRemovalInfo")) {
29  edm::InputTag tag = iConfig.getParameter<edm::InputTag>("clusterRemovalInfo");
30  if (!(tag == edm::InputTag())) {
32  }
33  }
34 
35  //register your products
36  produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
37  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
38  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
39  produces<std::vector<Trajectory> >();
40  produces<std::vector<int> >();
41  produces<TrajTrackAssociationCollection>();
42 }
43 
45  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
46  //
47  // create empty output collections
48  //
49  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
50  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
51  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
52  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
53  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
54 
55  //
56  //declare and get stuff to be retrieved from ES
57  //
61  edm::ESHandle<Propagator> thePropagator;
64  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
65 
67  setup.get<TrackerTopologyRcd>().get(httopo);
68 
69  //
70  //declare and get TrackColection to be retrieved from the event
71  //
72  AlgoProductCollection algoResults;
74  reco::BeamSpot bs;
75  getFromEvt(theEvent, theTCCollection, bs);
76  //protect against missing product
77  if (theTCCollection.failedToGet()) {
78  edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
79  } else {
80  LogDebug("TrackProducer") << "run the algorithm"
81  << "\n";
82  try {
84  theMF.product(),
85  *theTCCollection,
86  theFitter.product(),
87  thePropagator.product(),
88  theBuilder.product(),
89  bs,
90  algoResults);
91  } catch (cms::Exception& e) {
92  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
93  << "\n"
94  << e << "\n";
95  throw;
96  }
97  }
98 
99  //put everything in the event
100  putInEvt(theEvent,
101  thePropagator.product(),
102  theMeasTk.product(),
103  outputRHColl,
104  outputTColl,
105  outputTEColl,
106  outputTrajectoryColl,
107  outputIndecesInputColl,
108  algoResults,
109  theBuilder.product(),
110  httopo.product());
111  LogDebug("TrackProducer") << "end"
112  << "\n";
113 }
114 
115 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup) {
116  LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
117  //
118  // create empty output collections
119  //
120  std::vector<reco::TransientTrack> ttks;
121 
122  //
123  //declare and get stuff to be retrieved from ES
124  //
128  edm::ESHandle<Propagator> thePropagator;
131  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
132 
133  //
134  //declare and get TrackColection to be retrieved from the event
135  //
136  AlgoProductCollection algoResults;
138  reco::BeamSpot bs;
139  getFromEvt(theEvent, theTCCollection, bs);
140  //protect against missing product
141  if (theTCCollection.failedToGet()) {
142  edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
143  } else {
144  LogDebug("TrackProducer") << "run the algorithm"
145  << "\n";
146  try {
148  theMF.product(),
149  *theTCCollection,
150  theFitter.product(),
151  thePropagator.product(),
152  theBuilder.product(),
153  bs,
154  algoResults);
155  } catch (cms::Exception& e) {
156  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
157  << "\n"
158  << e << "\n";
159  throw;
160  }
161  }
162  ttks.reserve(algoResults.size());
163  for (auto& prod : algoResults) {
164  ttks.push_back(reco::TransientTrack(*(prod.track), thePropagator.product()->magneticField()));
165  }
166 
167  LogDebug("TrackProducer") << "end"
168  << "\n";
169 
170  return ttks;
171 }
#define LogDebug(id)
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackProducer.h:36
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.
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: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
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:73
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.