Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-30 22:39:11

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0003 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.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/Framework/interface/stream/EDProducer.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/PluginManager/interface/PluginInfo.h"
0013 #include "FWCore/PluginManager/interface/PluginManager.h"
0014 #include "FWCore/PluginManager/interface/standard.h"
0015 #include "FWCore/Utilities/interface/Algorithms.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitFillDescriptionWorkerFactory.h"
0018 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerBaseClass.h"
0019 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
0020 
0021 class EcalUncalibRecHitProducer : public edm::stream::EDProducer<> {
0022 public:
0023   explicit EcalUncalibRecHitProducer(const edm::ParameterSet& ps);
0024   void produce(edm::Event& evt, const edm::EventSetup& es) override;
0025   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0026 
0027 private:
0028   edm::EDGetTokenT<EBDigiCollection> ebDigiCollectionToken_;
0029   edm::EDGetTokenT<EEDigiCollection> eeDigiCollectionToken_;
0030 
0031   std::string ebHitCollection_;
0032   std::string eeHitCollection_;
0033 
0034   std::unique_ptr<EcalUncalibRecHitWorkerBaseClass> worker_;
0035 };
0036 
0037 EcalUncalibRecHitProducer::EcalUncalibRecHitProducer(const edm::ParameterSet& ps) {
0038   ebHitCollection_ = ps.getParameter<std::string>("EBhitCollection");
0039   eeHitCollection_ = ps.getParameter<std::string>("EEhitCollection");
0040   produces<EBUncalibratedRecHitCollection>(ebHitCollection_);
0041   produces<EEUncalibratedRecHitCollection>(eeHitCollection_);
0042 
0043   ebDigiCollectionToken_ = consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EBdigiCollection"));
0044 
0045   eeDigiCollectionToken_ = consumes<EEDigiCollection>(ps.getParameter<edm::InputTag>("EEdigiCollection"));
0046 
0047   std::string componentType = ps.getParameter<std::string>("algo");
0048   edm::ParameterSet algoConf = ps.getParameter<edm::ParameterSet>("algoPSet");
0049 
0050   edm::ConsumesCollector c{consumesCollector()};
0051   worker_ = EcalUncalibRecHitWorkerFactory::get()->create(componentType, algoConf, c);
0052 }
0053 
0054 void EcalUncalibRecHitProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055   EcalUncalibRecHitFillDescriptionWorkerFactory* factory = EcalUncalibRecHitFillDescriptionWorkerFactory::get();
0056   std::vector<edmplugin::PluginInfo> infos = factory->available();
0057 
0058   {
0059     edm::ParameterSetDescription desc;
0060     desc.add<edm::InputTag>("EBdigiCollection", edm::InputTag("ecalDigis", "ebDigis"));
0061     desc.add<std::string>("EEhitCollection", "EcalUncalibRecHitsEE");
0062     desc.add<edm::InputTag>("EEdigiCollection", edm::InputTag("ecalDigis", "eeDigis"));
0063     desc.add<std::string>("EBhitCollection", "EcalUncalibRecHitsEB");
0064 
0065     auto itInfos = infos.begin();
0066     assert(itInfos != infos.end());
0067 
0068     std::unique_ptr<edm::ParameterDescriptionCases<std::string>> s;
0069     {
0070       std::unique_ptr<EcalUncalibRecHitWorkerBaseClass> tmw(
0071           EcalUncalibRecHitFillDescriptionWorkerFactory::get()->create(itInfos->name_));
0072       s = (itInfos->name_ >>
0073            edm::ParameterDescription<edm::ParameterSetDescription>("algoPSet", tmw->getAlgoDescription(), true));
0074     }
0075     for (++itInfos; itInfos != infos.end(); ++itInfos) {
0076       std::unique_ptr<EcalUncalibRecHitWorkerBaseClass> tmw(
0077           EcalUncalibRecHitFillDescriptionWorkerFactory::get()->create(itInfos->name_));
0078       s = (std::move(s) or itInfos->name_ >> edm::ParameterDescription<edm::ParameterSetDescription>(
0079                                                  "algoPSet", tmw->getAlgoDescription(), true));
0080     }
0081     desc.ifValue(edm::ParameterDescription<std::string>("algo", "EcalUncalibRecHitWorkerMultiFit", true), std::move(s));
0082 
0083     descriptions.addDefault(desc);
0084   }
0085 
0086   for (std::vector<edmplugin::PluginInfo>::const_iterator itInfos = infos.begin(); itInfos != infos.end(); itInfos++) {
0087     std::unique_ptr<EcalUncalibRecHitWorkerBaseClass> fdWorker(
0088         EcalUncalibRecHitFillDescriptionWorkerFactory::get()->create(itInfos->name_));
0089 
0090     edm::ParameterSetDescription desc;
0091     desc.add<edm::InputTag>("EBdigiCollection", edm::InputTag("ecalDigis", "ebDigis"));
0092     desc.add<std::string>("EEhitCollection", "EcalUncalibRecHitsEE");
0093     desc.add<edm::InputTag>("EEdigiCollection", edm::InputTag("ecalDigis", "eeDigis"));
0094     desc.add<std::string>("EBhitCollection", "EcalUncalibRecHitsEB");
0095     desc.add<std::string>("algo", itInfos->name_);
0096     desc.add<edm::ParameterSetDescription>("algoPSet", fdWorker->getAlgoDescription());
0097 
0098     std::string algoName = itInfos->name_.substr(itInfos->name_.find("Worker") + 6, itInfos->name_.length());
0099     descriptions.add("ecal" + algoName + "UncalibRecHit", desc);
0100   }
0101 }
0102 
0103 void EcalUncalibRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0104   using namespace edm;
0105 
0106   Handle<EBDigiCollection> pEBDigis;
0107   Handle<EEDigiCollection> pEEDigis;
0108 
0109   const EBDigiCollection* ebDigis = nullptr;
0110   const EEDigiCollection* eeDigis = nullptr;
0111 
0112   evt.getByToken(ebDigiCollectionToken_, pEBDigis);
0113   ebDigis = pEBDigis.product();  // get a ptr to the produc
0114   edm::LogInfo("EcalUncalibRecHitInfo") << "total # ebDigis: " << ebDigis->size();
0115 
0116   evt.getByToken(eeDigiCollectionToken_, pEEDigis);
0117   eeDigis = pEEDigis.product();  // get a ptr to the product
0118   edm::LogInfo("EcalUncalibRecHitInfo") << "total # eeDigis: " << eeDigis->size();
0119 
0120   // tranparently get things from event setup
0121   worker_->set(es);
0122   worker_->set(evt);
0123 
0124   // prepare output
0125   auto ebUncalibRechits = std::make_unique<EBUncalibratedRecHitCollection>();
0126   auto eeUncalibRechits = std::make_unique<EEUncalibratedRecHitCollection>();
0127 
0128   // loop over EB digis
0129   if (ebDigis)
0130     worker_->run(evt, *ebDigis, *ebUncalibRechits);
0131 
0132   // loop over EB digis
0133   if (eeDigis)
0134     worker_->run(evt, *eeDigis, *eeUncalibRechits);
0135 
0136   // put the collection of recunstructed hits in the event
0137   evt.put(std::move(ebUncalibRechits), ebHitCollection_);
0138   evt.put(std::move(eeUncalibRechits), eeHitCollection_);
0139 }
0140 
0141 #include "FWCore/Framework/interface/MakerMacros.h"
0142 DEFINE_FWK_MODULE(EcalUncalibRecHitProducer);