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  setConf(iConfig);
21  setSrc(consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>("src")),
22  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot")),
23  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent")));
24  setAlias(iConfig.getParameter<std::string>("@module_label"));
25  std::string constraint_str = iConfig.getParameter<std::string>("constraint");
26  edm::InputTag trkconstrcoll = iConfig.getParameter<edm::InputTag>("srcConstr");
27 
28  if (constraint_str.empty())
29  constraint_ = none;
30  else if (constraint_str == "momentum") {
32  trkconstrcoll_ = consumes<TrackMomConstraintAssociationCollection>(trkconstrcoll);
33  } else if (constraint_str == "vertex") {
35  trkconstrcoll_ = consumes<TrackVtxConstraintAssociationCollection>(trkconstrcoll);
36  } else if (constraint_str == "trackParameters") {
38  trkconstrcoll_ = consumes<TrackParamConstraintAssociationCollection>(trkconstrcoll);
39  } else {
40  edm::LogError("TrackRefitter")
41  << "constraint: " << constraint_str
42  << " not understood. Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
43  throw cms::Exception("TrackRefitter")
44  << "unknown type of contraint! Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
45  }
46 
47  //register your products
48  produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
49  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
50  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
51  produces<std::vector<Trajectory>>();
52  produces<std::vector<int>>();
53  produces<TrajTrackAssociationCollection>();
54 }
55 
57  LogDebug("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
58  //
59  // create empty output collections
60  //
61  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
62  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
63  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
64  std::unique_ptr<std::vector<Trajectory>> outputTrajectoryColl(new std::vector<Trajectory>);
65  std::unique_ptr<std::vector<int>> outputIndecesInputColl(new std::vector<int>);
66 
67  //
68  //declare and get stuff to be retrieved from ES
69  //
73  edm::ESHandle<Propagator> thePropagator;
76  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
77 
79  setup.get<TrackerTopologyRcd>().get(httopo);
80 
81  //
82  //declare and get TrackCollection to be retrieved from the event
83  //
84  AlgoProductCollection algoResults;
86  switch (constraint_) {
87  case none: {
88  edm::Handle<edm::View<reco::Track>> theTCollection;
89  getFromEvt(theEvent, theTCollection, bs);
90 
91  LogDebug("TrackRefitter") << "TrackRefitter::produce(none):Number of Trajectories:" << (*theTCollection).size();
92 
93  if (bs.position() == math::XYZPoint(0., 0., 0.) && bs.type() == reco::BeamSpot::Unknown) {
94  edm::LogError("TrackRefitter") << " BeamSpot is (0,0,0), it is probably because is not valid in the event";
95  break;
96  }
97 
98  if (theTCollection.failedToGet()) {
100  labelsForToken(src_, labels);
101  edm::LogError("TrackRefitter") << "could not get the reco::TrackCollection." << labels.module;
102  break;
103  }
104  LogDebug("TrackRefitter") << "run the algorithm"
105  << "\n";
106 
107  try {
109  theMF.product(),
110  *theTCollection,
111  theFitter.product(),
112  thePropagator.product(),
113  theBuilder.product(),
114  bs,
115  algoResults);
116  } catch (cms::Exception &e) {
117  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
118  << "\n"
119  << e << "\n";
120  throw;
121  }
122  break;
123  }
124  case momentum: {
125  edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
126  theEvent.getByToken(trkconstrcoll_, theTCollectionWithConstraint);
127 
128  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
129  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
130  if (!recoBeamSpotHandle.isValid())
131  break;
132  bs = *recoBeamSpotHandle;
133  if (theTCollectionWithConstraint.failedToGet()) {
134  //edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product.";
135  break;
136  }
137  LogDebug("TrackRefitter") << "run the algorithm"
138  << "\n";
139  try {
141  theMF.product(),
142  *theTCollectionWithConstraint,
143  theFitter.product(),
144  thePropagator.product(),
145  theBuilder.product(),
146  bs,
147  algoResults);
148  } catch (cms::Exception &e) {
149  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithMomentum."
150  << "\n"
151  << e << "\n";
152  throw;
153  }
154  break;
155  }
156  case vertex: {
157  edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
158  theEvent.getByToken(trkconstrcoll_, theTCollectionWithConstraint);
159  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
160  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
161  if (!recoBeamSpotHandle.isValid())
162  break;
163  bs = *recoBeamSpotHandle;
164  if (theTCollectionWithConstraint.failedToGet()) {
165  edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
166  break;
167  }
168  LogDebug("TrackRefitter") << "run the algorithm"
169  << "\n";
170  try {
172  theMF.product(),
173  *theTCollectionWithConstraint,
174  theFitter.product(),
175  thePropagator.product(),
176  theBuilder.product(),
177  bs,
178  algoResults);
179  } catch (cms::Exception &e) {
180  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithVertex."
181  << "\n"
182  << e << "\n";
183  throw;
184  }
185  break;
186  }
187  case trackParameters: {
188  edm::Handle<TrackParamConstraintAssociationCollection> theTCollectionWithConstraint;
189  theEvent.getByToken(trkconstrcoll_, theTCollectionWithConstraint);
190  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
191  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
192  if (!recoBeamSpotHandle.isValid())
193  break;
194  bs = *recoBeamSpotHandle;
195  if (theTCollectionWithConstraint.failedToGet()) {
196  //edm::LogError("TrackRefitter")<<"could not get TrackParamConstraintAssociationCollection product.";
197  break;
198  }
199  LogDebug("TrackRefitter") << "run the algorithm"
200  << "\n";
201  try {
203  theMF.product(),
204  *theTCollectionWithConstraint,
205  theFitter.product(),
206  thePropagator.product(),
207  theBuilder.product(),
208  bs,
209  algoResults);
210  } catch (cms::Exception &e) {
211  edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrackParameters."
212  << "\n"
213  << e << "\n";
214  throw;
215  }
216  }
217  //default... there cannot be any other possibility due to the check in the ctor
218  }
219 
220  //put everything in th event
221  putInEvt(theEvent,
222  thePropagator.product(),
223  theMeasTk.product(),
224  outputRHColl,
225  outputTColl,
226  outputTEColl,
227  outputTrajectoryColl,
228  outputIndecesInputColl,
229  algoResults,
230  theBuilder.product(),
231  httopo.product());
232  LogDebug("TrackRefitter") << "end"
233  << "\n";
234 }
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
TrackProducerBase< reco::Track >::getFromES
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.
TrackRefitter::none
Definition: TrackRefitter.h:24
TrackProducerBase< reco::Track >::getFromEvt
virtual void getFromEvt(edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
Get TrackCandidateCollection from the Event (needed by TrackProducer)
electrons_cff.bool
bool
Definition: electrons_cff.py:393
MessageLogger.h
TrackerGeometry.h
TrackProducerAlgorithm::runWithVertex
void runWithVertex(const TrackingGeometry *, const MagneticField *, const VtxConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
TrackRefitter::TrackRefitter
TrackRefitter(const edm::ParameterSet &iConfig)
Constructor.
Definition: TrackRefitter.cc:16
TrackRefitter::constraint_
Constraint constraint_
Definition: TrackRefitter.h:25
TrackProducerBase< reco::Track >::setConf
void setConf(const edm::ParameterSet &conf)
Set parameter set.
Definition: TrackProducerBase.h:71
TrackProducerAlgorithm::runWithTrackParameters
void runWithTrackParameters(const TrackingGeometry *, const MagneticField *, const TrackParamConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
edm::Handle
Definition: AssociativeIterator.h:50
AlgoProductTraits< reco::Track >::AlgoProductCollection
std::vector< AlgoProduct > AlgoProductCollection
Definition: AlgoProductTraits.h:20
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
TrackRefitter::vertex
Definition: TrackRefitter.h:24
KfTrackProducerBase
Definition: KfTrackProducerBase.h:16
TrackerTopology.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
TrackerTopologyRcd.h
reco::BeamSpot
Definition: BeamSpot.h:21
edm::ESHandle< TrackerGeometry >
reco::TrackExtraCollection
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
TrackProducerBase< reco::Track >::setAlias
void setAlias(std::string alias)
set the aliases of produced collections
Definition: TrackProducerBase.h:83
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
TrackRefitter.h
TrajTrackAssociation.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::BeamSpot::Unknown
Definition: BeamSpot.h:24
edm::View
Definition: CaloClusterFwd.h:14
edm::HandleBase::failedToGet
bool failedToGet() const
Definition: HandleBase.h:72
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
TrackRefitter::trackParameters
Definition: TrackRefitter.h:24
TrackProducerBase< reco::Track >::src_
edm::EDGetToken src_
Definition: TrackProducerBase.h:104
KfTrackProducerBase::putInEvt
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.
Definition: KfTrackProducerBase.cc:21
TrackProducerBase< reco::Track >::alias_
std::string alias_
Definition: TrackProducerBase.h:107
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
TrackProducerBase< reco::Track >::setSrc
void setSrc(const edm::EDGetToken &src, const edm::EDGetTokenT< reco::BeamSpot > &bsSrc, const edm::EDGetTokenT< MeasurementTrackerEvent > &mteSrc)
set label of source collection
Definition: TrackProducerBase.h:74
TrackProducerBase< reco::Track >::bsSrc_
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
Definition: TrackProducerBase.h:110
Trajectory.h
TrackRefitter::trkconstrcoll_
edm::EDGetToken trkconstrcoll_
Definition: TrackRefitter.h:26
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
TrackRefitter::produce
void produce(edm::Event &, const edm::EventSetup &) override
Implementation of produce method.
Definition: TrackRefitter.cc:56
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TrackRefitter::theAlgo
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackRefitter.h:23
TrackProducerAlgorithm::runWithMomentum
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)
cms::Exception
Definition: Exception.h:70
TrackRefitter::momentum
Definition: TrackRefitter.h:24
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
TrackProducerAlgorithm::runWithTrack
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::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::OwnVector< TrackingRecHit >
edm::ProductLabels
Definition: ProductLabels.h:4
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37