00001 #include "RecoTracker/TrackProducer/plugins/GsfTrackProducer.h" 00002 // system include files 00003 #include <memory> 00004 // user include files 00005 #include "FWCore/Framework/interface/Frameworkfwd.h" 00006 #include "FWCore/Framework/interface/MakerMacros.h" 00007 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00008 #include "TrackingTools/GeomPropagators/interface/Propagator.h" 00009 #include "TrackingTools/PatternTools/interface/Trajectory.h" 00010 00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" 00012 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" 00013 #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h" 00014 #include "DataFormats/GsfTrackReco/interface/GsfComponent5D.h" 00015 00016 GsfTrackProducer::GsfTrackProducer(const edm::ParameterSet& iConfig): 00017 GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"), 00018 iConfig.getParameter<bool>("useHitsSplitting")), 00019 theAlgo(iConfig) 00020 { 00021 setConf(iConfig); 00022 setSrc( iConfig.getParameter<edm::InputTag>( "src" ), iConfig.getParameter<edm::InputTag>( "beamSpot" )); 00023 setAlias( iConfig.getParameter<std::string>( "@module_label" ) ); 00024 // string a = alias_; 00025 // a.erase(a.size()-6,a.size()); 00026 //register your products 00027 produces<reco::GsfTrackCollection>().setBranchAlias( alias_ + "GsfTracks" ); 00028 produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" ); 00029 produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias_ + "GsfTrackExtras" ); 00030 produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" ); 00031 produces<std::vector<Trajectory> >() ; 00032 00033 } 00034 00035 00036 void GsfTrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) 00037 { 00038 edm::LogInfo("GsfTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n"; 00039 // 00040 // create empty output collections 00041 // 00042 std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection); 00043 std::auto_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection); 00044 std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection); 00045 std::auto_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection); 00046 std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>); 00047 // 00048 //declare and get stuff to be retrieved from ES 00049 // 00050 edm::ESHandle<TrackerGeometry> theG; 00051 edm::ESHandle<MagneticField> theMF; 00052 edm::ESHandle<TrajectoryFitter> theFitter; 00053 edm::ESHandle<Propagator> thePropagator; 00054 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder; 00055 getFromES(setup,theG,theMF,theFitter,thePropagator,theBuilder); 00056 00057 // 00058 //declare and get TrackColection to be retrieved from the event 00059 // 00060 AlgoProductCollection algoResults; 00061 reco::BeamSpot bs; 00062 try{ 00063 edm::Handle<TrackCandidateCollection> theTCCollection; 00064 getFromEvt(theEvent,theTCCollection,bs); 00065 00066 // 00067 //run the algorithm 00068 // 00069 LogDebug("GsfTrackProducer") << "run the algorithm" << "\n"; 00070 theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection, 00071 theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults); 00072 } catch (cms::Exception &e){ edm::LogInfo("GsfTrackProducer") << "cms::Exception caught!!!" << "\n" << e << "\n"; throw; } 00073 // 00074 //put everything in the event 00075 putInEvt(theEvent, outputRHColl, outputTColl, outputTEColl, outputGsfTEColl, 00076 outputTrajectoryColl, algoResults, bs); 00077 LogDebug("GsfTrackProducer") << "end" << "\n"; 00078 } 00079 00080 00081 // std::vector<reco::TransientTrack> GsfTrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup) 00082 // { 00083 // edm::LogInfo("GsfTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n"; 00084 // // 00085 // // create empty output collections 00086 // // 00087 // std::vector<reco::TransientTrack> ttks; 00088 00089 // // 00090 // //declare and get stuff to be retrieved from ES 00091 // // 00092 // edm::ESHandle<TrackerGeometry> theG; 00093 // edm::ESHandle<MagneticField> theMF; 00094 // edm::ESHandle<TrajectoryFitter> theFitter; 00095 // edm::ESHandle<Propagator> thePropagator; 00096 // edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder; 00097 // getFromES(setup,theG,theMF,theFitter,thePropagator,theBuilder); 00098 00099 // // 00100 // //declare and get TrackColection to be retrieved from the event 00101 // // 00102 // AlgoProductCollection algoResults; 00103 // try{ 00104 // edm::Handle<TrackCandidateCollection> theTCCollection; 00105 // getFromEvt(theEvent,theTCCollection); 00106 00107 // // 00108 // //run the algorithm 00109 // // 00110 // LogDebug("GsfTrackProducer") << "run the algorithm" << "\n"; 00111 // theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection, 00112 // theFitter.product(), thePropagator.product(), theBuilder.product(), algoResults); 00113 // } catch (cms::Exception &e){ edm::LogInfo("GsfTrackProducer") << "cms::Exception caught!!!" << "\n" << e << "\n"; throw;} 00114 00115 00116 // for (AlgoProductCollection::iterator prod=algoResults.begin();prod!=algoResults.end(); prod++){ 00117 // ttks.push_back( reco::TransientTrack(*((*prod).second),thePropagator.product()->magneticField() )); 00118 // } 00119 00120 // LogDebug("GsfTrackProducer") << "end" << "\n"; 00121 00122 // return ttks; 00123 // } 00124 00125 00126 // void 00127 // GsfTrackProducer::putInEvt(edm::Event& evt, 00128 // std::auto_ptr<TrackingRecHitCollection>& selHits, 00129 // std::auto_ptr<reco::GsfTrackCollection>& selTracks, 00130 // std::auto_ptr<reco::TrackExtraCollection>& selTrackExtras, 00131 // std::auto_ptr<reco::GsfTrackExtraCollection>& selGsfTrackExtras, 00132 // std::auto_ptr<std::vector<Trajectory> >& selTrajectories, 00133 // AlgoProductCollection& algoResults) 00134 // { 00135 00136 // TrackingRecHitRefProd rHits = evt.getRefBeforePut<TrackingRecHitCollection>(); 00137 // reco::TrackExtraRefProd rTrackExtras = evt.getRefBeforePut<reco::TrackExtraCollection>(); 00138 // reco::GsfTrackExtraRefProd rGsfTrackExtras = evt.getRefBeforePut<reco::GsfTrackExtraCollection>(); 00139 // reco::GsfTrackRefProd rTracks = evt.getRefBeforePut<reco::GsfTrackCollection>(); 00140 00141 // edm::Ref<reco::TrackExtraCollection>::key_type idx = 0; 00142 // edm::Ref<reco::TrackExtraCollection>::key_type hidx = 0; 00143 // edm::Ref<reco::GsfTrackExtraCollection>::key_type idxGsf = 0; 00144 // for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){ 00145 // Trajectory * theTraj = (*i).first; 00146 // if(trajectoryInEvent_) selTrajectories->push_back(*theTraj); 00147 // const TrajectoryFitter::RecHitContainer& transHits = theTraj->recHits(); 00148 00149 // reco::GsfTrack * theTrack = (*i).second.first; 00150 // PropagationDirection seedDir = (*i).second.second; 00151 // // if( ) { 00152 // reco::GsfTrack t = * theTrack; 00153 // selTracks->push_back( t ); 00154 00155 // //sets the outermost and innermost TSOSs 00156 // TrajectoryStateOnSurface outertsos; 00157 // TrajectoryStateOnSurface innertsos; 00158 // unsigned int innerId, outerId; 00159 // if (theTraj->direction() == alongMomentum) { 00160 // outertsos = theTraj->lastMeasurement().updatedState(); 00161 // innertsos = theTraj->firstMeasurement().updatedState(); 00162 // outerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId(); 00163 // innerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId(); 00164 // } else { 00165 // outertsos = theTraj->firstMeasurement().updatedState(); 00166 // innertsos = theTraj->lastMeasurement().updatedState(); 00167 // outerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId(); 00168 // innerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId(); 00169 // } 00170 00171 // GlobalPoint v = outertsos.globalParameters().position(); 00172 // GlobalVector p = outertsos.globalParameters().momentum(); 00173 // math::XYZVector outmom( p.x(), p.y(), p.z() ); 00174 // math::XYZPoint outpos( v.x(), v.y(), v.z() ); 00175 // v = innertsos.globalParameters().position(); 00176 // p = innertsos.globalParameters().momentum(); 00177 // math::XYZVector inmom( p.x(), p.y(), p.z() ); 00178 // math::XYZPoint inpos( v.x(), v.y(), v.z() ); 00179 00180 // reco::TrackExtraRef teref= reco::TrackExtraRef ( rTrackExtras, idx ++ ); 00181 // reco::GsfTrack & track = selTracks->back(); 00182 // track.setExtra( teref ); 00183 // selTrackExtras->push_back( reco::TrackExtra (outpos, outmom, true, 00184 // inpos, inmom, true, 00185 // outertsos.curvilinearError(), outerId, 00186 // innertsos.curvilinearError(), innerId, 00187 // seedDir,theTraj->seedRef())); 00188 00189 // reco::TrackExtra & tx = selTrackExtras->back(); 00190 // size_t i = 0; 00191 // for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.begin(); 00192 // j != transHits.end(); j ++ ) { 00193 // TrackingRecHit * hit = (**j).hit()->clone(); 00194 // track.setHitPattern( * hit, i ++ ); 00195 // selHits->push_back( hit ); 00196 // tx.add( TrackingRecHitRef( rHits, hidx ++ ) ); 00197 // } 00198 00199 // //build the GsfTrackExtra 00200 // std::vector<reco::GsfComponent5D> outerStates; 00201 // outerStates.reserve(outertsos.components().size()); 00202 // fillStates(outertsos,outerStates); 00203 // std::vector<reco::GsfComponent5D> innerStates; 00204 // innerStates.reserve(innertsos.components().size()); 00205 // fillStates(innertsos,innerStates); 00206 00207 // reco::GsfTrackExtraRef terefGsf = reco::GsfTrackExtraRef ( rGsfTrackExtras, idxGsf ++ ); 00208 // track.setGsfExtra( terefGsf ); 00209 // selGsfTrackExtras->push_back( reco::GsfTrackExtra (outerStates, outertsos.localParameters().pzSign(), 00210 // innerStates, innertsos.localParameters().pzSign())); 00211 00212 // delete theTrack; 00213 // delete theTraj; 00214 // } 00215 00216 // evt.put( selTracks ); 00217 // evt.put( selTrackExtras ); 00218 // evt.put( selGsfTrackExtras ); 00219 // evt.put( selHits ); 00220 // if(trajectoryInEvent_) evt.put(selTrajectories); 00221 // } 00222 00223 00224 // void 00225 // GsfTrackProducer::fillStates (TrajectoryStateOnSurface tsos, 00226 // std::vector<reco::GsfComponent5D>& states) const 00227 // { 00228 // // std::cout << "in fill states" << std::endl; 00229 // // if ( !tsos.isValid() ) { 00230 // // std::cout << std::endl << std::endl << "invalid tsos" << std::endl; 00231 // // return; 00232 // // } 00233 // reco::GsfComponent5D::ParameterVector pLocS; 00234 // reco::GsfComponent5D::CovarianceMatrix cLocS; 00235 // std::vector<TrajectoryStateOnSurface> components(tsos.components()); 00236 // for ( std::vector<TrajectoryStateOnSurface>::const_iterator i=components.begin(); 00237 // i!=components.end(); ++i ) { 00238 // // if ( !(*i).isValid() ) { 00239 // // std::cout << std::endl << "invalid component" << std::endl; 00240 // // continue; 00241 // // } 00242 // // Unneeded hack ... now we have SMatrix in tracking too 00243 // // const AlgebraicVector& pLoc = i->localParameters().vector(); 00244 // // for ( int j=0; j<reco::GsfTrackExtra::dimension; ++j ) pLocS(j) = pLoc[j]; 00245 // // const AlgebraicSymMatrix& cLoc = i->localError().matrix(); 00246 // // for ( int j1=0; j1<reco::GsfTrack::dimension; ++j1 ) 00247 // // for ( int j2=0; j2<=j1; ++j2 ) cLocS(j1,j2) = cLoc[j1][j2]; 00248 // // states.push_back(reco::GsfComponent5D(i->weight(),pLocS,cLocS)); 00249 00250 // states.push_back(reco::GsfComponent5D(i->weight(),i->localParameters().vector(),i->localError().matrix())); 00251 // } 00252 // // std::cout << "end fill states" << std::endl; 00253 // }