00001 #include "RecoTracker/TrackProducer/plugins/TrackProducer.h"
00002
00003 #include <memory>
00004
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 "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00012
00013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00014
00015 TrackProducer::TrackProducer(const edm::ParameterSet& iConfig):
00016 KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
00017 iConfig.getParameter<bool>("useHitsSplitting")),
00018 theAlgo(iConfig)
00019 {
00020 setConf(iConfig);
00021 setSrc( iConfig.getParameter<edm::InputTag>( "src" ), iConfig.getParameter<edm::InputTag>( "beamSpot" ));
00022 setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
00023
00024 if ( iConfig.exists("clusterRemovalInfo") ) {
00025 edm::InputTag tag = iConfig.getParameter<edm::InputTag>("clusterRemovalInfo");
00026 if (!(tag == edm::InputTag())) { setClusterRemovalInfo( tag ); }
00027 }
00028
00029
00030 produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
00031 produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
00032 produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
00033 produces<std::vector<Trajectory> >() ;
00034 produces<TrajTrackAssociationCollection>();
00035
00036 }
00037
00038
00039 void TrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup)
00040 {
00041 edm::LogInfo("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
00042
00043
00044
00045 std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
00046 std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
00047 std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
00048 std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
00049
00050
00051
00052
00053 edm::ESHandle<TrackerGeometry> theG;
00054 edm::ESHandle<MagneticField> theMF;
00055 edm::ESHandle<TrajectoryFitter> theFitter;
00056 edm::ESHandle<Propagator> thePropagator;
00057 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00058 getFromES(setup,theG,theMF,theFitter,thePropagator,theBuilder);
00059
00060
00061
00062
00063 AlgoProductCollection algoResults;
00064 edm::Handle<TrackCandidateCollection> theTCCollection;
00065 reco::BeamSpot bs;
00066 getFromEvt(theEvent,theTCCollection,bs);
00067
00068 if (theTCCollection.failedToGet()){
00069 edm::LogError("TrackProducer") <<"could not get the TrackCandidateCollection.";}
00070 else{
00071 LogDebug("TrackProducer") << "run the algorithm" << "\n";
00072 try{
00073 theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection,
00074 theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00075 } catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate." << "\n" << e << "\n"; throw;}
00076 }
00077
00078
00079 putInEvt(theEvent, outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults);
00080 LogDebug("TrackProducer") << "end" << "\n";
00081 }
00082
00083
00084 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup)
00085 {
00086 edm::LogInfo("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
00087
00088
00089
00090 std::vector<reco::TransientTrack> ttks;
00091
00092
00093
00094
00095 edm::ESHandle<TrackerGeometry> theG;
00096 edm::ESHandle<MagneticField> theMF;
00097 edm::ESHandle<TrajectoryFitter> theFitter;
00098 edm::ESHandle<Propagator> thePropagator;
00099 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00100 getFromES(setup,theG,theMF,theFitter,thePropagator,theBuilder);
00101
00102
00103
00104
00105 AlgoProductCollection algoResults;
00106 edm::Handle<TrackCandidateCollection> theTCCollection;
00107 reco::BeamSpot bs;
00108 getFromEvt(theEvent,theTCCollection,bs);
00109
00110 if (theTCCollection.failedToGet()){
00111 edm::LogError("TrackProducer") <<"could not get the TrackCandidateCollection.";}
00112 else{
00113 LogDebug("TrackProducer") << "run the algorithm" << "\n";
00114 try{
00115 theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection,
00116 theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00117 }
00118 catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate." << "\n" << e << "\n"; throw; }
00119 }
00120
00121 for (AlgoProductCollection::iterator prod=algoResults.begin();prod!=algoResults.end(); prod++){
00122 ttks.push_back( reco::TransientTrack(*((*prod).second.first),thePropagator.product()->magneticField() ));
00123 }
00124
00125 LogDebug("TrackProducer") << "end" << "\n";
00126
00127 return ttks;
00128 }
00129
00130