CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackRefitter.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
6 
8 
12 
14  KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
15  iConfig.getParameter<bool>("useHitsSplitting")),
16  theAlgo(iConfig)
17 {
18  setConf(iConfig);
19  setSrc( consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
20  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )),
21  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>( "MeasurementTrackerEvent") ));
22  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
23  std::string constraint_str = iConfig.getParameter<std::string>( "constraint" );
24  edm::InputTag trkconstrcoll = iConfig.getParameter<edm::InputTag>( "srcConstr" );
25 
26 
27  if (constraint_str == "") constraint_ = none;
28  else if (constraint_str == "momentum") { constraint_ = momentum; trkconstrcoll_ = consumes<TrackMomConstraintAssociationCollection>(trkconstrcoll); }
29  else if (constraint_str == "vertex") { constraint_ = vertex; trkconstrcoll_ = consumes<TrackVtxConstraintAssociationCollection>(trkconstrcoll); }
30  else if (constraint_str == "trackParameters") { constraint_ = trackParameters; trkconstrcoll_ = consumes<TrackParamConstraintAssociationCollection>(trkconstrcoll); }
31  else {
32  edm::LogError("TrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
33  throw cms::Exception("TrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
34  }
35 
36  //register your products
37  produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
38  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
39  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
40  produces<std::vector<Trajectory> >() ;
41  produces<TrajTrackAssociationCollection>();
42 
43 }
44 
46 {
47  LogDebug("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
48  //
49  // create empty output collections
50  //
51  std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
52  std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
53  std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
54  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
55 
56  //
57  //declare and get stuff to be retrieved from ES
58  //
62  edm::ESHandle<Propagator> thePropagator;
65  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
66 
67  //
68  //declare and get TrackCollection to be retrieved from the event
69  //
70  AlgoProductCollection algoResults;
71  reco::BeamSpot bs;
72  switch(constraint_){
73  case none :
74  {
76  getFromEvt(theEvent,theTCollection,bs);
77  if (theTCollection.failedToGet()){
78  edm::LogError("TrackRefitter")<<"could not get the reco::TrackCollection."; break;}
79  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
80 
81  try {
82  theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection,
83  theFitter.product(), thePropagator.product(),
84  theBuilder.product(), bs, algoResults);
85  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
86  break;
87  }
88  case momentum :
89  {
90  edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
91  theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
92 
93 
94  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
95  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
96  bs = *recoBeamSpotHandle;
97  if (theTCollectionWithConstraint.failedToGet()){
98  //edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product.";
99  break;}
100  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
101  try {
102  theAlgo.runWithMomentum(theG.product(), theMF.product(), *theTCollectionWithConstraint,
103  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
104  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
105  break;
106  }
107  case vertex :
108  {
109  edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
110  theEvent.getByToken(trkconstrcoll_,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."; break;}
116  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
117  try {
118  theAlgo.runWithVertex(theG.product(), theMF.product(), *theTCollectionWithConstraint,
119  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
120  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
121  }
122  case trackParameters :
123  {
124  edm::Handle<TrackParamConstraintAssociationCollection> theTCollectionWithConstraint;
125  theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
126  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
127  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
128  bs = *recoBeamSpotHandle;
129  if (theTCollectionWithConstraint.failedToGet()){
130  //edm::LogError("TrackRefitter")<<"could not get TrackParamConstraintAssociationCollection product.";
131  break;}
132  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
133  try {
134  theAlgo.runWithTrackParameters(theG.product(), theMF.product(), *theTCollectionWithConstraint,
135  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
136  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
137  }
138  //default... there cannot be any other possibility due to the check in the ctor
139  }
140 
141 
142  //put everything in th event
143  putInEvt(theEvent, thePropagator.product(), theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults,theBuilder.product());
144  LogDebug("TrackRefitter") << "end" << "\n";
145 }
146 
#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:434
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
edm::EDGetToken trkconstrcoll_
Definition: TrackRefitter.h:26
void setAlias(std::string alias)
set the aliases of produced collections
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::auto_ptr< TrackingRecHitCollection > &, std::auto_ptr< reco::TrackCollection > &, std::auto_ptr< reco::TrackExtraCollection > &, std::auto_ptr< std::vector< Trajectory > > &, AlgoProductCollection &, TransientTrackingRecHitBuilder const *)
Put produced collections in the event.
void setConf(const edm::ParameterSet &conf)
Set parameter set.
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackRefitter.h:23
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) ...
std::vector< AlgoProduct > AlgoProductCollection
Constraint constraint_
Definition: TrackRefitter.h:25
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:80
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
virtual void produce(edm::Event &, const edm::EventSetup &) override
Implementation of produce method.
T const * product() const
Definition: ESHandle.h:62
void runWithTrackParameters(const TrackingGeometry *, const MagneticField *, const TrackParamConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:56
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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.
void runWithTrack(const TrackingGeometry *, const MagneticField *, const TrackCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
Run the Final Fit taking Tracks as input (for Refitter)
TrackRefitter(const edm::ParameterSet &iConfig)
Constructor.