GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
Public Member Functions
GGSDetectorConstruction Class Reference

Class for GGS detector construction. More...

#include <GGSDetectorConstruction.h>

Inheritance diagram for GGSDetectorConstruction:
Inheritance graph
[legend]
Collaboration diagram for GGSDetectorConstruction:
Collaboration graph
[legend]

Public Member Functions

 GGSDetectorConstruction (const G4String &library, const G4String &configDataCard)
 Constructor. More...
 
 GGSDetectorConstruction (const G4String &library, const G4String &detectorFlags, const G4String &configDataCard, bool verbose)
 Constructor. More...
 
 GGSDetectorConstruction (const G4String &gdxml)
 Constructor. More...
 
 ~GGSDetectorConstruction ()
 Destructor.
 
G4VPhysicalVolume * Construct ()
 Override of the Construct method. More...
 
void ConstructSDandField ()
 
const G4VPhysicalVolume * GetPhysicalWorld () const
 Returns a pointer to the physical world volume. More...
 
const GGSVGeometryConstructionGetGeometry () const
 Returns a pointer to the geometry. More...
 

Detailed Description

Class for GGS detector construction.

This class inherits from G4VUserDetectorConstruction and handles the detector construction. It loads the externally defined geometry, then finds the sensitive volumes and associate the corresponding hit type to each of them.

Definition at line 30 of file GGSDetectorConstruction.h.

Constructor & Destructor Documentation

GGSDetectorConstruction::GGSDetectorConstruction ( const G4String &  library,
const G4String &  configDataCard 
)

Constructor.

Constructor for geometry provided by a shared library.

Parameters
libraryThe shared library containing the concrete implementation of GGSVGeometryConstruction.
configDataCardData card for geometry configuration (behavior is geometry-dependent).

Definition at line 155 of file GGSDetectorConstruction.cpp.

156  : _physicalWorld(nullptr), _geometry(nullptr), _library(library), _configDataCard(configDataCard), _gdxml(""),
157  _messenger(this, "/GGS/"), _nToPrintForVectGeoParams{10} {
158  _messenger.DeclareProperty("nToPrintForVectGeoParams", _nToPrintForVectGeoParams,
159  "Maximum number of elemts to print for vector parameters (default: 10; 0 -> all)");
160 }
GGSDetectorConstruction::GGSDetectorConstruction ( const G4String &  library,
const G4String &  detectorFlags,
const G4String &  configDataCard,
bool  verbose 
)

Constructor.

Old constructor maintained for backward compatibility. The detector and verbosity flags are ignored (if needed, their functionalities can be implemented using a messenger for the geometry and a geometry datacard).

Parameters
libraryThe shared library containing the concrete implementation of GGSVGeometryConstruction.
detectorFlagsIgnored.
configDataCardData card for geometry configuration (behavior is geometry-dependent).
verboseIgnored.

Definition at line 164 of file GGSDetectorConstruction.cpp.

166  : _physicalWorld(nullptr), _geometry(nullptr), _library(library), _configDataCard(configDataCard), _gdxml(""),
167  _messenger(this, "/GGS/"), _nToPrintForVectGeoParams{10} {
168  _messenger.DeclareProperty("nToPrintForVectGeoParams", _nToPrintForVectGeoParams,
169  "Maximum number of elemts to print for vector parameters (default: 10; 0 -> all)");
170 }
GGSDetectorConstruction::GGSDetectorConstruction ( const G4String &  gdxml)

Constructor.

Constructor for geometry provided by a gdml file or by a DD4hep xml file.

Parameters
gdxmlThe gdml or xml file.

Definition at line 174 of file GGSDetectorConstruction.cpp.

175  : _physicalWorld(nullptr), _geometry(nullptr), _library(""), _configDataCard(""), _gdxml(gdxml),
176  _messenger(this, "/GGS/"), _nToPrintForVectGeoParams{10} {
177  _messenger.DeclareProperty("nToPrintForVectGeoParams", _nToPrintForVectGeoParams,
178  "Maximum number of elemts to print for vector parameters (default: 10; 0 -> all)");
179 }

Member Function Documentation

G4VPhysicalVolume * GGSDetectorConstruction::Construct ( )

Override of the Construct method.

This override constructs the geometry by loading the external geometry library, then identifies the sensitive volumes and associate the corresponding hits to them.

Returns
Pointer to the physical world volume.

