CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GsfTrackRefitter.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
6 
8 
14 
16  GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
17  iConfig.getParameter<bool>("useHitsSplitting")),
18  theAlgo(iConfig)
19 {
20  setConf(iConfig);
21  setSrc( consumes<reco::GsfTrackCollection>(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 
27  if (constraint_str == "") constraint_ = none;
28 // else if (constraint_str == "momentum") constraint_ = momentum;
29  else if (constraint_str == "vertex") {
31  gsfTrackVtxConstraintTag_ = consumes<GsfTrackVtxConstraintAssociationCollection>(iConfig.getParameter<edm::InputTag>("gsfTrackVtxConstraintTag"));
32  } else {
33  edm::LogError("GsfTrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex' or leave it empty";
34  throw cms::Exception("GsfTrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";
35  }
36 
37  //register your products
38  produces<reco::GsfTrackCollection>().setBranchAlias( alias_ + "GsfTracks" );
39  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
40  produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias_ + "GsfTrackExtras" );
41  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
42  produces<std::vector<Trajectory> >() ;
43  produces<TrajGsfTrackAssociationCollection>();
44 
45 }
46 
48 {
49  edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
50  //
51  // create empty output collections
52  //
53  std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
54  std::auto_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
55  std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
56  std::auto_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
57  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
58 
59  //
60  //declare and get stuff to be retrieved from ES
61  //
65  edm::ESHandle<Propagator> thePropagator;
67  // getFromES(setup,theG,theMF,theFitter,thePropagator);
69  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
70 
71  //
72  //declare and get TrackCollection to be retrieved from the event
73  //
74  AlgoProductCollection algoResults;
75  reco::BeamSpot bs;
76  switch(constraint_){
77  case none :
78  {
80  getFromEvt(theEvent,theTCollection,bs);
81  if (theTCollection.failedToGet()){
82  edm::LogError("GsfTrackRefitter")<<"could not get the reco::GsfTrackCollection."; return;}
83  LogDebug("GsfTrackRefitter") << "run the algorithm" << "\n";
84  try {
85  theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection,
86  theFitter.product(), thePropagator.product(),
87  theBuilder.product(), bs, algoResults);
88  }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
89  break;
90  }
91  case vertex :
92  {
94  theEvent.getByToken(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
95  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
96  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
97  bs = *recoBeamSpotHandle;
98  if (theTCollectionWithConstraint.failedToGet()){
99  edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
100  LogDebug("TrackRefitter") << "run the algorithm" << "\n";
101  try {
102  theAlgo.runWithVertex(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  }
106  //default... there cannot be any other possibility due to the check in the ctor
107  }
108 
109  //put everything in th event
110  putInEvt(theEvent, thePropagator.product(), theMeasTk.product(),
111  outputRHColl, outputTColl, outputTEColl, outputGsfTEColl, outputTrajectoryColl, algoResults, theBuilder.product(), bs);
112  LogDebug("GsfTrackRefitter") << "end" << "\n";
113 }
114 
#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:449
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.
virtual void produce(edm::Event &, const edm::EventSetup &) override
Implementation of produce method.
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
std::vector< AlgoProduct > AlgoProductCollection
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
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:60
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::auto_ptr< TrackingRecHitCollection > &, std::auto_ptr< reco::GsfTrackCollection > &, std::auto_ptr< reco::TrackExtraCollection > &, std::auto_ptr< reco::GsfTrackExtraCollection > &, std::auto_ptr< std::vector< Trajectory > > &, AlgoProductCollection &, TransientTrackingRecHitBuilder const *, const reco::BeamSpot &)
Put produced collections in the event.
TrackProducerAlgorithm< reco::GsfTrack > theAlgo
edm::EDGetTokenT< GsfTrackVtxConstraintAssociationCollection > gsfTrackVtxConstraintTag_
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)