Go to the documentation of this file.00001 #include "RecoTracker/TrackProducer/plugins/GsfTrackRefitter.h"
00002
00003 #include <memory>
00004
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
00027 else if (constraint_str == "vertex") constraint_ = vertex;
00028 else {
00029 edm::LogError("GsfTrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex' or leave it empty";
00030 throw cms::Exception("GsfTrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";
00031 }
00032
00033
00034 produces<reco::GsfTrackCollection>().setBranchAlias( alias_ + "GsfTracks" );
00035 produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
00036 produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias_ + "GsfTrackExtras" );
00037 produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
00038 produces<std::vector<Trajectory> >() ;
00039 produces<TrajGsfTrackAssociationCollection>();
00040
00041 }
00042
00043 void GsfTrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup)
00044 {
00045 edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
00046
00047
00048
00049 std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
00050 std::auto_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
00051 std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
00052 std::auto_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
00053 std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
00054
00055
00056
00057
00058 edm::ESHandle<TrackerGeometry> theG;
00059 edm::ESHandle<MagneticField> theMF;
00060 edm::ESHandle<TrajectoryFitter> theFitter;
00061 edm::ESHandle<Propagator> thePropagator;
00062 edm::ESHandle<MeasurementTracker> theMeasTk;
00063
00064 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
00065 getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
00066
00067
00068
00069
00070 AlgoProductCollection algoResults;
00071 reco::BeamSpot bs;
00072 switch(constraint_){
00073 case none :
00074 {
00075 edm::Handle<reco::GsfTrackCollection> theTCollection;
00076 getFromEvt(theEvent,theTCollection,bs);
00077 if (theTCollection.failedToGet()){
00078 edm::LogError("GsfTrackRefitter")<<"could not get the reco::GsfTrackCollection."; return;}
00079 LogDebug("GsfTrackRefitter") << "run the algorithm" << "\n";
00080 try {
00081 theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection,
00082 theFitter.product(), thePropagator.product(),
00083 theBuilder.product(), bs, algoResults);
00084 }catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
00085 break;
00086 }
00087 case vertex :
00088 {
00089 edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
00090 theEvent.getByType(theTCollectionWithConstraint);
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 TrackVtxConstraintAssociationCollection product."; break;}
00096 LogDebug("TrackRefitter") << "run the algorithm" << "\n";
00097 try {
00098 theAlgo.runWithVertex(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 }
00102
00103 }
00104
00105
00106 putInEvt(theEvent, thePropagator.product(), theMeasTk.product(),
00107 outputRHColl, outputTColl, outputTEColl, outputGsfTEColl, outputTrajectoryColl, algoResults, bs);
00108 LogDebug("GsfTrackRefitter") << "end" << "\n";
00109 }
00110