Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:59

0001 #include "RecoTracker/TrackProducer/plugins/GsfTrackRefitter.h"
0002 // system include files
0003 #include <memory>
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0010 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0011 #include "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"
0012 #include "TrackingTools/GsfTracking/interface/GsfTrackConstraintAssociation.h"
0013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0014 
0015 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0016 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0017 
0018 GsfTrackRefitter::GsfTrackRefitter(const edm::ParameterSet& iConfig)
0019     : GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
0020                            iConfig.getParameter<bool>("useHitsSplitting")),
0021       theAlgo(iConfig) {
0022   initTrackProducerBase(
0023       iConfig, consumesCollector(), consumes<edm::View<reco::GsfTrack>>(iConfig.getParameter<edm::InputTag>("src")));
0024   setAlias(iConfig.getParameter<std::string>("@module_label"));
0025   std::string constraint_str = iConfig.getParameter<std::string>("constraint");
0026 
0027   if (constraint_str.empty())
0028     constraint_ = none;
0029   //   else if (constraint_str == "momentum") constraint_ = momentum;
0030   else if (constraint_str == "vertex") {
0031     constraint_ = vertex;
0032     gsfTrackVtxConstraintTag_ = consumes<GsfTrackVtxConstraintAssociationCollection>(
0033         iConfig.getParameter<edm::InputTag>("gsfTrackVtxConstraintTag"));
0034   } else {
0035     edm::LogError("GsfTrackRefitter") << "constraint: " << constraint_str
0036                                       << " not understood. Set it to 'momentum', 'vertex' or leave it empty";
0037     throw cms::Exception("GsfTrackRefitter")
0038         << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";
0039   }
0040 
0041   //register your products
0042   produces<reco::GsfTrackCollection>().setBranchAlias(alias_ + "GsfTracks");
0043   produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0044   produces<reco::GsfTrackExtraCollection>().setBranchAlias(alias_ + "GsfTrackExtras");
0045   produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0046   produces<std::vector<Trajectory>>();
0047   produces<TrajGsfTrackAssociationCollection>();
0048 
0049   ttopoToken_ = esConsumes();
0050 }
0051 
0052 void GsfTrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0053   edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
0054   //
0055   // create empty output collections
0056   //
0057   std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0058   std::unique_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
0059   std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0060   std::unique_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
0061   std::unique_ptr<std::vector<Trajectory>> outputTrajectoryColl(new std::vector<Trajectory>);
0062 
0063   //
0064   //declare and get stuff to be retrieved from ES
0065   //
0066   edm::ESHandle<TrackerGeometry> theG;
0067   edm::ESHandle<MagneticField> theMF;
0068   edm::ESHandle<TrajectoryFitter> theFitter;
0069   edm::ESHandle<Propagator> thePropagator;
0070   edm::ESHandle<MeasurementTracker> theMeasTk;
0071   //  getFromES(setup,theG,theMF,theFitter,thePropagator);
0072   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0073   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0074 
0075   edm::ESHandle<TrackerTopology> httopo = setup.getHandle(ttopoToken_);
0076 
0077   //
0078   //declare and get TrackCollection to be retrieved from the event
0079   //
0080   AlgoProductCollection algoResults;
0081   reco::BeamSpot bs;
0082   switch (constraint_) {
0083     case none: {
0084       edm::Handle<edm::View<reco::GsfTrack>> theTCollection;
0085       getFromEvt(theEvent, theTCollection, bs);
0086       if (theTCollection.failedToGet()) {
0087         edm::LogError("GsfTrackRefitter") << "could not get the reco::GsfTrackCollection.";
0088         return;
0089       }
0090       LogDebug("GsfTrackRefitter") << "run the algorithm"
0091                                    << "\n";
0092       try {
0093         theAlgo.runWithTrack(theG.product(),
0094                              theMF.product(),
0095                              *theTCollection,
0096                              theFitter.product(),
0097                              thePropagator.product(),
0098                              theBuilder.product(),
0099                              bs,
0100                              algoResults);
0101       } catch (cms::Exception& e) {
0102         edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
0103                                        << "\n"
0104                                        << e << "\n";
0105         throw;
0106       }
0107       break;
0108     }
0109     case vertex: {
0110       edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
0111       theEvent.getByToken(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
0112       edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0113       theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
0114       bs = *recoBeamSpotHandle;
0115       if (theTCollectionWithConstraint.failedToGet()) {
0116         edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
0117         break;
0118       }
0119       LogDebug("TrackRefitter") << "run the algorithm"
0120                                 << "\n";
0121       try {
0122         theAlgo.runWithVertex(theG.product(),
0123                               theMF.product(),
0124                               *theTCollectionWithConstraint,
0125                               theFitter.product(),
0126                               thePropagator.product(),
0127                               theBuilder.product(),
0128                               bs,
0129                               algoResults);
0130       } catch (cms::Exception& e) {
0131         edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
0132                                        << "\n"
0133                                        << e << "\n";
0134         throw;
0135       }
0136     }
0137       //default... there cannot be any other possibility due to the check in the ctor
0138   }
0139 
0140   //put everything in th event
0141   putInEvt(theEvent,
0142            thePropagator.product(),
0143            theMeasTk.product(),
0144            outputRHColl,
0145            outputTColl,
0146            outputTEColl,
0147            outputGsfTEColl,
0148            outputTrajectoryColl,
0149            algoResults,
0150            theBuilder.product(),
0151            bs,
0152            httopo.product());
0153   LogDebug("GsfTrackRefitter") << "end"
0154                                << "\n";
0155 }