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 
15 
17  KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
18  iConfig.getParameter<bool>("useHitsSplitting")),
19  theAlgo(iConfig)
20 {
21  setConf(iConfig);
22  setSrc( consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
23  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )),
24  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>( "MeasurementTrackerEvent") ));
25  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
26  std::string constraint_str = iConfig.getParameter<std::string>( "constraint" );
27  edm::InputTag trkconstrcoll = iConfig.getParameter<edm::InputTag>( "srcConstr" );
28 
29 
30  if (constraint_str == "") constraint_ = none;
31  else if (constraint_str == "momentum") { constraint_ = momentum; trkconstrcoll_ = consumes<TrackMomConstraintAssociationCollection>(trkconstrcoll); }
32  else if (constraint_str == "vertex") { constraint_ = vertex; trkconstrcoll_ = consumes<TrackVtxConstraintAssociationCollection>(trkconstrcoll); }
33  else if (constraint_str == "trackParameters") { constraint_ = trackParameters; trkconstrcoll_ = consumes<TrackParamConstraintAssociationCollection>(trkconstrcoll); }
34  else {
35  edm::LogError("TrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
36  throw cms::Exception("TrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
37  }
38 
39  //register your products
40  produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
41  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
42  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
43  produces<std::vector<Trajectory> >() ;
44  produces<std::vector<int> >() ;
45  produces<TrajTrackAssociationCollection>();
46 
47 }
48 
50 {
51  LogDebug("TrackRefitter") << "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::TrackCollection> outputTColl(new reco::TrackCollection);
57  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
58  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
59  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
60 
61  //
62  //declare and get stuff to be retrieved from ES
63  //
67  edm::ESHandle<Propagator> thePropagator;
70  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
71 
73  setup.get<TrackerTopologyRcd>().get(httopo);
74 
75  //
76  //declare and get TrackCollection to be retrieved from the event
77  //
78  AlgoProductCollection algoResults;
79  reco::BeamSpot bs;
80  switch(constraint_){
81  case none :
82  {
84  getFromEvt(theEvent,theTCollection,bs);
85 
86  LogDebug("TrackRefitter") << "TrackRefitter::produce(none):Number of Trajectories:" << (*theTCollection).size();
87 
88  if (bs.position()==math::XYZPoint(0.,0.,0.) && bs.type() == reco::BeamSpot::Unknown) {
89  edm::LogError("TrackRefitter") << " BeamSpot is (0,0,0), it is probably because is not valid in the event"; break; }
90 
91  if (theTCollection.failedToGet()){
92  edm::LogError("TrackRefitter")<<"could not get the reco::TrackCollection."; break;}
93  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
94 
95  try {
96  theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection,
97  theFitter.product(), thePropagator.product(),
98  theBuilder.product(), bs, algoResults);
99  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
100  break;
101  }
102  case momentum :
103  {
104  edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
105  theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
106 
107 
108  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
109  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
110  if (!recoBeamSpotHandle.isValid()) break;
111  bs = *recoBeamSpotHandle;
112  if (theTCollectionWithConstraint.failedToGet()){
113  //edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product.";
114  break;}
115  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
116  try {
117  theAlgo.runWithMomentum(theG.product(), theMF.product(), *theTCollectionWithConstraint,
118  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
119  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
120  break;
121  }
122  case vertex :
123  {
124  edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
125  theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
126  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
127  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
128  if (!recoBeamSpotHandle.isValid()) break;
129  bs = *recoBeamSpotHandle;
130  if (theTCollectionWithConstraint.failedToGet()){
131  edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
132  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
133  try {
134  theAlgo.runWithVertex(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  case trackParameters :
139  {
140  edm::Handle<TrackParamConstraintAssociationCollection> theTCollectionWithConstraint;
141  theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
142  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
143  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
144  if (!recoBeamSpotHandle.isValid()) break;
145  bs = *recoBeamSpotHandle;
146  if (theTCollectionWithConstraint.failedToGet()){
147  //edm::LogError("TrackRefitter")<<"could not get TrackParamConstraintAssociationCollection product.";
148  break;}
149  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
150  try {
151  theAlgo.runWithTrackParameters(theG.product(), theMF.product(), *theTCollectionWithConstraint,
152  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
153  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
154  }
155  //default... there cannot be any other possibility due to the check in the ctor
156  }
157 
158 
159  //put everything in th event
160  putInEvt(theEvent, thePropagator.product(), theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, outputIndecesInputColl, algoResults,theBuilder.product(), httopo.product());
161  LogDebug("TrackRefitter") << "end" << "\n";
162 }
163 
#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)
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.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::EDGetToken trkconstrcoll_
Definition: TrackRefitter.h:27
void setAlias(std::string alias)
set the aliases of produced collections
void setConf(const edm::ParameterSet &conf)
Set parameter set.
TrackProducerAlgorithm< reco::Track > theAlgo
Definition: TrackRefitter.h:24
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) ...
bool isValid() const
Definition: HandleBase.h:75
Constraint constraint_
Definition: TrackRefitter.h:26
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:79
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
virtual void produce(edm::Event &, const edm::EventSetup &) override
Implementation of produce method.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void runWithTrackParameters(const TrackingGeometry *, const MagneticField *, const TrackParamConstraintAssociationCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
std::vector< AlgoProduct > AlgoProductCollection
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:59
const Point & position() const
position
Definition: BeamSpot.h:62
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
BeamType type() const
return beam type
Definition: BeamSpot.h:129
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.