Definition at line 235 of file GGSDetectorConstruction.cpp.

235  {
236 
237  static const std::string routineName("GGSDetectorConstruction::Construct");
238 
239  // 1. Construct the geometry
240  if (_library != "") {
241  // 1.1 Load the concrete GGSVGeometryConstruction from a shared library
242  if (!(GGSGeoPluginManager::GetInstance().LoadGeoPlugin(_library))) {
243  GGSCOUT(ERROR) << "Impossible to load geometry library " << _library << GGSENDL;
244  throw std::runtime_error("Impossible to load geometry library");
245  }
247  if (!_geometry) {
248  GGSCOUT(ERROR) << "Can't create the geometry." << GGSENDL;
249  }
250  GGSCOUT(INFO) << "Construct the detector." << GGSENDL;
251  _geometry->SetGeoDataCard(_configDataCard);
252  _physicalWorld = _geometry->Construct();
253  // Print geometry version
254  const std::string geoVersion = _geometry->GetVersion();
255  if (geoVersion != "") {
256  GGSCOUT(INFO) << "Geometry version: " << geoVersion << GGSENDL;
257  } else {
258  GGSCOUT(INFO) << "No geometry version available" << GGSENDL;
259  }
260  // Print geometry parameters
261  _geometry->ExportParameters(); // Will throw if something goes wrong, so don't check the return value
262  auto intParams = _geometry->GetIntParameters();
263  auto boolParams = _geometry->GetBoolParameters();
264  auto realParams = _geometry->GetRealParameters();
265  auto stringParams = _geometry->GetStringParameters();
266  auto vectIntParams = _geometry->GetVectIntParameters();
267  auto vectBoolParams = _geometry->GetVectBoolParameters();
268  auto vectRealParams = _geometry->GetVectRealParameters();
269  auto vectStringParams = _geometry->GetVectStringParameters();
270  if (intParams.size() != 0 || boolParams.size() != 0 || realParams.size() != 0 || stringParams.size() != 0 ||
271  vectIntParams.size() != 0 || vectBoolParams.size() != 0 || vectRealParams.size() != 0 ||
272  vectStringParams.size() != 0) {
273  GGSCOUT(INFO) << "Geometry parameters:\n";
274  for (auto &par : intParams) {
275  GGSCCOUT(INFO) << par.first << ": " << par.second << "\n";
276  }
277  for (auto &par : boolParams) {
278  GGSCCOUT(INFO) << par.first << ": " << (par.second ? "true" : "false") << "\n";
279  }
280  for (auto &par : realParams) {
281  GGSCCOUT(INFO) << par.first << ": " << par.second << "\n";
282  }
283  for (auto &par : stringParams) {
284  GGSCCOUT(INFO) << par.first << ": " << par.second << "\n";
285  }
286  PrintVectParams(vectIntParams, _nToPrintForVectGeoParams);
287  PrintVectParams(vectRealParams, _nToPrintForVectGeoParams);
288  PrintVectParams(vectBoolParams, _nToPrintForVectGeoParams);
289  PrintVectParams(vectStringParams, _nToPrintForVectGeoParams);
290  }
291  }
292 #ifdef USE_GDML
293  else if (_gdxml.length() > 4 && _gdxml.substr(_gdxml.length() - 5) == ".gdml") {
294  // 1.2 Build the geometry from a GDML file
295  G4GDMLParser gdmlParser;
296  gdmlParser.SetOverlapCheck(false);
297  try {
298  gdmlParser.Read(_gdxml, false);
299  } catch (int &ge) {
300  GGSCOUT(ERROR) << "G4GDML: " << ge << ", missing network connection? wrong schema URL?" << GGSENDL;
301  // G4GGSCOUT << "Try to read GDML file _WITHOUT_ schema validation" << G4GGSENDL;
302  // error, try without schema validation
303  // gdmlParser.ValidateSchema(false);
304  // gdmlParser.Read(_gdxml, false);
305  }
306  gdmlParser.StripNamePointers();
307  _physicalWorld = gdmlParser.GetWorldVolume();
308  if (!_physicalWorld) {
309  GGSCOUT(ERROR) << "Cannot build the GMDL geometry." << GGSENDL;
310  throw std::runtime_error("Cannot build the GMDL geometry.");
311  }
312  _geometry = new GGSGDMLGeometryConstruction(_physicalWorld);
313  }
314 #endif
315 #ifdef GGS_USE_DD4HEP
316  else if (_gdxml.length() > 3 && _gdxml.substr(_gdxml.length() - 4) == ".xml") {
317  // 1.3 Build the DD4hep geometry
318  dd4hep::Detector &detDesc = dd4hep::Detector::getInstance();
319  detDesc.fromXML(_gdxml);
320  dd4hep::DetElement world = detDesc.world();
321  dd4hep::sim::Geant4Converter conv(detDesc, dd4hep::NOLOG);
322  dd4hep::sim::Geant4GeometryInfo *geoInfo = conv.create(world).detach();
323  _physicalWorld = geoInfo->world();
324  _geometry = new GGSDD4hepGeometryConstruction(_physicalWorld);
325  }
326 #endif
327 
328  // 2. Construct the standard SDs
329  // This feature is removed from GGS, so print an error message and throw an exception.
330 
331  const G4LogicalVolumeStore *logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
332  std::vector<G4LogicalVolume *>::const_iterator i;
334  for (i = logicalVolumeStore->begin(); i != logicalVolumeStore->end(); i++) {
335  std::string logVolName = (*i)->GetName();
336  auto detVolName = logVolName.substr(0, logVolName.find_first_of(' '));
337  auto spacePos = logVolName.find_last_of(' ');
338  std::string scorerName("");
339  if (spacePos != std::string::npos)
340  scorerName = logVolName.substr(spacePos + 1);
341  // check if it is a sensitive volume
342  if (nameDecoder.IsSensitive(detVolName)) {
343  GGSCOUT(WARNING) << "This version of GGS does not support the definition of sensitive volumes by name ("
344  << detVolName << ").\n";
345  GGSCCOUT(WARNING) << "Please change the name of the volume and make it active using a datacard command."
346  << GGSENDL;
347  throw std::runtime_error("Use of removed feature: definition of sensitive volume by name.");
348  }
349  }
350 
351  return _physicalWorld;
352 }
#define GGSCCOUT(level)
Smart log utility which prints no header at the beginning of the line.
Definition: GGSSmartLog.h:126
const std::map< std::string, std::vector< bool > > & GetVectBoolParameters()
Getter method for vector-of-booleans geometry parameters.
const std::map< std::string, int > & GetIntParameters()
Getter method for integer geometry parameters.
const std::map< std::string, double > & GetRealParameters()
Getter method for real geometry parameters.
static GGSGeoPluginManager & GetInstance()
Get the singleton instance.
#define GGSENDL
Definition: GGSSmartLog.h:131
const std::map< std::string, std::vector< std::string > > & GetVectStringParameters()
Getter method for vector-of-strings geometry parameters.
virtual G4VPhysicalVolume * Construct()=0
Construct the detector - virtual method.
const std::map< std::string, std::vector< int > > & GetVectIntParameters()
Getter method for vector-of-integers geometry parameters.
const std::map< std::string, std::string > & GetStringParameters()
Getter method for string geometry parameters.
const std::map< std::string, std::vector< double > > & GetVectRealParameters()
Getter method for vector-of-reals geometry parameters.
virtual const std::string GetVersion()
Getter method for geometry version.
const std::map< std::string, bool > & GetBoolParameters()
Getter method for boolean geometry parameters.
virtual bool ExportParameters()
Function for exporting the geometry parameters.
GGSVGeometryConstruction * GetGeoConstruction()
Returns the geometry construction object.
static GGSNameDecoder & GetInstance()
Get instance of the singleton.
bool IsSensitive(const std::string &volumeName)
Check if the logical volume is sensitive.
Class needed to decode sensitive volume names.
void SetGeoDataCard(const G4String &dataCard)
Sets the geometry configuration datacard.
const GGSVGeometryConstruction* GGSDetectorConstruction::GetGeometry ( ) const
inline

Returns a pointer to the geometry.

Returns
Pointer to the geometry construction object.

Definition at line 85 of file GGSDetectorConstruction.h.

85 { return _geometry; }
const G4VPhysicalVolume* GGSDetectorConstruction::GetPhysicalWorld ( ) const
inline

Returns a pointer to the physical world volume.

Returns
Pointer to the physical world volume.

Definition at line 79 of file GGSDetectorConstruction.h.

79 { return _physicalWorld; }

The documentation for this class was generated from the following files: