CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 }
49 
51  edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
52  //
53  // create empty output collections
54  //
55  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
56  std::unique_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
57  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
58  std::unique_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
59  std::unique_ptr<std::vector<Trajectory>> outputTrajectoryColl(new std::vector<Trajectory>);
60 
61  //
62  //declare and get stuff to be retrieved from ES
63  //
67  edm::ESHandle<Propagator> thePropagator;
69  // getFromES(setup,theG,theMF,theFitter,thePropagator);
71  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
72 
74  setup.get<TrackerTopologyRcd>().get(httopo);
75 
76  //
77  //declare and get TrackCollection to be retrieved from the event
78  //
79  AlgoProductCollection algoResults;
81  switch (constraint_) {
82  case none: {
84  getFromEvt(theEvent, theTCollection, bs);
85  if (theTCollection.failedToGet()) {
86  edm::LogError("GsfTrackRefitter") << "could not get the reco::GsfTrackCollection.";
87  return;
88  }
89  LogDebug("GsfTrackRefitter") << "run the algorithm"
90  << "\n";
91  try {
93  theMF.product(),
94  *theTCollection,
95  theFitter.product(),
96  thePropagator.product(),
97  theBuilder.product(),
98  bs,
99  algoResults);
100  } catch (cms::Exception& e) {
101  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
102  << "\n"
103  << e << "\n";
104  throw;
105  }
106  break;
107  }
108  case vertex: {
109  edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
110  theEvent.getByToken(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
111  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
112  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
113  bs = *recoBeamSpotHandle;
114  if (theTCollectionWithConstraint.failedToGet()) {
115  edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
116  break;
117  }
118  LogDebug("TrackRefitter") << "run the algorithm"
119  << "\n";
120  try {
122  theMF.product(),
123  *theTCollectionWithConstraint,
124  theFitter.product(),
125  thePropagator.product(),
126  theBuilder.product(),
127  bs,
128  algoResults);
129  } catch (cms::Exception& e) {
130  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
131  << "\n"
132  << e << "\n";
133  throw;
134  }
135  }
136  //default... there cannot be any other possibility due to the check in the ctor
137  }
138 
139  //put everything in th event
140  putInEvt(theEvent,
141  thePropagator.product(),
142  theMeasTk.product(),
143  outputRHColl,
144  outputTColl,
145  outputTEColl,
146  outputGsfTEColl,
147  outputTrajectoryColl,
148  algoResults,
149  theBuilder.product(),
150  bs,
151  httopo.product());
152  LogDebug("GsfTrackRefitter") << "end"
153  << "\n";
154 }
virtual void getFromEvt(edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
Get TrackCandidateCollection from the Event (needed by TrackProducer)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
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.
Log< level::Error, false > LogError
void setAlias(std::string alias)
set the aliases of produced collections
GsfTrackRefitter(const edm::ParameterSet &iConfig)
Constructor.
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
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 &)
bool failedToGet() const
Definition: HandleBase.h:72
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
std::vector< AlgoProduct > AlgoProductCollection
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:88
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)