Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:49

0001 #include "FWCore/Framework/interface/stream/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 /// \class ME0PadDigiProducer
0023 
0024 class ME0PadDigiProducer : public edm::stream::EDProducer<> {
0025 public:
0026   explicit ME0PadDigiProducer(const edm::ParameterSet& ps);
0027 
0028   ~ME0PadDigiProducer() override;
0029 
0030   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0031 
0032   void produce(edm::Event&, const edm::EventSetup&) override;
0033 
0034 private:
0035   void buildPads(const ME0DigiCollection& digis, ME0PadDigiCollection& out_pads) const;
0036 
0037   /// Name of input digi Collection
0038   edm::EDGetTokenT<ME0DigiCollection> digi_token_;
0039   edm::InputTag digis_;
0040   edm::ESGetToken<ME0Geometry, MuonGeometryRecord> geom_token_;
0041 
0042   const ME0Geometry* geometry_;
0043 };
0044 
0045 ME0PadDigiProducer::ME0PadDigiProducer(const edm::ParameterSet& ps) : geometry_(nullptr) {
0046   digis_ = ps.getParameter<edm::InputTag>("InputCollection");
0047 
0048   digi_token_ = consumes<ME0DigiCollection>(digis_);
0049   geom_token_ = esConsumes<ME0Geometry, MuonGeometryRecord, edm::Transition::BeginRun>();
0050 
0051   produces<ME0PadDigiCollection>();
0052 }
0053 
0054 ME0PadDigiProducer::~ME0PadDigiProducer() {}
0055 
0056 void ME0PadDigiProducer::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
0057   edm::ESHandle<ME0Geometry> hGeom = eventSetup.getHandle(geom_token_);
0058   geometry_ = &*hGeom;
0059 }
0060 
0061 void ME0PadDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0062   edm::Handle<ME0DigiCollection> hdigis;
0063   e.getByToken(digi_token_, hdigis);
0064 
0065   // Create empty output
0066   std::unique_ptr<ME0PadDigiCollection> pPads(new ME0PadDigiCollection());
0067 
0068   // build the pads
0069   buildPads(*(hdigis.product()), *pPads);
0070 
0071   // store them in the event
0072   e.put(std::move(pPads));
0073 }
0074 
0075 void ME0PadDigiProducer::buildPads(const ME0DigiCollection& det_digis, ME0PadDigiCollection& out_pads) const {
0076   for (const auto& p : geometry_->etaPartitions()) {
0077     // set of <pad, bx> pairs, sorted first by pad then by bx
0078     std::set<std::pair<int, int> > proto_pads;
0079 
0080     // walk over digis in this partition,
0081     // and stuff them into a set of unique pads (equivalent of OR operation)
0082     auto digis = det_digis.get(p->id());
0083     for (auto d = digis.first; d != digis.second; ++d) {
0084       int pad_num = 1 + static_cast<int>(p->padOfStrip(d->strip()));
0085       proto_pads.emplace(pad_num, d->bx());
0086     }
0087 
0088     // fill the output collections
0089     for (const auto& d : proto_pads) {
0090       ME0PadDigi pad_digi(d.first, d.second);
0091       out_pads.insertDigi(p->id(), pad_digi);
0092     }
0093   }
0094 }
0095 
0096 DEFINE_FWK_MODULE(ME0PadDigiProducer);