CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GsfTrackProducer.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
10 
12 
17 
19  GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
20  iConfig.getParameter<bool>("useHitsSplitting")),
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  setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
28 // string a = alias_;
29 // a.erase(a.size()-6,a.size());
30  //register your products
31  produces<reco::GsfTrackCollection>().setBranchAlias( alias_ + "GsfTracks" );
32  produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
33  produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias_ + "GsfTrackExtras" );
34  produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
35  produces<std::vector<Trajectory> >() ;
36  produces<TrajGsfTrackAssociationCollection>();
37 
38 }
39 
40 
42 {
43  edm::LogInfo("GsfTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
44  //
45  // create empty output collections
46  //
47  std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
48  std::auto_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
49  std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
50  std::auto_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
51  std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
52 
53  //
54  //declare and get stuff to be retrieved from ES
55  //
59  edm::ESHandle<Propagator> thePropagator;
62  getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
63 
64  //
65  //declare and get TrackColection to be retrieved from the event
66  //
67  AlgoProductCollection algoResults;
68  reco::BeamSpot bs;
69  try{
71  getFromEvt(theEvent,theTCCollection,bs);
72 
73  //
74  //run the algorithm
75  //
76  LogDebug("GsfTrackProducer") << "run the algorithm" << "\n";
77  theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection,
78  theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
79  } catch (cms::Exception &e){ edm::LogInfo("GsfTrackProducer") << "cms::Exception caught!!!" << "\n" << e << "\n"; throw; }
80  //
81  //put everything in the event
82  putInEvt(theEvent, thePropagator.product(), theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputGsfTEColl,
83  outputTrajectoryColl, algoResults, bs);
84  LogDebug("GsfTrackProducer") << "end" << "\n";
85 }
86 
87 
88 // std::vector<reco::TransientTrack> GsfTrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup)
89 // {
90 // edm::LogInfo("GsfTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
91 // //
92 // // create empty output collections
93 // //
94 // std::vector<reco::TransientTrack> ttks;
95 
96 // //
97 // //declare and get stuff to be retrieved from ES
98 // //
99 // edm::ESHandle<TrackerGeometry> theG;
100 // edm::ESHandle<MagneticField> theMF;
101 // edm::ESHandle<TrajectoryFitter> theFitter;
102 // edm::ESHandle<Propagator> thePropagator;
103 // edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
104 // getFromES(setup,theG,theMF,theFitter,thePropagator,theBuilder);
105 
106 // //
107 // //declare and get TrackColection to be retrieved from the event
108 // //
109 // AlgoProductCollection algoResults;
110 // try{
111 // edm::Handle<TrackCandidateCollection> theTCCollection;
112 // getFromEvt(theEvent,theTCCollection);
113 
114 // //
115 // //run the algorithm
116 // //
117 // LogDebug("GsfTrackProducer") << "run the algorithm" << "\n";
118 // theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection,
119 // theFitter.product(), thePropagator.product(), theBuilder.product(), algoResults);
120 // } catch (cms::Exception &e){ edm::LogInfo("GsfTrackProducer") << "cms::Exception caught!!!" << "\n" << e << "\n"; throw;}
121 
122 
123 // for (AlgoProductCollection::iterator prod=algoResults.begin();prod!=algoResults.end(); prod++){
124 // ttks.push_back( reco::TransientTrack(*((*prod).second),thePropagator.product()->magneticField() ));
125 // }
126 
127 // LogDebug("GsfTrackProducer") << "end" << "\n";
128 
129 // return ttks;
130 // }
131 
132 
133 // void
134 // GsfTrackProducer::putInEvt(edm::Event& evt,
135 // std::auto_ptr<TrackingRecHitCollection>& selHits,
136 // std::auto_ptr<reco::GsfTrackCollection>& selTracks,
137 // std::auto_ptr<reco::TrackExtraCollection>& selTrackExtras,
138 // std::auto_ptr<reco::GsfTrackExtraCollection>& selGsfTrackExtras,
139 // std::auto_ptr<std::vector<Trajectory> >& selTrajectories,
140 // AlgoProductCollection& algoResults)
141 // {
142 
143 // TrackingRecHitRefProd rHits = evt.getRefBeforePut<TrackingRecHitCollection>();
144 // reco::TrackExtraRefProd rTrackExtras = evt.getRefBeforePut<reco::TrackExtraCollection>();
145 // reco::GsfTrackExtraRefProd rGsfTrackExtras = evt.getRefBeforePut<reco::GsfTrackExtraCollection>();
146 // reco::GsfTrackRefProd rTracks = evt.getRefBeforePut<reco::GsfTrackCollection>();
147 
148 // edm::Ref<reco::TrackExtraCollection>::key_type idx = 0;
149 // edm::Ref<reco::TrackExtraCollection>::key_type hidx = 0;
150 // edm::Ref<reco::GsfTrackExtraCollection>::key_type idxGsf = 0;
151 // for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){
152 // Trajectory * theTraj = (*i).first;
153 // if(trajectoryInEvent_) selTrajectories->push_back(*theTraj);
154 // const TrajectoryFitter::RecHitContainer& transHits = theTraj->recHits();
155 
156 // reco::GsfTrack * theTrack = (*i).second.first;
157 // PropagationDirection seedDir = (*i).second.second;
158 // // if( ) {
159 // reco::GsfTrack t = * theTrack;
160 // selTracks->push_back( t );
161 
162 // //sets the outermost and innermost TSOSs
163 // TrajectoryStateOnSurface outertsos;
164 // TrajectoryStateOnSurface innertsos;
165 // unsigned int innerId, outerId;
166 // if (theTraj->direction() == alongMomentum) {
167 // outertsos = theTraj->lastMeasurement().updatedState();
168 // innertsos = theTraj->firstMeasurement().updatedState();
169 // outerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
170 // innerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
171 // } else {
172 // outertsos = theTraj->firstMeasurement().updatedState();
173 // innertsos = theTraj->lastMeasurement().updatedState();
174 // outerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
175 // innerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
176 // }
177 
178 // GlobalPoint v = outertsos.globalParameters().position();
179 // GlobalVector p = outertsos.globalParameters().momentum();
180 // math::XYZVector outmom( p.x(), p.y(), p.z() );
181 // math::XYZPoint outpos( v.x(), v.y(), v.z() );
182 // v = innertsos.globalParameters().position();
183 // p = innertsos.globalParameters().momentum();
184 // math::XYZVector inmom( p.x(), p.y(), p.z() );
185 // math::XYZPoint inpos( v.x(), v.y(), v.z() );
186 
187 // reco::TrackExtraRef teref= reco::TrackExtraRef ( rTrackExtras, idx ++ );
188 // reco::GsfTrack & track = selTracks->back();
189 // track.setExtra( teref );
190 // selTrackExtras->push_back( reco::TrackExtra (outpos, outmom, true,
191 // inpos, inmom, true,
192 // outertsos.curvilinearError(), outerId,
193 // innertsos.curvilinearError(), innerId,
194 // seedDir,theTraj->seedRef()));
195 
196 // reco::TrackExtra & tx = selTrackExtras->back();
197 // size_t i = 0;
198 // for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.begin();
199 // j != transHits.end(); j ++ ) {
200 // TrackingRecHit * hit = (**j).hit()->clone();
201 // track.setHitPattern( * hit, i ++ );
202 // selHits->push_back( hit );
203 // tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
204 // }
205 
206 // //build the GsfTrackExtra
207 // std::vector<reco::GsfComponent5D> outerStates;
208 // outerStates.reserve(outertsos.components().size());
209 // fillStates(outertsos,outerStates);
210 // std::vector<reco::GsfComponent5D> innerStates;
211 // innerStates.reserve(innertsos.components().size());
212 // fillStates(innertsos,innerStates);
213 
214 // reco::GsfTrackExtraRef terefGsf = reco::GsfTrackExtraRef ( rGsfTrackExtras, idxGsf ++ );
215 // track.setGsfExtra( terefGsf );
216 // selGsfTrackExtras->push_back( reco::GsfTrackExtra (outerStates, outertsos.localParameters().pzSign(),
217 // innerStates, innertsos.localParameters().pzSign()));
218 
219 // delete theTrack;
220 // delete theTraj;
221 // }
222 
223 // evt.put( selTracks );
224 // evt.put( selTrackExtras );
225 // evt.put( selGsfTrackExtras );
226 // evt.put( selHits );
227 // if(trajectoryInEvent_) evt.put(selTrajectories);
228 // }
229 
230 
231 // void
232 // GsfTrackProducer::fillStates (TrajectoryStateOnSurface tsos,
233 // std::vector<reco::GsfComponent5D>& states) const
234 // {
235 // // std::cout << "in fill states" << std::endl;
236 // // if ( !tsos.isValid() ) {
237 // // std::cout << std::endl << std::endl << "invalid tsos" << std::endl;
238 // // return;
239 // // }
240 // reco::GsfComponent5D::ParameterVector pLocS;
241 // reco::GsfComponent5D::CovarianceMatrix cLocS;
242 // std::vector<TrajectoryStateOnSurface> components(tsos.components());
243 // for ( std::vector<TrajectoryStateOnSurface>::const_iterator i=components.begin();
244 // i!=components.end(); ++i ) {
245 // // if ( !(*i).isValid() ) {
246 // // std::cout << std::endl << "invalid component" << std::endl;
247 // // continue;
248 // // }
249 // // Unneeded hack ... now we have SMatrix in tracking too
250 // // const AlgebraicVector& pLoc = i->localParameters().vector();
251 // // for ( int j=0; j<reco::GsfTrackExtra::dimension; ++j ) pLocS(j) = pLoc[j];
252 // // const AlgebraicSymMatrix& cLoc = i->localError().matrix();
253 // // for ( int j1=0; j1<reco::GsfTrack::dimension; ++j1 )
254 // // for ( int j2=0; j2<=j1; ++j2 ) cLocS(j1,j2) = cLoc[j1][j2];
255 // // states.push_back(reco::GsfComponent5D(i->weight(),pLocS,cLocS));
256 
257 // states.push_back(reco::GsfComponent5D(i->weight(),i->localParameters().vector(),i->localError().matrix()));
258 // }
259 // // std::cout << "end fill states" << std::endl;
260 // }
#define LogDebug(id)
T getParameter(std::string const &) const
virtual void produce(edm::Event &, const edm::EventSetup &) override
TrackProducerAlgorithm< reco::GsfTrack > theAlgo
virtual void getFromEvt(edm::Event &, edm::Handle< TrackCandidateCollection > &, reco::BeamSpot &)
Get TrackCandidateCollection from the Event (needed by TrackProducer)
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
void setAlias(std::string alias)
set the aliases of produced collections
void setConf(const edm::ParameterSet &conf)
Set parameter set.
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::auto_ptr< TrackingRecHitCollection > &, std::auto_ptr< reco::GsfTrackCollection > &, std::auto_ptr< reco::TrackExtraCollection > &, std::auto_ptr< reco::GsfTrackExtraCollection > &, std::auto_ptr< std::vector< Trajectory > > &, AlgoProductCollection &, const reco::BeamSpot &)
Put produced collections in the event.
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
std::vector< AlgoProduct > AlgoProductCollection
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:9
T const * product() const
Definition: ESHandle.h:62
edm::EventID id() const
Definition: EventBase.h:56
void runWithCandidate(const TrackingGeometry *, const MagneticField *, const TrackCandidateCollection &, const TrajectoryFitter *, const Propagator *, const TransientTrackingRecHitBuilder *, const reco::BeamSpot &, AlgoProductCollection &)
Run the Final Fit taking TrackCandidates as input.
GsfTrackProducer(const edm::ParameterSet &iConfig)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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.