Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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::GsfTrackCollection>().setBranchAlias(alias_ + "GsfTracks");
0040   produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0041   produces<reco::GsfTrackExtraCollection>().setBranchAlias(alias_ + "GsfTrackExtras");
0042   produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0043   produces<std::vector<Trajectory> >();
0044   produces<TrajGsfTrackAssociationCollection>();
0045 }
0046 
0047 void GsfTrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0048   edm::LogInfo("GsfTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0049   //
0050   // create empty output collections
0051   //
0052   std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0053   std::unique_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
0054   std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0055   std::unique_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
0056   std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
0057 
0058   //
0059   //declare and get stuff to be retrieved from ES
0060   //
0061   edm::ESHandle<TrackerGeometry> theG;
0062   edm::ESHandle<MagneticField> theMF;
0063   edm::ESHandle<TrajectoryFitter> theFitter;
0064   edm::ESHandle<Propagator> thePropagator;
0065   edm::ESHandle<MeasurementTracker> theMeasTk;
0066   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0067   getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0068 
0069   TrackerTopology const& ttopo = setup.getData(theTopoToken);
0070 
0071   //
0072   //declare and get TrackColection to be retrieved from the event
0073   //
0074   AlgoProductCollection algoResults;
0075   reco::BeamSpot bs;
0076   try {
0077     edm::Handle<TrackCandidateCollection> theTCCollection;
0078     getFromEvt(theEvent, theTCCollection, bs);
0079 
0080     //
0081     //run the algorithm
0082     //
0083     LogDebug("GsfTrackProducer") << "run the algorithm"
0084                                  << "\n";
0085     theAlgo.runWithCandidate(theG.product(),
0086                              theMF.product(),
0087                              *theTCCollection,
0088                              theFitter.product(),
0089                              thePropagator.product(),
0090                              theBuilder.product(),
0091                              bs,
0092                              algoResults);
0093   } catch (cms::Exception& e) {
0094     edm::LogInfo("GsfTrackProducer") << "cms::Exception caught!!!"
0095                                      << "\n"
0096                                      << e << "\n";
0097     throw;
0098   }
0099   //
0100   //put everything in the event
0101   putInEvt(theEvent,
0102            thePropagator.product(),
0103            theMeasTk.product(),
0104            outputRHColl,
0105            outputTColl,
0106            outputTEColl,
0107            outputGsfTEColl,
0108            outputTrajectoryColl,
0109            algoResults,
0110            theBuilder.product(),
0111            bs,
0112            &ttopo);
0113   LogDebug("GsfTrackProducer") << "end"
0114                                << "\n";
0115 }
0116 
0117 void GsfTrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0118   edm::ParameterSetDescription desc;
0119 
0120   desc.add<edm::InputTag>("src", edm::InputTag("CkfElectronCandidates"));
0121   desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
0122   desc.add<std::string>("producer", std::string(""));
0123   desc.add<std::string>("Fitter", std::string("GsfElectronFittingSmoother"));
0124   desc.add<bool>("useHitsSplitting", false);
0125   desc.add<bool>("TrajectoryInEvent", false);
0126   desc.add<std::string>("TTRHBuilder", std::string("WithTrackAngle"));
0127   desc.add<std::string>("Propagator", std::string("fwdElectronPropagator"));
0128   desc.add<std::string>("NavigationSchool", std::string("SimpleNavigationSchool"));
0129   desc.add<std::string>("MeasurementTracker", std::string(""));
0130   desc.add<edm::InputTag>("MeasurementTrackerEvent", edm::InputTag("MeasurementTrackerEvent"));
0131   desc.add<bool>("GeometricInnerState", false);
0132   desc.add<std::string>("AlgorithmName", std::string("gsf"));
0133 
0134   descriptions.add("gsfTrackProducer", desc);
0135 }
0136 
0137 #include "FWCore/Framework/interface/MakerMacros.h"
0138 DEFINE_FWK_MODULE(GsfTrackProducer);