Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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