File indexing completed on 2024-04-06 12:24:05
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/Utilities/interface/InputTag.h"
0006 #include "FWCore/Framework/interface/global/EDProducer.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008
0009 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0010
0011 #include <vector>
0012
0013 class PackedCandidatesTrackLiteModifier : public edm::global::EDProducer<> {
0014 public:
0015 explicit PackedCandidatesTrackLiteModifier(const edm::ParameterSet &);
0016 ~PackedCandidatesTrackLiteModifier() override = default;
0017
0018 void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0019 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0020
0021 private:
0022 const edm::EDGetTokenT<pat::PackedCandidateCollection> inputCandidates_;
0023 const edm::EDPutTokenT<pat::PackedCandidateCollection> outputCandidates_;
0024 const unsigned int covSchema_;
0025 const unsigned int covVersion_;
0026 const unsigned int nHits_;
0027 const unsigned int nPixelHits_;
0028 };
0029
0030
0031 PackedCandidatesTrackLiteModifier::PackedCandidatesTrackLiteModifier(const edm::ParameterSet &iConfig)
0032 : inputCandidates_(
0033 consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("inputCandidates"))),
0034 outputCandidates_(produces<pat::PackedCandidateCollection>("")),
0035 covSchema_(iConfig.getParameter<unsigned int>("covSchema")),
0036 covVersion_(iConfig.getParameter<unsigned int>("covVersion")),
0037 nHits_(iConfig.getParameter<unsigned int>("nHits")),
0038 nPixelHits_(iConfig.getParameter<unsigned int>("nPixelHits")) {}
0039
0040 void PackedCandidatesTrackLiteModifier::produce(edm::StreamID,
0041 edm::Event &iEvent,
0042 const edm::EventSetup &iSetup) const {
0043 auto const &packedCandidates = iEvent.get(inputCandidates_);
0044
0045 pat::PackedCandidateCollection output;
0046 output.reserve(packedCandidates.size());
0047 for (auto const &cand : packedCandidates) {
0048 output.push_back(pat::PackedCandidate(cand));
0049
0050 if (!output.back().hasTrackDetails() && output.back().fromTrackCandidate())
0051 output.back().setTrackPropertiesLite(covSchema_, covVersion_, nHits_, nPixelHits_);
0052 }
0053
0054 iEvent.emplace(outputCandidates_, std::move(output));
0055 };
0056
0057 void PackedCandidatesTrackLiteModifier::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0058 edm::ParameterSetDescription desc;
0059
0060 desc.add<edm::InputTag>("inputCandidates", edm::InputTag("packedPFCandidates"));
0061 desc.add<unsigned int>("covSchema", 1025);
0062 desc.add<unsigned int>("covVersion", 1);
0063 desc.add<unsigned int>("nHits", 8);
0064 desc.add<unsigned int>("nPixelHits", 3);
0065
0066 descriptions.addWithDefaultLabel(desc);
0067 }
0068
0069
0070 #include "FWCore/Framework/interface/MakerMacros.h"
0071 DEFINE_FWK_MODULE(PackedCandidatesTrackLiteModifier);