Skip to content

Commit

Permalink
Merge pull request #31996 from bsunanda/Run3-gex31
Browse files Browse the repository at this point in the history
Run3-gex31 Identify fine detector in CaloSD and refine EcalDumpGeometry
  • Loading branch information
cmsbuild authored Oct 31, 2020
2 parents 51de474 + 1ba2111 commit 8445e80
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 14 deletions.
10 changes: 10 additions & 0 deletions SimG4CMS/Calo/interface/CaloSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class CaloSD : public SensitiveCaloDetector,
void fillHits(edm::PCaloHitContainer&, const std::string&) override;
void reset() override;

bool isItFineCalo(const G4VTouchable* touch);

protected:
virtual double getEnergyDeposit(const G4Step* step);
virtual double EnergyCorrected(const G4Step& step, const G4Track*);
Expand Down Expand Up @@ -142,6 +144,13 @@ class CaloSD : public SensitiveCaloDetector,
bool forceSave;

private:
struct Detector {
Detector() {}
std::string name;
G4LogicalVolume* lv;
int level;
};

const SimTrackManager* m_trackManager;

std::unique_ptr<CaloSlaveSD> slave;
Expand Down Expand Up @@ -170,6 +179,7 @@ class CaloSD : public SensitiveCaloDetector,
std::map<CaloHitID, CaloG4Hit*> hitMap;
std::map<int, TrackWithHistory*> tkMap;
std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
std::vector<Detector> fineDetectors_;
};

#endif // SimG4CMS_CaloSD_h
1 change: 1 addition & 0 deletions SimG4CMS/Calo/interface/EcalDumpGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EcalDumpGeometry {

private:
void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth);
std::string noRefl(const std::string &name);

EcalBarrelNumberingScheme ebNumbering_;
EcalEndcapNumberingScheme eeNumbering_;
Expand Down
66 changes: 66 additions & 0 deletions SimG4CMS/Calo/src/CaloSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
#include "SimG4Core/Notification/interface/TrackInformation.h"
#include "SimG4Core/Notification/interface/G4TrackToParticleID.h"
#include "SimG4Core/Notification/interface/SimTrackManager.h"
#include "Geometry/Records/interface/HcalParametersRcd.h"
#include "CondFormats/GeometryObjects/interface/CaloSimulationParameters.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "G4EventManager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4SDManager.hh"
#include "G4Step.hh"
#include "G4Track.hh"
Expand Down Expand Up @@ -101,6 +106,47 @@ CaloSD::CaloSD(const std::string& name,
<< eminHitD / CLHEP::MeV << " MeV (for nonzero depths);\n Time Slice Unit "
<< timeSlice << "\nIgnore TrackID Flag " << ignoreTrackID << " UseFineCaloID flag "
<< useFineCaloID_;

// 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);
}
}
#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
} else {
edm::LogError("CaloSim") << "CaloSD: Cannot find CaloSimulationParameters";
throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n";
}
}

