DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4HierarchyDump.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Detector.h>
16 #include <DD4hep/Plugins.h>
17 #include <DD4hep/Volumes.h>
18 #include <DD4hep/Printout.h>
20 
21 // Geant4 include files
22 #include <G4Version.hh>
23 #include <G4VisAttributes.hh>
24 #include <G4ProductionCuts.hh>
25 #include <G4VUserRegionInformation.hh>
26 #include <G4Element.hh>
27 #include <G4SDManager.hh>
28 
29 #include <G4AssemblyVolume.hh>
30 #include <G4Box.hh>
31 #include <G4Trd.hh>
32 #include <G4Tubs.hh>
33 #include <G4Cons.hh>
34 #include <G4Torus.hh>
35 #include <G4Sphere.hh>
36 #include <G4Polycone.hh>
37 #include <G4Polyhedra.hh>
38 #include <G4UnionSolid.hh>
39 #include <G4Paraboloid.hh>
40 #include <G4SubtractionSolid.hh>
41 #include <G4IntersectionSolid.hh>
42 
43 #include <G4Region.hh>
44 #include <G4UserLimits.hh>
45 #include <G4VSensitiveDetector.hh>
46 
47 #include <G4LogicalVolume.hh>
48 #include <G4Material.hh>
49 #include <G4Element.hh>
50 #include <G4Isotope.hh>
51 #include <G4Transform3D.hh>
52 #include <G4ThreeVector.hh>
53 #include <G4PVPlacement.hh>
54 #include <G4ElectroMagneticField.hh>
55 #include <G4FieldManager.hh>
56 
57 // C/C++ include files
58 #include <iostream>
59 #include <iomanip>
60 #include <sstream>
61 
62 using namespace dd4hep::sim;
63 
64 static const char* _T(const std::string& str) {
65  return str.c_str();
66 }
67 
69 Geant4HierarchyDump::Geant4HierarchyDump(Detector& description, unsigned long flags)
70  : m_detDesc(description), m_flags(flags)
71 {
73 }
74 
77 }
78 
79 void Geant4HierarchyDump::dump(const std::string& indent, const G4VPhysicalVolume* v) const {
80  G4LogicalVolume* lv = v->GetLogicalVolume();
81  G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
82  G4RotationMatrix* rot = v->GetObjectRotation();
83  G4Material* mat = lv->GetMaterial();
84  G4VSolid* sol = lv->GetSolid();
85  G4Region* rg = lv->GetRegion();
86  G4UserLimits* ul = lv->GetUserLimits();
87  G4int ndau = lv->GetNoDaughters();
88  std::stringstream str;
89  char text[32];
90 
91  printout(INFO, "Geant4Hierarchy", "%s -> Placement:%s LV:%s Material:%s Solid:%s # of Daughters:%d CopyNo:%d",
92  _T(indent), _T(v->GetName()), _T(lv->GetName()), _T(mat->GetName()),
93  _T(sol->GetName()), ndau, v->GetCopyNo());
94 
95  if (sd && (m_flags & G4DUMP_SOLID)) {
96  str.str("");
97  sol->StreamInfo(str);
98  printout(INFO, "Geant4Hierarchy", "%s Solid:%s", _T(indent), str.str().c_str());
99  }
100  if (rg && (m_flags & G4DUMP_LIMITS)) {
101  G4UserLimits* rg_limits = rg->GetUserLimits();
102  str.str("");
103  str << indent << " Region:" << rg->GetName() << " #Materials:" << rg->GetNumberOfMaterials() << " #Volumes:"
104  << rg->GetNumberOfRootVolumes();
105  if (rg_limits)
106  str << " Limits:" << rg_limits->GetType();
107  printout(INFO, "Geant4Hierarchy", str.str().c_str());
108  }
109  if (sd && (m_flags & G4DUMP_SENSDET)) {
110  printout(INFO, "Geant4Hierarchy", "%s Sens.det:%p %s path:%s Active:%-3s #Coll:%d", _T(indent), sd,
111  _T(sd->GetName()), _T(sd->GetFullPathName()), yes_no(sd->isActive()), sd->GetNumberOfCollections());
112  }
113  if (ul && (m_flags & G4DUMP_LIMITS)) {
114  printout(INFO, "Geant4Hierarchy", "%s Limits:%s ", _T(indent), _T(ul->GetType()));
115  }
116  if (rot && (m_flags & G4DUMP_MATRIX)) {
117  const G4ThreeVector t = v->GetTranslation();
118  const G4RotationMatrix& r = *rot;
119  double det =
120  r.xx()*r.yy()*r.zz() + r.xy()*r.yz()*r.zx() + r.xz()*r.yx()*r.zy() -
121  r.zx()*r.yy()*r.xz() - r.zy()*r.yz()*r.xx() - r.zz()*r.yx()*r.xy();
122  printout(INFO, "Geant4Hierarchy", "%s Matrix: %sREFLECTED Tr: %8.3g %8.3g %8.3g [mm]",
123  _T(indent), det > 0e0 ? "NOT " : "", t.x(), t.y(), t.z());
124  }
125  for (G4int idau = 0; idau < ndau; ++idau) {
126  ::snprintf(text, sizeof(text), " %-3d", idau);
127  dump(indent + text, lv->GetDaughter(idau));
128  }
129 }
dd4hep::sim::Geant4HierarchyDump::m_flags
unsigned long m_flags
Definition: Geant4HierarchyDump.h:48
dd4hep::sim::Geant4HierarchyDump::G4DUMP_SENSDET
@ G4DUMP_SENSDET
Definition: Geant4HierarchyDump.h:40
Volumes.h
v
View * v
Definition: MultiView.cpp:28
Detector.h
Geant4HierarchyDump.h
G4UserLimits
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:23
dd4hep::sim::Geant4HierarchyDump::Geant4HierarchyDump
Geant4HierarchyDump(Detector &description, unsigned long flags=G4DUMP_ALL)
Initializing Constructor.
Definition: Geant4HierarchyDump.cpp:69
G4VSensitiveDetector
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:59
dd4hep::sim::Geant4HierarchyDump::G4DUMP_LIMITS
@ G4DUMP_LIMITS
Definition: Geant4HierarchyDump.h:41
Plugins.h
dd4hep::sim::Geant4HierarchyDump::G4DUMP_MATRIX
@ G4DUMP_MATRIX
Definition: Geant4HierarchyDump.h:43
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4HierarchyDump::dump
virtual void dump(const std::string &indent, const G4VPhysicalVolume *vol) const
Dump the volume hierarchy as it is known to geant 4.
Definition: Geant4HierarchyDump.cpp:79
dd4hep::sim::Geant4HierarchyDump::~Geant4HierarchyDump
virtual ~Geant4HierarchyDump()
Standard destructor.
Definition: Geant4HierarchyDump.cpp:76
dd4hep::sim::Geant4HierarchyDump::G4DUMP_SOLID
@ G4DUMP_SOLID
Definition: Geant4HierarchyDump.h:39
Printout.h