CMS 3D CMS Logo

TrackRefitter.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
6 
8 
12 
15 
17  : KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
18  iConfig.getParameter<bool>("useHitsSplitting")),
19  theAlgo(iConfig),
20  ttopoToken_(esConsumes()) {
22  iConfig, consumesCollector(), consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>("src")));
23  setAlias(iConfig.getParameter<std::string>("@module_label"));
24  std::string constraint_str = iConfig.getParameter<std::string>("constraint");
25  edm::InputTag trkconstrcoll = iConfig.getParameter<edm::InputTag>("srcConstr");
26 
27  if (constraint_str.empty())
28  constraint_ = none;
29  else if (constraint_str == "momentum") {
31  trkconstrcoll_ = consumes<TrackMomConstraintAssociationCollection>(trkconstrcoll);
32  } else if (constraint_str == "vertex") {
34  trkconstrcoll_ = consumes<TrackVtxConstraintAssociationCollection>(trkconstrcoll);
35  } else if (constraint_str == "trackParameters") {
37  trkconstrcoll_ = consumes<TrackParamConstraintAssociationCollection>(trkconstrcoll);
38  } else {
39  edm::LogError("TrackRefitter")
40  << "constraint: " << constraint_str
41  << " not understood. Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
42  throw cms::Exception("TrackRefitter")
43  << "unknown type of contraint! Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
44  }
45 
46  //register your products
47  produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
48  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
49  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
50  produces<std::vector<Trajectory>>();
51  produces<std::vector<int>>();
52  produces<TrajTrackAssociationCollection>();
53 }
54 
56  LogDebug("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
57  //
58  // create empty output collections
59  //
60  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
61  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
62  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
63  std::unique_ptr<std::vector<Trajectory>> outputTrajectoryColl(new std::vector<Trajectory>);
64  std::unique_ptr<std::vector<int>> outputIndecesInputColl(new std::vector<int>);
65 
66  //
67  //declare and get stuff to be retrieved from ES
68  //
72  edm::ESHandle<Propagator> thePropagator;
75  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
76 
77  TrackerTopology const &ttopo = setup.getData(ttopoToken_);
78 
79  //
80  //declare and get TrackCollection to be retrieved from the event
81  //
82  AlgoProductCollection algoResults;
84  switch (constraint_) {
85  case none: {
86  edm::Handle<edm::View<reco::Track>> theTCollection;
87  getFromEvt(theEvent, theTCollection, bs);
88 
89  LogDebug("TrackRefitter") << "TrackRefitter::produce(none):Number of Trajectories:" << (*theTCollection).size();
90 
91  if (bs.position() == math::XYZPoint(0., 0., 0.) && bs.type() == reco::BeamSpot::Unknown) {
92  edm::LogError("TrackRefitter") << " BeamSpot is (0,0,0), it is probably because is not valid in the event";
93  break;
94  }
95 
96  if (theTCollection.failedToGet()) {
98  labelsForToken(src_, labels);
99  edm::LogError("TrackRefitter") << "could not get the reco::TrackCollection." << labels.module;
100  break;
101  }
102  LogDebug("TrackRefitter") << "run the algorithm"
103  << "\n";
104 
105  try {
107  theMF.product(),
108  *theTCollection,
109  theFitter.product(),
110  thePropagator.product(),
111  theBuilder.product(),
112  bs,
113  algoResults);
114  } catch (cms::Exception &e) {
115  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
116  << "\n"
117  << e << "\n";
118  throw;
119  }
120  break;
121  }
122  case momentum: {
123  edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
124  theEvent.getByToken(trkconstrcoll_, theTCollectionWithConstraint);
125 
126  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
127  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
128  if (!recoBeamSpotHandle.isValid())
129  break;
130  bs = *recoBeamSpotHandle;
131  if (theTCollectionWithConstraint.failedToGet()) {
132  //edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product.";
133  break;
134  }
135  LogDebug("TrackRefitter") << "run the algorithm"
136  << "\n";
137  try {
139  theMF.product(),
140  *theTCollectionWithConstraint,
141  theFitter.product(),
142  thePropagator.product(),
143  theBuilder.product(),
144  bs,
145  algoResults);
146  } catch (cms::Exception &e) {
147  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithMomentum."
148  << "\n"
149  << e << "\n";
150  throw;
151  }
152  break;
153  }
154  case vertex: {
155  edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
156  theEvent.getByToken(trkconstrcoll_, theTCollectionWithConstraint);
157  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
158  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
159  if (!recoBeamSpotHandle.isValid())
160  break;
161  bs = *recoBeamSpotHandle;
162  if (theTCollectionWithConstraint.failedToGet()) {
163  edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
164  break;
165  }
166  LogDebug("TrackRefitter") << "run the algorithm"
167  << "\n";
168  try {
170  theMF.product(),
171  *theTCollectionWithConstraint,
172  theFitter.product(),
173  thePropagator.product(),
174  theBuilder.product(),
175  bs,
176  algoResults);
177  } catch (cms::Exception &e) {
178  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithVertex."
179  << "\n"
180  << e << "\n";
181  throw;
182  }
183  break;
184  }
185  case trackParameters: {
186  edm::Handle<TrackParamConstraintAssociationCollection> theTCollectionWithConstraint;
187  theEvent.getByToken(trkconstrcoll_, theTCollectionWithConstraint);
188  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
189  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
190  if (!recoBeamSpotHandle.isValid())
191  break;
192  bs = *recoBeamSpotHandle;
193  if (theTCollectionWithConstraint.failedToGet()) {
194  //edm::LogError("TrackRefitter")<<"could not get TrackParamConstraintAssociationCollection product.";
195  break;
196  }
197  LogDebug("TrackRefitter") << "run the algorithm"
198  << "\n";
199  try {
201  theMF.product(),
202  *theTCollectionWithConstraint,
203  theFitter.product(),
204  thePropagator.product(),
205  theBuilder.product(),
206  bs,
207  algoResults);
208  } catch (cms::Exception &e) {
209  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrackParameters."
210  << "\n"
211  << e << "\n";
212  throw;
213  }
214  }
215  //default... there cannot be any other possibility due to the check in the ctor
216  }
217 
218  //put everything in th event
219  putInEvt(theEvent,
220  thePropagator.product(),
221  theMeasTk.product(),
222  outputRHColl,
223  outputTColl,
224  outputTEColl,
225  outputTrajectoryColl,
226  outputIndecesInputColl,
227  algoResults,
228  theBuilder.product(),
229  &ttopo);
230  LogDebug("TrackRefitter") << "end"
231  << "\n";
232 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::EDGetToken trkconstrcoll_
Definition: TrackRefitter.h:26
void initTrackProducerBase(const edm::ParameterSet &conf, edm::ConsumesCollector cc, const edm::EDGetToken &src)
Call this method in inheriting class&#39; constructor.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
Log< level::Error, false > LogError
void setAlias(std::string alias)
set the aliases of produced collections
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_
Definition: TrackRefitter.h:28
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackRefitter.h:23
bool failedToGet() const
Definition: HandleBase.h:72
T const * product() const
Definition: ESHandle.h:86
void runWithMomentum(const TrackingGeometry *, const MagneticField *, const TrackMomConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
Run the Final Fit taking TrackMomConstraintAssociation as input (Refitter with momentum constraint) ...
void runWithTrack(const TrackingGeometry *, const MagneticField *, const TrackView &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
Run the Final Fit taking Tracks as input (for Refitter)
edm::EventID id() const
Definition: EventBase.h:63
Constraint constraint_
Definition: TrackRefitter.h:25
void runWithVertex(const TrackingGeometry *, const MagneticField *, const VtxConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
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< AlgoProduct > AlgoProductCollection
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void runWithTrackParameters(const TrackingGeometry *, const MagneticField *, const TrackParamConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
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)
TrackRefitter(const edm::ParameterSet &iConfig)
Constructor.