File indexing completed on 2024-04-06 12:29:50
0001
0002
0003 #include <string>
0004 #include <vector>
0005
0006
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/DataRecord/interface/HBHEDarkeningRecord.h"
0012 #include "CondFormats/HcalObjects/interface/HBHEDarkening.h"
0013 #include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h"
0014 #include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h"
0015 #include "Geometry/HcalCommonData/interface/HcalSimulationConstants.h"
0016 #include "Geometry/Records/interface/HcalSimNumberingRecord.h"
0017 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0018 #include "SimG4CMS/Calo/interface/HCalSD.h"
0019
0020 #include "FWCore/Framework/interface/ConsumesCollector.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/Utilities/interface/ESGetToken.h"
0024 #include "FWCore/PluginManager/interface/ModuleDef.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026
0027 class HcalSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
0028 public:
0029 explicit HcalSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc)
0030 : hdscToken_{cc.esConsumes<edm::Transition::BeginRun>()},
0031 hdrcToken_{cc.esConsumes<edm::Transition::BeginRun>()},
0032 hscsToken_{cc.esConsumes<edm::Transition::BeginRun>()},
0033 hbdkToken_{
0034 cc.esConsumes<HBHEDarkening, HBHEDarkeningRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", "HB"})},
0035 hedkToken_{
0036 cc.esConsumes<HBHEDarkening, HBHEDarkeningRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", "HE"})},
0037 hcalDDSim_{nullptr},
0038 hcalDDRec_{nullptr},
0039 hcalSimConstants_{nullptr},
0040 hbDarkening_{nullptr},
0041 heDarkening_{nullptr} {
0042 edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HCalSD");
0043 agingFlagHB_ = m_HC.getParameter<bool>("HBDarkening");
0044 agingFlagHE_ = m_HC.getParameter<bool>("HEDarkening");
0045 forTBHC_ = m_HC.getUntrackedParameter<bool>("ForTBHCAL", false);
0046 forTBH2_ = m_HC.getUntrackedParameter<bool>("ForTBH2", false);
0047 }
0048
0049 void beginRun(const edm::EventSetup& es) final {
0050 hcalDDSim_ = &es.getData(hdscToken_);
0051 if ((!forTBHC_) && (!forTBH2_))
0052 hcalDDRec_ = &es.getData(hdrcToken_);
0053 edm::ESHandle<HcalSimulationConstants> hscs = es.getHandle(hscsToken_);
0054 if (hscs.isValid())
0055 hcalSimConstants_ = hscs.product();
0056 else
0057 edm::LogWarning("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HcalSimulationConstants";
0058 if (agingFlagHB_) {
0059 edm::ESHandle<HBHEDarkening> hbdark = es.getHandle(hbdkToken_);
0060 if (hbdark.isValid())
0061 hbDarkening_ = hbdark.product();
0062 else
0063 edm::LogVerbatim("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HBDarkening";
0064 }
0065 if (agingFlagHE_) {
0066 edm::ESHandle<HBHEDarkening> hedark = es.getHandle(hedkToken_);
0067 if (hedark.isValid())
0068 heDarkening_ = hedark.product();
0069 else
0070 edm::LogVerbatim("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HEDarkening";
0071 }
0072 }
0073
0074 std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0075 const SensitiveDetectorCatalog& clg,
0076 const edm::ParameterSet& p,
0077 const SimTrackManager* man,
0078 SimActivityRegistry& reg) const final {
0079 auto sd = std::make_unique<HCalSD>(
0080 iname, hcalDDSim_, hcalDDRec_, hcalSimConstants_, hbDarkening_, heDarkening_, clg, p, man);
0081 SimActivityRegistryEnroller::enroll(reg, sd.get());
0082 return sd;
0083 }
0084
0085 private:
0086 const edm::ESGetToken<HcalDDDSimConstants, HcalSimNumberingRecord> hdscToken_;
0087 const edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> hdrcToken_;
0088 const edm::ESGetToken<HcalSimulationConstants, HcalSimNumberingRecord> hscsToken_;
0089 const edm::ESGetToken<HBHEDarkening, HBHEDarkeningRecord> hbdkToken_;
0090 const edm::ESGetToken<HBHEDarkening, HBHEDarkeningRecord> hedkToken_;
0091 const HcalDDDSimConstants* hcalDDSim_;
0092 const HcalDDDRecConstants* hcalDDRec_;
0093 const HcalSimulationConstants* hcalSimConstants_;
0094 const HBHEDarkening* hbDarkening_;
0095 const HBHEDarkening* heDarkening_;
0096 bool agingFlagHB_, agingFlagHE_;
0097 bool forTBHC_, forTBH2_;
0098 };
0099
0100 typedef HCalSD HcalSensitiveDetector;
0101 DEFINE_SENSITIVEDETECTORBUILDER(HcalSensitiveDetectorBuilder, HcalSensitiveDetector);