CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/RecoTracker/TrackProducer/plugins/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   trkconstrcoll_=iConfig.getParameter<edm::InputTag>( "srcConstr" );
00023   
00024 
00025   if (constraint_str == "") constraint_ = none;
00026   else if (constraint_str == "momentum") constraint_ = momentum;
00027   else if (constraint_str == "vertex") constraint_ = vertex;
00028   else {
00029     edm::LogError("TrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex' or leave it empty";    
00030     throw cms::Exception("TrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";    
00031   }
00032 
00033   //register your products
00034   produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
00035   produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
00036   produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
00037   produces<std::vector<Trajectory> >() ;
00038   produces<TrajTrackAssociationCollection>();
00039 
00040 }
00041 
00042 void TrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup)
00043 {
00044   edm::LogInfo("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
00045   //
00046   // create empty output collections
00047   //
00048   std::auto_ptr<TrackingRecHitCollection>   outputRHColl (new TrackingRecHitCollection);
00049   std::auto_ptr<reco::TrackCollection>      outputTColl(new reco::TrackCollection);
00050   std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
00051   std::auto_ptr<std::vector<Trajectory> >   outputTrajectoryColl(new std::vector<Trajectory>);
00052 
00053   //
00054   //declare and get stuff to be retrieved from ES
00055   //
00056   edm::ESHandle<TrackerGeometry> theG;
00057   edm::ESHandle<MagneticField> theMF;
00058   edm::ESHandle<TrajectoryFitter> theFitter;
00059   edm::ESHandle<Propagator> thePropagator;
00060   edm::ESHandle<MeasurementTracker>  theMeasTk;
00061   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00062   getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
00063 
00064   //
00065   //declare and get TrackCollection to be retrieved from the event
00066   //
00067   AlgoProductCollection algoResults;
00068   reco::BeamSpot bs;
00069   switch(constraint_){
00070   case none :
00071     {
00072       edm::Handle<reco::TrackCollection> theTCollection;
00073       getFromEvt(theEvent,theTCollection,bs);
00074       if (theTCollection.failedToGet()){
00075         edm::LogError("TrackRefitter")<<"could not get the reco::TrackCollection."; break;}
00076       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00077 
00078       try {
00079         theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection, 
00080                              theFitter.product(), thePropagator.product(), 
00081                              theBuilder.product(), bs, algoResults);
00082       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00083       break;
00084     }
00085   case momentum :
00086     {
00087       edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
00088       theEvent.getByLabel(trkconstrcoll_,theTCollectionWithConstraint);
00089 
00090 
00091       edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00092       theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
00093       bs = *recoBeamSpotHandle;      
00094       if (theTCollectionWithConstraint.failedToGet()){
00095         edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product."; break;}
00096       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00097       try {
00098         theAlgo.runWithMomentum(theG.product(), theMF.product(), *theTCollectionWithConstraint, 
00099                                 theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
00100       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00101       break;}
00102   case  vertex :
00103     {
00104       edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
00105       theEvent.getByLabel(trkconstrcoll_,theTCollectionWithConstraint);
00106       edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00107       theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
00108       bs = *recoBeamSpotHandle;      
00109       if (theTCollectionWithConstraint.failedToGet()){
00110         edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
00111       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00112       try {
00113       theAlgo.runWithVertex(theG.product(), theMF.product(), *theTCollectionWithConstraint, 
00114                             theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);      
00115       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00116     }
00117     //default... there cannot be any other possibility due to the check in the ctor
00118   }
00119 
00120   
00121   //put everything in th event
00122   putInEvt(theEvent, thePropagator.product(), theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults);
00123   LogDebug("TrackRefitter") << "end" << "\n";
00124 }
00125