CMS 3D CMS Logo

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