7 #include "G4GDMLParser.hh"
8 #include "G4GeomTestVolume.hh"
9 #include "G4LogicalVolume.hh"
10 #include "G4LogicalVolumeStore.hh"
11 #include "G4PhysicalVolumeStore.hh"
12 #include "G4GeometryManager.hh"
13 #include "G4Region.hh"
14 #include "G4RegionStore.hh"
15 #include "G4Element.hh"
16 #include "G4ElementTable.hh"
17 #include "G4Material.hh"
18 #include "G4MaterialTable.hh"
19 #include "G4ProductionCutsTable.hh"
20 #include "G4MaterialCutsCouple.hh"
21 #include "G4SystemOfUnits.hh"
22 #include "G4VPhysicalVolume.hh"
23 #include "G4UnitsTable.hh"
35 G4VPhysicalVolume* world) {
36 bool mat =
p.getParameter<
bool>(
"MaterialFlag");
40 <<
"CMSG4CheckOverlap: OutputFileBaseName is not provided - no check is performed";
48 <<
"CMSG4CheckOverlap: file <" << sss <<
"> is not opened - no report provided";
50 edm::LogVerbatim(
"SimG4CoreGeometry") <<
"CMSG4CheckOverlap: output file <" << sss <<
"> is opened";
56 bool reg =
p.getParameter<
bool>(
"RegionFlag");
64 bool geom =
p.getParameter<
bool>(
"GeomFlag");
70 <<
"CMSG4CheckOverlap: file <" << sss <<
"> is not opened - no report provided";
72 edm::LogVerbatim(
"SimG4CoreGeometry") <<
"CMSG4CheckOverlap: output file <" << sss <<
"> is opened";
79 bool oFlag =
p.getParameter<
bool>(
"OverlapFlag");
85 <<
"CMSG4CheckOverlap: file <" << sss <<
"> is not opened - no report provided";
87 edm::LogVerbatim(
"SimG4CoreGeometry") <<
"CMSG4CheckOverlap: output file <" <<
ss <<
"> is opened";
97 int nelm = G4Element::GetNumberOfElements();
98 int nmat = G4Material::GetNumberOfMaterials();
99 G4ProductionCutsTable* theCoupleTable = G4ProductionCutsTable::GetProductionCutsTable();
100 int ncouples = theCoupleTable->GetTableSize();
101 fout <<
"====================================================================="
103 fout <<
"NumberOfElements " << nelm <<
"\n";
104 fout <<
"NumberOfMaterials " << nmat <<
"\n";
105 fout <<
"NumberOfCouples " << ncouples <<
"\n";
106 fout <<
"====================================================================="
108 fout <<
"ElementsDump:"
110 G4ElementTable* elmtab = G4Element::GetElementTable();
112 fout <<
"====================================================================="
114 G4MaterialTable* mattab = G4Material::GetMaterialTable();
115 fout <<
"MaterialsDump:"
118 for (
int i = 0;
i < nmat; ++
i) {
119 fout <<
"### Material " <<
i <<
" " << ((*mattab)[
i])->GetNumberOfElements() <<
" elements\n";
120 fout << (*mattab)[
i] <<
"\n";
122 fout <<
"====================================================================="
124 fout <<
"MaterialsCutsCoupleDump:"
126 const std::vector<G4double>* gcut = theCoupleTable->GetEnergyCutsVector(0);
127 const std::vector<G4double>* ecut = theCoupleTable->GetEnergyCutsVector(1);
128 const std::vector<G4double>* pcut = theCoupleTable->GetEnergyCutsVector(2);
129 const std::vector<G4double>* icut = theCoupleTable->GetEnergyCutsVector(3);
130 for (
int i = 0;
i < ncouples; ++
i) {
131 const G4MaterialCutsCouple* couple = theCoupleTable->GetMaterialCutsCouple(
i);
132 const G4ProductionCuts* aCut = couple->GetProductionCuts();
133 fout <<
"Index : " <<
i <<
" used in the geometry : ";
134 if (couple->IsUsed()) {
139 fout <<
" Material : " << couple->GetMaterial()->GetName() <<
"\n";
140 fout <<
" Range cuts : "
141 <<
" gamma " << G4BestUnit(aCut->GetProductionCut(0),
"Length") <<
" e- "
142 << G4BestUnit(aCut->GetProductionCut(1),
"Length") <<
" e+ "
143 << G4BestUnit(aCut->GetProductionCut(2),
"Length") <<
" proton "
144 << G4BestUnit(aCut->GetProductionCut(3),
"Length") <<
"\n";
145 fout <<
" Energy thresholds : ";
146 fout <<
" gamma " << G4BestUnit((*gcut)[
i],
"Energy") <<
" e- " << G4BestUnit((*ecut)[
i],
"Energy")
147 <<
" e+ " << G4BestUnit((*pcut)[
i],
"Energy") <<
" proton " << G4BestUnit((*icut)[
i],
"Energy") <<
"\n";
149 fout <<
"======================================================================"
154 const G4RegionStore* regs = G4RegionStore::GetInstance();
155 const G4PhysicalVolumeStore*
pvs = G4PhysicalVolumeStore::GetInstance();
156 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
157 int numPV =
pvs->size();
158 int numLV = lvs->size();
159 int nreg = regs->size();
160 fout <<
"====================================================================="
162 fout <<
"NumberOfRegions " << nreg <<
"\n";
163 fout <<
"NumberOfLogicalVolumes " << numLV <<
"\n";
164 fout <<
"NumberOfPhysicalVolumes " << numPV <<
"\n";
165 fout <<
"====================================================================="
167 G4GeometryManager::GetInstance()->CloseGeometry(
true,
true, world);
168 fout <<
"====================================================================="
173 std::vector<std::string> nodeNames =
p.getParameter<std::vector<std::string>>(
"NodeNames");
176 double tolerance =
p.getParameter<
double>(
"Tolerance") * CLHEP::mm;
177 int nPoints =
p.getParameter<
int>(
"Resolution");
178 bool verbose =
p.getParameter<
bool>(
"Verbose");
179 bool regionFlag =
p.getParameter<
bool>(
"RegionFlag");
180 bool gdmlFlag =
p.getParameter<
bool>(
"gdmlFlag");
181 int nPrints =
p.getParameter<
int>(
"ErrorThreshold");
182 int level =
p.getParameter<
int>(
"Level");
183 int depth =
p.getParameter<
int>(
"Depth");
185 const G4RegionStore* regStore = G4RegionStore::GetInstance();
188 const G4PhysicalVolumeStore*
pvs = G4PhysicalVolumeStore::GetInstance();
189 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
190 unsigned int numPV =
pvs->size();
191 unsigned int numLV = lvs->size();
192 unsigned int nn = nodeNames.size();
194 std::vector<G4String> savedgdml;
196 fout <<
"====================================================================="
198 fout <<
"CMSG4OverlapCheck is initialised with " << nodeNames.size() <<
" nodes; "
199 <<
" nPoints= " << nPoints <<
"; tolerance= " <<
tolerance / mm <<
" mm; verbose: " <<
verbose <<
"\n"
200 <<
" RegionFlag: " << regionFlag <<
" PVname: " <<
PVname <<
" LVname: " <<
LVname <<
"\n"
201 <<
" Nlv= " << numLV <<
" Npv= " << numPV <<
"\n";
202 fout <<
"====================================================================="
206 for (
unsigned int ii = 0;
ii <
nn; ++
ii) {
207 if (nodeNames[
ii].
empty() ||
"world" == nodeNames[
ii] ||
"World" == nodeNames[
ii]) {
208 nodeNames[
ii] =
"DDDWorld";
209 fout <<
"### Check overlaps for DDDWorld "
211 G4VPhysicalVolume*
pv =
pvs->GetVolume(
"DDDWorld");
213 test.SetErrorsThreshold(nPrints);
215 }
else if (regionFlag) {
216 fout <<
"---------------------------------------------------------------"
218 fout <<
"### Check overlaps for G4Region Node[" <<
ii <<
"] : " << nodeNames[
ii] <<
"\n";
219 G4Region* reg = regStore->GetRegion((G4String)nodeNames[
ii]);
221 fout <<
"### NO G4Region found - EXIT"
225 std::vector<G4LogicalVolume*>::iterator rootLVItr = reg->GetRootLogicalVolumeIterator();
226 unsigned int numRootLV = reg->GetNumberOfRootVolumes();
227 fout <<
" " << numRootLV <<
" Root Logical Volumes in this region"
230 for (
unsigned int iLV = 0; iLV < numRootLV; ++iLV, ++rootLVItr) {
233 fout <<
"### Check overlaps for G4LogicalVolume " << lv->GetName() <<
"\n";
234 for (
unsigned int i = 0;
i < numPV; ++
i) {
235 if (((*
pvs)[
i])->GetLogicalVolume() == lv) {
236 G4String pvname = ((*pvs)[
i])->GetName();
238 for (
unsigned int k = 0;
k < savedgdml.size(); ++
k) {
239 if (pvname == savedgdml[
k]) {
245 fout <<
"### Check overlaps for PhysVolume " << pvname <<
" is skipted because was already done"
249 savedgdml.push_back(pvname);
250 fout <<
"### Check overlaps for PhysVolume " << pvname <<
"\n";
254 gdml.Write(pvname +
".gdml", (*
pvs)[
i],
true);
257 test.SetErrorsThreshold(nPrints);
263 fout <<
"### Check overlaps for PhysVolume Node[" <<
ii <<
"] : " << nodeNames[
ii] <<
"\n";
264 G4VPhysicalVolume*
pv =
pvs->GetVolume((G4String)nodeNames[
ii]);
266 test.SetErrorsThreshold(nPrints);
272 fout <<
"----------- List of PhysVolumes by name -----------------"
274 for (
unsigned int i = 0;
i < numPV; ++
i) {
276 fout <<
" ##### PhysVolume " <<
PVname <<
" [" << ((*pvs)[
i])->GetCopyNo()
277 <<
"] LV: " << ((*pvs)[
i])->GetLogicalVolume()->GetName()
278 <<
" Mother LV: " << ((*pvs)[
i])->GetMotherLogical()->GetName()
279 <<
" Region: " << ((*pvs)[
i])->GetLogicalVolume()->GetRegion()->GetName() <<
"\n";
280 fout <<
" Translation: " << ((*pvs)[
i])->GetObjectTranslation() <<
"\n";
281 fout <<
" Rotation: " << ((*pvs)[
i])->GetObjectRotationValue() <<
"\n";
284 gdml.Write(
PVname +
".gdml", (*
pvs)[
i],
true);
290 fout <<
"---------- List of Logical Volumes by name ------------------"
292 for (
unsigned int i = 0;
i < numLV; ++
i) {
293 if (
LVname == ((*lvs)[
i])->GetName()) {
294 G4int
np = ((*lvs)[
i])->GetNoDaughters();
295 fout <<
" ##### LogVolume " <<
LVname <<
" " <<
np <<
" daughters"
296 <<
" Region: " << ((*lvs)[
i])->GetRegion()->GetName() <<
"\n";
297 fout << *(((*lvs)[
i])->GetSolid()) <<
"\n";
298 for (G4int
j = 0;
j <
np; ++
j) {
299 G4VPhysicalVolume*
pv = ((*lvs)[
i])->GetDaughter(
j);
301 fout <<
" PV: " <<
pv->GetName() <<
" [" <<
pv->GetCopyNo() <<
"]"
302 <<
" type: " <<
pv->VolumeType() <<
" multiplicity: " <<
pv->GetMultiplicity()
303 <<
" LV: " <<
pv->GetLogicalVolume()->GetName() <<
"\n";
304 fout <<
" Translation: " <<
pv->GetObjectTranslation() <<
"\n";
305 fout <<
" Rotation: " <<
pv->GetObjectRotationValue() <<
"\n";
306 fout << *(
pv->GetLogicalVolume()->GetSolid()) <<
"\n";
312 fout <<
"---------------- End of overlap checks ---------------------"