Skip to content

Commit

Permalink
Merge pull request #34521 from bsunanda/Run3-gex83C
Browse files Browse the repository at this point in the history
Run3-gex83C Convert one more SD (Hcal) to new format
  • Loading branch information
cmsbuild authored Jul 21, 2021
2 parents 0ad6a56 + 43c16b2 commit 9d63f03
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 64 deletions.
8 changes: 6 additions & 2 deletions SimG4CMS/Calo/interface/HCalSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <map>
Expand All @@ -38,7 +38,11 @@ class TH1F;
class HCalSD : public CaloSD, public Observer<const BeginOfJob*> {
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*);
Expand Down
5 changes: 2 additions & 3 deletions SimG4CMS/Calo/interface/HcalTestNS.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#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"
#include "Geometry/HcalCommonData/interface/HcalNumberingFromDDD.h"

class HcalTestNS {
public:
HcalTestNS(const edm::EventSetup*);
HcalTestNS(const HcalDDDRecConstants*);
virtual ~HcalTestNS();

bool compare(HcalNumberingFromDDD::HcalID const&, uint32_t const&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
101 changes: 101 additions & 0 deletions SimG4CMS/Calo/plugins/HcalSensitiveDetectorBuilder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

// system include files
#include <string>
#include <vector>

// 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<edm::Transition::BeginRun>()},
hdrcToken_{cc.esConsumes<edm::Transition::BeginRun>()},
hscsToken_{cc.esConsumes<edm::Transition::BeginRun>()},
hbdkToken_{
cc.esConsumes<HBHEDarkening, HBHEDarkeningRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", "HB"})},
hedkToken_{
cc.esConsumes<HBHEDarkening, HBHEDarkeningRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", "HE"})},
hcalDDSim_{nullptr},
hcalDDRec_{nullptr},
hcalSimConstants_{nullptr},
hbDarkening_{nullptr},
heDarkening_{nullptr} {
edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HCalSD");
agingFlagHB_ = m_HC.getParameter<bool>("HBDarkening");
agingFlagHE_ = m_HC.getParameter<bool>("HEDarkening");
forTBHC_ = m_HC.getUntrackedParameter<bool>("ForTBHCAL", false);
forTBH2_ = m_HC.getUntrackedParameter<bool>("ForTBH2", false);
}

void beginRun(const edm::EventSetup& es) final {
hcalDDSim_ = &es.getData(hdscToken_);
if ((!forTBHC_) && (!forTBH2_))
hcalDDRec_ = &es.getData(hdrcToken_);
edm::ESHandle<HcalSimulationConstants> 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<HBHEDarkening> 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<HBHEDarkening> hedark = es.getHandle(hedkToken_);
if (hedark.isValid())
heDarkening_ = hedark.product();
else
edm::LogVerbatim("HcalSim") << "HcalSensitiveDetectorBuilder does not find record for HEDarkening";
}
}

std::unique_ptr<SensitiveDetector> make(const std::string& iname,
const SensitiveDetectorCatalog& clg,
const edm::ParameterSet& p,
const SimTrackManager* man,
SimActivityRegistry& reg) const final {
auto sd = std::make_unique<HCalSD>(
iname, hcalDDSim_, hcalDDRec_, hcalSimConstants_, hbDarkening_, heDarkening_, clg, p, man);
SimActivityRegistryEnroller::enroll(reg, sd.get());
return sd;
}

private:
const edm::ESGetToken<HcalDDDSimConstants, HcalSimNumberingRecord> hdscToken_;
const edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> hdrcToken_;
const edm::ESGetToken<HcalSimulationConstants, HcalSimNumberingRecord> hscsToken_;
const edm::ESGetToken<HBHEDarkening, HBHEDarkeningRecord> hbdkToken_;
const edm::ESGetToken<HBHEDarkening, HBHEDarkeningRecord> 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);
3 changes: 0 additions & 3 deletions SimG4CMS/Calo/plugins/module.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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;
Expand Down
55 changes: 12 additions & 43 deletions SimG4CMS/Calo/src/HCalSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -55,10 +54,10 @@ HCalSD::HCalSD(const std::string& name,
manager,
(float)(p.getParameter<edm::ParameterSet>("HCalSD").getParameter<double>("TimeSliceUnit")),
p.getParameter<edm::ParameterSet>("HCalSD").getParameter<bool>("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) {
Expand Down Expand Up @@ -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<HcalDDDSimConstants> hdc;
es.get<HcalSimNumberingRecord>().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<HcalSimulationConstants> hdsc;
es.get<HcalSimNumberingRecord>().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;
Expand Down Expand Up @@ -263,18 +243,7 @@ HCalSD::HCalSD(const std::string& name,

//Test Hcal Numbering Scheme
if (testNS_)
m_HcalTestNS = std::make_unique<HcalTestNS>(&es);

if (agingFlagHB) {
edm::ESHandle<HBHEDarkening> hdark;
es.get<HBHEDarkeningRecord>().get("HB", hdark);
m_HBDarkening = &*hdark;
}
if (agingFlagHE) {
edm::ESHandle<HBHEDarkening> hdark;
es.get<HBHEDarkeningRecord>().get("HE", hdark);
m_HEDarkening = &*hdark;
}
m_HcalTestNS = std::make_unique<HcalTestNS>(hcnr);

for (int i = 0; i < 9; ++i) {
hit_[i] = time_[i] = dist_[i] = nullptr;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 1 addition & 12 deletions SimG4CMS/Calo/src/HcalTestNS.cc
Original file line number Diff line number Diff line change
@@ -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<HcalDDDRecConstants> hdc;
iSetup->get<HcalRecNumberingRecord>().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() {}

Expand Down

0 comments on commit 9d63f03

Please sign in to comment.