Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-18 03:42:23

0001 /** \class TrackProducer
0002  *  Produce Tracks from TrackCandidates
0003  *
0004  *  \author cerati
0005  */
0006 
0007 // system include files
0008 #include <memory>
0009 
0010 // user include files
0011 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 #include "FWCore/Framework/interface/stream/EDProducer.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0017 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0018 #include "RecoTracker/TrackProducer/interface/KfTrackProducerBase.h"
0019 #include "RecoTracker/TrackProducer/interface/TrackProducerAlgorithm.h"
0020 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0021 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0022 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0023 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0024 
0025 class TrackProducer : public KfTrackProducerBase, public edm::stream::EDProducer<> {
0026 public:
0027   /// Constructor
0028   explicit TrackProducer(const edm::ParameterSet& iConfig);
0029 
0030   /// Implementation of produce method
0031   void produce(edm::Event&, const edm::EventSetup&) override;
0032 
0033   /// Get Transient Tracks
0034   std::vector<reco::TransientTrack> getTransient(edm::Event&, const edm::EventSetup&);
0035 
0036   //   /// Put produced collections in the event
0037   //   virtual void putInEvt(edm::Event&,
0038   //            std::unique_ptr<TrackingRecHitCollection>&,
0039   //            std::unique_ptr<TrackCollection>&,
0040   //            std::unique_ptr<reco::TrackExtraCollection>&,
0041   //            std::unique_ptr<std::vector<Trajectory> >&,
0042   //            AlgoProductCollection&);
0043 
0044   /// fillDescriptions
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046 
0047 private:
0048   TrackProducerAlgorithm<reco::Track> theAlgo;
0049   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> theTTopoToken;
0050 };
0051 
0052 TrackProducer::TrackProducer(const edm::ParameterSet& iConfig)
0053     : KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
0054                           iConfig.getParameter<bool>("useHitsSplitting")),
0055       theAlgo(iConfig),
0056       theTTopoToken(esConsumes()) {
0057   initTrackProducerBase(
0058       iConfig, consumesCollector(), consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")));
0059   setAlias(iConfig.getParameter<std::string>("@module_label"));
0060 
0061   edm::InputTag tag = iConfig.getParameter<edm::InputTag>("clusterRemovalInfo");
0062   if (!(tag == edm::InputTag())) {
0063     setClusterRemovalInfo(tag);
0064   }
0065 
0066   //register your products
0067   produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0068   produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0069   // TrackCollection refers to TrackingRechit and TrackExtra
0070   // collections, need to declare its production after them to work
0071   // around a rare race condition in framework scheduling
0072   produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
0073   produces<std::vector<Trajectory> >();
0074   produces<std::vector<int> >();
0075   produces<TrajTrackAssociationCollection>();
0076 }
0077 
0078 void TrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0079   edm::ParameterSetDescription desc;
0080   desc.add<bool>("TrajectoryInEvent", false);
0081   desc.add<bool>("useHitsSplitting", false);
0082   desc.add<edm::InputTag>("src", edm::InputTag("ckfTrackCandidates"));
0083   desc.add<edm::InputTag>("clusterRemovalInfo", edm::InputTag(""));
0084   TrackProducerAlgorithm<reco::Track>::fillPSetDescription(desc);
0085   KfTrackProducerBase::fillPSetDescription(desc);
0086   descriptions.addWithDefaultLabel(desc);
0087 }
0088 
0089 void TrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0090   LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0091   //
0092   // create empty output collections
0093   //
0094   std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0095   std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
0096   std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0097   std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
0098   std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
0099 
0100   //
0101   //declare and get stuff to be retrieved from ES
0102   //
0103   edm::ESHandle<TrackerGeometry> theG;
0104   edm::ESHandle<MagneticField> theMF;
0105   edm::ESHandle<TrajectoryFitter> theFitter;
0106   edm::ESHandle<Propagator> thePropagator;
0107   edm::ESHandle<MeasurementTracker> theMeasTk;
0108   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0109   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0110 
0111   TrackerTopology const& ttopo = setup.getData(theTTopoToken);
0112 
0113   //
0114   //declare and get TrackColection to be retrieved from the event
0115   //
0116   AlgoProductCollection algoResults;
0117   edm::Handle<TrackCandidateCollection> theTCCollection;
0118   reco::BeamSpot bs;
0119   getFromEvt(theEvent, theTCCollection, bs);
0120   //protect against missing product
0121   if (theTCCollection.failedToGet()) {
0122     edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
0123   } else {
0124     LogDebug("TrackProducer") << "run the algorithm"
0125                               << "\n";
0126     try {
0127       theAlgo.runWithCandidate(theG.product(),
0128                                theMF.product(),
0129                                *theTCCollection,
0130                                theFitter.product(),
0131                                thePropagator.product(),
0132                                theBuilder.product(),
0133                                bs,
0134                                algoResults);
0135     } catch (cms::Exception& e) {
0136       edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
0137                                      << "\n"
0138                                      << e << "\n";
0139       throw;
0140     }
0141   }
0142 
0143   //put everything in the event
0144   putInEvt(theEvent,
0145            thePropagator.product(),
0146            theMeasTk.product(),
0147            outputRHColl,
0148            outputTColl,
0149            outputTEColl,
0150            outputTrajectoryColl,
0151            outputIndecesInputColl,
0152            algoResults,
0153            theBuilder.product(),
0154            &ttopo);
0155   LogDebug("TrackProducer") << "end"
0156                             << "\n";
0157 }
0158 
0159 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup) {
0160   LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0161   //
0162   // create empty output collections
0163   //
0164   std::vector<reco::TransientTrack> ttks;
0165 
0166   //
0167   //declare and get stuff to be retrieved from ES
0168   //
0169   edm::ESHandle<TrackerGeometry> theG;
0170   edm::ESHandle<MagneticField> theMF;
0171   edm::ESHandle<TrajectoryFitter> theFitter;
0172   edm::ESHandle<Propagator> thePropagator;
0173   edm::ESHandle<MeasurementTracker> theMeasTk;
0174   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0175   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0176 
0177   //
0178   //declare and get TrackColection to be retrieved from the event
0179   //
0180   AlgoProductCollection algoResults;
0181   edm::Handle<TrackCandidateCollection> theTCCollection;
0182   reco::BeamSpot bs;
0183   getFromEvt(theEvent, theTCCollection, bs);
0184   //protect against missing product
0185   if (theTCCollection.failedToGet()) {
0186     edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
0187   } else {
0188     LogDebug("TrackProducer") << "run the algorithm"
0189                               << "\n";
0190     try {
0191       theAlgo.runWithCandidate(theG.product(),
0192                                theMF.product(),
0193                                *theTCCollection,
0194                                theFitter.product(),
0195                                thePropagator.product(),
0196                                theBuilder.product(),
0197                                bs,
0198                                algoResults);
0199     } catch (cms::Exception& e) {
0200       edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
0201                                      << "\n"
0202                                      << e << "\n";
0203       throw;
0204     }
0205   }
0206   ttks.reserve(algoResults.size());
0207   for (auto& prod : algoResults) {
0208     ttks.push_back(reco::TransientTrack(*(prod.track), thePropagator.product()->magneticField()));
0209   }
0210 
0211   LogDebug("TrackProducer") << "end"
0212                             << "\n";
0213 
0214   return ttks;
0215 }
0216 
0217 #include "FWCore/Framework/interface/MakerMacros.h"
0218 DEFINE_FWK_MODULE(TrackProducer);