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