CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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");
40 }
41 
43  edm::LogInfo("DAFTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
44 
45  //empty output collections
46  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
47  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
48  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
49  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
50  std::unique_ptr<TrajAnnealingCollection> outputTrajAnnColl(new TrajAnnealingCollection);
51  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
52 
53  //new tracks collections (changes before and after DAF)
54  std::unique_ptr<TrackingRecHitCollection> outputRHCollBeforeDAF(new TrackingRecHitCollection);
55  std::unique_ptr<reco::TrackCollection> outputTCollBeforeDAF(new reco::TrackCollection);
56  std::unique_ptr<reco::TrackExtraCollection> outputTECollBeforeDAF(new reco::TrackExtraCollection);
57  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollBeforeDAF(new std::vector<Trajectory>);
58  std::unique_ptr<std::vector<int> > outputIndecesInputCollBeforeDAF(new std::vector<int>);
59  //----
60  std::unique_ptr<TrackingRecHitCollection> outputRHCollAfterDAF(new TrackingRecHitCollection);
61  std::unique_ptr<reco::TrackCollection> outputTCollAfterDAF(new reco::TrackCollection);
62  std::unique_ptr<reco::TrackExtraCollection> outputTECollAfterDAF(new reco::TrackExtraCollection);
63  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollAfterDAF(new std::vector<Trajectory>);
64  std::unique_ptr<std::vector<int> > outputIndecesInputCollAfterDAF(new std::vector<int>);
65 
66  //declare and get stuff to be retrieved from ES
70  edm::ESHandle<Propagator> thePropagator;
73  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
74 
76  setup.get<TrackerTopologyRcd>().get(httopo);
77 
78  //get additional es_modules needed by the DAF
79  edm::ESHandle<MultiRecHitCollector> measurementCollectorHandle;
80  std::string measurementCollectorName = getConf().getParameter<std::string>("MeasurementCollector");
81  setup.get<MultiRecHitRecord>().get(measurementCollectorName, measurementCollectorHandle);
83  std::string updatorName = getConf().getParameter<std::string>("UpdatorName");
84  setup.get<MultiRecHitRecord>().get(updatorName, updatorHandle);
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 }
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.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
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.
std::vector< TrajAnnealing > TrajAnnealingCollection
Definition: TrajAnnealing.h:36
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.
DAFTrackProducerAlgorithm theAlgo
void setAlias(std::string alias)
set the aliases of produced collections
edm::EDGetToken srcTT_
void getFromEvt(edm::Event &, edm::Handle< TrajTrackAssociationCollection > &, reco::BeamSpot &)
def move
Definition: eostools.py:511
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
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:88
DAFTrackProducer(const edm::ParameterSet &iConfig)
const edm::ParameterSet & getConf() const
tuple size
Write out results.
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)