Skip to content

Commit

Permalink
Merge pull request #32711 from bsunanda/Run3-sim82
Browse files Browse the repository at this point in the history
Run3-sim82 Define fine calorimeters thrugh python
  • Loading branch information
cmsbuild authored Jan 24, 2021
2 parents 1ece93d + 5ac789d commit dc7bcc5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 53 deletions.
73 changes: 36 additions & 37 deletions SimG4CMS/Calo/src/CaloSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <memory>
#include <sstream>

// #define EDM_ML_DEBUG
//#define EDM_ML_DEBUG

CaloSD::CaloSD(const std::string& name,
const edm::EventSetup& es,
Expand Down Expand Up @@ -70,6 +70,9 @@ CaloSD::CaloSD(const std::string& name,
correctT = beamZ / CLHEP::c_light / CLHEP::nanosecond;
doFineCalo_ = m_CaloSD.getParameter<bool>("DoFineCalo");
eMinFine_ = m_CaloSD.getParameter<double>("EminFineTrack") * CLHEP::MeV;
std::vector<std::string> fineNames = m_CaloSD.getParameter<std::vector<std::string>>("FineCaloNames");
std::vector<int> fineLevels = m_CaloSD.getParameter<std::vector<int>>("FineCaloLevels");
std::vector<int> useFines = m_CaloSD.getParameter<std::vector<int>>("UseFineCalo");

SetVerboseLevel(verbn);
meanResponse.reset(nullptr);
Expand Down Expand Up @@ -110,46 +113,42 @@ CaloSD::CaloSD(const std::string& name,
<< timeSlice << "\nIgnore TrackID Flag " << ignoreTrackID << " doFineCalo flag "
<< doFineCalo_;

// Get pointer to CaloSimulationParameters
edm::ESHandle<CaloSimulationParameters> csps;
es.get<HcalParametersRcd>().get(csps);
if (csps.isValid()) {
const CaloSimulationParameters* csp = csps.product();
edm::LogVerbatim("CaloSim") << "CaloSD: " << csp->fCaloNames_.size() << " entries for fineCalorimeters:";
for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++)
edm::LogVerbatim("CaloSim") << " [" << i << "] " << csp->fCaloNames_[i] << ":" << csp->fLevels_[i];

const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
std::vector<G4LogicalVolume*>::const_iterator lvcite;
for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++) {
G4LogicalVolume* lv = nullptr;
G4String name = static_cast<G4String>(csp->fCaloNames_[i]);
for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
if ((*lvcite)->GetName() == name) {
lv = (*lvcite);
break;
}
}
if (lv != nullptr) {
CaloSD::Detector detector;
detector.name = name;
detector.lv = lv;
detector.level = csp->fLevels_[i];
fineDetectors_.emplace_back(detector);
// Treat fine calorimeters
edm::LogVerbatim("CaloSim") << "CaloSD: Have a possibility of " << fineNames.size() << " fine calorimeters of which "
<< useFines.size() << " are selected";
for (unsigned int k = 0; k < fineNames.size(); ++k)
edm::LogVerbatim("CaloSim") << "[" << k << "] " << fineNames[k] << " at " << fineLevels[k];
std::ostringstream st1;
for (unsigned int k = 0; k < useFines.size(); ++k)
st1 << " [" << k << "] " << useFines[k] << ":" << fineNames[useFines[k]];
edm::LogVerbatim("CaloSim") << "CaloSD used calorimeters" << st1.str();
const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
std::vector<G4LogicalVolume*>::const_iterator lvcite;
for (unsigned int i = 0; i < useFines.size(); i++) {
G4LogicalVolume* lv = nullptr;
G4String name = static_cast<G4String>(fineNames[useFines[i]]);
for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
if ((*lvcite)->GetName() == name) {
lv = (*lvcite);
break;
}
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("CaloSim") << "CaloSD::Loads information for " << fineDetectors_.size() << " fine detectors";
unsigned int k(0);
for (const auto& detector : fineDetectors_) {
edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level
<< " pointer to LV: " << detector.lv;
if (lv != nullptr) {
CaloSD::Detector detector;
detector.name = name;
detector.lv = lv;
detector.level = fineLevels[useFines[i]];
fineDetectors_.emplace_back(detector);
}
#endif
} else {
edm::LogError("CaloSim") << "CaloSD: Cannot find CaloSimulationParameters";
throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n";
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("CaloSim") << "CaloSD::Loads information for " << fineDetectors_.size() << " fine detectors";
unsigned int k(0);
for (const auto& detector : fineDetectors_) {
edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level
<< " pointer to LV: " << detector.lv;
}
#endif
}

CaloSD::~CaloSD() {}
Expand Down
30 changes: 16 additions & 14 deletions SimG4CMS/Calo/src/CaloTrkProcessing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
#include "FWCore/Utilities/interface/Exception.h"

#include "G4EventManager.hh"

#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Step.hh"
#include "G4Track.hh"

#include "G4SystemOfUnits.hh"

// #define EDM_ML_DEBUG
#include <sstream>
//#define EDM_ML_DEBUG

CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
const edm::EventSetup& es,
Expand All @@ -35,9 +34,20 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
putHistory_ = m_p.getParameter<bool>("PutHistory");
doFineCalo_ = m_p.getParameter<bool>("DoFineCalo");
eMinFine_ = m_p.getParameter<double>("EminFineTrack") * CLHEP::MeV;
std::vector<std::string> fineNames = m_p.getParameter<std::vector<std::string> >("FineCaloNames");
std::vector<int> fineLevels = m_p.getParameter<std::vector<int> >("FineCaloLevels");
std::vector<int> useFines = m_p.getParameter<std::vector<int> >("UseFineCalo");

edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: Initialised with TestBeam = " << testBeam_ << " Emin = " << eMin_
<< " Flags " << putHistory_ << " (History), " << doFineCalo_ << " (Special Calorimeter)";
edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: Have a possibility of " << fineNames.size()
<< " fine calorimeters of which " << useFines.size() << " are selected";
for (unsigned int k = 0; k < fineNames.size(); ++k)
edm::LogVerbatim("CaloSim") << "[" << k << "] " << fineNames[k] << " at " << fineLevels[k];
std::ostringstream st1;
for (unsigned int k = 0; k < useFines.size(); ++k)
st1 << " [" << k << "] " << useFines[k] << ":" << fineNames[useFines[k]];
edm::LogVerbatim("CaloSim") << "CaloTrkProcessing used calorimeters" << st1.str();

// Get pointer to CaloSimulationParameters
edm::ESHandle<CaloSimulationParameters> csps;
Expand All @@ -60,14 +70,6 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: " << csp->insideLevel_.size() << " entries for insideLevel:";
for (unsigned int i = 0; i < csp->insideLevel_.size(); i++)
edm::LogVerbatim("CaloSim") << " (" << i << ") " << csp->insideLevel_[i];
edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: " << csp->fCaloNames_.size()
<< " entries for fineCalorimeterNames:";
for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++)
edm::LogVerbatim("CaloSim") << " (" << i << ") " << csp->fCaloNames_[i];
edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: " << csp->fLevels_.size()
<< " entries for fineCalorimeterLevels:";
for (unsigned int i = 0; i < csp->fLevels_.size(); i++)
edm::LogVerbatim("CaloSim") << " (" << i << ") " << csp->fLevels_[i];
#endif

if (csp->caloNames_.size() < csp->neighbours_.size()) {
Expand Down Expand Up @@ -125,9 +127,9 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
istart += csp->neighbours_[i];
}

for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++) {
for (unsigned int i = 0; i < useFines.size(); i++) {
G4LogicalVolume* lv = nullptr;
G4String name = static_cast<G4String>(csp->fCaloNames_[i]);
G4String name = static_cast<G4String>(fineNames[useFines[i]]);
for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
if ((*lvcite)->GetName() == name) {
lv = (*lvcite);
Expand All @@ -138,7 +140,7 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
CaloTrkProcessing::Detector detector;
detector.name = name;
detector.lv = lv;
detector.level = csp->fLevels_[i];
detector.level = fineLevels[useFines[i]];
detector.fromDets.clear();
detector.fromDetL.clear();
detector.fromLevels.clear();
Expand Down
9 changes: 7 additions & 2 deletions SimG4CMS/Calo/test/python/runHGC4_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@
process.g4SimHits.Physics.type = 'SimG4Core/Physics/FTFP_BERT_EMM'
process.g4SimHits.Physics.DefaultCutValue = 0.1
process.g4SimHits.HGCSD.CornerMinMask = 3
process.g4SimHits.CaloSD.UseFineCaloID = True
process.g4SimHits.CaloSD.UseFineCalo = [2]
process.g4SimHits.CaloTrkProcessing.UseFineCalo = [2]
process.g4SimHits.TrackingAction.UseFineCalo = [2]
process.g4SimHits.CaloSD.DoFineCalo = True
process.g4SimHits.CaloTrkProcessing.DoFineCalo = True
process.g4SimHits.TrackingAction.DoFineCalo = True
process.g4SimHits.CaloSD.EminFineTrack = 1000.0
process.g4SimHits.CaloTrkProcessing.EminFineTrack = 1000.0
process.g4SimHits.CaloTrkProcessing.EminFinePhoton = 500.0
process.g4SimHits.TrackingAction.EminFineTrack = 1000.0

# Schedule definition
process.schedule = cms.Schedule(process.generation_step,
Expand Down
3 changes: 3 additions & 0 deletions SimG4Core/Application/python/g4SimHits_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
DoFineCalo = cms.bool(False),
# currently unused; left in place for future studies
EminFineTrack = cms.double(10000.0),
FineCaloNames = cms.vstring('ECAL', 'HCAL', 'HGCal', 'HFNoseVol', 'VCAL'),
FineCaloLevels = cms.vint32(4, 4, 8, 3, 3),
UseFineCalo = cms.vint32(2, 3),
)

## enable fine calorimeter functionality: must occur *before* common PSet is used below
Expand Down

0 comments on commit dc7bcc5

Please sign in to comment.