GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs 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 &gdml)
 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 29 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 33 of file GGSDetectorConstruction.cpp.

34  : _physicalWorld(NULL), _geometry(NULL), _library(library), _configDataCard(configDataCard), _gdml("") {}
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 38 of file GGSDetectorConstruction.cpp.

40  : _physicalWorld(NULL), _geometry(NULL), _library(library), _configDataCard(configDataCard), _gdml("") {}
GGSDetectorConstruction::GGSDetectorConstruction ( const G4String &  gdml)

Constructor.

Constructor for geometry provided by a gdml file.

Parameters
gdmlThe gdml file.

Definition at line 44 of file GGSDetectorConstruction.cpp.

45  : _physicalWorld(NULL), _geometry(NULL), _library(""), _configDataCard(""), _gdml(gdml) {}

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 53 of file GGSDetectorConstruction.cpp.

53  {
54 
55  static const std::string routineName("GGSDetectorConstruction::Construct");
56 
57  // 1. Construct the geometry
58  if (_library != "") {
59  // 1.1 Load the concrete GGSVGeometryConstruction from a shared library
60  if (!(GGSGeoPluginManager::GetInstance().LoadGeoPlugin(_library))) {
61  COUT(ERROR) << "Impossible to load geometry library " << _library << ENDL;
62  throw std::runtime_error("Impossible to load geometry library");
63  }
65  if (!_geometry) {
66  COUT(ERROR) << "Can't create the geometry." << ENDL;
67  }
68  COUT(INFO) << "Construct the detector." << ENDL;
69  _geometry->SetGeoDataCard(_configDataCard);
70  _physicalWorld = _geometry->Construct();
71  // Print geometry version
72  const std::string geoVersion = _geometry->GetVersion();
73  if (geoVersion != "") {
74  COUT(INFO) << "Geometry version: " << geoVersion << ENDL;
75  } else {
76  COUT(INFO) << "No geometry version available" << ENDL;
77  }
78  // Print geometry parameters
79  _geometry->ExportParameters(); // Will throw if something goes wrong, so don't check the return value
80  auto intParams = _geometry->GetIntParameters();
81  auto boolParams = _geometry->GetBoolParameters();
82  auto realParams = _geometry->GetRealParameters();
83  auto stringParams = _geometry->GetStringParameters();
84  auto vectIntParams = _geometry->GetVectIntParameters();
85  auto vectBoolParams = _geometry->GetVectBoolParameters();
86  auto vectRealParams = _geometry->GetVectRealParameters();
87  auto vectStringParams = _geometry->GetVectStringParameters();
88  if (intParams.size() + boolParams.size() + realParams.size() + stringParams.size() > 0) {
89  COUT(INFO) << "Geometry parameters:\n";
90  for (auto &par : intParams) {
91  CCOUT(INFO) << par.first << ": " << par.second << "\n";
92  }
93  for (auto &par : boolParams) {
94  CCOUT(INFO) << par.first << ": " << (par.second ? "true" : "false") << "\n";
95  }
96  for (auto &par : realParams) {
97  CCOUT(INFO) << par.first << ": " << par.second << "\n";
98  }
99  for (auto &par : stringParams) {
100  CCOUT(INFO) << par.first << ": " << par.second << "\n";
101  }
102  for (auto &par : vectIntParams) {
103  CCOUT(INFO) << par.first << ": {";
104  for (size_t iVal = 0; iVal < par.second.size() - 1; ++iVal) {
105  std::cout << par.second[iVal] << ", ";
106  }
107  std::cout << par.second.back() << "}\n";
108  }
109  for (auto &par : vectRealParams) {
110  CCOUT(INFO) << par.first << ": {";
111  for (size_t iVal = 0; iVal < par.second.size() - 1; ++iVal) {
112  std::cout << par.second[iVal] << ", ";
113  }
114  std::cout << par.second.back() << "}\n";
115  }
116  for (auto &par : vectBoolParams) {
117  CCOUT(INFO) << par.first << ": {";
118  for (size_t iVal = 0; iVal < par.second.size() - 1; ++iVal) {
119  std::cout << par.second[iVal] << ", ";
120  }
121  std::cout << par.second.back() << "}\n";
122  }
123  for (auto &par : vectStringParams) {
124  CCOUT(INFO) << par.first << ": {";
125  for (size_t iVal = 0; iVal < par.second.size() - 1; ++iVal) {
126  std::cout << par.second[iVal] << ", ";
127  }
128  std::cout << par.second.back() << "}\n";
129  }
130  }
131  }
132 #ifdef USE_GDML
133  else {
134  // 1.2 Build the geometry from a GDML file
135  G4GDMLParser gdmlParser;
136  gdmlParser.SetOverlapCheck(false);
137  try {
138  gdmlParser.Read(_gdml, false);
139  } catch (int &ge) {
140  COUT(ERROR) << "G4GDML: " << ge << ", missing network connection? wrong schema URL?" << ENDL;
141  // G4COUT << "Try to read GDML file _WITHOUT_ schema validation" << G4ENDL;
142  // error, try without schema validation
143  // gdmlParser.ValidateSchema(false);
144  // gdmlParser.Read(_gdml, false);
145  }
146  gdmlParser.StripNamePointers();
147  _physicalWorld = gdmlParser.GetWorldVolume();
148  if (!_physicalWorld) {
149  COUT(ERROR) << "Cannot build the GMDL geometry." << ENDL;
150  throw std::runtime_error("Cannot build the GMDL geometry.");
151  }
152  }
153 #endif
154 
155  // 2. Construct the standard SDs
156  // This feature is removed from GGS, so print an error message and throw an exception.
157 
158  const G4LogicalVolumeStore *logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
159  std::vector<G4LogicalVolume *>::const_iterator i;
161  for (i = logicalVolumeStore->begin(); i != logicalVolumeStore->end(); i++) {
162  std::string logVolName = (*i)->GetName();
163  auto detVolName = logVolName.substr(0, logVolName.find_first_of(' '));
164  auto spacePos = logVolName.find_last_of(' ');
165  std::string scorerName("");
166  if (spacePos != std::string::npos)
167  scorerName = logVolName.substr(spacePos + 1);
168  // check if it is a sensitive volume
169  if (nameDecoder.IsSensitive(detVolName)) {
170  COUT(WARNING) << "This version of GGS does not support the definition of sensitive volumes by name ("
171  << detVolName << ").\n";
172  CCOUT(WARNING) << "Please change the name of the volume and make it active using a datacard command." << ENDL;
173  throw std::runtime_error("Use of removed feature: definition of sensitive volume by name.");
174  }
175  }
176 
177  return _physicalWorld;
178 }
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 ENDL
Definition: GGSSmartLog.h:105
const std::map< std::string, std::vector< std::string > > & GetVectStringParameters()
Getter method for vector-of-strings geometry parameters.
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
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.
#define CCOUT(level)
Smart log utility which prints no header at the beginning of the line.
Definition: GGSSmartLog.h:100
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 84 of file GGSDetectorConstruction.h.

84 { 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 78 of file GGSDetectorConstruction.h.

78 { return _physicalWorld; }

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