Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:10

0001 /** \class TrackProducer
0002  *  Produce Tracks from TrackCandidates
0003  *  
0004 */
0005 //
0006 // Original Author:  Olga Kodolova,40 R-A12,+41227671273,
0007 //         Created:  Fri Feb 19 10:14:02 CET 2010
0008 //
0009 //
0010 
0011 // system include files
0012 #include <memory>
0013 // user include files
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/Utilities/interface/isFinite.h"
0020 #include "FWCore/Framework/interface/global/EDProducer.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0023 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0024 #include "DataFormats/TrackReco/interface/Track.h"
0025 
0026 class TrackFromPackedCandidateProducer : public edm::global::EDProducer<> {
0027 public:
0028   /// Constructor
0029   explicit TrackFromPackedCandidateProducer(const edm::ParameterSet& iConfig);
0030 
0031   /// fill descriptions
0032   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0033 
0034   /// Implementation of produce method
0035   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0036 
0037 private:
0038   const edm::EDGetTokenT<std::vector<pat::PackedCandidate> > tokenPFCandidates_;
0039 };
0040 
0041 TrackFromPackedCandidateProducer::TrackFromPackedCandidateProducer(const edm::ParameterSet& iConfig)
0042     : tokenPFCandidates_(
0043           consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidates"))) {
0044   produces<reco::TrackCollection>();
0045 }
0046 
0047 void TrackFromPackedCandidateProducer::fillDescriptions(edm::ConfigurationDescriptions& iDescriptions) {
0048   edm::ParameterSetDescription desc;
0049   desc.add<edm::InputTag>("PFCandidates");
0050   iDescriptions.addWithDefaultLabel(desc);
0051 }
0052 
0053 void TrackFromPackedCandidateProducer::produce(edm::StreamID theStreamID,
0054                                                edm::Event& theEvent,
0055                                                const edm::EventSetup& setup) const {
0056   //
0057   // create empty output collections
0058   //
0059   auto outputTColl = std::make_unique<reco::TrackCollection>();
0060   auto const pfCandidates = theEvent.get(tokenPFCandidates_);
0061   outputTColl->reserve(pfCandidates.size());
0062 
0063   for (auto const& pf : pfCandidates) {
0064     if (pf.hasTrackDetails()) {
0065       const reco::Track& mytrack = pf.pseudoTrack();
0066       using namespace edm;
0067       if (isNotFinite(mytrack.pt()) || isNotFinite(mytrack.eta()) || isNotFinite(mytrack.phi()))
0068         continue;
0069       outputTColl->push_back(mytrack);
0070     }
0071   }
0072   //put everything in the event
0073   theEvent.put(std::move(outputTColl));
0074 }
0075 #include "FWCore/Framework/interface/MakerMacros.h"
0076 DEFINE_FWK_MODULE(TrackFromPackedCandidateProducer);