Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/GsfTrackReco/interface/GsfComponent5D.h"
0002 #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h"
0003 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0004 #include "FWCore/Framework/interface/stream/EDProducer.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0007 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0008 #include "RecoTracker/TrackProducer/interface/GsfTrackProducerBase.h"
0009 #include "RecoTracker/TrackProducer/interface/TrackProducerAlgorithm.h"
0010 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0011 #include "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"
0012 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0013 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0014 
0015 class GsfTrackProducer : public GsfTrackProducerBase, public edm::stream::EDProducer<> {
0016 public:
0017   explicit GsfTrackProducer(const edm::ParameterSet& iConfig);
0018   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0019 
0020   void produce(edm::Event&, const edm::EventSetup&) override;
0021 
0022 private:
0023   TrackProducerAlgorithm<reco::GsfTrack> theAlgo;
0024 
0025   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> theTopoToken;
0026 };
0027 
0028 GsfTrackProducer::GsfTrackProducer(const edm::ParameterSet& iConfig)
0029     : GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
0030                            iConfig.getParameter<bool>("useHitsSplitting")),
0031       theAlgo(iConfig),
0032       theTopoToken(esConsumes()) {
0033   initTrackProducerBase(
0034       iConfig, consumesCollector(), consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")));
0035   setAlias(iConfig.getParameter<std::string>("@module_label"));
0036   //   string a = alias_;
0037   //   a.erase(a.size()-6,a.size());
0038   //register your products
0039   produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0040   produces<reco::GsfTrackExtraCollection>().setBranchAlias(alias_ + "GsfTrackExtras");
0041   produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0042   // GsfTrackCollection refers to TrackingRechit, TrackExtra, and
0043   // GsfTrackExtra collections, need to declare its production after
0044   // them to work around a rare race condition in framework scheduling
0045   produces<reco::GsfTrackCollection>().setBranchAlias(alias_ + "GsfTracks");
0046   produces<std::vector<Trajectory> >();
0047   produces<TrajGsfTrackAssociationCollection>();
0048 }
0049 
0050 void GsfTrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0051   edm::ParameterSetDescription desc;
0052   desc.add<bool>("TrajectoryInEvent", false);
0053   desc.add<bool>("useHitsSplitting", false);
0054   desc.add<edm::InputTag>("src", edm::InputTag("CkfElectronCandidates"));
0055   TrackProducerAlgorithm<reco::GsfTrack>::fillPSetDescription(desc);
0056   GsfTrackProducerBase::fillPSetDescription(desc);
0057   descriptions.addWithDefaultLabel(desc);
0058 }
0059 
0060 void GsfTrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0061   edm::LogInfo("GsfTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0062   //
0063   // create empty output collections
0064   //
0065   std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0066   std::unique_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
0067   std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0068   std::unique_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
0069   std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
0070 
0071   //
0072   //declare and get stuff to be retrieved from ES
0073   //
0074   edm::ESHandle<TrackerGeometry> theG;
0075   edm::ESHandle<MagneticField> theMF;
0076   edm::ESHandle<TrajectoryFitter> theFitter;
0077   edm::ESHandle<Propagator> thePropagator;
0078   edm::ESHandle<MeasurementTracker> theMeasTk;
0079   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0080   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0081 
0082   TrackerTopology const& ttopo = setup.getData(theTopoToken);
0083 
0084   //
0085   //declare and get TrackColection to be retrieved from the event
0086   //
0087   AlgoProductCollection algoResults;
0088   reco::BeamSpot bs;
0089   try {
0090     edm::Handle<TrackCandidateCollection> theTCCollection;
0091     getFromEvt(theEvent, theTCCollection, bs);
0092 
0093     //
0094     //run the algorithm
0095     //
0096     LogDebug("GsfTrackProducer") << "run the algorithm"
0097                                  << "\n";
0098     theAlgo.runWithCandidate(theG.product(),
0099                              theMF.product(),
0100                              *theTCCollection,
0101                              theFitter.product(),
0102                              thePropagator.product(),
0103                              theBuilder.product(),
0104                              bs,
0105                              algoResults);
0106   } catch (cms::Exception& e) {
0107     edm::LogInfo("GsfTrackProducer") << "cms::Exception caught!!!"
0108                                      << "\n"
0109                                      << e << "\n";
0110     throw;
0111   }
0112   //
0113   //put everything in the event
0114   putInEvt(theEvent,
0115            thePropagator.product(),
0116            theMeasTk.product(),
0117            outputRHColl,
0118            outputTColl,
0119            outputTEColl,
0120            outputGsfTEColl,
0121            outputTrajectoryColl,
0122            algoResults,
0123            theBuilder.product(),
0124            bs,
0125            &ttopo);
0126   LogDebug("GsfTrackProducer") << "end"
0127                                << "\n";
0128 }
0129 
0130 #include "FWCore/Framework/interface/MakerMacros.h"
0131 DEFINE_FWK_MODULE(GsfTrackProducer);