TrackFromPackedCandidateProducer

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/** \class TrackProducer
 *  Produce Tracks from TrackCandidates
 *  
*/
//
// Original Author:  Olga Kodolova,40 R-A12,+41227671273,
//         Created:  Fri Feb 19 10:14:02 CET 2010
//
//

// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/isFinite.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackReco/interface/Track.h"

class TrackFromPackedCandidateProducer : public edm::global::EDProducer<> {
public:
  /// Constructor
  explicit TrackFromPackedCandidateProducer(const edm::ParameterSet& iConfig);

  /// fill descriptions
  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

  /// Implementation of produce method
  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

private:
  const edm::EDGetTokenT<std::vector<pat::PackedCandidate> > tokenPFCandidates_;
};

TrackFromPackedCandidateProducer::TrackFromPackedCandidateProducer(const edm::ParameterSet& iConfig)
    : tokenPFCandidates_(
          consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidates"))) {
  produces<reco::TrackCollection>();
}

void TrackFromPackedCandidateProducer::fillDescriptions(edm::ConfigurationDescriptions& iDescriptions) {
  edm::ParameterSetDescription desc;
  desc.add<edm::InputTag>("PFCandidates");
  iDescriptions.addWithDefaultLabel(desc);
}

void TrackFromPackedCandidateProducer::produce(edm::StreamID theStreamID,
                                               edm::Event& theEvent,
                                               const edm::EventSetup& setup) const {
  //
  // create empty output collections
  //
  auto outputTColl = std::make_unique<reco::TrackCollection>();
  auto const pfCandidates = theEvent.get(tokenPFCandidates_);
  outputTColl->reserve(pfCandidates.size());

  for (auto const& pf : pfCandidates) {
    if (pf.hasTrackDetails()) {
      const reco::Track& mytrack = pf.pseudoTrack();
      using namespace edm;
      if (isNotFinite(mytrack.pt()) || isNotFinite(mytrack.eta()) || isNotFinite(mytrack.phi()))
        continue;
      outputTColl->push_back(mytrack);
    }
  }
  //put everything in the event
  theEvent.put(std::move(outputTColl));
}
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(TrackFromPackedCandidateProducer);