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( iConfig.getParameter<edm::InputTag>( "src" ), iConfig.getParameter<edm::InputTag>( "beamSpot" ));
20  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
21  std::string constraint_str = iConfig.getParameter<std::string>( "constraint" );
22  trkconstrcoll_=iConfig.getParameter<edm::InputTag>( "srcConstr" );
23 
24 
25  if (constraint_str == "") constraint_ = none;
26  else if (constraint_str == "momentum") constraint_ = momentum;
27  else if (constraint_str == "vertex") constraint_ = vertex;
28  else if (constraint_str == "trackParameters") constraint_ = trackParameters;
29  else {
30  edm::LogError("TrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
31  throw cms::Exception("TrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
32  }
33 
34  //register your products
35  produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
36  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
37  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
38  produces<std::vector<Trajectory> >() ;
39  produces<TrajTrackAssociationCollection>();
40 
41 }
42 
44 {
45  LogDebug("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
46  //
47  // create empty output collections
48  //
49  std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
50  std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
51  std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
52  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
53 
54  //
55  //declare and get stuff to be retrieved from ES
56  //
60  edm::ESHandle<Propagator> thePropagator;
63  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
64 
65  //
66  //declare and get TrackCollection to be retrieved from the event
67  //
68  AlgoProductCollection algoResults;
69  reco::BeamSpot bs;
70  switch(constraint_){
71  case none :
72  {
74  getFromEvt(theEvent,theTCollection,bs);
75  if (theTCollection.failedToGet()){
76  edm::LogError("TrackRefitter")<<"could not get the reco::TrackCollection."; break;}
77  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
78 
79  try {
80  theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection,
81  theFitter.product(), thePropagator.product(),
82  theBuilder.product(), bs, algoResults);
83  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
84  break;
85  }
86  case momentum :
87  {
88  edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
89  theEvent.getByLabel(trkconstrcoll_,theTCollectionWithConstraint);
90 
91 
92  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
93  theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
94  bs = *recoBeamSpotHandle;
95  if (theTCollectionWithConstraint.failedToGet()){
96  //edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product.";
97  break;}
98  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
99  try {
100  theAlgo.runWithMomentum(theG.product(), theMF.product(), *theTCollectionWithConstraint,
101  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
102  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
103  break;
104  }
105  case vertex :
106  {
107  edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
108  theEvent.getByLabel(trkconstrcoll_,theTCollectionWithConstraint);
109  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
110  theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
111  bs = *recoBeamSpotHandle;
112  if (theTCollectionWithConstraint.failedToGet()){
113  edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
114  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
115  try {
116  theAlgo.runWithVertex(theG.product(), theMF.product(), *theTCollectionWithConstraint,
117  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
118  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
119  }
120  case trackParameters :
121  {
122  edm::Handle<TrackParamConstraintAssociationCollection> theTCollectionWithConstraint;
123  theEvent.getByLabel(trkconstrcoll_,theTCollectionWithConstraint);
124  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
125  theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
126  bs = *recoBeamSpotHandle;
127  if (theTCollectionWithConstraint.failedToGet()){
128  //edm::LogError("TrackRefitter")<<"could not get TrackParamConstraintAssociationCollection product.";
129  break;}
130  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
131  try {
132  theAlgo.runWithTrackParameters(theG.product(), theMF.product(), *theTCollectionWithConstraint,
133  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
134  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
135  }
136  //default... there cannot be any other possibility due to the check in the ctor
137  }
138 
139 
140  //put everything in th event
141  putInEvt(theEvent, thePropagator.product(), theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults);
142  LogDebug("TrackRefitter") << "end" << "\n";
143 }
144 
#define LogDebug(id)
T getParameter(std::string const &) const
virtual void produce(edm::Event &, const edm::EventSetup &)
Implementation of produce method.
virtual void getFromEvt(edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
Get TrackCandidateCollection from the Event (needed by TrackProducer)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
void setAlias(std::string alias)
set the aliases of produced collections
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackRefitter.h:25
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) ...
void setConf(edm::ParameterSet conf)
Set parameter set.
edm::InputTag trkconstrcoll_
Definition: TrackRefitter.h:28
std::vector< AlgoProduct > AlgoProductCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void setSrc(edm::InputTag src, edm::InputTag bsSrc)
set label of source collection
Constraint constraint_
Definition: TrackRefitter.h:27
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
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::EventID id() const
Definition: EventBase.h:56
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 &)
Put produced collections in the event.
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.