File indexing completed on 2024-04-06 12:33:20
0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007
0008 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0009 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
0010
0011 class CrossingFramePSimHitToPSimHitsConverter : public edm::global::EDProducer<> {
0012 public:
0013 CrossingFramePSimHitToPSimHitsConverter(const edm::ParameterSet& iConfig);
0014
0015 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0016
0017 void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0018
0019 private:
0020 struct InputInfo {
0021 using Token = edm::EDGetTokenT<CrossingFrame<PSimHit>>;
0022 InputInfo(Token t, const std::string& i) : token(t), instance(i) {}
0023 Token token;
0024 std::string instance;
0025 };
0026
0027 std::vector<InputInfo> input_;
0028 };
0029
0030 CrossingFramePSimHitToPSimHitsConverter::CrossingFramePSimHitToPSimHitsConverter(const edm::ParameterSet& iConfig) {
0031 auto src = iConfig.getParameter<std::vector<edm::InputTag>>("src");
0032 input_.reserve(src.size());
0033 for (const auto& tag : src) {
0034 input_.emplace_back(consumes<CrossingFrame<PSimHit>>(tag), tag.instance());
0035 produces<std::vector<PSimHit>>(input_.back().instance);
0036 }
0037 }
0038
0039 void CrossingFramePSimHitToPSimHitsConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0040 edm::ParameterSetDescription desc;
0041 desc.add<std::vector<edm::InputTag>>("src", std::vector<edm::InputTag>());
0042 descriptions.add("crossingFramePSimHitToPSimHits", desc);
0043 }
0044
0045 void CrossingFramePSimHitToPSimHitsConverter::produce(edm::StreamID,
0046 edm::Event& iEvent,
0047 const edm::EventSetup& iSetup) const {
0048 for (const auto& input : input_) {
0049 edm::Handle<CrossingFrame<PSimHit>> hframe;
0050 iEvent.getByToken(input.token, hframe);
0051 const auto& frame = *hframe;
0052 const auto& signalHits = frame.getSignal();
0053 const auto& pileupHits = frame.getPileups();
0054
0055 auto output = std::make_unique<std::vector<PSimHit>>();
0056 output->reserve(signalHits.size() + pileupHits.size());
0057 for (const auto& ptr : signalHits)
0058 output->emplace_back(*ptr);
0059 for (const auto& ptr : pileupHits)
0060 output->emplace_back(*ptr);
0061 iEvent.put(std::move(output), input.instance);
0062 }
0063 }
0064
0065
0066 DEFINE_FWK_MODULE(CrossingFramePSimHitToPSimHitsConverter);