File indexing completed on 2024-04-06 12:20:28
0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Utilities/interface/ESGetToken.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "DataFormats/GEMDigi/interface/ME0DigiCollection.h"
0015 #include "DataFormats/GEMDigi/interface/ME0PadDigiCollection.h"
0016
0017 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0018 #include "Geometry/GEMGeometry/interface/ME0Geometry.h"
0019
0020 #include <set>
0021
0022
0023
0024 class ME0PadDigiProducer : public edm::global::EDProducer<> {
0025 public:
0026 explicit ME0PadDigiProducer(const edm::ParameterSet& ps);
0027
0028 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0029
0030 private:
0031 ME0PadDigiCollection buildPads(const ME0DigiCollection& digis, const ME0Geometry& geometry) const;
0032
0033
0034 edm::EDGetTokenT<ME0DigiCollection> digi_token_;
0035 edm::InputTag digis_;
0036 edm::ESGetToken<ME0Geometry, MuonGeometryRecord> geom_token_;
0037 edm::EDPutTokenT<ME0PadDigiCollection> put_token_;
0038 };
0039
0040 ME0PadDigiProducer::ME0PadDigiProducer(const edm::ParameterSet& ps) {
0041 digis_ = ps.getParameter<edm::InputTag>("InputCollection");
0042
0043 digi_token_ = consumes<ME0DigiCollection>(digis_);
0044 geom_token_ = esConsumes<ME0Geometry, MuonGeometryRecord>();
0045
0046 put_token_ = produces<ME0PadDigiCollection>();
0047 }
0048
0049 void ME0PadDigiProducer::produce(edm::StreamID, edm::Event& e, const edm::EventSetup& eventSetup) const {
0050 auto const& geometry = eventSetup.getData(geom_token_);
0051
0052 edm::Handle<ME0DigiCollection> hdigis;
0053 e.getByToken(digi_token_, hdigis);
0054
0055
0056 e.emplace(put_token_, buildPads(*(hdigis.product()), geometry));
0057 }
0058
0059 ME0PadDigiCollection ME0PadDigiProducer::buildPads(const ME0DigiCollection& det_digis,
0060 const ME0Geometry& geometry) const {
0061 ME0PadDigiCollection out_pads;
0062 for (const auto& p : geometry.etaPartitions()) {
0063
0064 std::set<std::pair<int, int> > proto_pads;
0065
0066
0067
0068 auto digis = det_digis.get(p->id());
0069 for (auto d = digis.first; d != digis.second; ++d) {
0070 int pad_num = 1 + static_cast<int>(p->padOfStrip(d->strip()));
0071 proto_pads.emplace(pad_num, d->bx());
0072 }
0073
0074
0075 for (const auto& d : proto_pads) {
0076 ME0PadDigi pad_digi(d.first, d.second);
0077 out_pads.insertDigi(p->id(), pad_digi);
0078 }
0079 }
0080 return out_pads;
0081 }
0082
0083 DEFINE_FWK_MODULE(ME0PadDigiProducer);