CMS 3D CMS Logo

DAFTrackProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
16 
19 
21  : KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"), false), theAlgo(iConfig) {
23  iConfig, consumesCollector(), consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")));
24  srcTT_ = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("src"));
25  setAlias(iConfig.getParameter<std::string>("@module_label"));
26 
27  //register your products
28  produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
29  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
30  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
31  produces<std::vector<Trajectory> >();
32  produces<TrajTrackAssociationCollection>();
33  produces<TrajAnnealingCollection>().setBranchAlias(alias_ + "TrajectoryAnnealing");
34  produces<reco::TrackCollection>("beforeDAF").setBranchAlias(alias_ + "TracksBeforeDAF");
35  produces<reco::TrackExtraCollection>("beforeDAF").setBranchAlias(alias_ + "TrackExtrasBeforeDAF");
36  produces<reco::TrackCollection>("afterDAF").setBranchAlias(alias_ + "TracksAfterDAF");
37  produces<reco::TrackExtraCollection>("afterDAF").setBranchAlias(alias_ + "TrackExtrasAfterDAF");
38 
39  TrajAnnSaving_ = iConfig.getParameter<bool>("TrajAnnealingSaving");
41  std::string measurementCollectorName = getConf().getParameter<std::string>("MeasurementCollector");
42  measurementCollectorToken_ = esConsumes(edm::ESInputTag("", measurementCollectorName));
43  std::string updatorName = getConf().getParameter<std::string>("UpdatorName");
44  updatorToken_ = esConsumes(edm::ESInputTag("", updatorName));
45 }
46 
48  edm::LogInfo("DAFTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
49 
50  //empty output collections
51  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
52  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
53  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
54  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
55  std::unique_ptr<TrajAnnealingCollection> outputTrajAnnColl(new TrajAnnealingCollection);
56  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
57 
58  //new tracks collections (changes before and after DAF)
59  std::unique_ptr<TrackingRecHitCollection> outputRHCollBeforeDAF(new TrackingRecHitCollection);
60  std::unique_ptr<reco::TrackCollection> outputTCollBeforeDAF(new reco::TrackCollection);
61  std::unique_ptr<reco::TrackExtraCollection> outputTECollBeforeDAF(new reco::TrackExtraCollection);
62  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollBeforeDAF(new std::vector<Trajectory>);
63  std::unique_ptr<std::vector<int> > outputIndecesInputCollBeforeDAF(new std::vector<int>);
64  //----
65  std::unique_ptr<TrackingRecHitCollection> outputRHCollAfterDAF(new TrackingRecHitCollection);
66  std::unique_ptr<reco::TrackCollection> outputTCollAfterDAF(new reco::TrackCollection);
67  std::unique_ptr<reco::TrackExtraCollection> outputTECollAfterDAF(new reco::TrackExtraCollection);
68  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollAfterDAF(new std::vector<Trajectory>);
69  std::unique_ptr<std::vector<int> > outputIndecesInputCollAfterDAF(new std::vector<int>);
70 
71  //declare and get stuff to be retrieved from ES
75  edm::ESHandle<Propagator> thePropagator;
78  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
79 
81 
82  //get additional es_modules needed by the DAF
83  edm::ESHandle<MultiRecHitCollector> measurementCollectorHandle = setup.getHandle(measurementCollectorToken_);
85 
86  //get MeasurementTrackerEvent
88  theEvent.getByToken(mteSrc_, mte);
89 
90  //declare and get TrackCollection
91  AlgoProductCollection algoResults;
93  TrajAnnealingCollection trajannResults;
94 
95  //declare and get new tracks collections
96  AlgoProductCollection algoResultsBeforeDAF;
97  AlgoProductCollection algoResultsAfterDAF;
98  try {
99  edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
100  getFromEvt(theEvent, trajTrackAssociationHandle, bs);
101 
102  //run the algorithm
103  LogDebug("DAFTrackProducer") << "run the DAF algorithm"
104  << "\n";
106  theMF.product(),
107  *trajTrackAssociationHandle,
108  &*mte,
109  theFitter.product(),
110  theBuilder.product(),
111  measurementCollectorHandle.product(),
112  updatorHandle.product(),
113  bs,
114  algoResults,
115  trajannResults,
117  algoResultsBeforeDAF,
118  algoResultsAfterDAF);
119 
120  } catch (cms::Exception& e) {
121  edm::LogInfo("DAFTrackProducer") << "cms::Exception caught!!!"
122  << "\n"
123  << e << "\n";
124  throw;
125  }
126 
127  //put everything in the event
128  putInEvt(theEvent,
129  thePropagator.product(),
130  theMeasTk.product(),
131  outputRHColl,
132  outputTColl,
133  outputTEColl,
134  outputTrajectoryColl,
135  outputIndecesInputColl,
136  algoResults,
137  theBuilder.product(),
138  httopo.product());
139  putInEvtTrajAnn(theEvent, trajannResults, outputTrajAnnColl);
140 
141  //put in theEvent before and after DAF tracks collections
142  putInEvt(theEvent,
143  thePropagator.product(),
144  theMeasTk.product(),
145  outputRHCollBeforeDAF,
146  outputTCollBeforeDAF,
147  outputTECollBeforeDAF,
148  outputTrajectoryCollBeforeDAF,
149  outputIndecesInputCollBeforeDAF,
150  algoResultsBeforeDAF,
151  theBuilder.product(),
152  httopo.product(),
153  1);
154  putInEvt(theEvent,
155  thePropagator.product(),
156  theMeasTk.product(),
157  outputRHCollAfterDAF,
158  outputTCollAfterDAF,
159  outputTECollAfterDAF,
160  outputTrajectoryCollAfterDAF,
161  outputIndecesInputCollAfterDAF,
162  algoResultsAfterDAF,
163  theBuilder.product(),
164  httopo.product(),
165  2);
166 
167  LogDebug("DAFTrackProducer") << "end the DAF algorithm."
168  << "\n";
169 }
170 //----------------------------------------------------------------------------------------------------------//
172  edm::Handle<TrajTrackAssociationCollection>& trajTrackAssociationHandle,
173  reco::BeamSpot& bs) {
174  //get the TrajTrackMap from the event
175  //WARNING: src has always to be redefined in cfg file
176  theEvent.getByToken(srcTT_, trajTrackAssociationHandle);
177 
178  //get the BeamSpot
179  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
180  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
181  bs = *recoBeamSpotHandle;
182 }
183 //----------------------------------------------------------------------------------------------------------//
185  TrajAnnealingCollection& trajannResults,
186  std::unique_ptr<TrajAnnealingCollection>& outputTrajAnnColl) {
187  const int size = trajannResults.size();
188  outputTrajAnnColl->reserve(size);
189 
190  for (unsigned int i = 0; i < trajannResults.size(); i++) {
191  outputTrajAnnColl->push_back(trajannResults[i]);
192  }
193 
194  theEvent.put(std::move(outputTrajAnnColl));
195 }
size
Write out results.
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
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.
const edm::ParameterSet & getConf() const
std::vector< TrajAnnealing > TrajAnnealingCollection
Definition: TrajAnnealing.h:36
edm::ESGetToken< SiTrackerMultiRecHitUpdator, MultiRecHitRecord > updatorToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void initTrackProducerBase(const edm::ParameterSet &conf, edm::ConsumesCollector cc, const edm::EDGetToken &src)
Call this method in inheriting class&#39; constructor.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
DAFTrackProducerAlgorithm theAlgo
void setAlias(std::string alias)
set the aliases of produced collections
void getFromEvt(edm::Event &, edm::Handle< TrajTrackAssociationCollection > &, reco::BeamSpot &)
T const * product() const
Definition: ESHandle.h:86
edm::ESGetToken< MultiRecHitCollector, MultiRecHitRecord > measurementCollectorToken_
edm::EDGetTokenT< TrajTrackAssociationCollection > srcTT_
edm::EventID id() const
Definition: EventBase.h:63
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
Log< level::Info, false > LogInfo
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
std::vector< AlgoProduct > AlgoProductCollection
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
DAFTrackProducer(const edm::ParameterSet &iConfig)
void runWithCandidate(const TrackingGeometry *, const MagneticField *, const TrajTrackAssociationCollection &, const MeasurementTrackerEvent *measTk, const TrajectoryFitter *, const TransientTrackingRecHitBuilder *, const MultiRecHitCollector *measurementTracker, const SiTrackerMultiRecHitUpdator *, const reco::BeamSpot &, AlgoProductCollection &, TrajAnnealingCollection &, bool, AlgoProductCollection &, AlgoProductCollection &) const
Run the Final Fit taking TrackCandidates as input.
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &, const edm::EventSetup &) override
Method where the procduction take place. To be implemented in concrete classes.
void putInEvtTrajAnn(edm::Event &theEvent, TrajAnnealingCollection &trajannResults, std::unique_ptr< TrajAnnealingCollection > &selTrajAnn)
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.
#define LogDebug(id)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_