Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-10 10:03:11

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::TrackCollection>().setBranchAlias(alias_ + "Tracks");
0036   produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0037   produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0038   produces<std::vector<Trajectory> >();
0039   produces<std::vector<int> >();
0040   produces<TrajTrackAssociationCollection>();
0041 }
0042 
0043 void TrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0044   LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0045   //
0046   // create empty output collections
0047   //
0048   std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0049   std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
0050   std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0051   std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
0052   std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
0053 
0054   //
0055   //declare and get stuff to be retrieved from ES
0056   //
0057   edm::ESHandle<TrackerGeometry> theG;
0058   edm::ESHandle<MagneticField> theMF;
0059   edm::ESHandle<TrajectoryFitter> theFitter;
0060   edm::ESHandle<Propagator> thePropagator;
0061   edm::ESHandle<MeasurementTracker> theMeasTk;
0062   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0063   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0064 
0065   TrackerTopology const& ttopo = setup.getData(theTTopoToken);
0066 
0067   //
0068   //declare and get TrackColection to be retrieved from the event
0069   //
0070   AlgoProductCollection algoResults;
0071   edm::Handle<TrackCandidateCollection> theTCCollection;
0072   reco::BeamSpot bs;
0073   getFromEvt(theEvent, theTCCollection, bs);
0074   //protect against missing product
0075   if (theTCCollection.failedToGet()) {
0076     edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
0077   } else {
0078     LogDebug("TrackProducer") << "run the algorithm"
0079                               << "\n";
0080     try {
0081       theAlgo.runWithCandidate(theG.product(),
0082                                theMF.product(),
0083                                *theTCCollection,
0084                                theFitter.product(),
0085                                thePropagator.product(),
0086                                theBuilder.product(),
0087                                bs,
0088                                algoResults);
0089     } catch (cms::Exception& e) {
0090       edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
0091                                      << "\n"
0092                                      << e << "\n";
0093       throw;
0094     }
0095   }
0096 
0097   //put everything in the event
0098   putInEvt(theEvent,
0099            thePropagator.product(),
0100            theMeasTk.product(),
0101            outputRHColl,
0102            outputTColl,
0103            outputTEColl,
0104            outputTrajectoryColl,
0105            outputIndecesInputColl,
0106            algoResults,
0107            theBuilder.product(),
0108            &ttopo);
0109   LogDebug("TrackProducer") << "end"
0110                             << "\n";
0111 }
0112 
0113 std::vector<reco::TransientTrack> TrackProducer::getTransient(edm::Event& theEvent, const edm::EventSetup& setup) {
0114   LogDebug("TrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0115   //
0116   // create empty output collections
0117   //
0118   std::vector<reco::TransientTrack> ttks;
0119 
0120   //
0121   //declare and get stuff to be retrieved from ES
0122   //
0123   edm::ESHandle<TrackerGeometry> theG;
0124   edm::ESHandle<MagneticField> theMF;
0125   edm::ESHandle<TrajectoryFitter> theFitter;
0126   edm::ESHandle<Propagator> thePropagator;
0127   edm::ESHandle<MeasurementTracker> theMeasTk;
0128   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0129   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0130 
0131   //
0132   //declare and get TrackColection to be retrieved from the event
0133   //
0134   AlgoProductCollection algoResults;
0135   edm::Handle<TrackCandidateCollection> theTCCollection;
0136   reco::BeamSpot bs;
0137   getFromEvt(theEvent, theTCCollection, bs);
0138   //protect against missing product
0139   if (theTCCollection.failedToGet()) {
0140     edm::LogError("TrackProducer") << "could not get the TrackCandidateCollection.";
0141   } else {
0142     LogDebug("TrackProducer") << "run the algorithm"
0143                               << "\n";
0144     try {
0145       theAlgo.runWithCandidate(theG.product(),
0146                                theMF.product(),
0147                                *theTCCollection,
0148                                theFitter.product(),
0149                                thePropagator.product(),
0150                                theBuilder.product(),
0151                                bs,
0152                                algoResults);
0153     } catch (cms::Exception& e) {
0154       edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithCandidate."
0155                                      << "\n"
0156                                      << e << "\n";
0157       throw;
0158     }
0159   }
0160   ttks.reserve(algoResults.size());
0161   for (auto& prod : algoResults) {
0162     ttks.push_back(reco::TransientTrack(*(prod.track), thePropagator.product()->magneticField()));
0163   }
0164 
0165   LogDebug("TrackProducer") << "end"
0166                             << "\n";
0167 
0168   return ttks;
0169 }