Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:51

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 "Geometry/HGCalTBCommonData/interface/HGCalTBDDDConstants.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 #include "SimG4CMS/Calo/interface/HGCSD.h"
0014 
0015 #include "FWCore/Framework/interface/ConsumesCollector.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.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 HGCSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
0023 public:
0024   explicit HGCSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc) {
0025     edm::ParameterSet m_HGC = p.getParameter<edm::ParameterSet>("HGCSD");
0026     num_ = m_HGC.getUntrackedParameter<int>("Detectors");
0027     for (int k = 0; k < num_; ++k) {
0028       hgcToken_.emplace_back(cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", name0_[k]}));
0029       edm::LogVerbatim("HGCSim") << "HGCSensitiveDetectorBuilder::Initailize Token[" << k << "] for " << name0_[k];
0030     }
0031   }
0032 
0033   void beginRun(const edm::EventSetup& es) final {
0034     for (const auto& token : hgcToken_)
0035       hgcons_.emplace_back(es.getHandle(token));
0036   }
0037 
0038   std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0039                                           const SensitiveDetectorCatalog& clg,
0040                                           const edm::ParameterSet& p,
0041                                           const SimTrackManager* man,
0042                                           SimActivityRegistry& reg) const final {
0043     const HGCalTBDDDConstants* hgc = nullptr;
0044     for (int k = 0; k < num_; ++k) {
0045       if (iname.find(name1_[k]) != std::string::npos) {
0046         if (hgcons_[k].isValid())
0047           hgc = hgcons_[k].product();
0048         break;
0049       }
0050     }
0051     auto sd = std::make_unique<HGCSD>(iname, hgc, clg, p, man);
0052     SimActivityRegistryEnroller::enroll(reg, sd.get());
0053     return sd;
0054   }
0055 
0056 private:
0057   static constexpr unsigned int nameSize_ = 3;
0058   const std::string name0_[nameSize_] = {"HGCalEESensitive", "HGCalHESiliconSensitive", "HGCalHEScintillatorSensitive"};
0059   const std::string name1_[nameSize_] = {"HitsEE", "HitsHEfront", "HitsHEback"};
0060   int num_;
0061   std::vector<edm::ESGetToken<HGCalTBDDDConstants, IdealGeometryRecord>> hgcToken_;
0062   std::vector<edm::ESHandle<HGCalTBDDDConstants>> hgcons_;
0063 };
0064 
0065 typedef HGCSD HGCSensitiveDetector;
0066 DEFINE_SENSITIVEDETECTORBUILDER(HGCSensitiveDetectorBuilder, HGCSensitiveDetector);