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) {
22  setConf(iConfig);
23  setSrc(consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")),
24  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot")),
25  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent")));
26  srcTT_ = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("src"));
27  setAlias(iConfig.getParameter<std::string>("@module_label"));
28 
29  //register your products
30  produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
31  produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
32  produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
33  produces<std::vector<Trajectory> >();
34  produces<TrajTrackAssociationCollection>();
35  produces<TrajAnnealingCollection>().setBranchAlias(alias_ + "TrajectoryAnnealing");
36  produces<reco::TrackCollection>("beforeDAF").setBranchAlias(alias_ + "TracksBeforeDAF");
37  produces<reco::TrackExtraCollection>("beforeDAF").setBranchAlias(alias_ + "TrackExtrasBeforeDAF");
38  produces<reco::TrackCollection>("afterDAF").setBranchAlias(alias_ + "TracksAfterDAF");
39  produces<reco::TrackExtraCollection>("afterDAF").setBranchAlias(alias_ + "TrackExtrasAfterDAF");
40 
41  TrajAnnSaving_ = iConfig.getParameter<bool>("TrajAnnealingSaving");
42 }
43 
45  edm::LogInfo("DAFTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
46 
47  //empty output collections
48  std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
49  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
50  std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
51  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
52  std::unique_ptr<TrajAnnealingCollection> outputTrajAnnColl(new TrajAnnealingCollection);
53  std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
54 
55  //new tracks collections (changes before and after DAF)
56  std::unique_ptr<TrackingRecHitCollection> outputRHCollBeforeDAF(new TrackingRecHitCollection);
57  std::unique_ptr<reco::TrackCollection> outputTCollBeforeDAF(new reco::TrackCollection);
58  std::unique_ptr<reco::TrackExtraCollection> outputTECollBeforeDAF(new reco::TrackExtraCollection);
59  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollBeforeDAF(new std::vector<Trajectory>);
60  std::unique_ptr<std::vector<int> > outputIndecesInputCollBeforeDAF(new std::vector<int>);
61  //----
62  std::unique_ptr<TrackingRecHitCollection> outputRHCollAfterDAF(new TrackingRecHitCollection);
63  std::unique_ptr<reco::TrackCollection> outputTCollAfterDAF(new reco::TrackCollection);
64  std::unique_ptr<reco::TrackExtraCollection> outputTECollAfterDAF(new reco::TrackExtraCollection);
65  std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollAfterDAF(new std::vector<Trajectory>);
66  std::unique_ptr<std::vector<int> > outputIndecesInputCollAfterDAF(new std::vector<int>);
67 
68  //declare and get stuff to be retrieved from ES
72  edm::ESHandle<Propagator> thePropagator;
75  getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
76 
78  setup.get<TrackerTopologyRcd>().get(httopo);
79 
80  //get additional es_modules needed by the DAF
81  edm::ESHandle<MultiRecHitCollector> measurementCollectorHandle;
82  std::string measurementCollectorName = getConf().getParameter<std::string>("MeasurementCollector");
83  setup.get<MultiRecHitRecord>().get(measurementCollectorName, measurementCollectorHandle);
85  std::string updatorName = getConf().getParameter<std::string>("UpdatorName");
86  setup.get<MultiRecHitRecord>().get(updatorName, updatorHandle);
87 
88  //get MeasurementTrackerEvent
90  theEvent.getByToken(mteSrc_, mte);
91 
92  //declare and get TrackCollection
93  AlgoProductCollection algoResults;
94  reco::BeamSpot bs;
95  TrajAnnealingCollection trajannResults;
96 
97  //declare and get new tracks collections
98  AlgoProductCollection algoResultsBeforeDAF;
99  AlgoProductCollection algoResultsAfterDAF;
100  try {
101  edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
102  getFromEvt(theEvent, trajTrackAssociationHandle, bs);
103 
104  //run the algorithm
105  LogDebug("DAFTrackProducer") << "run the DAF algorithm"
106  << "\n";
108  theMF.product(),
109  *trajTrackAssociationHandle,
110  &*mte,
111  theFitter.product(),
112  theBuilder.product(),
113  measurementCollectorHandle.product(),
114  updatorHandle.product(),
115  bs,
116  algoResults,
117  trajannResults,
119  algoResultsBeforeDAF,
120  algoResultsAfterDAF);
121 
122  } catch (cms::Exception& e) {
123  edm::LogInfo("DAFTrackProducer") << "cms::Exception caught!!!"
124  << "\n"
125  << e << "\n";
126  throw;
127  }
128 
129  //put everything in the event
130  putInEvt(theEvent,
131  thePropagator.product(),
132  theMeasTk.product(),
133  outputRHColl,
134  outputTColl,
135  outputTEColl,
136  outputTrajectoryColl,
137  outputIndecesInputColl,
138  algoResults,
139  theBuilder.product(),
140  httopo.product());
141  putInEvtTrajAnn(theEvent, trajannResults, outputTrajAnnColl);
142 
143  //put in theEvent before and after DAF tracks collections
144  putInEvt(theEvent,
145  thePropagator.product(),
146  theMeasTk.product(),
147  outputRHCollBeforeDAF,
148  outputTCollBeforeDAF,
149  outputTECollBeforeDAF,
150  outputTrajectoryCollBeforeDAF,
151  outputIndecesInputCollBeforeDAF,
152  algoResultsBeforeDAF,
153  theBuilder.product(),
154  httopo.product(),
155  1);
156  putInEvt(theEvent,
157  thePropagator.product(),
158  theMeasTk.product(),
159  outputRHCollAfterDAF,
160  outputTCollAfterDAF,
161  outputTECollAfterDAF,
162  outputTrajectoryCollAfterDAF,
163  outputIndecesInputCollAfterDAF,
164  algoResultsAfterDAF,
165  theBuilder.product(),
166  httopo.product(),
167  2);
168 
169  LogDebug("DAFTrackProducer") << "end the DAF algorithm."
170  << "\n";
171 }
172 //----------------------------------------------------------------------------------------------------------//
174  edm::Handle<TrajTrackAssociationCollection>& trajTrackAssociationHandle,
175  reco::BeamSpot& bs) {
176  //get the TrajTrackMap from the event
177  //WARNING: src has always to be redefined in cfg file
178  theEvent.getByToken(srcTT_, trajTrackAssociationHandle);
179 
180  //get the BeamSpot
181  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
182  theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
183  bs = *recoBeamSpotHandle;
184 }
185 //----------------------------------------------------------------------------------------------------------//
187  TrajAnnealingCollection& trajannResults,
188  std::unique_ptr<TrajAnnealingCollection>& outputTrajAnnColl) {
189  const int size = trajannResults.size();
190  outputTrajAnnColl->reserve(size);
191 
192  for (unsigned int i = 0; i < trajannResults.size(); i++) {
193  outputTrajAnnColl->push_back(trajannResults[i]);
194  }
195 
196  theEvent.put(std::move(outputTrajAnnColl));
197 }
#define LogDebug(id)
size
Write out results.
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
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
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.
DAFTrackProducerAlgorithm theAlgo
void setAlias(std::string alias)
set the aliases of produced collections
void setConf(const edm::ParameterSet &conf)
Set parameter set.
edm::EDGetToken srcTT_
void getFromEvt(edm::Event &, edm::Handle< TrajTrackAssociationCollection > &, reco::BeamSpot &)
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
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
std::vector< AlgoProduct > AlgoProductCollection
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:73
DAFTrackProducer(const edm::ParameterSet &iConfig)
const edm::ParameterSet & getConf() const
T const * product() const
Definition: ESHandle.h:86
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.