20#include "BDSException.hh"
21#include "BDSGeometryExternal.hh"
22#include "BDSGeometryFactory.hh"
23#include "BDSGlobalConstants.hh"
24#include "BDSImportanceFileLoader.hh"
25#include "BDSParallelWorldImportance.hh"
26#include "BDSUtilities.hh"
29#include "G4GeometryCell.hh"
31#include "G4LogicalVolume.hh"
32#include "G4PVPlacement.hh"
33#include "G4VisAttributes.hh"
34#include "G4VPhysicalVolume.hh"
37#include "src-external/gzstream/gzstream.h"
45BDSParallelWorldImportance::BDSParallelWorldImportance(G4String name,
46 G4String importanceWorldGeometryFile,
47 G4String importanceValuesFile):
48 G4VUserParallelWorld(
"importanceWorld_" + name),
50 imGeomFile(importanceWorldGeometryFile),
51 imVolMap(importanceValuesFile),
52 componentName(
"importanceWorld")
66 if (importanceMapFile.rfind(
"gz") != std::string::npos)
72 throw BDSException(__METHOD_NAME__,
"Compressed file loading - but BDSIM not compiled with ZLIB.");
85BDSParallelWorldImportance::~BDSParallelWorldImportance()
104 G4LogicalVolume* worldLV =
imWorldPV->GetLogicalVolume();
107 G4VisAttributes* importanceWorldVis =
new G4VisAttributes(*(
visAttr));
108 importanceWorldVis->SetForceWireframe(
true);
109 worldLV->SetVisAttributes(importanceWorldVis);
117 for (G4int i = 0; i < (G4int)container->GetNoDaughters(); i++)
119 G4VPhysicalVolume* daughter = container->GetDaughter(i);
120 daughter->SetMotherLogical(worldLV);
122 G4VPhysicalVolume* parallelPV =
new G4PVPlacement(daughter->GetRotation(),
123 daughter->GetTranslation(),
124 daughter->GetLogicalVolume(),
130 G4GeometryCell cell(*parallelPV, 0);
139 {
return G4GeometryCell(*p,0);}
142 G4cout << __METHOD_NAME__ <<
" Couldn't get G4GeometryCell" << G4endl;
149 G4IStore* aIstore = G4IStore::GetInstance(
imWorldPV->GetName());
152 G4GeometryCell gWorldVolumeCell(*
imWorldPV, 0);
155 aIstore->AddImportanceGeometryCell(1, gWorldVolumeCell);
160 G4String cellName = cell.GetPhysicalVolume().GetName();
163 if (!aIstore->IsKnown(cell))
164 {aIstore->AddImportanceGeometryCell(importanceValue, cell.GetPhysicalVolume(), 0);}
167 G4String message =
"Geometry cell \"" + cellName +
"\" already exists and has been previously\n";
168 message +=
"added to the IStore.";
176 auto flagsCache(G4cout.flags());
179 {G4cout << std::left << std::setw(25) << cellAndImportance.first <<
" " << cellAndImportance.second << G4endl;}
180 G4cout.flags(flagsCache);
188 G4String pureCellName = cellName;
192 pureCellName = pureCellName.erase(0,
componentName.size()+1);
196 const G4String prepend =
"PREPEND";
199 std::size_t found = pureCellName.find(prepend);
200 pureCellName.erase(found, found + prepend.size());
206 std::size_t found = pureCellName.find(
"_pv_pv");
207 pureCellName.erase(found+3, found+6);
213 G4double importanceValue = (*result).second;
215 if (importanceValue < 0)
217 G4String message =
"Importance value is negative for cell \"" + pureCellName +
"\".";
222 G4String message =
"Importance value is zero for cell \"" + pureCellName +
"\".";
225 return importanceValue;
230 G4String message =
"An importance value was not found for the cell \"" + pureCellName +
"\" in \n";
231 message +=
"the importance world geometry.";
236void BDSParallelWorldImportance::ConstructSD()
General exception with possible name of object and message.
G4LogicalVolume * GetContainerLogicalVolume() const
Accessor - see member for more info.
A loaded piece of externally provided geometry.
BDSGeometryExternal * BuildGeometry(G4String componentName, const G4String &formatAndFilePath, std::map< G4String, G4Colour * > *colourMapping=nullptr, G4bool autoColour=true, G4double suggestedLength=0, G4double suggestedHorizontalWidth=0, std::vector< G4String > *namedVacuumVolumes=nullptr, G4bool makeSensitive=true, BDSSDType sensitivityType=BDSSDType::energydep, BDSSDType vacuumSensitivityType=BDSSDType::energydepvacuum, G4bool stripOuterVolumeAndMakeAssembly=false, G4UserLimits *userLimitsToAttachToAllLVs=nullptr, G4bool dontReloadGeometry=false)
static BDSGeometryFactory * Instance()
Singleton accessor.
static BDSGlobalConstants * Instance()
Access method.
A loader for importance values used in importance sampling.
const G4VPhysicalVolume * GetPVolume(G4int index) const
Get stores physical volume from index.
void AddPVolume(const G4GeometryCell &cell)
Add geometry cell to the store.
const G4String componentName
String preprended to geometry with preprocessGDML.
BDSImportanceVolumeStore imVolumeStore
Store of geometry cells for importance volumes.
G4double GetCellImportanceValue(const G4String &cellName)
Get importance value of a given physical volume name.
void AddIStore()
Create IStore for all importance sampling geometry cells.
std::map< G4String, G4double > imVolumesAndValues
Container for all user placed physical volumes and corresponding importance values.
G4VPhysicalVolume * imWorldPV
Importance sampling world volume.
G4int verbosity
Cached global constants values.
G4GeometryCell GetGeometryCell(G4int i) const
Get geometry cell from store.
G4VisAttributes * visAttr
Cached global constants values.
G4UserLimits * userLimits
Cached global constants values.
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
G4String GetFullPath(G4String filename, bool excludeNameFromPath=false, bool useCWDForPrefix=false)
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())