CMS 3D CMS Logo

TrackRefitter.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TrackProducer/plugins/TrackRefitter.h"
00002 // system include files
00003 #include <memory>
00004 // user include files
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00010 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00012 
00013 TrackRefitter::TrackRefitter(const edm::ParameterSet& iConfig):
00014   KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
00015                       iConfig.getParameter<bool>("useHitsSplitting")),
00016   theAlgo(iConfig)
00017 {
00018   setConf(iConfig);
00019   setSrc( iConfig.getParameter<edm::InputTag>( "src" ), iConfig.getParameter<edm::InputTag>( "beamSpot" ));
00020   setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
00021   std::string  constraint_str = iConfig.getParameter<std::string>( "constraint" );
00022 
00023   if (constraint_str == "") constraint_ = none;
00024   else if (constraint_str == "momentum") constraint_ = momentum;
00025   else if (constraint_str == "vertex") constraint_ = vertex;
00026   else {
00027     edm::LogError("TrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex' or leave it empty";    
00028     throw cms::Exception("TrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";    
00029   }
00030 
00031   //register your products
00032   produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
00033   produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
00034   produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
00035   produces<std::vector<Trajectory> >() ;
00036   produces<TrajTrackAssociationCollection>();
00037 
00038 }
00039 
00040 void TrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup)
00041 {
00042   edm::LogInfo("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
00043   //
00044   // create empty output collections
00045   //
00046   std::auto_ptr<TrackingRecHitCollection>   outputRHColl (new TrackingRecHitCollection);
00047   std::auto_ptr<reco::TrackCollection>      outputTColl(new reco::TrackCollection);
00048   std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
00049   std::auto_ptr<std::vector<Trajectory> >   outputTrajectoryColl(new std::vector<Trajectory>);
00050 
00051   //
00052   //declare and get stuff to be retrieved from ES
00053   //
00054   edm::ESHandle<TrackerGeometry> theG;
00055   edm::ESHandle<MagneticField> theMF;
00056   edm::ESHandle<TrajectoryFitter> theFitter;
00057   edm::ESHandle<Propagator> thePropagator;
00058   //  getFromES(setup,theG,theMF,theFitter,thePropagator);
00059   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00060   getFromES(setup,theG,theMF,theFitter,thePropagator,theBuilder);
00061 
00062   //
00063   //declare and get TrackCollection to be retrieved from the event
00064   //
00065   AlgoProductCollection algoResults;
00066   reco::BeamSpot bs;
00067   switch(constraint_){
00068   case none :
00069     {
00070       edm::Handle<reco::TrackCollection> theTCollection;
00071       getFromEvt(theEvent,theTCollection,bs);
00072       if (theTCollection.failedToGet()){
00073         edm::LogError("TrackRefitter")<<"could not get the reco::TrackCollection."; break;}
00074       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00075       try {
00076         theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection, 
00077                              theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00078       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00079       break;
00080     }
00081   case momentum :
00082     {
00083       edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
00084       theEvent.getByType(theTCollectionWithConstraint);
00085       edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00086       theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
00087       bs = *recoBeamSpotHandle;      
00088       if (theTCollectionWithConstraint.failedToGet()){
00089         edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product."; break;}
00090       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00091       try {
00092         theAlgo.runWithMomentum(theG.product(), theMF.product(), *theTCollectionWithConstraint, 
00093                                 theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00094       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00095       break;}
00096   case  vertex :
00097     {
00098       edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
00099       theEvent.getByType(theTCollectionWithConstraint);
00100       edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00101       theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
00102       bs = *recoBeamSpotHandle;      
00103       if (theTCollectionWithConstraint.failedToGet()){
00104         edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
00105       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00106       try {
00107       theAlgo.runWithVertex(theG.product(), theMF.product(), *theTCollectionWithConstraint, 
00108                             theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);      
00109       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00110     }
00111     //default... there cannot be any other possibility due to the check in the ctor
00112   }
00113 
00114   
00115   //put everything in th event
00116   putInEvt(theEvent, outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults);
00117   LogDebug("TrackRefitter") << "end" << "\n";
00118 }
00119 

Generated on Tue Jun 9 17:46:00 2009 for CMSSW by  doxygen 1.5.4