Newer
Older
// $Id$
//====================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
Pere Mato
committed
#include "DDG4/Geant4DetectorConstruction.h"
#include "DDG4/Geant4HierarchyDump.h"
Pere Mato
committed
#include "DDG4/Geant4Converter.h"
Pere Mato
committed
#include "DD4hep/LCDD.h"
#include "TGeoManager.h"
#include "G4PVPlacement.hh"
Pere Mato
committed
#ifdef GEANT4_HAS_GDML
#include "G4GDMLParser.hh"
#endif
using namespace std;
using namespace DD4hep;
using namespace DD4hep::Simulation;
Pere Mato
committed
namespace {
static Geant4DetectorConstruction* s_instance = 0;
/// Instance accessor
Geant4DetectorConstruction* Geant4DetectorConstruction::instance(Geant4Kernel& kernel) {
if ( 0 == s_instance ) s_instance = new Geant4DetectorConstruction(kernel);
return s_instance;
}
/// Initializing constructor for other clients
Geant4DetectorConstruction::Geant4DetectorConstruction(Geometry::LCDD& lcdd)
: Geant4Action(0,"DetectorConstruction"), m_lcdd(lcdd), m_world(0)
{
m_outputLevel = PrintLevel(printLevel()-1);
s_instance = this;
}
/// Initializing constructor for DDG4
Geant4DetectorConstruction::Geant4DetectorConstruction(Geant4Kernel& kernel)
: Geant4Action(0,"DetectorConstruction"), m_lcdd(kernel.lcdd()), m_world(0)
{
m_outputLevel = kernel.getOutputLevel("Geant4Converter");
Geant4DetectorConstruction::~Geant4DetectorConstruction() {
s_instance = 0;
Pere Mato
committed
}
G4VPhysicalVolume* Geant4DetectorConstruction::Construct() {
Geant4Mapping& g4map = Geant4Mapping::instance();
Geometry::DetElement world = m_lcdd.world();
Geant4GeometryInfo* info = conv.create(world).detach();
Markus Frank
committed
g4map.attach(info);
m_world = info->world();
m_lcdd.apply("DD4hepVolumeManager", 0, 0);
// Create Geant4 volume manager
g4map.volumeManager();
//Geant4HierarchyDump dmp(m_lcdd);
//dmp.dump("",m_world);
Pere Mato
committed
#ifdef GEANT4_HAS_GDML
if ( ::getenv("DUMP_GDML") ) {
G4GDMLParser parser;
parser.Write("detector.gdml",m_world);
}
#endif
return m_world;
}
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/// Access to the converted regions
const Geant4GeometryMaps::RegionMap& Geant4DetectorConstruction::regions() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Regions;
throw runtime_error("+++ Geant4DetectorConstruction::regions: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted sensitive detectors
const Geant4GeometryMaps::SensDetMap& Geant4DetectorConstruction::sensitives() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4SensDets;
throw runtime_error("+++ Geant4DetectorConstruction::sensitives: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted volumes
const Geant4GeometryMaps::VolumeMap& Geant4DetectorConstruction::volumes() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Volumes;
throw runtime_error("+++ Geant4DetectorConstruction::volumes: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted shapes
const Geant4GeometryMaps::SolidMap& Geant4DetectorConstruction::shapes() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Solids;
throw runtime_error("+++ Geant4DetectorConstruction::shapes: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted limit sets
const Geant4GeometryMaps::LimitMap& Geant4DetectorConstruction::limits() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Limits;
throw runtime_error("+++ Geant4DetectorConstruction::limits: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted assemblies
const Geant4GeometryMaps::AssemblyMap& Geant4DetectorConstruction::assemblies() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4AssemblyVolumes;
throw runtime_error("+++ Geant4DetectorConstruction::assemblies: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted placements
const Geant4GeometryMaps::PlacementMap& Geant4DetectorConstruction::placements() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Placements;
throw runtime_error("+++ Geant4DetectorConstruction::placements: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted materials
const Geant4GeometryMaps::MaterialMap& Geant4DetectorConstruction::materials() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Materials;
throw runtime_error("+++ Geant4DetectorConstruction::materials: Access not possible. Geometry is not yet converted!");
}
/// Access to the converted elements
const Geant4GeometryMaps::ElementMap& Geant4DetectorConstruction::elements() const {
Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
if ( p ) return p->g4Elements;
throw runtime_error("+++ Geant4DetectorConstruction::elements: Access not possible. Geometry is not yet converted!");
}