Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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