CMS 3D CMS Logo

GsfTrackRefitter.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
6 
8 
14 
17 
19  : GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
20  iConfig.getParameter<bool>("useHitsSplitting")),
21  theAlgo(iConfig) {
23  iConfig, consumesCollector(), consumes<edm::View<reco::GsfTrack>>(iConfig.getParameter<edm::InputTag>("src")));
24  setAlias(iConfig.getParameter<std::string>("@module_label"));
25  std::string constraint_str = iConfig.getParameter<std::string>("constraint");
26 
27  if (constraint_str.empty())
28  constraint_ = none;
29  // else if (constraint_str == "momentum") constraint_ = momentum;
30  else if (constraint_str == "vertex") {
32  gsfTrackVtxConstraintTag_ = consumes<GsfTrackVtxConstraintAssociationCollection>(
33  iConfig.getParameter<edm::InputTag>("gsfTrackVtxConstraintTag"));
34  } else {
35  edm::LogError("GsfTrackRefitter") << "constraint: " << constraint_str
36  << " not understood. Set it to 'momentum', 'vertex' or leave it empty";
37  throw cms::Exception("GsfTrackRefitter")
38  << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";
39  }
40 
41  //register your products
42  produces<reco::GsfTrackCollection>().setBranchAlias(alias_ + "GsfTracks");
43  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
44  produces<reco::GsfTrackExtraCollection>().setBranchAlias(alias_ + "GsfTrackExtras");
45  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
46  produces<std::vector<Trajectory>>();
47  produces<TrajGsfTrackAssociationCollection>();
48 
50 }
51 
53  edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
54  //
55  // create empty output collections
56  //
57  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
58  std::unique_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
59  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
60  std::unique_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
61  std::unique_ptr<std::vector<Trajectory>> outputTrajectoryColl(new std::vector<Trajectory>);
62 
63  //
64  //declare and get stuff to be retrieved from ES
65  //
69  edm::ESHandle<Propagator> thePropagator;
71  // getFromES(setup,theG,theMF,theFitter,thePropagator);
73  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
74 
76 
77  //
78  //declare and get TrackCollection to be retrieved from the event
79  //
80  AlgoProductCollection algoResults;
82  switch (constraint_) {
83  case none: {
85  getFromEvt(theEvent, theTCollection, bs);
86  if (theTCollection.failedToGet()) {
87  edm::LogError("GsfTrackRefitter") << "could not get the reco::GsfTrackCollection.";
88  return;
89  }
90  LogDebug("GsfTrackRefitter") << "run the algorithm"
91  << "\n";
92  try {
94  theMF.product(),
95  *theTCollection,
96  theFitter.product(),
97  thePropagator.product(),
98  theBuilder.product(),
99  bs,
100  algoResults);
101  } catch (cms::Exception& e) {
102  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
103  << "\n"
104  << e << "\n";
105  throw;
106  }
107  break;
108  }
109  case vertex: {
110  edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
111  theEvent.getByToken(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
112  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
113  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
114  bs = *recoBeamSpotHandle;
115  if (theTCollectionWithConstraint.failedToGet()) {
116  edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
117  break;
118  }
119  LogDebug("TrackRefitter") << "run the algorithm"
120  << "\n";
121  try {
123  theMF.product(),
124  *theTCollectionWithConstraint,
125  theFitter.product(),
126  thePropagator.product(),
127  theBuilder.product(),
128  bs,
129  algoResults);
130  } catch (cms::Exception& e) {
131  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
132  << "\n"
133  << e << "\n";
134  throw;
135  }
136  }
137  //default... there cannot be any other possibility due to the check in the ctor
138  }
139 
140  //put everything in th event
141  putInEvt(theEvent,
142  thePropagator.product(),
143  theMeasTk.product(),
144  outputRHColl,
145  outputTColl,
146  outputTEColl,
147  outputGsfTEColl,
148  outputTrajectoryColl,
149  algoResults,
150  theBuilder.product(),
151  bs,
152  httopo.product());
153  LogDebug("GsfTrackRefitter") << "end"
154  << "\n";
155 }
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)
Constraint constraint_
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
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:528
Log< level::Error, false > LogError
void setAlias(std::string alias)
set the aliases of produced collections
GsfTrackRefitter(const edm::ParameterSet &iConfig)
Constructor.
bool failedToGet() const
Definition: HandleBase.h:72
T const * product() const
Definition: ESHandle.h:86
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_
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)
void produce(edm::Event &, const edm::EventSetup &) override
Implementation of produce method.
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
edm::EventID id() const
Definition: EventBase.h:63
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::unique_ptr< TrackingRecHitCollection > &, std::unique_ptr< reco::GsfTrackCollection > &, std::unique_ptr< reco::TrackExtraCollection > &, std::unique_ptr< reco::GsfTrackExtraCollection > &, std::unique_ptr< std::vector< Trajectory > > &, AlgoProductCollection &, TransientTrackingRecHitBuilder const *, const reco::BeamSpot &, const TrackerTopology *ttopo)
Put produced collections in the event.
Log< level::Info, false > LogInfo
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
std::vector< AlgoProduct > AlgoProductCollection
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
TrackProducerAlgorithm< reco::GsfTrack > theAlgo
edm::EDGetTokenT< GsfTrackVtxConstraintAssociationCollection > gsfTrackVtxConstraintTag_
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)