Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-27 14:07:56

0001 
0002 // system include files
0003 #include <string>
0004 #include <vector>
0005 
0006 // user include files
0007 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h"
0008 #include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h"
0009 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"
0010 
0011 #include "CondFormats/GeometryObjects/interface/EcalSimulationParameters.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 #include "SimG4CMS/Calo/interface/ECalSD.h"
0014 
0015 #include "FWCore/Framework/interface/ConsumesCollector.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Utilities/interface/ESGetToken.h"
0019 #include "FWCore/PluginManager/interface/ModuleDef.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 
0022 class EcalSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
0023 public:
0024   explicit EcalSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc) {
0025     edm::ParameterSet m_EC = p.getParameter<edm::ParameterSet>("ECalSD");
0026     num_ = m_EC.getUntrackedParameter<int>("Detectors");
0027     for (int k = 0; k < num_; ++k)
0028       ecToken_.emplace_back(cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", name_[k]}));
0029   }
0030 
0031   void beginRun(const edm::EventSetup& es) final {
0032     for (const auto& token : ecToken_)
0033       ecpar_.emplace_back(es.getHandle(token));
0034   }
0035 
0036   std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0037                                           const SensitiveDetectorCatalog& clg,
0038                                           const edm::ParameterSet& p,
0039                                           const SimTrackManager* man,
0040                                           SimActivityRegistry& reg) const final {
0041     int k = static_cast<int>(std::find(name_, name_ + num_, iname) - name_);
0042     auto const& par = ((k < num_) && ecpar_[k].isValid()) ? ecpar_[k].product() : nullptr;
0043     auto sd = std::make_unique<ECalSD>(iname, par, clg, p, man);
0044     SimActivityRegistryEnroller::enroll(reg, sd.get());
0045     return sd;
0046   }
0047 
0048 private:
0049   static constexpr unsigned int nameSize_ = 3;
0050   const std::string name_[nameSize_] = {"EcalHitsEB", "EcalHitsEE", "EcalHitsES"};
0051   int num_;
0052   std::vector<edm::ESGetToken<EcalSimulationParameters, IdealGeometryRecord>> ecToken_;
0053   std::vector<edm::ESHandle<EcalSimulationParameters>> ecpar_;
0054 };
0055 
0056 typedef ECalSD EcalSensitiveDetector;
0057 DEFINE_SENSITIVEDETECTORBUILDER(EcalSensitiveDetectorBuilder, EcalSensitiveDetector);