 |
DD4hep
1.35.0
Detector Description Toolkit for High Energy Physics
|
Go to the documentation of this file.
87 std::pair<std::string, PlacedVolume>
resolve_path(
const char* vol_path)
const;
88 void printG4(
const std::string& prefix,
const G4VPhysicalVolume* g4pv)
const;
117 #include <TGeoScaledShape.h>
120 #include <G4LogicalVolume.hh>
121 #include <G4PVPlacement.hh>
122 #include <G4Material.hh>
123 #include <G4Version.hh>
124 #include <G4VSolid.hh>
125 #include <CLHEP/Units/SystemOfUnits.h>
127 #ifndef GEANT4_NO_GDML
128 #include <G4GDMLParser.hh>
201 else if ( ::getenv(
"DUMP_GDML") )
writeGDML(::getenv(
"DUMP_GDML"));
205 std::pair<std::string, dd4hep::PlacedVolume>
207 std::string p = vol_path;
218 return make_pair(p,pv);
225 for (
auto it = g4map.begin(); it != g4map.end(); ++it ) {
226 const auto* mat = (*it).second;
227 if ( mat->GetName() == mat_name ) {
228 std::stringstream output;
229 const auto* ion = mat->GetIonisation();
230 printP2(
"+++ Dump of GEANT4 material: %s", mat_name);
234 output << std::setprecision(12);
235 output << ion->GetMeanExcitationEnergy()/CLHEP::eV;
239 output <<
" MEE: UNKNOWN";
240 always(
"+++ printMaterial: \n%s\n", output.str().c_str());
244 warning(
"+++ printMaterial: FAILED to find the material %s", mat_name);
246 warning(
"+++ printMaterial: Property materialName not set!");
253 const G4LogicalVolume* vol = 0;
256 auto vit = g4map.g4Volumes.find(pv.
volume());
257 warning(
"+++ printVolume: %s", vol_path);
258 if ( vit != g4map.g4Volumes.end() ) {
260 auto* sol = vol->GetSolid();
261 const auto* mat = vol->GetMaterial();
262 const auto* ion = mat->GetIonisation();
265 printP2(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
266 printP2(
"+++ Dump of GEANT4 solid: %s", vol_path);
268 std::stringstream output;
273 output << std::setprecision(12);
274 output << ion->GetMeanExcitationEnergy()/CLHEP::eV;
278 output <<
" MEE: UNKNOWN";
281 output << std::endl << *sol;
282 printP2(
"%s", output.str().c_str());
283 printP2(
"+++ Dump of ROOT solid: %s", vol_path);
285 if ( sh->IsA() == TGeoScaledShape::Class() ) {
286 TGeoScaledShape* scaled = (TGeoScaledShape*)sh.
ptr();
287 const Double_t* scale = scaled->GetScale()->GetScale();
288 double dot = scale[0]*scale[1]*scale[2];
289 printP2(
"+++ TGeoScaledShape: %8.3g %8.3g %8.3g [%s]", scale[0], scale[1], scale[2],
290 dot > 0e0 ?
"RIGHT handed" :
"LEFT handed");
292 else if ( pit != g4map.g4Placements.end() ) {
293 const G4VPhysicalVolume* pl = (*pit).second;
294 const G4RotationMatrix* rot = pl->GetRotation();
295 const G4ThreeVector& tr = pl->GetTranslation();
296 G4Transform3D transform(rot ? *rot : G4RotationMatrix(), tr);
298 HepGeom::Rotate3D rr;
300 transform.getDecomposition(sc,rr,tt);
301 double dot = sc(0,0)*sc(1,1)*sc(2,2);
302 printP2(
"+++ TGeoShape: %8.3g %8.3g %8.3g [%s]", sc(0,0), sc(1,1), sc(2,2),
303 dot > 0e0 ?
"RIGHT handed" :
"LEFT handed");
305 const TGeoMatrix* matrix = pv->GetMatrix();
307 matrix->TestBit(TGeoMatrix::kGeoReflection) ?
"LEFT handed" :
"RIGHT handed");
308 printP2(
"+++ Shape: %s cubic volume: %8.3g mm^3 area: %8.3g mm^2",
309 sol->GetName().c_str(), sol->GetCubicVolume(), sol->GetSurfaceArea());
314 auto ai = g4map.g4AssemblyVolumes.find(pv.
ptr());
315 if ( ai != g4map.g4AssemblyVolumes.end() ) {
317 warning(
"+++ printVolume: volume %s is an assembly...need to resolve imprint",vol_path);
318 for(Int_t i=0; i <
v->GetNdaughters(); ++i) {
319 TGeoNode* dau_nod =
v->GetNode(i);
320 std::string p = vol_path + std::string(
"/") + dau_nod->GetName();
326 warning(
"+++ printVolume: FAILED to find the volume %s in geant4 mapping...",vol_path);
329 warning(
"+++ printVolume: FAILED to dump invalid volume",vol_path);
337 if ( physVol.second.isValid() ) {
341 warning(
"+++ printVolume: Property VolumePath not set. [Ignored]");
349 if ( pv.isValid() ) {
351 TGeoVolume* vol = pv->GetVolume();
352 for(Int_t i=0; i < vol->GetNdaughters(); ++i) {
354 std::string path = (p +
"/") + dau_pv.
name();
362 warning(
"+++ printVolume: Could not access Volume/DetElement '%s'", vol_path ? vol_path :
"UNKNOWN");
369 if ( pv.isValid() ) {
371 TGeoVolume* vol = pv->GetVolume();
372 for(Int_t i=0; i < vol->GetNdaughters(); ++i) {
374 std::string path = (p +
"/") + dau_pv.
name();
382 warning(
"+++ printVolume: Could not access Volume/DetElement '%s'", vol_path ? vol_path :
"UNKNOWN");
390 auto pv = physVol.second;
391 if ( pv.isValid() ) {
393 auto it = g4map.find(pv.volume());
394 if ( it != g4map.end() ) {
395 const G4LogicalVolume* vol = (*it).second;
396 auto* g4_sol = vol->GetSolid();
397 Box rt_sol = pv.volume().solid();
398 printP2(
"Geant4 Shape: %s cubic volume: %8.3g mm^3 area: %8.3g mm^2",
399 g4_sol->GetName().c_str(), g4_sol->GetCubicVolume(), g4_sol->GetSurfaceArea());
400 #if G4VERSION_NUMBER>=1040
401 G4ThreeVector pMin, pMax;
402 double conv = (dd4hep::centimeter/CLHEP::centimeter)/2.0;
403 g4_sol->BoundingLimits(pMin,pMax);
404 printP2(
"Geant4 Bounding box extends: %8.3g %8.3g %8.3g",
405 (pMax.x()-pMin.x())*conv, (pMax.y()-pMin.y())*conv, (pMax.z()-pMin.z())*conv);
407 printP2(
"ROOT Bounding box dimensions: %8.3g %8.3g %8.3g",
408 rt_sol->GetDX(), rt_sol->GetDY(), rt_sol->GetDZ());
413 warning(
"+++ checkVolume: FAILED to find the volume %s from the top volume",vol_path);
415 warning(
"+++ checkVolume: Property VolumePath not set. [Ignored]");
421 #ifdef GEANT4_NO_GDML
422 warning(
"+++ writeGDML: GDML not found in the present Geant4 build! Output: %s not written", output);
425 if ( output && ::strlen(output) > 0 && output !=
m_dumpGDML.c_str() )
435 const char* gdml_dmp = ::getenv(
"DUMP_GDML");
438 parser.Write(gdml_dmp, w);
439 info(
"+++ writeGDML: Wrote GDML file: %s", gdml_dmp);
443 warning(
"+++ writeGDML: Neither property DumpGDML nor environment DUMP_GDML set. No file written!");
449 std::string path = prefix +
"/";
450 printP2(
"+++ GEANT4 volume: %s", prefix.c_str());
451 auto* g4v = g4pv->GetLogicalVolume();
452 for(
size_t i=0, n=g4v->GetNoDaughters(); i<n; ++i) {
453 auto* dau = g4v->GetDaughter(i);
454 printG4(path + dau->GetName(), dau);
461 if ( pv.isValid() ) {
463 auto it = g4map.find(pv);
464 if ( it != g4map.end() ) {
470 warning(
"+++ printVolume: Could not access Volume/DetElement '%s'", vol_path ? vol_path :
"UNKNOWN");
478 "' [uses argument - or - property DumpGDML]",
480 m_control->
addCall(
"printVolume",
"Print Geant4 volume properties [uses argument]",
482 m_control->
addCall(
"printTree",
"Print volume tree WITHOUT properties [uses argument]",
484 m_control->
addCall(
"printG4Tree",
"Print Geant4 volume tree [uses argument]",
486 m_control->
addCall(
"printVolumeTree",
"Print volume tree with properties [uses argument]",
488 m_control->
addCall(
"checkVolume",
"Check Geant4 volume properties [uses argument]",
490 m_control->
addCall(
"printMaterial",
"Print Geant4 material properties [uses argument]",
Helper to dump Geant4 volume hierarchy.
bool debugRegions
Property: Flag to debug regions during conversion mechanism.
bool m_debugElements
Property: Flag to debug elements during conversion mechanism.
int printVolumeTree(const char *vol_path)
Print volume tree with attributes.
bool debugMaterials
Property: Flag to debug materials during conversion mechanism.
void printP2(const char *fmt,...) const
Support for messages with variable output level using output level+2.
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
unsigned long m_dumpHierarchy
Property: Dump geometry hierarchy if not NULL. Flags can steer actions.
int printVolTree(const char *vol_path)
Print volume tree WITHOUT attributes.
Geometry converter from dd4hep to Geant 4.
void setWorld(G4VPhysicalVolume *volume)
Set the geometry world.
bool debugLimits
Property: Flag to debug LimitSets during conversion mechanism.
bool debugElements
Property: Flag to debug elements during conversion mechanism.
virtual void installCommandMessenger() override
Install command control messenger to write GDML file from command prompt.
Geant4GeometryInfo & data() const
Access to the data pointer.
Handle class holding a placed volume (also called physical volume)
virtual ~Geant4DetectorGeometryConstruction()
Default destructor.
bool m_debugMaterials
Property: Flag to debug materials during conversion mechanism.
PlacedVolume placement() const
Access to the physical volume of this detector element.
void printG4(const std::string &prefix, const G4VPhysicalVolume *g4pv) const
Class to create Geant4 detector geometry from TGeo representation in memory.
Geant4GeometryMaps::MaterialMap g4Materials
bool debugSurfaces
Property: Flag to debug surfaces during conversion mechanism.
Solid solid() const
Access to Solid (Shape)
bool isValid() const
Check the validity of the object held by the handle.
bool m_printSensitives
Property: Flag to dump all sensitives after the conversion procedure.
bool debugShapes
Property: Flag to debug shapes during conversion mechanism.
static void increment(T *)
Increment count according to type information.
int printVolumeObj(const char *vol_path, PlacedVolume pv, int flg)
Print geant4 volume.
static Geant4Mapping & instance()
Possibility to define a singleton instance.
int printMaterial(const char *mat_name)
Print geant4 material.
const char * name() const
Access the object name (or "" if not supported by the object)
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
void warning(const char *fmt,...) const
Support of warning messages.
G4VPhysicalVolume * world() const
Access to geometry world.
Detector & detectorDescription() const
Access to detector description.
G4VPhysicalVolume * world
Reference to the world after construction.
void info(const char *fmt,...) const
Support of info messages.
bool debugPlacements
Property: Flag to debug placements during conversion mechanism.
Geant4 detector construction context definition.
Geant4Converter & create(DetElement top)
Create geometry conversion.
Handle class describing a detector element.
bool m_debugShapes
Property: Flag to debug shapes during conversion mechanism.
Detector & description
Reference to geometry object.
Handle class holding a placed volume (also called physical volume)
bool m_printPlacements
Property: Flag to dump all placements after the conversion procedure.
bool m_debugReflections
Property: Flag to debug reflections during conversion mechanism.
Geometry mapping from dd4hep to Geant 4.
std::pair< std::string, PlacedVolume > resolve_path(const char *vol_path) const
Geant4GeometryMaps::PlacementMap g4Placements
Definition of the generic callback structure for member functions.
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
static void decrement(T *)
Decrement count according to type information.
bool m_debugPlacements
Property: Flag to debug placements during conversion mechanism.
int m_geoInfoPrintLevel
Property: Printout level of info object.
Geant4VolumeManager volumeManager() const
Access the volume manager.
bool m_debugRegions
Property: Flag to debug regions during conversion mechanism.
Geant4DetectorGeometryConstruction(Geant4Context *ctxt, const std::string &nam)
Initializing constructor for DDG4.
PrintLevel outputLevel() const
Access the output level.
long debugVolManager
Debug flag when populating the Geant4 volume manager (Option set by Geant4DetectorGeometryConstructio...
bool debugVolumes
Property: Flag to debug volumes during conversion mechanism.
bool printSensitives
Property: Flag to dump all sensitives after the conversion procedure.
int checkVolume(const char *vol_path)
Check geant4 volume.
bool m_debugSurfaces
Property: Flag to debug regions during conversion mechanism.
int printVolume(const char *vol_path)
Print geant4 volume.
Geant4UIMessenger * m_control
Control directory of this action.
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Geant4Kernel & kernel() const
Access to the kernel object.
bool m_debugLimits
Property: Flag to debug limit sets during conversion mechanism.
Class describing a box shape.
T * ptr() const
Access to the held object.
void attach(Geant4GeometryInfo *data)
Set a new data block.
virtual void installCommandMessenger()
Install command control messenger if wanted.
void constructGeo(Geant4DetectorConstructionContext *ctxt) override
Geometry construction callback. Called at "Construct()".
bool m_haveVolManager
Property: Flag to instantiate Geant4 volume manager.
Namespace for the AIDA detector description toolkit.
bool debugReflections
Property: Flag to debug reflections during conversion mechanism.
void addCall(const std::string &name, const std::string &description, const Callback &cb, size_t npar=0)
Add a new callback structure.
Volume volume() const
Logical volume of this placement.
The main interface to the dd4hep detector description package.
void always(const char *fmt,...) const
Support of always printed messages.
std::string m_dumpGDML
Property: G4 GDML dump file name (default: empty. If non empty, dump)
int writeGDML(const char *gdml_output)
Write GDML file.
virtual void dump(const std::string &indent, const G4VPhysicalVolume *vol) const
Dump the volume hierarchy as it is known to geant 4.
bool haveVolManager
Disable building Geant4 voilume manager. Throw exception when accessed.
Geant4GeometryInfo * detach()
Release data and pass over the ownership.
long m_debugVolManager
Property: Flag to debug G4 volume manager population.
Geant4GeometryInfo * geometry
The cached geometry information.
virtual void enableUI()
Enable and install UI messenger.
G4VPhysicalVolume * world() const
The world placement.
Basic implementation of the Geant4 detector construction action.
bool printPlacements
Property: Flag to dump all placements after the conversion procedure.
bool m_debugVolumes
Property: Flag to debug volumes during conversion mechanism.
Generic context to extend user, run and event information.
int printG4Tree(const char *vol_path)
Print geant4 volume tree.
Geant4Context * context() const
Access the context.
Geant4GeometryMaps::VolumeMap g4Volumes