CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoTracker/TrackProducer/plugins/GsfTrackRefitter.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TrackProducer/plugins/GsfTrackRefitter.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 "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"
00012 #include "TrackingTools/GsfTracking/interface/GsfTrackConstraintAssociation.h"
00013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00014 
00015 GsfTrackRefitter::GsfTrackRefitter(const edm::ParameterSet& iConfig):
00016   GsfTrackProducerBase(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   std::string  constraint_str = iConfig.getParameter<std::string>( "constraint" );
00024 
00025   if (constraint_str == "") constraint_ = none;
00026 //   else if (constraint_str == "momentum") constraint_ = momentum;
00027   else if (constraint_str == "vertex") {
00028     constraint_ = vertex;
00029     gsfTrackVtxConstraintTag_ = iConfig.getParameter<edm::InputTag>("gsfTrackVtxConstraintTag");
00030   } else {
00031     edm::LogError("GsfTrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex' or leave it empty";    
00032     throw cms::Exception("GsfTrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";    
00033   }
00034 
00035   //register your products
00036   produces<reco::GsfTrackCollection>().setBranchAlias( alias_ + "GsfTracks" );
00037   produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
00038   produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias_ + "GsfTrackExtras" );
00039   produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
00040   produces<std::vector<Trajectory> >() ;
00041   produces<TrajGsfTrackAssociationCollection>();
00042 
00043 }
00044 
00045 void GsfTrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup)
00046 {
00047   edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
00048   //
00049   // create empty output collections
00050   //
00051   std::auto_ptr<TrackingRecHitCollection>   outputRHColl (new TrackingRecHitCollection);
00052   std::auto_ptr<reco::GsfTrackCollection>      outputTColl(new reco::GsfTrackCollection);
00053   std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
00054   std::auto_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
00055   std::auto_ptr<std::vector<Trajectory> >   outputTrajectoryColl(new std::vector<Trajectory>);
00056 
00057   //
00058   //declare and get stuff to be retrieved from ES
00059   //
00060   edm::ESHandle<TrackerGeometry> theG;
00061   edm::ESHandle<MagneticField> theMF;
00062   edm::ESHandle<TrajectoryFitter> theFitter;
00063   edm::ESHandle<Propagator> thePropagator;
00064   edm::ESHandle<MeasurementTracker>  theMeasTk;
00065   //  getFromES(setup,theG,theMF,theFitter,thePropagator);
00066   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00067   getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
00068 
00069   //
00070   //declare and get TrackCollection to be retrieved from the event
00071   //
00072   AlgoProductCollection algoResults;
00073   reco::BeamSpot bs;
00074   switch(constraint_){
00075   case none :
00076     {
00077       edm::Handle<reco::GsfTrackCollection> theTCollection;
00078       getFromEvt(theEvent,theTCollection,bs);
00079       if (theTCollection.failedToGet()){
00080         edm::LogError("GsfTrackRefitter")<<"could not get the reco::GsfTrackCollection."; return;}
00081       LogDebug("GsfTrackRefitter") << "run the algorithm" << "\n";
00082       try {
00083         theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection, 
00084                              theFitter.product(), thePropagator.product(),  
00085                              theBuilder.product(), bs, algoResults);
00086       }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00087       break;
00088     }
00089   case vertex :
00090     {
00091       edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
00092       theEvent.getByLabel(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
00093       edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00094       theEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
00095       bs = *recoBeamSpotHandle;      
00096       if (theTCollectionWithConstraint.failedToGet()){
00097         edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
00098       LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00099       try {
00100       theAlgo.runWithVertex(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     }
00104     //default... there cannot be any other possibility due to the check in the ctor
00105   }
00106   
00107   //put everything in th event
00108   putInEvt(theEvent, thePropagator.product(), theMeasTk.product(),
00109            outputRHColl, outputTColl, outputTEColl, outputGsfTEColl, outputTrajectoryColl, algoResults, bs);
00110   LogDebug("GsfTrackRefitter") << "end" << "\n";
00111 }
00112