CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DAFTrackProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
16 
17 
18 
20  KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),false),
21  theAlgo(iConfig)
22 {
23  setConf(iConfig);
24  setSrc( consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
25  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )),
26  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>( "MeasurementTrackerEvent") ));
27  src_ = consumes<TrajectoryCollection>(iConfig.getParameter<edm::InputTag>( "src" ));
28  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
29 
30  //register your products
31  produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
32  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
33  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
34  produces<std::vector<Trajectory> >();
35  produces<TrajTrackAssociationCollection>();
36  produces<TrajAnnealingCollection>().setBranchAlias( alias_ + "TrajectoryAnnealing" );
37 
38  TrajAnnSaving_ = iConfig.getParameter<bool>("TrajAnnealingSaving");
39 }
40 
41 
43 {
44  edm::LogInfo("DAFTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
45 
46  //empty output collections
47  std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
48  std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
49  std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
50  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
51  std::auto_ptr<TrajAnnealingCollection> outputTrajAnnColl(new TrajAnnealingCollection);
52 
53  //declare and get stuff to be retrieved from ES
57  edm::ESHandle<Propagator> thePropagator;
60  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
61 
62  //get additional es_modules needed by the DAF
63  edm::ESHandle<MultiRecHitCollector> measurementCollectorHandle;
64  std::string measurementCollectorName = getConf().getParameter<std::string>("MeasurementCollector");
65  setup.get<MultiRecHitRecord>().get(measurementCollectorName, measurementCollectorHandle);
67  std::string updatorName = getConf().getParameter<std::string>("UpdatorName");
68  setup.get<MultiRecHitRecord>().get(updatorName, updatorHandle);
69 
70  //get MeasurementTrackerEvent
72  theEvent.getByToken(mteSrc_, mte);
73 
74 
75  //declare and get TrackColection
76  AlgoProductCollection algoResults;
77  reco::BeamSpot bs;
78  TrajAnnealingCollection trajannResults;
79  try{
80 
81  edm::Handle<std::vector<Trajectory> > theTrajectoryCollection;
82  getFromEvt(theEvent,theTrajectoryCollection,bs);
83 
84  //obsolete?
85  //measurementCollectorHandle->updateEvent(theEvent);
86 
87  //run the algorithm
88  LogDebug("DAFTrackProducer") << "run the DAF algorithm" << "\n";
89  theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTrajectoryCollection, &*mte,
90  theFitter.product(), theBuilder.product(),
91  measurementCollectorHandle.product(), updatorHandle.product(), bs,
92  algoResults, trajannResults, TrajAnnSaving_);
93 
94  } catch (cms::Exception &e){
95  edm::LogInfo("DAFTrackProducer") << "cms::Exception caught!!!" << "\n" << e << "\n";
96  throw;
97  }
98 
99  //put everything in the event
100  putInEvt(theEvent, thePropagator.product(),theMeasTk.product(),
101  outputRHColl, outputTColl, outputTEColl,
102  outputTrajectoryColl, algoResults, theBuilder.product());
103  putInEvtTrajAnn(theEvent, trajannResults, outputTrajAnnColl);
104 
105  LogDebug("DAFTrackProducer") << "end the DAF algorithm." << "\n";
106 }
107 
109 {
110 
111  //get the TrajectoryCollection from the event
112  //WARNING: src has always to be redefined in cfg file
113  theEvent.getByToken(src_,theTrajectoryCollection );
114 
115  //get the BeamSpot
116  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
117  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
118  bs = *recoBeamSpotHandle;
119 
120 }
121 
123  std::auto_ptr<TrajAnnealingCollection>& outputTrajAnnColl){
124  const int size = trajannResults.size();
125  outputTrajAnnColl->reserve(size);
126 
127  for(unsigned int i = 0; i < trajannResults.size() ; i++){
128  outputTrajAnnColl->push_back(trajannResults[i]);
129  }
130 
131  theEvent.put( outputTrajAnnColl );
132 }
133 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
DAFTrackProducerAlgorithm theAlgo
std::vector< TrajAnnealing > TrajAnnealingCollection
Definition: TrajAnnealing.h:42
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.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetToken src_
void getFromEvt(edm::Event &, edm::Handle< TrajectoryCollection > &, reco::BeamSpot &)
std::vector< AlgoProduct > AlgoProductCollection
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
void setSrc(const edm::EDGetToken &src, const edm::EDGetTokenT< reco::BeamSpot > &bsSrc, const edm::EDGetTokenT< MeasurementTrackerEvent > &mteSrc)
set label of source collection
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
void putInEvtTrajAnn(edm::Event &theEvent, TrajAnnealingCollection &trajannResults, std::auto_ptr< TrajAnnealingCollection > &selTrajAnn)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:56
void runWithCandidate(const TrackingGeometry *, const MagneticField *, const std::vector< Trajectory > &, const MeasurementTrackerEvent *measTk, const TrajectoryFitter *, const TransientTrackingRecHitBuilder *, const MultiRecHitCollector *measurementTracker, const SiTrackerMultiRecHitUpdator *, const reco::BeamSpot &, AlgoProductCollection &, TrajAnnealingCollection &, bool) const
Run the Final Fit taking TrackCandidates as input.
volatile std::atomic< bool > shutdown_flag false
DAFTrackProducer(const edm::ParameterSet &iConfig)
const edm::ParameterSet & getConf() const
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
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.