CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTracker/TrackProducer/plugins/TrackProducer.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TrackProducer/plugins/TrackProducer.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 "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   //register your products
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   // create empty output collections
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   //declare and get stuff to be retrieved from ES
00052   //
00053   edm::ESHandle<TrackerGeometry> theG;
00054   edm::ESHandle<MagneticField> theMF;
00055   edm::ESHandle<TrajectoryFitter> theFitter;
00056   edm::ESHandle<Propagator> thePropagator;
00057   edm::ESHandle<MeasurementTracker>  theMeasTk;
00058   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00059   getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
00060 
00061   //
00062   //declare and get TrackColection to be retrieved from the event
00063   //
00064   AlgoProductCollection algoResults;
00065   edm::Handle<TrackCandidateCollection> theTCCollection;
00066   reco::BeamSpot bs;
00067   getFromEvt(theEvent,theTCCollection,bs);
00068   //protect against missing product  
00069   if (theTCCollection.failedToGet()){
00070     edm::LogError("TrackProducer") <<"could not get the TrackCandidateCollection.";} 
00071   else{
00072     LogDebug("TrackProducer") << "run the algorithm" << "\n";
00073     try{  
00074       theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection, 
00075                                theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00076     } catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate." << "\n" << e << "\n"; throw;}
00077   }
00078   
00079   //put everything in the event
00080   putInEvt(theEvent, thePropagator.product(),theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults);
00081   LogDebug("TrackProducer") << "end" << "\n";
00082 }
00083 
00084 
00085 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup)
00086 {
00087   edm::LogInfo("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
00088   //
00089   // create empty output collections
00090   //
00091   std::vector<reco::TransientTrack> ttks;
00092 
00093   //
00094   //declare and get stuff to be retrieved from ES
00095   //
00096   edm::ESHandle<TrackerGeometry> theG;
00097   edm::ESHandle<MagneticField> theMF;
00098   edm::ESHandle<TrajectoryFitter> theFitter;
00099   edm::ESHandle<Propagator> thePropagator;
00100   edm::ESHandle<MeasurementTracker>  theMeasTk;
00101   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00102   getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
00103 
00104   //
00105   //declare and get TrackColection to be retrieved from the event
00106   //
00107   AlgoProductCollection algoResults;
00108   edm::Handle<TrackCandidateCollection> theTCCollection;
00109   reco::BeamSpot bs;
00110   getFromEvt(theEvent,theTCCollection,bs);
00111   //protect against missing product  
00112   if (theTCCollection.failedToGet()){
00113     edm::LogError("TrackProducer") <<"could not get the TrackCandidateCollection.";}
00114   else{
00115     LogDebug("TrackProducer") << "run the algorithm" << "\n";
00116     try{  
00117       theAlgo.runWithCandidate(theG.product(), theMF.product(), *theTCCollection, 
00118                                theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00119     }
00120     catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate." << "\n" << e << "\n"; throw; }
00121   }
00122   
00123   for (AlgoProductCollection::iterator prod=algoResults.begin();prod!=algoResults.end(); prod++){
00124     ttks.push_back( reco::TransientTrack(*((*prod).second.first),thePropagator.product()->magneticField() ));
00125   }
00126 
00127   LogDebug("TrackProducer") << "end" << "\n";
00128 
00129   return ttks;
00130 }
00131 
00132