Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Geant4 sequential #27706

Merged
merged 7 commits into from Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion SimG4Core/Application/interface/ExceptionHandler.h
Expand Up @@ -29,7 +29,6 @@ class ExceptionHandler : public G4VExceptionHandler {
G4ExceptionSeverity severity,
const char *description) override;

private:
ExceptionHandler(const ExceptionHandler &) = delete;
ExceptionHandler &operator=(const ExceptionHandler &right) = delete;
};
Expand Down
34 changes: 16 additions & 18 deletions SimG4Core/Application/python/g4SimHits_cfi.py
Expand Up @@ -44,16 +44,14 @@
g4GeometryDD4hepSource = cms.bool(False),
NonBeamEvent = cms.bool(False),
G4EventManagerVerbosity = cms.untracked.int32(0),
G4StackManagerVerbosity = cms.untracked.int32(0),
G4TrackingManagerVerbosity = cms.untracked.int32(0),
UseMagneticField = cms.bool(True),
StoreRndmSeeds = cms.bool(False),
RestoreRndmSeeds = cms.bool(False),
PhysicsTablesDirectory = cms.string('PhysicsTables'),
StorePhysicsTables = cms.bool(False),
RestorePhysicsTables = cms.bool(False),
CheckGeometry = cms.bool(False),
G4CheckOverlap = cms.PSet(
PhysicsTablesDirectory = cms.untracked.string('PhysicsTables'),
StorePhysicsTables = cms.untracked.bool(False),
RestorePhysicsTables = cms.untracked.bool(False),
CheckGeometry = cms.untracked.bool(False),
G4CheckOverlap = cms.untracked.PSet(
OutputBaseName = cms.string('2017'),
MaterialFlag = cms.bool(True),
GeomFlag = cms.bool(True),
Expand All @@ -71,21 +69,21 @@
NodeNames = cms.vstring('World')
),
G4Commands = cms.vstring(),
SteppingVerbosity = cms.int32(0),
StepVerboseThreshold = cms.double(0.1), # in GeV
VerboseEvents = cms.vint32(),
VertexNumber = cms.vint32(),
VerboseTracks = cms.vint32(),
FileNameField = cms.string(''),
FileNameGDML = cms.string(''),
FileNameRegions = cms.string(''),
SteppingVerbosity = cms.untracked.int32(0),
StepVerboseThreshold = cms.untracked.double(0.1), # in GeV
VerboseEvents = cms.untracked.vint32(),
VertexNumber = cms.untracked.vint32(),
VerboseTracks = cms.untracked.vint32(),
FileNameField = cms.untracked.string(''),
FileNameGDML = cms.untracked.string(''),
FileNameRegions = cms.untracked.string(''),
Watchers = cms.VPSet(),
HepMCProductLabel = cms.InputTag("generatorSmeared"),
theLHCTlinkTag = cms.InputTag("LHCTransport"),
CustomUIsession = cms.untracked.PSet(
Type = cms.untracked.string("MessageLogger"), # MessageLoggerThreadPrefix, FilePerThread; the non-default ones are meant only for MT debugging
ThreadPrefix = cms.untracked.string("W"), # For MessageLoggerThreadPrefix
ThreadFile = cms.untracked.string("sim_output_thread"), # For FilePerThread
Type = cms.untracked.string("MessageLogger"), # alternatives: MessageLoggerThreadPrefix, FilePerThread
ThreadPrefix = cms.untracked.string("W"), # for MessageLoggerThreadPrefix
ThreadFile = cms.untracked.string("sim_output_thread"), # for FilePerThread
),
MagneticField = cms.PSet(
UseLocalMagFieldManager = cms.bool(False),
Expand Down
65 changes: 42 additions & 23 deletions SimG4Core/Application/src/RunManager.cc
Expand Up @@ -69,6 +69,12 @@
#include "G4Field.hh"
#include "G4FieldManager.hh"

#include "G4LogicalVolume.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4Region.hh"
#include "G4RegionStore.hh"

#include "G4GDMLParser.hh"
#include "G4SystemOfUnits.hh"

Expand Down Expand Up @@ -121,9 +127,9 @@ RunManager::RunManager(edm::ParameterSet const& p, edm::ConsumesCollector&& iC)
m_currentRun(nullptr),
m_currentEvent(nullptr),
m_simEvent(nullptr),
m_PhysicsTablesDir(p.getParameter<std::string>("PhysicsTablesDirectory")),
m_StorePhysicsTables(p.getParameter<bool>("StorePhysicsTables")),
m_RestorePhysicsTables(p.getParameter<bool>("RestorePhysicsTables")),
m_PhysicsTablesDir(p.getUntrackedParameter<std::string>("PhysicsTablesDirectory", "")),
m_StorePhysicsTables(p.getUntrackedParameter<bool>("StorePhysicsTables", false)),
m_RestorePhysicsTables(p.getUntrackedParameter<bool>("RestorePhysicsTables", false)),
m_EvtMgrVerbosity(p.getUntrackedParameter<int>("G4EventManagerVerbosity", 0)),
m_pField(p.getParameter<edm::ParameterSet>("MagneticField")),
m_pGenerator(p.getParameter<edm::ParameterSet>("Generator")),
Expand All @@ -133,7 +139,7 @@ RunManager::RunManager(edm::ParameterSet const& p, edm::ConsumesCollector&& iC)
m_pStackingAction(p.getParameter<edm::ParameterSet>("StackingAction")),
m_pTrackingAction(p.getParameter<edm::ParameterSet>("TrackingAction")),
m_pSteppingAction(p.getParameter<edm::ParameterSet>("SteppingAction")),
m_g4overlap(p.getParameter<edm::ParameterSet>("G4CheckOverlap")),
m_g4overlap(p.getUntrackedParameter<edm::ParameterSet>("G4CheckOverlap")),
m_G4Commands(p.getParameter<std::vector<std::string> >("G4Commands")),
m_p(p) {
m_UIsession.reset(new CustomUIsession());
Expand All @@ -142,10 +148,10 @@ RunManager::RunManager(edm::ParameterSet const& p, edm::ConsumesCollector&& iC)

m_physicsList.reset(nullptr);

m_check = p.getParameter<bool>("CheckGeometry");
m_WriteFile = p.getParameter<std::string>("FileNameGDML");
m_FieldFile = p.getParameter<std::string>("FileNameField");
m_RegionFile = p.getParameter<std::string>("FileNameRegions");
m_check = p.getUntrackedParameter<bool>("CheckGeometry", false);
m_WriteFile = p.getUntrackedParameter<std::string>("FileNameGDML", "");
m_FieldFile = p.getUntrackedParameter<std::string>("FileNameField", "");
m_RegionFile = p.getUntrackedParameter<std::string>("FileNameRegions", "");

m_userRunAction = nullptr;
m_runInterface = nullptr;
Expand Down Expand Up @@ -187,9 +193,10 @@ void RunManager::initG4(const edm::EventSetup& es) {
bool geoFromDD4hep = m_p.getParameter<bool>("g4GeometryDD4hepSource");
bool cuts = m_pPhysics.getParameter<bool>("CutsPerRegion");
bool protonCut = m_pPhysics.getParameter<bool>("CutsOnProton");
int verb = std::max(m_pPhysics.getParameter<int>("Verbosity"), m_p.getParameter<int>("SteppingVerbosity"));
int verb = std::max(m_pPhysics.getUntrackedParameter<int>("Verbosity", 0),
m_p.getUntrackedParameter<int>("SteppingVerbosity", 0));
edm::LogVerbatim("SimG4CoreApplication")
<< "RunManagerMT: start initialising of geometry DD4Hep: " << geoFromDD4hep << "\n"
<< "RunManager: start initialising of geometry DD4Hep: " << geoFromDD4hep << "\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@civanch this looks a minor copy-and-paste typo, although the fix is correct

<< " cutsPerRegion: " << cuts << " cutForProton: " << protonCut << "\n"
<< " G4 verbosity: " << verb;

Expand All @@ -210,17 +217,28 @@ void RunManager::initG4(const edm::EventSetup& es) {
const DDCompactView* pDD = nullptr;
const cms::DDCompactView* pDD4hep = nullptr;
if (geoFromDD4hep) {
edm::ESTransientHandle<cms::DDCompactView> pDD;
es.get<IdealGeometryRecord>().get(pDD);
pDD4hep = pDD.product();
edm::ESTransientHandle<cms::DDCompactView> ph;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@civanch I agree that the code looks cleaner, but according to https://en.cppreference.com/w/cpp/language/scope it was not strictly wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiocos , before the fix it was crashing with the weird diagnostic...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@civanch but I would imagine not here. Anyway it is ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiocos , you are right.

es.get<IdealGeometryRecord>().get(ph);
pDD4hep = ph.product();
} else {
edm::ESTransientHandle<DDCompactView> pDD;
es.get<IdealGeometryRecord>().get(pDD);
pDD = pDD.product();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the contrary this was the real bug, am I correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiocos , I think so.

edm::ESTransientHandle<DDCompactView> ph;
es.get<IdealGeometryRecord>().get(ph);
pDD = ph.product();
}
SensitiveDetectorCatalog catalog;
const DDDWorld* world = new DDDWorld(pDD, pDD4hep, catalog, verb, cuts, protonCut);
G4VPhysicalVolume* pworld = world->GetWorldVolume();

const G4RegionStore* regStore = G4RegionStore::GetInstance();
const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
unsigned int numPV = pvs->size();
unsigned int numLV = lvs->size();
unsigned int nn = regStore->size();
edm::LogVerbatim("SimG4CoreApplication")
<< "###RunManager: " << numPV << " PhysVolumes; " << numLV << " LogVolumes; " << nn << " Regions.";

m_kernel->DefineWorldVolume(pworld, true);
m_registry.dddWorldSignal_(world);

if (m_pUseMagneticField) {
Expand Down Expand Up @@ -317,11 +335,11 @@ void RunManager::initG4(const edm::EventSetup& es) {
BeginOfJob aBeginOfJob(&es);
m_registry.beginOfJobSignal_(&aBeginOfJob);

G4int sv = m_p.getParameter<int>("SteppingVerbosity");
G4double elim = m_p.getParameter<double>("StepVerboseThreshold") * CLHEP::GeV;
std::vector<int> ve = m_p.getParameter<std::vector<int> >("VerboseEvents");
std::vector<int> vn = m_p.getParameter<std::vector<int> >("VertexNumber");
std::vector<int> vt = m_p.getParameter<std::vector<int> >("VerboseTracks");
G4int sv = m_p.getUntrackedParameter<int>("SteppingVerbosity", 0);
G4double elim = m_p.getUntrackedParameter<double>("StepVerboseThreshold", 0.1) * CLHEP::GeV;
std::vector<int> ve = m_p.getUntrackedParameter<std::vector<int> >("VerboseEvents");
std::vector<int> vn = m_p.getUntrackedParameter<std::vector<int> >("VertexNumber");
std::vector<int> vt = m_p.getUntrackedParameter<std::vector<int> >("VerboseTracks");

if (sv > 0) {
m_sVerbose.reset(new CMSSteppingVerbose(sv, elim, ve, vn, vt));
Expand All @@ -335,6 +353,7 @@ void RunManager::initG4(const edm::EventSetup& es) {
G4UImanager::GetUIpointer()->ApplyCommand(m_G4Commands[it]);
}
}
G4StateManager::GetStateManager()->SetNewState(G4State_Init);

if (!m_WriteFile.empty()) {
G4GDMLParser gdml;
Expand All @@ -344,7 +363,7 @@ void RunManager::initG4(const edm::EventSetup& es) {
}

// G4Region dump file name
auto regionFile = m_p.getParameter<std::string>("FileNameRegions");
auto regionFile = m_p.getUntrackedParameter<std::string>("FileNameRegions", "");

// Geometry checks
if (m_check || !regionFile.empty()) {
Expand All @@ -367,7 +386,7 @@ void RunManager::stopG4() {
}
}

void RunManager::produce(edm::Event& inpevt, const edm::EventSetup& es) {
void RunManager::produce(edm::Event& inpevt, const edm::EventSetup&) {
m_currentEvent = generateEvent(inpevt);
m_simEvent = new G4SimEvent;
m_simEvent->hepEvent(m_generator->genEvent());
Expand Down
18 changes: 9 additions & 9 deletions SimG4Core/Application/src/RunManagerMT.cc
Expand Up @@ -61,12 +61,12 @@
RunManagerMT::RunManagerMT(edm::ParameterSet const& p)
: m_managerInitialized(false),
m_runTerminated(false),
m_PhysicsTablesDir(p.getParameter<std::string>("PhysicsTablesDirectory")),
m_StorePhysicsTables(p.getParameter<bool>("StorePhysicsTables")),
m_RestorePhysicsTables(p.getParameter<bool>("RestorePhysicsTables")),
m_PhysicsTablesDir(p.getUntrackedParameter<std::string>("PhysicsTablesDirectory", "")),
m_StorePhysicsTables(p.getUntrackedParameter<bool>("StorePhysicsTables", false)),
m_RestorePhysicsTables(p.getUntrackedParameter<bool>("RestorePhysicsTables", false)),
m_pPhysics(p.getParameter<edm::ParameterSet>("Physics")),
m_pRunAction(p.getParameter<edm::ParameterSet>("RunAction")),
m_g4overlap(p.getParameter<edm::ParameterSet>("G4CheckOverlap")),
m_g4overlap(p.getUntrackedParameter<edm::ParameterSet>("G4CheckOverlap")),
m_G4Commands(p.getParameter<std::vector<std::string> >("G4Commands")),
m_p(p) {
m_currentRun = nullptr;
Expand All @@ -83,7 +83,7 @@ RunManagerMT::RunManagerMT(edm::ParameterSet const& p)
m_stateManager->SetExceptionHandler(new ExceptionHandler());
m_geometryManager->G4GeometryManager::GetInstance();

m_check = p.getParameter<bool>("CheckGeometry");
m_check = p.getUntrackedParameter<bool>("CheckGeometry", false);
}

RunManagerMT::~RunManagerMT() { stopG4(); }
Expand All @@ -98,8 +98,8 @@ void RunManagerMT::initG4(const DDCompactView* pDD,
bool geoFromDD4hep = m_p.getParameter<bool>("g4GeometryDD4hepSource");
bool cuts = m_pPhysics.getParameter<bool>("CutsPerRegion");
bool protonCut = m_pPhysics.getParameter<bool>("CutsOnProton");
int verb =
std::max(m_pPhysics.getUntrackedParameter<int>("Verbosity", 0), m_p.getParameter<int>("SteppingVerbosity"));
int verb = std::max(m_pPhysics.getUntrackedParameter<int>("Verbosity", 0),
m_p.getUntrackedParameter<int>("SteppingVerbosity", 0));
edm::LogVerbatim("SimG4CoreApplication")
<< "RunManagerMT: start initialising of geometry DD4Hep: " << geoFromDD4hep << "\n"
<< " cutsPerRegion: " << cuts << " cutForProton: " << protonCut << "\n"
Expand Down Expand Up @@ -212,7 +212,7 @@ void RunManagerMT::initG4(const DDCompactView* pDD,
initializeUserActions();

// geometry dump
auto writeFile = m_p.getParameter<std::string>("FileNameGDML");
auto writeFile = m_p.getUntrackedParameter<std::string>("FileNameGDML", "");
if (!writeFile.empty()) {
G4GDMLParser gdml;
gdml.SetRegionExport(true);
Expand All @@ -221,7 +221,7 @@ void RunManagerMT::initG4(const DDCompactView* pDD,
}

// G4Region dump file name
auto regionFile = m_p.getParameter<std::string>("FileNameRegions");
auto regionFile = m_p.getUntrackedParameter<std::string>("FileNameRegions", "");

// Geometry checks
if (m_check || !regionFile.empty()) {
Expand Down
19 changes: 9 additions & 10 deletions SimG4Core/Application/src/RunManagerMTWorker.cc
Expand Up @@ -82,8 +82,7 @@ namespace {
void createWatchers(const edm::ParameterSet& iP,
SimActivityRegistry* iReg,
std::vector<std::shared_ptr<SimWatcher> >& oWatchers,
std::vector<std::shared_ptr<SimProducer> >& oProds,
int thisThreadID) {
std::vector<std::shared_ptr<SimProducer> >& oProds) {
if (!iP.exists("Watchers")) {
return;
}
Expand Down Expand Up @@ -236,7 +235,7 @@ void RunManagerMTWorker::initializeTLS() {
}
}
if (m_hasWatchers) {
createWatchers(m_p, m_tls->registry.get(), m_tls->watchers, m_tls->producers, thisID);
createWatchers(m_p, m_tls->registry.get(), m_tls->watchers, m_tls->producers);
}
}

Expand All @@ -251,7 +250,7 @@ void RunManagerMTWorker::initializeThread(RunManagerMT& runManagerMaster, const
// Initialize per-thread output
G4Threading::G4SetThreadId(thisID);
G4UImanager::GetUIpointer()->SetUpForAThread(thisID);
const std::string& uitype = m_pCustomUIsession.getUntrackedParameter<std::string>("Type");
const std::string& uitype = m_pCustomUIsession.getUntrackedParameter<std::string>("Type", "MessageLogger");
if (uitype == "MessageLogger") {
m_tls->UIsession.reset(new CustomUIsession());
} else if (uitype == "MessageLoggerThreadPrefix") {
Expand Down Expand Up @@ -299,7 +298,7 @@ void RunManagerMTWorker::initializeThread(RunManagerMT& runManagerMaster, const
tM->SetFieldManager(fieldManager);
fieldBuilder.build(fieldManager, tM->GetPropagatorInField());

std::string fieldFile = m_p.getParameter<std::string>("FileNameField");
std::string fieldFile = m_p.getUntrackedParameter<std::string>("FileNameField", "");
if (!fieldFile.empty()) {
std::call_once(applyOnce, []() { dumpMF = true; });
if (dumpMF) {
Expand Down Expand Up @@ -348,11 +347,11 @@ void RunManagerMTWorker::initializeThread(RunManagerMT& runManagerMaster, const
BeginOfJob aBeginOfJob(&es);
m_tls->registry->beginOfJobSignal_(&aBeginOfJob);

G4int sv = m_p.getParameter<int>("SteppingVerbosity");
G4double elim = m_p.getParameter<double>("StepVerboseThreshold") * CLHEP::GeV;
std::vector<int> ve = m_p.getParameter<std::vector<int> >("VerboseEvents");
std::vector<int> vn = m_p.getParameter<std::vector<int> >("VertexNumber");
std::vector<int> vt = m_p.getParameter<std::vector<int> >("VerboseTracks");
G4int sv = m_p.getUntrackedParameter<int>("SteppingVerbosity", 0);
G4double elim = m_p.getUntrackedParameter<double>("StepVerboseThreshold", 0.1) * CLHEP::GeV;
std::vector<int> ve = m_p.getUntrackedParameter<std::vector<int> >("VerboseEvents");
std::vector<int> vn = m_p.getUntrackedParameter<std::vector<int> >("VertexNumber");
std::vector<int> vt = m_p.getUntrackedParameter<std::vector<int> >("VerboseTracks");

if (sv > 0) {
m_sVerbose.reset(new CMSSteppingVerbose(sv, elim, ve, vn, vt));
Expand Down