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) {
22  setConf(iConfig);
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  std::string constraint_str = iConfig.getParameter<std::string>("constraint");
28 
29  if (constraint_str.empty())
30  constraint_ = none;
31  // else if (constraint_str == "momentum") constraint_ = momentum;
32  else if (constraint_str == "vertex") {
34  gsfTrackVtxConstraintTag_ = consumes<GsfTrackVtxConstraintAssociationCollection>(
35  iConfig.getParameter<edm::InputTag>("gsfTrackVtxConstraintTag"));
36  } else {
37  edm::LogError("GsfTrackRefitter") << "constraint: " << constraint_str
38  << " not understood. Set it to 'momentum', 'vertex' or leave it empty";
39  throw cms::Exception("GsfTrackRefitter")
40  << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";
41  }
42 
43  //register your products
44  produces<reco::GsfTrackCollection>().setBranchAlias(alias_ + "GsfTracks");
45  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
46  produces<reco::GsfTrackExtraCollection>().setBranchAlias(alias_ + "GsfTrackExtras");
47  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
48  produces<std::vector<Trajectory>>();
49  produces<TrajGsfTrackAssociationCollection>();
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  setup.get<TrackerTopologyRcd>().get(httopo);
77 
78  //
79  //declare and get TrackCollection to be retrieved from the event
80  //
81  AlgoProductCollection algoResults;
82  reco::BeamSpot bs;
83  switch (constraint_) {
84  case none: {
86  getFromEvt(theEvent, theTCollection, bs);
87  if (theTCollection.failedToGet()) {
88  edm::LogError("GsfTrackRefitter") << "could not get the reco::GsfTrackCollection.";
89  return;
90  }
91  LogDebug("GsfTrackRefitter") << "run the algorithm"
92  << "\n";
93  try {
95  theMF.product(),
96  *theTCollection,
97  theFitter.product(),
98  thePropagator.product(),
99  theBuilder.product(),
100  bs,
101  algoResults);
102  } catch (cms::Exception& e) {
103  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
104  << "\n"
105  << e << "\n";
106  throw;
107  }
108  break;
109  }
110  case vertex: {
111  edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
112  theEvent.getByToken(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
113  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
114  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
115  bs = *recoBeamSpotHandle;
116  if (theTCollectionWithConstraint.failedToGet()) {
117  edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
118  break;
119  }
120  LogDebug("TrackRefitter") << "run the algorithm"
121  << "\n";
122  try {
124  theMF.product(),
125  *theTCollectionWithConstraint,
126  theFitter.product(),
127  thePropagator.product(),
128  theBuilder.product(),
129  bs,
130  algoResults);
131  } catch (cms::Exception& e) {
132  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
133  << "\n"
134  << e << "\n";
135  throw;
136  }
137  }
138  //default... there cannot be any other possibility due to the check in the ctor
139  }
140 
141  //put everything in th event
142  putInEvt(theEvent,
143  thePropagator.product(),
144  theMeasTk.product(),
145  outputRHColl,
146  outputTColl,
147  outputTEColl,
148  outputGsfTEColl,
149  outputTrajectoryColl,
150  algoResults,
151  theBuilder.product(),
152  bs,
153  httopo.product());
154  LogDebug("GsfTrackRefitter") << "end"
155  << "\n";
156 }
#define LogDebug(id)
T getParameter(std::string const &) const
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:525
Constraint constraint_
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
void setAlias(std::string alias)
set the aliases of produced collections
void setConf(const edm::ParameterSet &conf)
Set parameter set.
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.
void setSrc(const edm::EDGetToken &src, const edm::EDGetTokenT< reco::BeamSpot > &bsSrc, const edm::EDGetTokenT< MeasurementTrackerEvent > &mteSrc)
set label of source collection
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
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:73
TrackProducerAlgorithm< reco::GsfTrack > theAlgo
edm::EDGetTokenT< GsfTrackVtxConstraintAssociationCollection > gsfTrackVtxConstraintTag_
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.