Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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