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

Extended test on Geant4 geometry #27592

Merged
merged 4 commits into from Jul 27, 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,7 +1,7 @@
#ifndef SimG4Core_CustomUIsessionThreadPrefix_H
#define SimG4Core_CustomUIsessionThreadPrefix_H

#include "SimG4Core/Application/interface/CustomUIsession.h"
#include "SimG4Core/Geometry/interface/CustomUIsession.h"

/**
* This class is intended for debugging of multithreaded simulation
Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/Application/interface/CustomUIsessionToFile.h
@@ -1,7 +1,7 @@
#ifndef SimG4Core_CustomUIsessionToFile_H
#define SimG4Core_CustomUIsessionToFile_H

#include "SimG4Core/Application/interface/CustomUIsession.h"
#include "SimG4Core/Geometry/interface/CustomUIsession.h"

#include <fstream>

Expand Down
15 changes: 0 additions & 15 deletions SimG4Core/Application/interface/G4RegionReporter.h

This file was deleted.

2 changes: 1 addition & 1 deletion SimG4Core/Application/interface/OscarProducer.h
Expand Up @@ -9,7 +9,7 @@
#include "FWCore/Framework/interface/Run.h"

#include "SimG4Core/Application/interface/RunManager.h"
#include "SimG4Core/Application/interface/CustomUIsession.h"
#include "SimG4Core/Geometry/interface/CustomUIsession.h"

#include <memory>

Expand Down
28 changes: 18 additions & 10 deletions SimG4Core/Application/python/g4SimHits_cfi.py
Expand Up @@ -52,12 +52,20 @@
PhysicsTablesDirectory = cms.string('PhysicsTables'),
StorePhysicsTables = cms.bool(False),
RestorePhysicsTables = cms.bool(False),
CheckOverlap = cms.untracked.bool(False),
CheckGeometry = cms.bool(False),
Copy link
Contributor

Choose a reason for hiding this comment

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

@civanch why this and other verbosity flags are moved from untracked to tracked? What is the rationale behind it?

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, "verbosity" parameters were added by different peoples and historically some are tracked, another untracked. The way how these parameters are used is well defined: only for debuging. They mainly are inside this base python file. Likely some may be removed, another may stay "tracked".

G4CheckOverlap = cms.PSet(
Tolerance = cms.untracked.double(0.0),
Resolution = cms.untracked.int32(10000),
RegionFlag = cms.untracked.bool(True), # if true - selection by G4Region name
gdmlFlag = cms.untracked.bool(True), # if true - dump gdml file
OutputBaseName = cms.string('2017'),
MaterialFlag = cms.bool(True),
GeomFlag = cms.bool(True),
OverlapFlag = cms.bool(False),
RegionFlag = cms.bool(True), # if true - selection by G4Region name
gdmlFlag = cms.bool(False), # if true - dump gdml file
Verbose = cms.bool(True),
Tolerance = cms.double(0.0),
Resolution = cms.int32(10000),
ErrorThreshold = cms.int32(1),
Level = cms.int32(1),
Depth = cms.int32(3), # -1 means check whatever depth
PVname = cms.string(''),
LVname = cms.string(''),
NodeNames = cms.vstring('World')
Expand All @@ -68,9 +76,9 @@
VerboseEvents = cms.vint32(),
VertexNumber = cms.vint32(),
VerboseTracks = cms.vint32(),
FileNameField = cms.untracked.string(''),
FileNameGDML = cms.untracked.string(''),
FileNameRegions = cms.untracked.string(''),
FileNameField = cms.string(''),
FileNameGDML = cms.string(''),
FileNameRegions = cms.string(''),
Watchers = cms.VPSet(),
HepMCProductLabel = cms.InputTag("generatorSmeared"),
theLHCTlinkTag = cms.InputTag("LHCTransport"),
Expand All @@ -81,7 +89,7 @@
),
MagneticField = cms.PSet(
UseLocalMagFieldManager = cms.bool(False),
Verbosity = cms.untracked.bool(False),
Verbosity = cms.bool(False),
Copy link
Contributor

Choose a reason for hiding this comment

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

@civanch similar question here for instance

ConfGlobalMFM = cms.PSet(
Volume = cms.string('OCMS'),
OCMS = cms.PSet(
Expand Down Expand Up @@ -118,7 +126,7 @@
type = cms.string('SimG4Core/Physics/FTFP_BERT_EMM'),
DummyEMPhysics = cms.bool(False),
CutsPerRegion = cms.bool(True),
CutsOnProton = cms.untracked.bool(True),
CutsOnProton = cms.bool(True),
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 I understand more

DefaultCutValue = cms.double(1.0), ## cuts in cm
G4BremsstrahlungThreshold = cms.double(0.5), ## cut in GeV
Verbosity = cms.untracked.int32(0),
Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/Application/src/OscarMTMasterThread.cc
@@ -1,7 +1,7 @@
#include "SimG4Core/Application/interface/OscarMTMasterThread.h"

#include "SimG4Core/Application/interface/RunManagerMT.h"
#include "SimG4Core/Application/interface/CustomUIsession.h"
#include "SimG4Core/Geometry/interface/CustomUIsession.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
Expand Down
31 changes: 14 additions & 17 deletions SimG4Core/Application/src/RunManager.cc
Expand Up @@ -7,7 +7,6 @@
#include "SimG4Core/Application/interface/TrackingAction.h"
#include "SimG4Core/Application/interface/SteppingAction.h"
#include "SimG4Core/Application/interface/ParametrisedEMPhysics.h"
#include "SimG4Core/Application/interface/G4RegionReporter.h"
#include "SimG4Core/Application/interface/CMSGDMLWriteStructure.h"
#include "SimG4Core/Application/interface/ExceptionHandler.h"

Expand All @@ -34,9 +33,9 @@
#include "SimG4Core/Notification/interface/CurrentG4Track.h"
#include "SimG4Core/Notification/interface/SimG4Exception.h"
#include "SimG4Core/Notification/interface/CMSSteppingVerbose.h"
#include "SimG4Core/Application/interface/CustomUIsession.h"

#include "SimG4Core/Geometry/interface/G4CheckOverlap.h"
#include "SimG4Core/Geometry/interface/CustomUIsession.h"
#include "SimG4Core/Geometry/interface/CMSG4CheckOverlap.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
Expand Down Expand Up @@ -143,10 +142,10 @@ RunManager::RunManager(edm::ParameterSet const& p, edm::ConsumesCollector&& iC)

m_physicsList.reset(nullptr);

m_check = p.getUntrackedParameter<bool>("CheckOverlap", false);
m_WriteFile = p.getUntrackedParameter<std::string>("FileNameGDML", "");
m_FieldFile = p.getUntrackedParameter<std::string>("FileNameField", "");
m_RegionFile = p.getUntrackedParameter<std::string>("FileNameRegions", "");
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_userRunAction = nullptr;
m_runInterface = nullptr;
Expand Down Expand Up @@ -187,9 +186,8 @@ 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.getUntrackedParameter<bool>("CutsOnProton", true);
int verb =
std::max(m_pPhysics.getUntrackedParameter<int>("Verbosity", 0), m_p.getParameter<int>("SteppingVerbosity"));
bool protonCut = m_pPhysics.getParameter<bool>("CutsOnProton");
int verb = std::max(m_pPhysics.getParameter<int>("Verbosity"), m_p.getParameter<int>("SteppingVerbosity"));
edm::LogVerbatim("SimG4CoreApplication")
<< "RunManagerMT: start initialising of geometry DD4Hep: " << geoFromDD4hep << "\n"
<< " cutsPerRegion: " << cuts << " cutForProton: " << protonCut << "\n"
Expand Down Expand Up @@ -276,7 +274,7 @@ void RunManager::initG4(const edm::EventSetup& es) {
}

// exotic particle physics
double monopoleMass = m_pPhysics.getUntrackedParameter<double>("MonopoleMass", 0);
double monopoleMass = m_pPhysics.getUntrackedParameter<double>("MonopoleMass", 0.);
if (monopoleMass > 0.0) {
phys->RegisterPhysics(new CMSMonopolePhysics(fPDGTable, m_pPhysics));
}
Expand Down Expand Up @@ -345,13 +343,12 @@ void RunManager::initG4(const edm::EventSetup& es) {
gdml.Write(m_WriteFile, pworld, true);
}

if (!m_RegionFile.empty()) {
G4RegionReporter rrep;
rrep.ReportRegions(m_RegionFile);
}
// G4Region dump file name
auto regionFile = m_p.getParameter<std::string>("FileNameRegions");

if (m_check) {
G4CheckOverlap check(m_g4overlap);
// Geometry checks
if (m_check || !regionFile.empty()) {
CMSG4CheckOverlap check(m_g4overlap, regionFile, m_UIsession.get(), pworld);
}

// If the Geant4 particle table is needed, decomment the lines below
Expand Down
28 changes: 13 additions & 15 deletions SimG4Core/Application/src/RunManagerMT.cc
Expand Up @@ -4,10 +4,10 @@
#include "SimG4Core/Application/interface/SimRunInterface.h"
#include "SimG4Core/Application/interface/RunAction.h"
#include "SimG4Core/Application/interface/ParametrisedEMPhysics.h"
#include "SimG4Core/Application/interface/CustomUIsession.h"
#include "SimG4Core/Application/interface/ExceptionHandler.h"

#include "SimG4Core/Geometry/interface/DDDWorld.h"
#include "SimG4Core/Geometry/interface/CustomUIsession.h"

#include "SimG4Core/Physics/interface/PhysicsListFactory.h"
#include "SimG4Core/PhysicsLists/interface/CMSMonopolePhysics.h"
Expand All @@ -19,9 +19,8 @@
#include "SimG4Core/Notification/interface/SimTrackManager.h"
#include "SimG4Core/Notification/interface/BeginOfJob.h"
#include "SimG4Core/Notification/interface/CurrentG4Track.h"
#include "SimG4Core/Application/interface/G4RegionReporter.h"
#include "SimG4Core/Application/interface/CMSGDMLWriteStructure.h"
#include "SimG4Core/Geometry/interface/G4CheckOverlap.h"
#include "SimG4Core/Geometry/interface/CMSG4CheckOverlap.h"

#include "DetectorDescription/Core/interface/DDCompactView.h"
#include "DetectorDescription/DDCMS/interface/DDCompactView.h"
Expand Down Expand Up @@ -84,7 +83,7 @@ RunManagerMT::RunManagerMT(edm::ParameterSet const& p)
m_stateManager->SetExceptionHandler(new ExceptionHandler());
m_geometryManager->G4GeometryManager::GetInstance();

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

RunManagerMT::~RunManagerMT() { stopG4(); }
Expand All @@ -98,7 +97,7 @@ void RunManagerMT::initG4(const DDCompactView* pDD,
}
bool geoFromDD4hep = m_p.getParameter<bool>("g4GeometryDD4hepSource");
bool cuts = m_pPhysics.getParameter<bool>("CutsPerRegion");
bool protonCut = m_pPhysics.getUntrackedParameter<bool>("CutsOnProton", true);
bool protonCut = m_pPhysics.getParameter<bool>("CutsOnProton");
int verb =
std::max(m_pPhysics.getUntrackedParameter<int>("Verbosity", 0), m_p.getParameter<int>("SteppingVerbosity"));
edm::LogVerbatim("SimG4CoreApplication")
Expand All @@ -122,6 +121,9 @@ void RunManagerMT::initG4(const DDCompactView* pDD,
edm::LogVerbatim("SimG4CoreApplication")
<< "###RunManagerMT: " << numPV << " PhysVolumes; " << numLV << " LogVolumes; " << nn << " Regions.";

if (m_check) {
m_kernel->SetVerboseLevel(2);
}
m_kernel->DefineWorldVolume(world, true);
m_registry.dddWorldSignal_(m_world.get());

Expand Down Expand Up @@ -210,24 +212,20 @@ void RunManagerMT::initG4(const DDCompactView* pDD,
initializeUserActions();

// geometry dump
auto writeFile = m_p.getUntrackedParameter<std::string>("FileNameGDML", "");
auto writeFile = m_p.getParameter<std::string>("FileNameGDML");
if (!writeFile.empty()) {
G4GDMLParser gdml;
gdml.SetRegionExport(true);
gdml.SetEnergyCutsExport(true);
gdml.Write(writeFile, m_world->GetWorldVolume(), true);
}

// G4Region dump
auto regionFile = m_p.getUntrackedParameter<std::string>("FileNameRegions", "");
if (!regionFile.empty()) {
G4RegionReporter rrep;
rrep.ReportRegions(regionFile);
}
// G4Region dump file name
auto regionFile = m_p.getParameter<std::string>("FileNameRegions");

// Intersection check
if (m_check) {
G4CheckOverlap check(m_g4overlap);
// Geometry checks
if (m_check || !regionFile.empty()) {
CMSG4CheckOverlap check(m_g4overlap, regionFile, m_UIsession.get(), world);
}

// If the Geant4 particle table is needed, decomment the lines below
Expand Down
11 changes: 6 additions & 5 deletions SimG4Core/Application/src/RunManagerMTWorker.cc
Expand Up @@ -6,11 +6,12 @@
#include "SimG4Core/Application/interface/StackingAction.h"
#include "SimG4Core/Application/interface/TrackingAction.h"
#include "SimG4Core/Application/interface/SteppingAction.h"
#include "SimG4Core/Application/interface/CustomUIsession.h"
#include "SimG4Core/Application/interface/CustomUIsessionThreadPrefix.h"
#include "SimG4Core/Application/interface/CustomUIsessionToFile.h"
#include "SimG4Core/Application/interface/ExceptionHandler.h"

#include "SimG4Core/Geometry/interface/CustomUIsession.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/Event.h"
Expand Down Expand Up @@ -254,11 +255,11 @@ void RunManagerMTWorker::initializeThread(RunManagerMT& runManagerMaster, const
if (uitype == "MessageLogger") {
m_tls->UIsession.reset(new CustomUIsession());
} else if (uitype == "MessageLoggerThreadPrefix") {
m_tls->UIsession.reset(
new CustomUIsessionThreadPrefix(m_pCustomUIsession.getUntrackedParameter<std::string>("ThreadPrefix"), thisID));
m_tls->UIsession.reset(new CustomUIsessionThreadPrefix(
m_pCustomUIsession.getUntrackedParameter<std::string>("ThreadPrefix", ""), thisID));
} else if (uitype == "FilePerThread") {
m_tls->UIsession.reset(
new CustomUIsessionToFile(m_pCustomUIsession.getUntrackedParameter<std::string>("ThreadFile"), thisID));
new CustomUIsessionToFile(m_pCustomUIsession.getUntrackedParameter<std::string>("ThreadFile", ""), thisID));
} else {
throw edm::Exception(edm::errors::Configuration)
<< "Invalid value of CustomUIsession.Type '" << uitype
Expand Down Expand Up @@ -298,7 +299,7 @@ void RunManagerMTWorker::initializeThread(RunManagerMT& runManagerMaster, const
tM->SetFieldManager(fieldManager);
fieldBuilder.build(fieldManager, tM->GetPropagatorInField());

std::string fieldFile = m_p.getUntrackedParameter<std::string>("FileNameField", "");
std::string fieldFile = m_p.getParameter<std::string>("FileNameField");
if (!fieldFile.empty()) {
std::call_once(applyOnce, []() { dumpMF = true; });
if (dumpMF) {
Expand Down
22 changes: 22 additions & 0 deletions SimG4Core/Geometry/interface/CMSG4CheckOverlap.h
@@ -0,0 +1,22 @@
#ifndef SimG4Core_CMSG4CheckOverlap_H
#define SimG4Core_CMSG4CheckOverlap_H

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <fstream>

class CustomUIsession;
class G4VPhysicalVolume;

class CMSG4CheckOverlap {
public:
CMSG4CheckOverlap(edm::ParameterSet const& p, std::string& regFile, CustomUIsession*, G4VPhysicalVolume* world);
~CMSG4CheckOverlap();

private:
void makeReportForMaterials(std::ofstream& fout);
void makeReportForGeometry(std::ofstream& fout, G4VPhysicalVolume* world);
void makeReportForOverlaps(std::ofstream& fout, const edm::ParameterSet& p);
};

#endif
15 changes: 15 additions & 0 deletions SimG4Core/Geometry/interface/CMSG4RegionReporter.h
@@ -0,0 +1,15 @@
#ifndef SimG4Core_CMSG4RegionReporter_H
#define SimG4Core_CMSG4RegionReporter_H

#include <string>

class CMSG4RegionReporter {
public:
CMSG4RegionReporter();

~CMSG4RegionReporter();

void ReportRegions(const std::string& ss);
};

#endif
Expand Up @@ -6,6 +6,10 @@

#include "FWCore/MessageLogger/interface/MessageLogger.h"

//#include <iostream>
//#include <iomanip>
#include <fstream>

class CustomUIsession : public G4UIsession {
public:
CustomUIsession();
Expand All @@ -14,8 +18,14 @@ class CustomUIsession : public G4UIsession {
G4int ReceiveG4cout(const G4String& coutString) override;
G4int ReceiveG4cerr(const G4String& cerrString) override;

void sendToFile(std::ofstream*);
inline void stopSendToFile() { fout = nullptr; }

protected:
std::string trim(const std::string& str);

private:
std::ofstream* fout;
};

#endif
12 changes: 0 additions & 12 deletions SimG4Core/Geometry/interface/G4CheckOverlap.h

This file was deleted.