diff --git a/SimG4CMS/Calo/interface/HCalSD.h b/SimG4CMS/Calo/interface/HCalSD.h index 339d562d4b9d2..4ff2a8bf86fc2 100644 --- a/SimG4CMS/Calo/interface/HCalSD.h +++ b/SimG4CMS/Calo/interface/HCalSD.h @@ -20,9 +20,9 @@ #include "SimG4Core/Notification/interface/BeginOfJob.h" #include "Geometry/HcalCommonData/interface/HcalNumberingFromDDD.h" #include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h" +#include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h" #include "Geometry/HcalCommonData/interface/HcalSimulationConstants.h" #include "Geometry/Records/interface/HcalParametersRcd.h" -#include "FWCore/Utilities/interface/ESGetToken.h" #include "G4String.hh" #include @@ -38,7 +38,11 @@ class TH1F; class HCalSD : public CaloSD, public Observer { public: HCalSD(const std::string&, - const edm::EventSetup&, + const HcalDDDSimConstants*, + const HcalDDDRecConstants*, + const HcalSimulationConstants*, + const HBHEDarkening*, + const HBHEDarkening*, const SensitiveDetectorCatalog&, edm::ParameterSet const&, const SimTrackManager*); diff --git a/SimG4CMS/Calo/interface/HcalTestNS.h b/SimG4CMS/Calo/interface/HcalTestNS.h index 53a07711d4cf3..35c4aa0be7033 100644 --- a/SimG4CMS/Calo/interface/HcalTestNS.h +++ b/SimG4CMS/Calo/interface/HcalTestNS.h @@ -1,13 +1,11 @@ #ifndef SimG4CMS_HcalTestNS_h #define SimG4CMS_HcalTestNS_h -#include "FWCore/Framework/interface/EventSetup.h" -#include "Geometry/HcalCommonData/interface/HcalNumberingFromDDD.h" #include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h" class HcalTestNS { public: - HcalTestNS(const edm::EventSetup*); + HcalTestNS(const HcalDDDRecConstants*); virtual ~HcalTestNS(); bool compare(HcalNumberingFromDDD::HcalID const&, uint32_t const&); diff --git a/SimG4CMS/Calo/src/CaloTrkProcessingBuilder.cc b/SimG4CMS/Calo/plugins/CaloTrkProcessingBuilder.cc similarity index 98% rename from SimG4CMS/Calo/src/CaloTrkProcessingBuilder.cc rename to SimG4CMS/Calo/plugins/CaloTrkProcessingBuilder.cc index 074bc59ae56b6..5a3d454618c05 100644 --- a/SimG4CMS/Calo/src/CaloTrkProcessingBuilder.cc +++ b/SimG4CMS/Calo/plugins/CaloTrkProcessingBuilder.cc @@ -7,7 +7,7 @@ // [Notes on implementation] // // Original Author: Sunanda Banerjee -// Created: Fri, 12 Jun 2021 23:18:17 GMT +// Created: Tue, 12 Jul 2021 23:18:17 GMT // // system include files diff --git a/SimG4CMS/Calo/plugins/HcalSensitiveDetectorBuilder.cc b/SimG4CMS/Calo/plugins/HcalSensitiveDetectorBuilder.cc new file mode 100644 index 0000000000000..3b277bf1eed0e --- /dev/null +++ b/SimG4CMS/Calo/plugins/HcalSensitiveDetectorBuilder.cc @@ -0,0 +1,89 @@ + +// system include files +#include +#include + +// user include files +#include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h" +#include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h" +#include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h" + +#include "CondFormats/DataRecord/interface/HBHEDarkeningRecord.h" +#include "CondFormats/HcalObjects/interface/HBHEDarkening.h" +#include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h" +#include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h" +#include "Geometry/HcalCommonData/interface/HcalSimulationConstants.h" +#include "Geometry/Records/interface/HcalSimNumberingRecord.h" +#include "Geometry/Records/interface/HcalRecNumberingRecord.h" +#include "SimG4CMS/Calo/interface/HCalSD.h" + +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/ESGetToken.h" +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +class HcalSensitiveDetectorBuilder : public SensitiveDetectorMakerBase { +public: + explicit HcalSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc) + : hdscToken_{cc.esConsumes()}, hdrcToken_{cc.esConsumes()}, hscsToken_{cc.esConsumes()}, hbdkToken_{cc.esConsumes(edm::ESInputTag{"","HB"})}, hedkToken_{cc.esConsumes(edm::ESInputTag{"","HE"})}, hcalDDSim_{nullptr}, hcalDDRec_{nullptr}, hcalSimConstants_{nullptr}, hbDarkening_{nullptr}, heDarkening_{nullptr} { + edm::ParameterSet m_HC = p.getParameter("HCalSD"); + agingFlagHB_ = m_HC.getParameter("HBDarkening"); + agingFlagHE_ = m_HC.getParameter("HEDarkening"); + forTBHC_ = m_HC.getUntrackedParameter("ForTBHCAL", false); + forTBH2_ = m_HC.getUntrackedParameter("ForTBH2", false); +} + + void beginRun(const edm::EventSetup& es) final { + hcalDDSim_ = &es.getData(hdscToken_); + if ((!forTBHC_) && (!forTBH2_)) + hcalDDRec_ = &es.getData(hdrcToken_); + edm::ESHandle hscs = es.getHandle(hscsToken_); + if (hscs.isValid()) + hcalSimConstants_ = hscs.product(); + else + edm::LogWarning("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HcalSimulationConstants"; + if (agingFlagHB_) { + edm::ESHandle hbdark = es.getHandle(hbdkToken_); + if (hbdark.isValid()) + hbDarkening_ = hbdark.product(); + else + edm::LogVerbatim("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HBDarkening"; + } + if (agingFlagHE_) { + edm::ESHandle hedark = es.getHandle(hedkToken_); + if (hedark.isValid()) + heDarkening_ = hedark.product(); + else + edm::LogVerbatim("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HEDarkening"; + } + } + + std::unique_ptr make(const std::string& iname, + const SensitiveDetectorCatalog& clg, + const edm::ParameterSet& p, + const SimTrackManager* man, + SimActivityRegistry& reg) const final { + auto sd = std::make_unique(iname, hcalDDSim_, hcalDDRec_, hcalSimConstants_, hbDarkening_, heDarkening_, clg, p, man); + SimActivityRegistryEnroller::enroll(reg, sd.get()); + return sd; + } + +private: + const edm::ESGetToken hdscToken_; + const edm::ESGetToken hdrcToken_; + const edm::ESGetToken hscsToken_; + const edm::ESGetToken hbdkToken_; + const edm::ESGetToken hedkToken_; + const HcalDDDSimConstants* hcalDDSim_; + const HcalDDDRecConstants* hcalDDRec_; + const HcalSimulationConstants* hcalSimConstants_; + const HBHEDarkening* hbDarkening_; + const HBHEDarkening* heDarkening_; + bool agingFlagHB_, agingFlagHE_; + bool forTBHC_, forTBH2_; +}; + +typedef HCalSD HcalSensitiveDetector; +DEFINE_SENSITIVEDETECTORBUILDER(HcalSensitiveDetectorBuilder, HcalSensitiveDetector); diff --git a/SimG4CMS/Calo/plugins/module.cc b/SimG4CMS/Calo/plugins/module.cc index 72fc32b2fbd90..06a08bb6b8067 100644 --- a/SimG4CMS/Calo/plugins/module.cc +++ b/SimG4CMS/Calo/plugins/module.cc @@ -1,5 +1,4 @@ #include "SimG4CMS/Calo/interface/ECalSD.h" -#include "SimG4CMS/Calo/interface/HCalSD.h" #include "SimG4CMS/Calo/interface/HGCSD.h" #include "SimG4CMS/Calo/interface/HGCalSD.h" #include "SimG4CMS/Calo/interface/HGCScintSD.h" @@ -12,8 +11,6 @@ typedef ECalSD EcalSensitiveDetector; DEFINE_SENSITIVEDETECTOR(EcalSensitiveDetector); -typedef HCalSD HcalSensitiveDetector; -DEFINE_SENSITIVEDETECTOR(HcalSensitiveDetector); typedef HGCSD HGCSensitiveDetector; DEFINE_SENSITIVEDETECTOR(HGCSensitiveDetector); typedef HGCalSD HGCalSensitiveDetector; diff --git a/SimG4CMS/Calo/src/HCalSD.cc b/SimG4CMS/Calo/src/HCalSD.cc index f3566a4b229a7..e55d31e95e3d6 100644 --- a/SimG4CMS/Calo/src/HCalSD.cc +++ b/SimG4CMS/Calo/src/HCalSD.cc @@ -11,15 +11,10 @@ #include "SimG4Core/Notification/interface/G4TrackToParticleID.h" #include "DataFormats/HcalDetId/interface/HcalDetId.h" -#include "Geometry/Records/interface/HcalSimNumberingRecord.h" #include "CondFormats/GeometryObjects/interface/HcalSimulationParameters.h" -#include "FWCore/Framework/interface/ESTransientHandle.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Utilities/interface/Exception.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "CommonTools/UtilAlgos/interface/TFileService.h" -#include "CondFormats/DataRecord/interface/HBHEDarkeningRecord.h" #include "G4LogicalVolumeStore.hh" #include "G4LogicalVolume.hh" @@ -45,7 +40,11 @@ #endif HCalSD::HCalSD(const std::string& name, - const edm::EventSetup& es, + const HcalDDDSimConstants* hcns, + const HcalDDDRecConstants* hcnr, + const HcalSimulationConstants* hscs, + const HBHEDarkening* hbd, + const HBHEDarkening* hed, const SensitiveDetectorCatalog& clg, edm::ParameterSet const& p, const SimTrackManager* manager) @@ -55,10 +54,10 @@ HCalSD::HCalSD(const std::string& name, manager, (float)(p.getParameter("HCalSD").getParameter("TimeSliceUnit")), p.getParameter("HCalSD").getParameter("IgnoreTrackID")), - hcalConstants_(nullptr), - hcalSimConstants_(nullptr), - m_HBDarkening(nullptr), - m_HEDarkening(nullptr), + hcalConstants_(hcns), + hcalSimConstants_(hscs), + m_HBDarkening(hbd), + m_HEDarkening(hed), isHF(false), weight_(1.0), depth_(1) { @@ -135,28 +134,9 @@ HCalSD::HCalSD(const std::string& name, << "Application of Fiducial Cut " << applyFidCut << "Flag for test number|neutral density filter " << testNumber << " " << neutralDensity; - // Get pointers to HcalDDDConstant and HcalSimulationParameters - edm::ESHandle hdc; - es.get().get(hdc); - if (hdc.isValid()) { - hcalConstants_ = hdc.product(); - } else { - edm::LogError("HcalSim") << "HCalSD : Cannot find HcalDDDSimConstant"; - throw cms::Exception("Unknown", "HCalSD") << "Cannot find HcalDDDSimConstant\n"; - } if (forTBHC) { useHF = false; matNames.emplace_back("Scintillator"); - } else { - edm::ESHandle hdsc; - es.get().get(hdsc); - if (hdsc.isValid()) { - hcalSimConstants_ = hdsc.product(); - matNames = hcalSimConstants_->hcalsimpar()->hcalMaterialNames_; - } else { - edm::LogError("HcalSim") << "HCalSD : Cannot find HcalDDDSimulationConstant"; - throw cms::Exception("Unknown", "HCalSD") << "Cannot find HcalDDDSimulationConstant\n"; - } } HcalNumberingScheme* scheme; @@ -263,18 +243,7 @@ HCalSD::HCalSD(const std::string& name, //Test Hcal Numbering Scheme if (testNS_) - m_HcalTestNS = std::make_unique(&es); - - if (agingFlagHB) { - edm::ESHandle hdark; - es.get().get("HB", hdark); - m_HBDarkening = &*hdark; - } - if (agingFlagHE) { - edm::ESHandle hdark; - es.get().get("HE", hdark); - m_HEDarkening = &*hdark; - } + m_HcalTestNS = std::make_unique(hcnr); for (int i = 0; i < 9; ++i) { hit_[i] = time_[i] = dist_[i] = nullptr; @@ -506,7 +475,7 @@ double HCalSD::getEnergyDeposit(const G4Step* aStep) { weight_ = layerWeight(det + 2, hitPoint, depth_, lay); } - if (m_HBDarkening && det == 1) { + if (agingFlagHB && m_HBDarkening && det == 1) { double dweight = m_HBDarkening->degradation(deliveredLumi, ieta, lay); weight_ *= dweight; #ifdef EDM_ML_DEBUG @@ -515,7 +484,7 @@ double HCalSD::getEnergyDeposit(const G4Step* aStep) { #endif } - if (m_HEDarkening && det == 2) { + if (agingFlagHE && m_HEDarkening && det == 2) { double dweight = m_HEDarkening->degradation(deliveredLumi, ieta, lay); weight_ *= dweight; #ifdef EDM_ML_DEBUG diff --git a/SimG4CMS/Calo/src/HcalTestNS.cc b/SimG4CMS/Calo/src/HcalTestNS.cc index 7747021010cc7..ec78ecb55e26a 100644 --- a/SimG4CMS/Calo/src/HcalTestNS.cc +++ b/SimG4CMS/Calo/src/HcalTestNS.cc @@ -1,23 +1,12 @@ #include "DataFormats/HcalDetId/interface/HcalDetId.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "Geometry/HcalCommonData/interface/HcalHitRelabeller.h" -#include "Geometry/Records/interface/HcalRecNumberingRecord.h" #include "SimG4CMS/Calo/interface/HcalNumberingScheme.h" #include "SimG4CMS/Calo/interface/HcalTestNumberingScheme.h" #include "SimG4CMS/Calo/interface/HcalTestNS.h" //#define EDM_ML_DEBUG -HcalTestNS::HcalTestNS(const edm::EventSetup* iSetup) { - edm::ESHandle hdc; - iSetup->get().get(hdc); - if (hdc.isValid()) { - hcons_ = hdc.product(); - } else { - edm::LogError("HcalSim") << "HcalTestNS : Cannot find HcalDDDRecConstant"; - hcons_ = nullptr; - } -} +HcalTestNS::HcalTestNS(const HcalDDDRecConstants* hcons) : hcons_(hcons) { } HcalTestNS::~HcalTestNS() {}