CaloSD::~CaloSD() {}
Expand Down Expand Up @@ -254,6 +300,26 @@ double CaloSD::EnergyCorrected(const G4Step& aStep, const G4Track*) { return aSt

bool CaloSD::getFromLibrary(const G4Step*) { return false; }

bool CaloSD::isItFineCalo(const G4VTouchable* touch) {
bool ok(false);
int level = ((touch->GetHistoryDepth()) + 1);
for (const auto& detector : fineDetectors_) {
if (level > 0 && level >= detector.level) {
int ii = level - detector.level;
G4LogicalVolume* lv = touch->GetVolume(ii)->GetLogicalVolume();
ok = (lv == detector.lv);
#ifdef EDM_ML_DEBUG
std::string name = (lv == 0) ? "Unknown" : lv->GetName();
edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level "
<< detector.level << " Flag " << ok;
#endif
if (ok)
break;
}
}
return ok;
}

void CaloSD::Initialize(G4HCofThisEvent* HCE) {
totalHits = 0;

Expand Down
6 changes: 3 additions & 3 deletions SimG4CMS/Calo/src/CaloTrkProcessing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
<< ":" << eMinFine_ << ":" << eMinFinePhoton_ << " MeV and Flags " << putHistory_
<< " (History), " << doFineCalo_ << " (Special Calorimeter)";

// Get pointers to HcalDDDConstant and HcalSimulationParameters
// Get pointer to CaloSimulationParameters
edm::ESHandle<CaloSimulationParameters> csps;
es.get<HcalParametersRcd>().get(csps);
if (csps.isValid()) {
Expand Down Expand Up @@ -148,8 +148,8 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
}
}
} else {
edm::LogError("HcalSim") << "CaloTrkProcessing: Cannot find CaloSimulationParameters";
throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n";
edm::LogError("CaloSim") << "CaloTrkProcessing: Cannot find CaloSimulationParameters";
throw cms::Exception("Unknown", "CaloTrkProcessing") << "Cannot find CaloSimulationParameters\n";
}

edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: with " << detectors_.size() << " calorimetric volumes";
Expand Down
11 changes: 10 additions & 1 deletion SimG4CMS/Calo/src/EcalDumpGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth)
double a2 = (std::abs(solid->GetTanAlpha2()) > 1.e-5) ? solid->GetTanAlpha2() : 0.0;
pars.emplace_back(a2);
}
infoVec_.emplace_back(CaloDetInfo(id, lvname, globalpoint, pars));
infoVec_.emplace_back(CaloDetInfo(id, noRefl(lvname), globalpoint, pars));
}
break;
}
Expand All @@ -115,3 +115,12 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth)
if (leafDepth > 0)
fHistory_.BackLevel();
}

std::string EcalDumpGeometry::noRefl(const std::string& name) {
if (name.find("_refl") == std::string::npos) {
return name;
} else {
size_t n = name.size();
return name.substr(0, n - 5);
}
}
11 changes: 5 additions & 6 deletions SimG4CMS/Calo/test/python/runHGC2_cfg.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import FWCore.ParameterSet.Config as cms
from Configuration.Eras.Era_Phase2C9_cff import Phase2C9

process = cms.Process("PROD",Phase2C9)

process = cms.Process("PROD")
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi")
process.load("Geometry.CMSCommonData.cmsExtendedGeometry2023D3XML_cfi")
process.load("Configuration.Geometry.GeometryExtended2026D49_cff")
process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi")
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Configuration.EventContent.EventContent_cff")
process.load("Geometry.HcalCommonData.hcalDDConstants_cff")
process.load("Geometry.HGCalCommonData.hgcalV6ParametersInitialization_cfi")
process.load("Geometry.HGCalCommonData.hgcalV6NumberingInitialization_cfi")
process.load('Configuration.StandardSequences.Generator_cff')
process.load('Configuration.StandardSequences.SimIdeal_cff')
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
from Configuration.AlCa.autoCond import autoCond
process.GlobalTag.globaltag = autoCond['run2_mc']
process.GlobalTag.globaltag = autoCond['phase2_realistic']

process.MessageLogger = cms.Service("MessageLogger",
destinations = cms.untracked.vstring('cout'),
Expand Down
5 changes: 1 addition & 4 deletions SimG4CMS/Calo/test/python/runHGC4_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
process = cms.Process("PROD",Phase2C11)
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi")
process.load("Configuration.Geometry.GeometryExtended2026D62_cff")
#process.load("Geometry.HGCalCommonData.testHGCalV14XML_cfi")
#process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi")
#process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi")
process.load("Configuration.Geometry.GeometryExtended2026D71_cff")
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Configuration.EventContent.EventContent_cff")
process.load('Configuration.StandardSequences.Generator_cff')
Expand Down

0 comments on commit 8445e80

Please sign in to comment.