Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:10

0001 // -*- C++ -*-
0002 //
0003 // Package:     SimG4CMS/Muon
0004 // Class  :     MuonSensitiveDetectorBuilder
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Christopher Jones
0010 //         Created:  Fri, 04 Jun 2021 18:18:17 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h"
0017 #include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h"
0018 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"
0019 
0020 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0021 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0022 
0023 #include "SimG4CMS/Muon/interface/MuonSensitiveDetector.h"
0024 
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 #include "FWCore/Framework/interface/EventSetup.h"
0027 #include "FWCore/Framework/interface/ConsumesCollector.h"
0028 #include "FWCore/Utilities/interface/ESGetToken.h"
0029 #include "FWCore/PluginManager/interface/ModuleDef.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 class MuonSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
0033 public:
0034   explicit MuonSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc)
0035       : offmap_{nullptr},
0036         mdc_{nullptr},
0037         offsetToken_{cc.esConsumes<edm::Transition::BeginRun>()},
0038         geomConstantsToken_{cc.esConsumes<edm::Transition::BeginRun>()} {}
0039 
0040   void beginRun(const edm::EventSetup& es) final {
0041     edm::ESHandle<MuonOffsetMap> mom = es.getHandle(offsetToken_);
0042     offmap_ = (mom.isValid()) ? mom.product() : nullptr;
0043     edm::LogVerbatim("MuonSim") << "Finds the offset map at " << offmap_;
0044     mdc_ = &es.getData(geomConstantsToken_);
0045   }
0046 
0047   std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0048                                           const SensitiveDetectorCatalog& clg,
0049                                           const edm::ParameterSet& p,
0050                                           const SimTrackManager* man,
0051                                           SimActivityRegistry& reg) const final {
0052     auto sd = std::make_unique<MuonSensitiveDetector>(iname, offmap_, *mdc_, clg, p, man);
0053     SimActivityRegistryEnroller::enroll(reg, sd.get());
0054     return sd;
0055   }
0056 
0057 private:
0058   const MuonOffsetMap* offmap_;
0059   const MuonGeometryConstants* mdc_;
0060   const edm::ESGetToken<MuonOffsetMap, IdealGeometryRecord> offsetToken_;
0061   const edm::ESGetToken<MuonGeometryConstants, IdealGeometryRecord> geomConstantsToken_;
0062   double ePersistentCutGeV_;
0063   bool allMuonsPersistent_;
0064   bool printHits_;
0065   bool dd4hep_;
0066 };
0067 
0068 DEFINE_SENSITIVEDETECTORBUILDER(MuonSensitiveDetectorBuilder, MuonSensitiveDetector);