Skip to content

Commit e6f90ca

Browse files
authored
Merge pull request #48739 from civanch/g4tests_geom_extra
[SIM] added test of geometry and improved run time info
2 parents 829c8b0 + 51385d8 commit e6f90ca

File tree

6 files changed

+124
-9
lines changed

6 files changed

+124
-9
lines changed

SimG4Core/Application/src/RunManagerMTWorker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ RunManagerMTWorker::RunManagerMTWorker(const edm::ParameterSet& p, edm::Consumes
181181
m_G4CommandsEndRun(p.getParameter<std::vector<std::string>>("G4CommandsEndRun")),
182182
m_p(p) {
183183
int id = getThreadIndex();
184-
if (id > CurrentG4Track::NumberOfThreads()) {
185-
CurrentG4Track::setNumberOfThreads(id);
184+
if (id + 1 > CurrentG4Track::numberOfWorkers()) {
185+
CurrentG4Track::setNumberOfWorkers(id + 1);
186186
}
187187
edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker for the thread " << id;
188188

SimG4Core/Geometry/interface/CMSG4CheckOverlap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CMSG4CheckOverlap {
1717
void makeReportForMaterials(std::ofstream& fout);
1818
void makeReportForGeometry(std::ofstream& fout, G4VPhysicalVolume* world);
1919
void makeReportForOverlaps(std::ofstream& fout, const edm::ParameterSet& p, G4VPhysicalVolume* world);
20+
void makeReportForGivenRegion(std::ofstream& fout, const std::string& rname);
2021
};
2122

2223
#endif

SimG4Core/Geometry/src/CMSG4CheckOverlap.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ CMSG4CheckOverlap::CMSG4CheckOverlap(const edm::ParameterSet& p,
7878
}
7979
}
8080

81+
const std::string& rname = p.getParameter<std::string>("NodeName");
82+
if (!rname.empty()) {
83+
const std::string qqq = p.getParameter<std::string>("LVname") + ".txt";
84+
std::ofstream fout(qqq.c_str(), std::ios::out);
85+
if (fout.fail()) {
86+
edm::LogWarning("SimG4CoreGeometry")
87+
<< "CMSG4CheckOverlap: file <" << qqq << "> is not opened - no report provided";
88+
} else {
89+
edm::LogVerbatim("SimG4CoreGeometry") << "CMSG4CheckOverlap: output file <" << qqq << "> is opened";
90+
session->sendToFile(&fout);
91+
makeReportForGivenRegion(fout, rname);
92+
session->stopSendToFile();
93+
fout.close();
94+
}
95+
}
96+
8197
bool gdmlFlag = p.getParameter<bool>("gdmlFlag");
8298
if (gdmlFlag) {
8399
std::string PVname = p.getParameter<std::string>("PVname");
@@ -164,6 +180,28 @@ void CMSG4CheckOverlap::makeReportForMaterials(std::ofstream& fout) {
164180
<< "\n";
165181
}
166182

183+
void CMSG4CheckOverlap::makeReportForGivenRegion(std::ofstream& fout, const std::string& rname) {
184+
const G4RegionStore* regs = G4RegionStore::GetInstance();
185+
const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
186+
fout << "====================================================================="
187+
<< "\n";
188+
fout << "Logical volumes in the region " << rname << "\n";
189+
fout << "====================================================================="
190+
<< "\n";
191+
auto reg = regs->GetRegion((G4String)rname);
192+
if (nullptr == reg) {
193+
fout << "G4Region " << rname << "does not exist \n";
194+
return;
195+
}
196+
unsigned int numRootLV = reg->GetNumberOfRootVolumes();
197+
fout << "Number of Root Logical Volumes: " << numRootLV << "\n";
198+
for (auto const& lv : *lvs) {
199+
if (reg == lv->GetRegion()) {
200+
fout << lv->GetName() << " isRoot: " << lv->IsRootRegion() << "\n";
201+
}
202+
}
203+
}
204+
167205
void CMSG4CheckOverlap::makeReportForGeometry(std::ofstream& fout, G4VPhysicalVolume* world) {
168206
const G4RegionStore* regs = G4RegionStore::GetInstance();
169207
const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();

SimG4Core/Notification/interface/CurrentG4Track.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
* It provides immediate access to the currently tracked G4Track
99
* for places that can't access this information easily,
1010
* like StackingAction.
11-
* It also provide an access to the total number of threads in the run
11+
* It also provide an access to the total number of workers in the run
1212
*/
1313

1414
class CurrentG4Track {
1515
public:
1616
static const G4Track *track();
17-
static int NumberOfThreads();
18-
static void setNumberOfThreads(int);
17+
static int numberOfWorkers();
18+
static void setNumberOfWorkers(int);
1919
static void setTrack(const G4Track *);
2020

2121
private:
2222
static thread_local const G4Track *m_track;
23-
static int m_nThreads;
23+
static int m_nWorkers;
2424
};
2525

2626
#endif
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "SimG4Core/Notification/interface/CurrentG4Track.h"
22

3-
int CurrentG4Track::m_nThreads = 0;
3+
int CurrentG4Track::m_nWorkers = 0;
44
thread_local const G4Track* CurrentG4Track::m_track = nullptr;
55

66
void CurrentG4Track::setTrack(const G4Track* t) { m_track = t; }
77

88
const G4Track* CurrentG4Track::track() { return m_track; }
99

10-
int CurrentG4Track::NumberOfThreads() { return m_nThreads; };
10+
int CurrentG4Track::numberOfWorkers() { return m_nWorkers; };
1111

12-
void CurrentG4Track::setNumberOfThreads(int n) { m_nThreads = n; };
12+
void CurrentG4Track::setNumberOfWorkers(int n) { m_nWorkers = n; };
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
###############################################################################
2+
# Way to use this:
3+
# cmsRun g4HGCalPringLV_cfg.py geometry=D121 tol=0.01
4+
#
5+
# Options for geometry D110, D121
6+
#
7+
###############################################################################
8+
import FWCore.ParameterSet.Config as cms
9+
import os, sys, importlib, re
10+
import FWCore.ParameterSet.VarParsing as VarParsing
11+
12+
####################################################################
13+
### SETUP OPTIONS
14+
options = VarParsing.VarParsing('standard')
15+
options.register('geometry',
16+
"D121",
17+
VarParsing.VarParsing.multiplicity.singleton,
18+
VarParsing.VarParsing.varType.string,
19+
"geometry of operations: D110, D121")
20+
options.register('tol',
21+
0.01,
22+
VarParsing.VarParsing.multiplicity.singleton,
23+
VarParsing.VarParsing.varType.float,
24+
"Tolerance for checking overlaps: 0.0, 0.01, 0.1, 1.0"
25+
)
26+
27+
### get and parse the command line arguments
28+
options.parseArguments()
29+
30+
print(options)
31+
32+
####################################################################
33+
# Use the options
34+
35+
geomName = "Run4" + options.geometry
36+
geomFile = "Configuration.Geometry.GeometryExtended" + geomName + "Reco_cff"
37+
import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings
38+
GLOBAL_TAG, ERA = _settings.get_era_and_conditions(geomName)
39+
baseName = "HGCalRun4" + options.geometry
40+
print("Geometry Name: ", geomName)
41+
print("Geom file Name: ", geomFile)
42+
print("Global Tag Name: ", GLOBAL_TAG)
43+
print("Era Name: ", ERA)
44+
print("Base file Name: ", baseName)
45+
46+
process = cms.Process('G4PrintGeometry',ERA)
47+
48+
process.load(geomFile)
49+
from SimG4Core.PrintGeomInfo.g4TestGeometry_cfi import *
50+
process = checkOverlap(process)
51+
52+
# enable Geant4 overlap check
53+
process.g4SimHits.CheckGeometry = True
54+
55+
# Geant4 geometry check
56+
process.g4SimHits.G4CheckOverlap.OutputBaseName = cms.string(baseName)
57+
process.g4SimHits.G4CheckOverlap.OverlapFlag = cms.bool(False)
58+
process.g4SimHits.G4CheckOverlap.Tolerance = cms.double(options.tol)
59+
process.g4SimHits.G4CheckOverlap.Resolution = cms.int32(10000)
60+
process.g4SimHits.G4CheckOverlap.Depth = cms.int32(-1)
61+
# tells if NodeName is G4Region or G4PhysicalVolume
62+
process.g4SimHits.G4CheckOverlap.RegionFlag = cms.bool(True)
63+
# list of names
64+
process.g4SimHits.G4CheckOverlap.NodeName = cms.string('HGCalRegion')
65+
# enable dump gdml file
66+
process.g4SimHits.G4CheckOverlap.gdmlFlag = cms.bool(False)
67+
# if defined a G4PhysicsVolume info is printed
68+
process.g4SimHits.G4CheckOverlap.PVname = ''
69+
# if defined a list of daughter volumes is printed
70+
process.g4SimHits.G4CheckOverlap.LVname = 'lvD121'
71+
72+
# extra output files, created if a name is not empty
73+
process.g4SimHits.FileNameField = ''
74+
process.g4SimHits.FileNameGDML = ''
75+
process.g4SimHits.FileNameRegions = ''
76+
#

0 commit comments

Comments
 (0)