Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:45

0001 // ESRecHitProducer author : Chia-Ming, Kuo
0002 
0003 #include "DataFormats/Common/interface/EDCollection.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0006 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0007 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/stream/EDProducer.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "RecoLocalCalo/EcalRecProducers/interface/ESRecHitWorkerFactory.h"
0013 
0014 #include "ESRecHitWorker.h"
0015 
0016 class ESRecHitProducer : public edm::stream::EDProducer<> {
0017 public:
0018   explicit ESRecHitProducer(const edm::ParameterSet& ps);
0019   void produce(edm::Event& e, const edm::EventSetup& es) override;
0020 
0021 private:
0022   const edm::EDGetTokenT<ESDigiCollection> digiToken_;
0023   const std::string rechitCollection_;  // secondary name to be given to collection of hits
0024 
0025   std::unique_ptr<ESRecHitWorkerBaseClass> worker_;
0026 };
0027 
0028 ESRecHitProducer::ESRecHitProducer(edm::ParameterSet const& ps)
0029     : digiToken_(consumes<ESDigiCollection>(ps.getParameter<edm::InputTag>("ESdigiCollection"))),
0030       rechitCollection_(ps.getParameter<std::string>("ESrechitCollection")),
0031       worker_{ESRecHitWorkerFactory::get()->create(ps.getParameter<std::string>("algo"), ps, consumesCollector())} {
0032   produces<ESRecHitCollection>(rechitCollection_);
0033 }
0034 
0035 void ESRecHitProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0036   edm::Handle<ESDigiCollection> digiHandle;
0037   const ESDigiCollection* digi = nullptr;
0038   e.getByToken(digiToken_, digiHandle);
0039 
0040   digi = digiHandle.product();
0041   LogDebug("ESRecHitInfo") << "total # ESdigis: " << digi->size();
0042 
0043   // Create empty output
0044   auto rec = std::make_unique<ESRecHitCollection>();
0045 
0046   if (digi) {
0047     rec->reserve(digi->size());
0048 
0049     worker_->set(es);
0050 
0051     // run the algorithm
0052     for (ESDigiCollection::const_iterator i(digi->begin()); i != digi->end(); i++) {
0053       worker_->run(i, *rec);
0054     }
0055   }
0056 
0057   e.put(std::move(rec), rechitCollection_);
0058 }
0059 
0060 #include "FWCore/Framework/interface/MakerMacros.h"
0061 DEFINE_FWK_MODULE(ESRecHitProducer);