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 
19 
20 
22  KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),false),
23  theAlgo(iConfig)
24 {
25  setConf(iConfig);
26  setSrc( consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
27  consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )),
28  consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>( "MeasurementTrackerEvent") ));
29  srcTT_ = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>( "src" ));
30  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
31 
32  //register your products
33  produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
34  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
35  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
36  produces<std::vector<Trajectory> >();
37  produces<TrajTrackAssociationCollection>();
38  produces<TrajAnnealingCollection>().setBranchAlias( alias_ + "TrajectoryAnnealing" );
39  produces<reco::TrackCollection>("beforeDAF").setBranchAlias( alias_ + "TracksBeforeDAF" );
40  produces<reco::TrackExtraCollection>("beforeDAF").setBranchAlias( alias_ + "TrackExtrasBeforeDAF" );
41  produces<reco::TrackCollection>("afterDAF").setBranchAlias( alias_ + "TracksAfterDAF" );
42  produces<reco::TrackExtraCollection>("afterDAF").setBranchAlias( alias_ + "TrackExtrasAfterDAF" );
43 
44  TrajAnnSaving_ = iConfig.getParameter<bool>("TrajAnnealingSaving");
45 }
46 
47 
49 {
50  edm::LogInfo("DAFTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
51 
52  //empty output collections
53  std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
54  std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
55  std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
56  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
57  std::auto_ptr<TrajAnnealingCollection> outputTrajAnnColl(new TrajAnnealingCollection);
58 
59  //new tracks collections (changes before and after DAF)
60  std::auto_ptr<TrackingRecHitCollection> outputRHCollBeforeDAF (new TrackingRecHitCollection);
61  std::auto_ptr<reco::TrackCollection> outputTCollBeforeDAF(new reco::TrackCollection);
62  std::auto_ptr<reco::TrackExtraCollection> outputTECollBeforeDAF(new reco::TrackExtraCollection);
63  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryCollBeforeDAF(new std::vector<Trajectory>);
64  //----
65  std::auto_ptr<TrackingRecHitCollection> outputRHCollAfterDAF (new TrackingRecHitCollection);
66  std::auto_ptr<reco::TrackCollection> outputTCollAfterDAF(new reco::TrackCollection);
67  std::auto_ptr<reco::TrackExtraCollection> outputTECollAfterDAF(new reco::TrackExtraCollection);
68  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryCollAfterDAF(new std::vector<Trajectory>);
69 
70  //declare and get stuff to be retrieved from ES
74  edm::ESHandle<Propagator> thePropagator;
77  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
78 
80  setup.get<TrackerTopologyRcd>().get(httopo);
81 
82  //get additional es_modules needed by the DAF
83  edm::ESHandle<MultiRecHitCollector> measurementCollectorHandle;
84  std::string measurementCollectorName = getConf().getParameter<std::string>("MeasurementCollector");
85  setup.get<MultiRecHitRecord>().get(measurementCollectorName, measurementCollectorHandle);
87  std::string updatorName = getConf().getParameter<std::string>("UpdatorName");
88  setup.get<MultiRecHitRecord>().get(updatorName, updatorHandle);
89 
90  //get MeasurementTrackerEvent
92  theEvent.getByToken(mteSrc_, mte);
93 
94 
95  //declare and get TrackCollection
96  AlgoProductCollection algoResults;
97  reco::BeamSpot bs;
98  TrajAnnealingCollection trajannResults;
99 
100  //declare and get new tracks collections
101  AlgoProductCollection algoResultsBeforeDAF;
102  AlgoProductCollection algoResultsAfterDAF;
103  try{
104 
105  edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
106  getFromEvt(theEvent,trajTrackAssociationHandle,bs);
107 
108 
109  //run the algorithm
110  LogDebug("DAFTrackProducer") << "run the DAF algorithm" << "\n";
111  theAlgo.runWithCandidate(theG.product(), theMF.product(),
112  *trajTrackAssociationHandle,
113  &*mte,
114  theFitter.product(), theBuilder.product(),
115  measurementCollectorHandle.product(), updatorHandle.product(), bs,
116  algoResults, trajannResults, TrajAnnSaving_,
117  algoResultsBeforeDAF, algoResultsAfterDAF);
118 
119  } catch (cms::Exception &e){
120  edm::LogInfo("DAFTrackProducer") << "cms::Exception caught!!!" << "\n" << e << "\n";
121  throw;
122  }
123 
124  //put everything in the event
125  putInEvt(theEvent, thePropagator.product(),theMeasTk.product(),
126  outputRHColl, outputTColl, outputTEColl,
127  outputTrajectoryColl, algoResults, theBuilder.product(), httopo.product());
128  putInEvtTrajAnn(theEvent, trajannResults, outputTrajAnnColl);
129 
130  //put in theEvent before and after DAF tracks collections
131  putInEvt(theEvent, thePropagator.product(),theMeasTk.product(),
132  outputRHCollBeforeDAF, outputTCollBeforeDAF, outputTECollBeforeDAF,
133  outputTrajectoryCollBeforeDAF, algoResultsBeforeDAF, theBuilder.product(), httopo.product(), 1);
134  putInEvt(theEvent, thePropagator.product(),theMeasTk.product(),
135  outputRHCollAfterDAF, outputTCollAfterDAF, outputTECollAfterDAF,
136  outputTrajectoryCollAfterDAF, algoResultsAfterDAF, theBuilder.product(), httopo.product(), 2);
137 
138  LogDebug("DAFTrackProducer") << "end the DAF algorithm." << "\n";
139 }
140 //----------------------------------------------------------------------------------------------------------//
142 {
143 
144  //get the TrajTrackMap from the event
145  //WARNING: src has always to be redefined in cfg file
146  theEvent.getByToken(srcTT_,trajTrackAssociationHandle);
147 
148  //get the BeamSpot
149  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
150  theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
151  bs = *recoBeamSpotHandle;
152 
153 }
154 //----------------------------------------------------------------------------------------------------------//
156  std::auto_ptr<TrajAnnealingCollection>& outputTrajAnnColl){
157  const int size = trajannResults.size();
158  outputTrajAnnColl->reserve(size);
159 
160  for(unsigned int i = 0; i < trajannResults.size() ; i++){
161  outputTrajAnnColl->push_back(trajannResults[i]);
162  }
163 
164  theEvent.put( outputTrajAnnColl );
165 }
#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:464
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< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
DAFTrackProducerAlgorithm theAlgo
std::vector< TrajAnnealing > TrajAnnealingCollection
Definition: TrajAnnealing.h:42
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 &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
std::vector< AlgoProduct > AlgoProductCollection
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
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 *, const TrackerTopology *ttopo, int BeforeOrAfter=0)
Put produced collections in the event.
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:11
void putInEvtTrajAnn(edm::Event &theEvent, TrajAnnealingCollection &trajannResults, std::auto_ptr< TrajAnnealingCollection > &selTrajAnn)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< reco::BeamSpot > bsSrc_
edm::EventID id() const
Definition: EventBase.h:60
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 produce(edm::Event &, const edm::EventSetup &) override
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.