File indexing completed on 2024-04-06 12:29:58
0001
0002
0003
0004 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h"
0005 #include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h"
0006 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"
0007
0008 #include "DetectorDescription/Core/interface/DDCompactView.h"
0009 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0010 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0011 #include "SimG4CMS/CherenkovAnalysis/interface/DreamSD.h"
0012
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Utilities/interface/ESGetToken.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/PluginManager/interface/ModuleDef.h"
0019
0020 class DreamSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
0021 public:
0022 explicit DreamSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc) {
0023 fromDD4hep_ = p.getParameter<bool>("g4GeometryDD4hepSource");
0024 if (fromDD4hep_)
0025 cpvTokenDD4hep_ = cc.esConsumes<edm::Transition::BeginRun>();
0026 else
0027 cpvTokenDDD_ = cc.esConsumes<edm::Transition::BeginRun>();
0028 edm::LogVerbatim("EcalSim") << "DreamSensitiveDetectorBuilder called with dd4hep flag " << fromDD4hep_;
0029 }
0030
0031 void beginRun(const edm::EventSetup& es) final {
0032 if (fromDD4hep_) {
0033 cpvDD4hep_ = &es.getData(cpvTokenDD4hep_);
0034 } else {
0035 cpvDDD_ = &es.getData(cpvTokenDDD_);
0036 }
0037 }
0038
0039 std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0040 const SensitiveDetectorCatalog& clg,
0041 const edm::ParameterSet& p,
0042 const SimTrackManager* man,
0043 SimActivityRegistry& reg) const final {
0044 auto sd = std::make_unique<DreamSD>(iname, cpvDDD_, cpvDD4hep_, clg, p, man);
0045 SimActivityRegistryEnroller::enroll(reg, sd.get());
0046 return sd;
0047 }
0048
0049 private:
0050 bool fromDD4hep_;
0051 edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
0052 edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4hep_;
0053 const DDCompactView* cpvDDD_;
0054 const cms::DDCompactView* cpvDD4hep_;
0055 };
0056
0057 typedef DreamSD DreamSensitiveDetector;
0058 DEFINE_SENSITIVEDETECTORBUILDER(DreamSensitiveDetectorBuilder, DreamSensitiveDetector);