File indexing completed on 2025-01-18 09:14:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Detector.h>
0016 #include <DD4hep/Plugins.h>
0017 #include <DD4hep/Volumes.h>
0018 #include <DD4hep/Printout.h>
0019 #include <DDG4/Geant4HierarchyDump.h>
0020
0021
0022 #include <G4Version.hh>
0023 #include <G4VisAttributes.hh>
0024 #include <G4ProductionCuts.hh>
0025 #include <G4VUserRegionInformation.hh>
0026 #include <G4Element.hh>
0027 #include <G4SDManager.hh>
0028
0029 #include <G4AssemblyVolume.hh>
0030 #include <G4Box.hh>
0031 #include <G4Trd.hh>
0032 #include <G4Tubs.hh>
0033 #include <G4Cons.hh>
0034 #include <G4Torus.hh>
0035 #include <G4Sphere.hh>
0036 #include <G4Polycone.hh>
0037 #include <G4Polyhedra.hh>
0038 #include <G4UnionSolid.hh>
0039 #include <G4Paraboloid.hh>
0040 #include <G4SubtractionSolid.hh>
0041 #include <G4IntersectionSolid.hh>
0042
0043 #include <G4Region.hh>
0044 #include <G4UserLimits.hh>
0045 #include <G4VSensitiveDetector.hh>
0046
0047 #include <G4LogicalVolume.hh>
0048 #include <G4Material.hh>
0049 #include <G4Element.hh>
0050 #include <G4Isotope.hh>
0051 #include <G4Transform3D.hh>
0052 #include <G4ThreeVector.hh>
0053 #include <G4PVPlacement.hh>
0054 #include <G4ElectroMagneticField.hh>
0055 #include <G4FieldManager.hh>
0056
0057
0058 #include <iostream>
0059 #include <iomanip>
0060 #include <sstream>
0061
0062 using namespace dd4hep::sim;
0063
0064 static const char* _T(const std::string& str) {
0065 return str.c_str();
0066 }
0067
0068
0069 Geant4HierarchyDump::Geant4HierarchyDump(Detector& description, unsigned long flags)
0070 : m_detDesc(description), m_flags(flags)
0071 {
0072 m_flags &= ~G4DUMP_SOLID;
0073 }
0074
0075
0076 Geant4HierarchyDump::~Geant4HierarchyDump() {
0077 }
0078
0079 void Geant4HierarchyDump::dump(const std::string& indent, const G4VPhysicalVolume* v) const {
0080 G4LogicalVolume* lv = v->GetLogicalVolume();
0081 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
0082 G4RotationMatrix* rot = v->GetObjectRotation();
0083 G4Material* mat = lv->GetMaterial();
0084 G4VSolid* sol = lv->GetSolid();
0085 G4Region* rg = lv->GetRegion();
0086 G4UserLimits* ul = lv->GetUserLimits();
0087 G4int ndau = lv->GetNoDaughters();
0088 std::stringstream str;
0089 char text[32];
0090
0091 printout(INFO, "Geant4Hierarchy", "%s -> Placement:%s LV:%s Material:%s Solid:%s # of Daughters:%d CopyNo:%d",
0092 _T(indent), _T(v->GetName()), _T(lv->GetName()), _T(mat->GetName()),
0093 _T(sol->GetName()), ndau, v->GetCopyNo());
0094
0095 if (sd && (m_flags & G4DUMP_SOLID)) {
0096 str.str("");
0097 sol->StreamInfo(str);
0098 printout(INFO, "Geant4Hierarchy", "%s Solid:%s", _T(indent), str.str().c_str());
0099 }
0100 if (rg && (m_flags & G4DUMP_LIMITS)) {
0101 G4UserLimits* rg_limits = rg->GetUserLimits();
0102 str.str("");
0103 str << indent << " Region:" << rg->GetName() << " #Materials:" << rg->GetNumberOfMaterials() << " #Volumes:"
0104 << rg->GetNumberOfRootVolumes();
0105 if (rg_limits)
0106 str << " Limits:" << rg_limits->GetType();
0107 printout(INFO, "Geant4Hierarchy", str.str().c_str());
0108 }
0109 if (sd && (m_flags & G4DUMP_SENSDET)) {
0110 printout(INFO, "Geant4Hierarchy", "%s Sens.det:%p %s path:%s Active:%-3s #Coll:%d", _T(indent), sd,
0111 _T(sd->GetName()), _T(sd->GetFullPathName()), yes_no(sd->isActive()), sd->GetNumberOfCollections());
0112 }
0113 if (ul && (m_flags & G4DUMP_LIMITS)) {
0114 printout(INFO, "Geant4Hierarchy", "%s Limits:%s ", _T(indent), _T(ul->GetType()));
0115 }
0116 if (rot && (m_flags & G4DUMP_MATRIX)) {
0117 const G4ThreeVector t = v->GetTranslation();
0118 const G4RotationMatrix& r = *rot;
0119 double det =
0120 r.xx()*r.yy()*r.zz() + r.xy()*r.yz()*r.zx() + r.xz()*r.yx()*r.zy() -
0121 r.zx()*r.yy()*r.xz() - r.zy()*r.yz()*r.xx() - r.zz()*r.yx()*r.xy();
0122 printout(INFO, "Geant4Hierarchy", "%s Matrix: %sREFLECTED Tr: %8.3g %8.3g %8.3g [mm]",
0123 _T(indent), det > 0e0 ? "NOT " : "", t.x(), t.y(), t.z());
0124 }
0125 for (G4int idau = 0; idau < ndau; ++idau) {
0126 ::snprintf(text, sizeof(text), " %-3d", idau);
0127 dump(indent + text, lv->GetDaughter(idau));
0128 }
0129 }