7 #include "G4GDMLParser.hh" 8 #include "G4GeomTestVolume.hh" 9 #include "G4RunManagerKernel.hh" 10 #include "G4LogicalVolume.hh" 11 #include "G4LogicalVolumeStore.hh" 12 #include "G4PhysicalVolumeStore.hh" 13 #include "G4GeometryManager.hh" 14 #include "G4Region.hh" 15 #include "G4RegionStore.hh" 16 #include "G4Element.hh" 17 #include "G4ElementTable.hh" 18 #include "G4Material.hh" 19 #include "G4MaterialTable.hh" 20 #include "G4ProductionCutsTable.hh" 21 #include "G4MaterialCutsCouple.hh" 22 #include "G4SystemOfUnits.hh" 23 #include "G4VPhysicalVolume.hh" 24 #include "G4UnitsTable.hh" 36 G4VPhysicalVolume* world) {
37 bool mat =
p.getParameter<
bool>(
"MaterialFlag");
41 <<
"CMSG4CheckOverlap: OutputFileBaseName is not provided - no check is performed";
49 <<
"CMSG4CheckOverlap: file <" << sss <<
"> is not opened - no report provided";
51 edm::LogVerbatim(
"SimG4CoreGeometry") <<
"CMSG4CheckOverlap: output file <" << sss <<
"> is opened";
57 bool reg =
p.getParameter<
bool>(
"RegionFlag");
65 bool geom =
p.getParameter<
bool>(
"GeomFlag");
71 <<
"CMSG4CheckOverlap: file <" << sss <<
"> is not opened - no report provided";
73 edm::LogVerbatim(
"SimG4CoreGeometry") <<
"CMSG4CheckOverlap: output file <" << sss <<
"> is opened";
81 bool gdmlFlag =
p.getParameter<
bool>(
"gdmlFlag");
85 G4GDMLParser gdml =
nullptr;
86 gdml.SetRegionExport(
true);
87 gdml.SetEnergyCutsExport(
true);
88 gdml.SetSDExport(
true);
89 gdml.Write(
ss +
".gdml", world,
true);
93 bool oFlag =
p.getParameter<
bool>(
"OverlapFlag");
99 <<
"CMSG4CheckOverlap: file <" << sss <<
"> is not opened - no report provided";
101 edm::LogVerbatim(
"SimG4CoreGeometry") <<
"CMSG4CheckOverlap: output file <" <<
ss <<
"> is opened";
111 int nelm = G4Element::GetNumberOfElements();
112 int nmat = G4Material::GetNumberOfMaterials();
113 G4ProductionCutsTable* theCoupleTable = G4ProductionCutsTable::GetProductionCutsTable();
114 int ncouples = theCoupleTable->GetTableSize();
115 fout <<
"=====================================================================" 117 fout <<
"NumberOfElements " << nelm <<
"\n";
118 fout <<
"NumberOfMaterials " << nmat <<
"\n";
119 fout <<
"NumberOfCouples " << ncouples <<
"\n";
120 fout <<
"=====================================================================" 122 fout <<
"ElementsDump:" 124 G4ElementTable* elmtab = G4Element::GetElementTable();
126 fout <<
"=====================================================================" 128 G4MaterialTable* mattab = G4Material::GetMaterialTable();
129 fout <<
"MaterialsDump:" 132 for (
int i = 0;
i < nmat; ++
i) {
133 fout <<
"### Material " <<
i <<
" " << ((*mattab)[
i])->GetNumberOfElements() <<
" elements\n";
134 fout << (*mattab)[
i] <<
"\n";
136 fout <<
"=====================================================================" 138 fout <<
"MaterialsCutsCoupleDump:" 140 const std::vector<G4double>* gcut = theCoupleTable->GetEnergyCutsVector(0);
141 const std::vector<G4double>*
ecut = theCoupleTable->GetEnergyCutsVector(1);
142 const std::vector<G4double>* pcut = theCoupleTable->GetEnergyCutsVector(2);
143 const std::vector<G4double>* icut = theCoupleTable->GetEnergyCutsVector(3);
144 for (
int i = 0;
i < ncouples; ++
i) {
145 const G4MaterialCutsCouple* couple = theCoupleTable->GetMaterialCutsCouple(
i);
146 const G4ProductionCuts* aCut = couple->GetProductionCuts();
147 fout <<
"Index : " <<
i <<
" used in the geometry : ";
148 if (couple->IsUsed()) {
153 fout <<
" Material : " << couple->GetMaterial()->GetName() <<
"\n";
154 fout <<
" Range cuts : " 155 <<
" gamma " << G4BestUnit(aCut->GetProductionCut(0),
"Length") <<
" e- " 156 << G4BestUnit(aCut->GetProductionCut(1),
"Length") <<
" e+ " 157 << G4BestUnit(aCut->GetProductionCut(2),
"Length") <<
" proton " 158 << G4BestUnit(aCut->GetProductionCut(3),
"Length") <<
"\n";
159 fout <<
" Energy thresholds : ";
160 fout <<
" gamma " << G4BestUnit((*gcut)[
i],
"Energy") <<
" e- " << G4BestUnit((*
ecut)[
i],
"Energy")
161 <<
" e+ " << G4BestUnit((*pcut)[
i],
"Energy") <<
" proton " << G4BestUnit((*icut)[
i],
"Energy") <<
"\n";
163 fout <<
"======================================================================" 168 const G4RegionStore* regs = G4RegionStore::GetInstance();
169 const G4PhysicalVolumeStore*
pvs = G4PhysicalVolumeStore::GetInstance();
170 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
171 int numPV =
pvs->size();
172 int numLV = lvs->size();
173 int nreg = regs->size();
174 fout <<
"=====================================================================" 176 fout <<
"NumberOfRegions " << nreg <<
"\n";
177 fout <<
"NumberOfLogicalVolumes " << numLV <<
"\n";
178 fout <<
"NumberOfPhysicalVolumes " << numPV <<
"\n";
179 fout <<
"=====================================================================" 181 G4GeometryManager::GetInstance()->CloseGeometry(
true,
true, world);
182 fout <<
"=====================================================================" 188 G4VPhysicalVolume* world) {
189 std::vector<std::string> nodeNames =
p.getParameter<std::vector<std::string>>(
"NodeNames");
192 double tolerance =
p.getParameter<
double>(
"Tolerance") * CLHEP::mm;
193 int nPoints =
p.getParameter<
int>(
"Resolution");
194 bool verbose =
p.getParameter<
bool>(
"Verbose");
195 bool regionFlag =
p.getParameter<
bool>(
"RegionFlag");
196 bool gdmlFlag =
p.getParameter<
bool>(
"gdmlFlag");
197 int nPrints =
p.getParameter<
int>(
"ErrorThreshold");
199 const G4RegionStore* regStore = G4RegionStore::GetInstance();
202 const G4PhysicalVolumeStore*
pvs = G4PhysicalVolumeStore::GetInstance();
203 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
204 unsigned int numPV =
pvs->size();
205 unsigned int numLV = lvs->size();
206 unsigned int nn = nodeNames.size();
208 std::vector<G4String> savedgdml;
210 fout <<
"=====================================================================" 212 fout <<
"CMSG4OverlapCheck is initialised with " << nodeNames.size() <<
" nodes; " 213 <<
" nPoints= " << nPoints <<
"; tolerance= " <<
tolerance / mm <<
" mm; verbose: " <<
verbose <<
"\n" 214 <<
" RegionFlag: " << regionFlag <<
" PVname: " <<
PVname <<
" LVname: " <<
LVname <<
"\n" 215 <<
" Nlv= " << numLV <<
" Npv= " << numPV <<
"\n";
216 fout <<
"=====================================================================" 219 G4GDMLParser* gdml =
nullptr;
221 gdml =
new G4GDMLParser();
222 gdml->SetRegionExport(
true);
223 gdml->SetEnergyCutsExport(
true);
224 gdml->SetSDExport(
true);
227 for (
unsigned int ii = 0;
ii <
nn; ++
ii) {
228 if (nodeNames[
ii].
empty() ||
"world" == nodeNames[
ii] ||
"World" == nodeNames[
ii]) {
229 nodeNames[
ii] = world->GetName();
230 fout <<
"### Check overlaps for World " 233 test.SetErrorsThreshold(nPrints);
234 test.TestOverlapInTree();
235 }
else if (regionFlag) {
236 fout <<
"---------------------------------------------------------------" 238 fout <<
"### Check overlaps for G4Region Node[" <<
ii <<
"] : " << nodeNames[
ii] <<
"\n";
239 G4Region* reg = regStore->GetRegion((G4String)nodeNames[
ii]);
241 fout <<
"### NO G4Region found - EXIT" 245 std::vector<G4LogicalVolume*>::iterator rootLVItr = reg->GetRootLogicalVolumeIterator();
246 unsigned int numRootLV = reg->GetNumberOfRootVolumes();
247 fout <<
" " << numRootLV <<
" Root Logical Volumes in this region" 250 for (
unsigned int iLV = 0; iLV < numRootLV; ++iLV, ++rootLVItr) {
253 fout <<
"### Check overlaps for G4LogicalVolume " << lv->GetName() <<
"\n";
254 for (
unsigned int i = 0;
i < numPV; ++
i) {
255 if (((*
pvs)[
i])->GetLogicalVolume() == lv) {
256 G4String pvname = ((*pvs)[
i])->GetName();
258 for (
unsigned int k = 0;
k < savedgdml.size(); ++
k) {
259 if (pvname == savedgdml[
k]) {
265 fout <<
"### Check overlaps for PhysVolume " << pvname <<
" is skipted because was already done" 269 savedgdml.push_back(pvname);
270 fout <<
"### Check overlaps for PhysVolume " << pvname <<
"\n";
273 gdml->Write(pvname +
".gdml", (*
pvs)[
i],
true);
276 test.SetErrorsThreshold(nPrints);
277 test.TestOverlapInTree();
282 fout <<
"### Check overlaps for PhysVolume Node[" <<
ii <<
"] : " << nodeNames[
ii] <<
"\n";
283 G4VPhysicalVolume*
pv =
pvs->GetVolume((G4String)nodeNames[
ii]);
285 test.SetErrorsThreshold(nPrints);
286 test.TestOverlapInTree();
291 fout <<
"----------- List of PhysVolumes by name -----------------" 293 for (
unsigned int i = 0;
i < numPV; ++
i) {
295 fout <<
" ##### PhysVolume " <<
PVname <<
" [" << ((*pvs)[
i])->GetCopyNo()
296 <<
"] LV: " << ((*pvs)[
i])->GetLogicalVolume()->GetName()
297 <<
" Mother LV: " << ((*pvs)[
i])->GetMotherLogical()->GetName()
298 <<
" Region: " << ((*pvs)[
i])->GetLogicalVolume()->GetRegion()->GetName() <<
"\n";
299 fout <<
" Translation: " << ((*pvs)[
i])->GetObjectTranslation() <<
"\n";
300 fout <<
" Rotation: " << ((*pvs)[
i])->GetObjectRotationValue() <<
"\n";
302 gdml->Write(
PVname +
".gdml", (*
pvs)[
i],
true);
308 fout <<
"---------- List of Logical Volumes by name ------------------" 310 for (
unsigned int i = 0;
i < numLV; ++
i) {
311 if (
LVname == ((*lvs)[
i])->GetName()) {
312 G4int
np = ((*lvs)[
i])->GetNoDaughters();
313 fout <<
" ##### LogVolume " <<
LVname <<
" " <<
np <<
" daughters" 314 <<
" Region: " << ((*lvs)[
i])->GetRegion()->GetName() <<
"\n";
315 fout << *(((*lvs)[
i])->GetSolid()) <<
"\n";
316 for (G4int
j = 0;
j <
np; ++
j) {
317 G4VPhysicalVolume*
pv = ((*lvs)[
i])->GetDaughter(
j);
319 fout <<
" PV: " <<
pv->GetName() <<
" [" <<
pv->GetCopyNo() <<
"]" 320 <<
" type: " <<
pv->VolumeType() <<
" multiplicity: " <<
pv->GetMultiplicity()
321 <<
" LV: " <<
pv->GetLogicalVolume()->GetName() <<
"\n";
322 fout <<
" Translation: " <<
pv->GetObjectTranslation() <<
"\n";
323 fout <<
" Rotation: " <<
pv->GetObjectRotationValue() <<
"\n";
324 fout << *(
pv->GetLogicalVolume()->GetSolid()) <<
"\n";
330 fout <<
"---------------- End of overlap checks ---------------------" void makeReportForGeometry(std::ofstream &fout, G4VPhysicalVolume *world)
Log< level::Info, true > LogVerbatim
void sendToFile(std::ofstream *)
void makeReportForMaterials(std::ofstream &fout)
void ReportRegions(const std::string &ss)
void makeReportForOverlaps(std::ofstream &fout, const edm::ParameterSet &p, G4VPhysicalVolume *world)
Log< level::Warning, false > LogWarning
CMSG4CheckOverlap(edm::ParameterSet const &p, std::string ®File, CustomUIsession *, G4VPhysicalVolume *world)