32 #include "TGeoShape.h"
38 #include "TGeoSphere.h"
39 #include "TGeoTorus.h"
44 #include "TGeoMatrix.h"
45 #include "TGeoBoolNode.h"
46 #include "TGeoParaboloid.h"
47 #include "TGeoCompositeShape.h"
48 #include "TGeoShapeAssembly.h"
49 #include "TGeoScaledShape.h"
50 #include "TGeoManager.h"
55 #include "G4VisAttributes.hh"
56 #include "G4ProductionCuts.hh"
57 #include "G4VUserRegionInformation.hh"
59 #include "G4Element.hh"
67 #include "G4Sphere.hh"
68 #include "G4Polycone.hh"
69 #include "G4Polyhedra.hh"
70 #include "G4UnionSolid.hh"
71 #include "G4Paraboloid.hh"
72 #include "G4Ellipsoid.hh"
73 #include "G4EllipticalTube.hh"
74 #include "G4SubtractionSolid.hh"
75 #include "G4IntersectionSolid.hh"
76 #include "G4Region.hh"
77 #include "G4UserLimits.hh"
78 #include "G4LogicalVolume.hh"
79 #include "G4Material.hh"
80 #include "G4Element.hh"
81 #include "G4Isotope.hh"
82 #include "G4Transform3D.hh"
83 #include "G4ThreeVector.hh"
84 #include "G4PVPlacement.hh"
85 #include "G4ElectroMagneticField.hh"
86 #include "G4FieldManager.hh"
87 #include "G4ReflectionFactory.hh"
88 #include "CLHEP/Units/SystemOfUnits.h"
95 using namespace DD4hep::Simulation;
97 using namespace DD4hep::Geometry;
98 using namespace DD4hep;
103 #include "G4RotationMatrix.hh"
104 #include "G4AffineTransform.hh"
105 #include "G4LogicalVolume.hh"
106 #include "G4VPhysicalVolume.hh"
107 #include "G4ReflectionFactory.hh"
110 const TGeoNode* parent,
113 G4LogicalVolume* pMotherLV,
114 G4Transform3D& transformation,
118 TGeoVolume* vol = parent->GetVolume();
123 unsigned int numberOfDaughters;
125 if( copyNumBase == 0 )
127 numberOfDaughters = pMotherLV->GetNoDaughters();
131 numberOfDaughters = copyNumBase;
140 std::vector<G4AssemblyTriplet> triplets = pAssembly->fTriplets;
143 for(
unsigned int i = 0; i < triplets.size(); i++ ) {
144 const TGeoNode* node = pAssembly->
m_entries[i];
145 Chain new_chain = chain;
146 new_chain.push_back(node);
149 G4Transform3D Ta( *(triplets[i].GetRotation()),
150 triplets[i].GetTranslation() );
151 if ( triplets[i].IsReflection() ) { Ta = Ta * G4ReflectZ3D(); }
153 G4Transform3D Tfinal = transformation * Ta;
155 if ( triplets[i].GetVolume() )
167 std::stringstream pvName;
171 << GetImprintsCount()
173 << triplets[i].GetVolume()->GetName().c_str()
182 G4PhysicalVolumesPair pvPlaced
183 = G4ReflectionFactory::Instance()->Place( Tfinal,
184 pvName.str().c_str(),
185 triplets[i].GetVolume(),
188 numberOfDaughters + i,
193 fPVStore.push_back( pvPlaced.first );
196 cout <<
" Assembly:Parent:" << parent->GetName() <<
" " << node->GetName()
197 <<
" " << (
void*)node <<
" G4:" << pvName.str() <<
" Daughter:"
202 if ( pvPlaced.second ) {
203 G4Exception(
"G4AssemblyVolume::MakeImprint(..)",
"GeomVol0003", FatalException,
204 "Fancy construct popping new mother from the stack!");
208 else if ( triplets[i].GetAssembly() ) {
210 imprint(info, parent, new_chain, (
Geant4AssemblyVolume*)triplets[i].GetAssembly(), pMotherLV, Tfinal, i*100+copyNumBase, surfCheck );
214 G4Exception(
"G4AssemblyVolume::MakeImprint(..)",
215 "GeomVol0003", FatalException,
216 "Triplet has no volume and no assembly");
224 static string indent =
"";
225 static Double_t s_identity_rot[] = { 1., 0., 0., 0., 1., 0., 0., 0., 1. };
226 struct MyTransform3D :
public G4Transform3D {
227 MyTransform3D(
double XX,
double XY,
double XZ,
double DX,
double YX,
double YY,
double YZ,
double DY,
double ZX,
double ZY,
228 double ZZ,
double DZ)
229 : G4Transform3D(XX, XY, XZ, DX, YX, YY, YZ, DY, ZX, ZY, ZZ, DZ) {
231 MyTransform3D(
const double* t,
const double* r = s_identity_rot)
232 : G4Transform3D(r[0],r[1],r[2],t[0]*
CM_2_MM,r[3],r[4],r[5],t[1]*
CM_2_MM,r[6],r[7],r[8],t[2]*
CM_2_MM) {
236 #if 0 // warning: unused function 'handleName' [-Wunused-function]
237 void handleName(
const TGeoNode* n) {
238 TGeoVolume*
v = n->GetVolume();
239 TGeoMedium*
m = v->GetMedium();
240 TGeoShape*
s = v->GetShape();
242 printout(
DEBUG,
"G4",
"TGeoNode:'%s' Vol:'%s' Shape:'%s' Medium:'%s'", n->GetName(), v->GetName(), s->GetName(),
247 class G4UserRegionInformation :
public G4VUserRegionInformation {
251 bool storeSecondaries;
252 G4UserRegionInformation()
253 : threshold(0.0), storeSecondaries(false) {
255 virtual ~G4UserRegionInformation() {
257 virtual void Print()
const {
258 if (region.isValid())
288 g4e = G4Element::GetElement(name,
false);
290 if (element->GetNisotopes() > 1) {
291 g4e =
new G4Element(name, element->GetTitle(), element->GetNisotopes());
292 for (
int i = 0, n = element->GetNisotopes(); i < n; ++i) {
293 TGeoIsotope* iso = element->GetIsotope(i);
294 G4Isotope* g4iso = G4Isotope::GetIsotope(iso->GetName(),
false);
296 g4iso =
new G4Isotope(iso->GetName(), iso->GetZ(), iso->GetN(), iso->GetA());
298 g4e->AddIsotope(g4iso, element->GetRelativeAbundance(i));
302 g4e =
new G4Element(element->GetTitle(), name, element->Z(), element->A() * (
CLHEP::g /
CLHEP::mole));
317 mat = G4Material::GetMaterial(name,
false);
319 TGeoMaterial* material = medium->GetMaterial();
320 G4State state = kStateUndefined;
324 switch (material->GetState()) {
325 case TGeoMaterial::kMatStateSolid:
328 case TGeoMaterial::kMatStateLiquid:
329 state = kStateLiquid;
331 case TGeoMaterial::kMatStateGas:
335 case TGeoMaterial::kMatStateUndefined:
336 state = kStateUndefined;
339 if (material->IsMixture()) {
340 double A_total = 0.0;
341 double W_total = 0.0;
342 TGeoMixture*
mix = (TGeoMixture*) material;
343 int nElements = mix->GetNelements();
344 mat =
new G4Material(name, density, nElements, state,
345 material->GetTemperature(), material->GetPressure());
346 for (
int i = 0; i < nElements; ++i) {
347 A_total += (mix->GetAmixt())[i];
348 W_total += (mix->GetWmixt())[i];
350 for (
int i = 0; i < nElements; ++i) {
351 TGeoElement*
e = mix->GetElement(i);
355 "Missing component %s for material %s. A=%f W=%f",
356 e->GetName(), mix->GetName(), A_total, W_total);
359 mat->AddElement(g4e, (mix->GetWmixt())[i] / W_total);
363 double z = material->GetZ(), a = material->GetA();
364 if ( z < 1.0000001 ) z = 1.0;
365 if ( a < 0.5000001 ) a = 1.0;
366 mat =
new G4Material(name, z, a, density, state,
367 material->GetTemperature(), material->GetPressure());
382 if (0 != (solid =
data().g4Solids[shape])) {
385 else if (shape->IsA() == TGeoShapeAssembly::Class()) {
391 else if (shape->IsA() == TGeoBBox::Class()) {
392 const TGeoBBox* s = (
const TGeoBBox*) shape;
395 else if (shape->IsA() == TGeoTube::Class()) {
396 const TGeoTube* s = (
const TGeoTube*) shape;
399 else if (shape->IsA() == TGeoTubeSeg::Class()) {
400 const TGeoTubeSeg* s = (
const TGeoTubeSeg*) shape;
404 else if (shape->IsA() == TGeoEltu::Class()) {
405 const TGeoEltu* s = (
const TGeoEltu*) shape;
408 else if (shape->IsA() == TGeoTrd1::Class()) {
409 const TGeoTrd1* s = (
const TGeoTrd1*) shape;
413 else if (shape->IsA() == TGeoTrd2::Class()) {
414 const TGeoTrd2* s = (
const TGeoTrd2*) shape;
418 else if (shape->IsA() == TGeoHype::Class()) {
419 const TGeoHype* s = (
const TGeoHype*) shape;
420 solid =
new G4Hype(name, s->GetRmin() *
CM_2_MM, s->GetRmax() *
CM_2_MM,
424 else if (shape->IsA() == TGeoPgon::Class()) {
425 const TGeoPgon* s = (
const TGeoPgon*) shape;
427 double phi_total = (s->GetDphi() + s->GetPhi1()) *
DEGREE_2_RAD;
428 vector<double> rmin, rmax, z;
429 for (Int_t i = 0; i < s->GetNz(); ++i) {
430 rmin.push_back(s->GetRmin(i) *
CM_2_MM);
431 rmax.push_back(s->GetRmax(i) *
CM_2_MM);
432 z.push_back(s->GetZ(i) *
CM_2_MM);
434 solid =
new G4Polyhedra(name, phi_start, phi_total, s->GetNedges(), s->GetNz(), &z[0], &rmin[0], &rmax[0]);
436 else if (shape->IsA() == TGeoPcon::Class()) {
437 const TGeoPcon* s = (
const TGeoPcon*) shape;
439 double phi_total = (s->GetDphi() + s->GetPhi1()) *
DEGREE_2_RAD;
440 vector<double> rmin, rmax, z;
441 for (Int_t i = 0; i < s->GetNz(); ++i) {
442 rmin.push_back(s->GetRmin(i) *
CM_2_MM);
443 rmax.push_back(s->GetRmax(i) *
CM_2_MM);
444 z.push_back(s->GetZ(i) *
CM_2_MM);
446 solid =
new G4Polycone(name, phi_start, phi_total, s->GetNz(), &z[0], &rmin[0], &rmax[0]);
448 else if (shape->IsA() == TGeoCone::Class()) {
449 const TGeoCone* s = (
const TGeoCone*) shape;
453 else if (shape->IsA() == TGeoConeSeg::Class()) {
458 else if (shape->IsA() == TGeoParaboloid::Class()) {
459 const TGeoParaboloid* s = (
const TGeoParaboloid*) shape;
463 else if (shape->IsA() == TGeoEllisoid::Class()) {
464 const TGeoParaboloid* s = (
const TGeoParaboloid*) shape;
468 else if (shape->IsA() == TGeoSphere::Class()) {
469 const TGeoSphere* s = (
const TGeoSphere*) shape;
473 else if (shape->IsA() == TGeoTorus::Class()) {
474 const TGeoTorus* s = (
const TGeoTorus*) shape;
478 else if (shape->IsA() == TGeoTrap::Class()) {
479 const TGeoTrap* s = (
const TGeoTrap*) shape;
480 solid =
new G4Trap(name, s->GetDz() *
CM_2_MM, s->GetTheta(), s->GetPhi(),
484 else if (shape->IsA() == TGeoCompositeShape::Class()) {
485 const TGeoCompositeShape* s = (
const TGeoCompositeShape*) shape;
486 const TGeoBoolNode*
boolean = s->GetBoolNode();
487 TGeoBoolNode::EGeoBoolType oper =
boolean->GetBooleanOperator();
488 TGeoMatrix* m =
boolean->GetRightMatrix();
489 G4VSolid* left = (G4VSolid*)
handleSolid(name +
"_left", boolean->GetLeftShape());
490 G4VSolid* right = (G4VSolid*)
handleSolid(name +
"_right", boolean->GetRightShape());
493 throw runtime_error(
"G4Converter: No left Geant4 Solid present for composite shape:" + name);
496 throw runtime_error(
"G4Converter: No right Geant4 Solid present for composite shape:" + name);
503 TGeoShape* ls =
boolean->GetLeftShape();
504 TGeoShape* rs =
boolean->GetRightShape();
505 if (strcmp(ls->ClassName(),
"TGeoScaledShape") == 0 &&
506 strcmp(rs->ClassName(),
"TGeoBBox") == 0) {
507 if (strcmp(((TGeoScaledShape *)ls)->GetShape()->ClassName(),
"TGeoSphere") == 0) {
508 if (oper == TGeoBoolNode::kGeoIntersection) {
509 TGeoScaledShape* lls = (TGeoScaledShape *)ls;
510 TGeoBBox* rrs = (TGeoBBox*)rs;
511 double sx = lls->GetScale()->GetScale()[0];
512 double sy = lls->GetScale()->GetScale()[1];
513 double radius = ((TGeoSphere *)lls->GetShape())->GetRmax();
514 double dz = rrs->GetDZ();
515 double zorig = rrs->GetOrigin()[2];
516 double zcut2 = dz + zorig;
517 double zcut1 = 2 * zorig - zcut2;
518 solid =
new G4Ellipsoid(name,
520 sy * radius * CM_2_MM,
530 if (m->IsRotation()) {
531 MyTransform3D transform(m->GetTranslation(),m->GetRotationMatrix());
532 if (oper == TGeoBoolNode::kGeoSubtraction)
533 solid =
new G4SubtractionSolid(name, left, right, transform);
534 else if (oper == TGeoBoolNode::kGeoUnion)
535 solid =
new G4UnionSolid(name, left, right, transform);
536 else if (oper == TGeoBoolNode::kGeoIntersection)
537 solid =
new G4IntersectionSolid(name, left, right, transform);
540 const Double_t *t = m->GetTranslation();
541 G4ThreeVector transform(t[0] *
CM_2_MM, t[1] * CM_2_MM, t[2] * CM_2_MM);
542 if (oper == TGeoBoolNode::kGeoSubtraction)
543 solid =
new G4SubtractionSolid(name, left, right, 0, transform);
544 else if (oper == TGeoBoolNode::kGeoUnion)
545 solid =
new G4UnionSolid(name, left, right, 0, transform);
546 else if (oper == TGeoBoolNode::kGeoIntersection)
547 solid =
new G4IntersectionSolid(name, left, right, 0, transform);
552 string err =
"Failed to handle unknown solid shape:" + name +
" of type " + string(shape->IsA()->GetName());
553 throw runtime_error(err);
563 Geant4GeometryMaps::VolumeMap::const_iterator volIt = info.
g4Volumes.find(volume);
565 const TGeoVolume* v = volume;
567 string n = v->GetName();
568 TGeoMedium* m = v->GetMedium();
569 TGeoShape* s = v->GetShape();
570 G4VSolid* solid = (G4VSolid*)
handleSolid(s->GetName(),
s);
571 G4Material* medium = 0;
572 bool assembly = s->IsA() == TGeoShapeAssembly::Class() || v->IsA() == TGeoVolumeAssembly::Class();
575 G4UserLimits* user_limits = 0;
579 throw runtime_error(
"G4Cnv::volume[" + name +
"]: + FATAL Failed to "
580 "access Geant4 user limits.");
584 G4VisAttributes* vis_attr = 0;
589 G4Region* region = 0;
593 throw runtime_error(
"G4Cnv::volume[" + name +
"]: + FATAL Failed to "
594 "access Geant4 region.");
598 printout(lvl,
"Geant4Converter",
"++ Convert Volume %-32s: %p %s/%s assembly:%s",
599 n.c_str(),
v, s->IsA()->GetName(), v->IsA()->GetName(),
yes_no(assembly));
607 throw runtime_error(
"G4Converter: No Geant4 Solid present for volume:" + n);
610 throw runtime_error(
"G4Converter: No Geant4 material present for volume:" + n);
616 G4LogicalVolume* vol =
new G4LogicalVolume(solid, medium, n, 0, 0, user_limits);
620 vol->SetRegion(region);
621 region->AddRootLogicalVolume(vol);
624 vol->SetVisAttributes(vis_attr);
627 printout(
m_outputLevel,
"Geant4Converter",
"++ Volume + %s converted: %p ---> G4: %p", n.c_str(),
v, vol);
635 const TGeoVolume* v = volume;
642 info.
limits[lim].insert(v);
652 TGeoVolume* mot_vol = node->GetVolume();
653 if ( mot_vol->IsA() != TGeoVolumeAssembly::Class() ) {
661 for(Int_t i=0; i < mot_vol->GetNdaughters(); ++i) {
662 TGeoNode* d = mot_vol->GetNode(i);
663 TGeoVolume* dau_vol = d->GetVolume();
664 TGeoMatrix* tr = d->GetMatrix();
665 MyTransform3D transform(tr->GetTranslation(),tr->IsRotation() ? tr->GetRotationMatrix() : s_identity_rot);
666 if ( dau_vol->IsA() == TGeoVolumeAssembly::Class() ) {
667 Geant4GeometryMaps::AssemblyMap::iterator assIt = info.
g4AssemblyVolumes.find(d);
669 printout(
FATAL,
"Geant4Converter",
"+++ Invalid child assembly at %s : %d parent: %s child:%s",
670 __FILE__, __LINE__, name.c_str(), d->GetName());
674 "to mother %s Tr:x=%8.3f y=%8.3f z=%8.3f",
675 dau_vol->GetName(), mot_vol->GetName(),
676 transform.dx(), transform.dy(), transform.dz());
679 Geant4GeometryMaps::VolumeMap::iterator volIt = info.
g4Volumes.find(dau_vol);
681 printout(
FATAL,
"Geant4Converter",
"+++ Invalid child volume at %s : %d parent: %s child:%s",
682 __FILE__, __LINE__, name.c_str(), d->GetName());
686 "to mother %s Tr:x=%8.3f y=%8.3f z=%8.3f",
687 dau_vol->GetName(), mot_vol->GetName(),
688 transform.dx(), transform.dy(), transform.dz());
699 Geant4GeometryMaps::PlacementMap::const_iterator g4it = info.
g4Placements.find(node);
700 G4VPhysicalVolume* g4 = (g4it == info.
g4Placements.end()) ? 0 : (*g4it).second;
702 TGeoVolume* mot_vol = node->GetMotherVolume();
703 TGeoVolume* vol = node->GetVolume();
704 TGeoMatrix* tr = node->GetMatrix();
706 printout(
FATAL,
"Geant4Converter",
"++ Attempt to handle placement without transformation:%p %s of type %s vol:%p", node,
707 node->GetName(), node->IsA()->GetName(), vol);
710 printout(
FATAL,
"Geant4Converter",
"++ Unknown G4 volume:%p %s of type %s ptr:%p", node, node->GetName(),
711 node->IsA()->GetName(), vol);
714 int copy = node->GetNumber();
715 bool node_is_assembly = vol->IsA() == TGeoVolumeAssembly::Class();
716 bool mother_is_assembly = mot_vol ? mot_vol->IsA() == TGeoVolumeAssembly::Class() :
false;
717 MyTransform3D transform(tr->GetTranslation(),tr->IsRotation() ? tr->GetRotationMatrix() : s_identity_rot);
718 Geant4GeometryMaps::VolumeMap::const_iterator volIt = info.
g4Volumes.find(mot_vol);
720 if ( mother_is_assembly ) {
728 "to mother %s Tr:x=%8.3f y=%8.3f z=%8.3f",
729 vol->GetName(), mot_vol->GetName(),
730 transform.dx(), transform.dy(), transform.dz());
733 else if ( node_is_assembly ) {
739 "Tr:x=%8.3f y=%8.3f z=%8.3f",
740 node->GetName(), mot_vol->GetName(),
741 transform.dx(), transform.dy(), transform.dz());
744 chain.push_back(node);
745 ass->imprint(info,node,chain,ass,(*volIt).second, transform, copy,
m_checkOverlaps);
748 else if ( node != gGeoManager->GetTopNode() && volIt == info.
g4Volumes.end() ) {
749 throw logic_error(
"Geant4Converter: Invalid mother volume found!");
751 G4LogicalVolume* g4vol = info.
g4Volumes[vol];
752 G4LogicalVolume* g4mot = info.
g4Volumes[mot_vol];
753 g4 =
new G4PVPlacement(transform,
764 printout(
ERROR,
"Geant4Converter",
"++ Attempt to DOUBLE-place physical volume: %s No:%d", name.c_str(), node->GetNumber());
774 g4 =
new G4Region(r.
name());
776 G4ProductionCuts* cuts =
new G4ProductionCuts();
778 g4->SetProductionCuts(cuts);
781 G4UserRegionInformation* info =
new G4UserRegionInformation();
785 g4->SetUserInformation(info);
788 vector < string > &limits = r.
limits();
789 for (vector<string>::const_iterator i = limits.begin(); i != limits.end(); ++i) {
790 const string& nam = *i;
795 for (Geant4GeometryMaps::LimitMap::const_iterator j = lm.begin(); j != lm.end(); ++j) {
796 if (nam == (*j).first->GetName()) {
797 g4->SetUserLimits((*j).second);
805 throw runtime_error(
"G4Region: Failed to resolve user limitset:" + *i);
817 g4 =
new G4UserLimits(limitset->GetName());
818 const set<Limit>& limits = ls.
limits();
819 for (LimitSet::Object::const_iterator i = limits.begin(); i != limits.end(); ++i) {
821 if (l.
name ==
"step_length_max")
823 else if (l.
name ==
"track_length_max")
825 else if (l.
name ==
"time_max")
827 else if (l.
name ==
"ekin_min")
829 else if (l.
name ==
"range_min")
830 g4->SetUserMinRange(l.
value);
832 throw runtime_error(
"Unknown Geant4 user limit: " + l.
toString());
842 G4VisAttributes* g4 = info.
g4Vis[attr];
844 float r = 0,
g = 0, b = 0;
847 g4 =
new G4VisAttributes(attr.
visible(), G4Colour(r,
g, b, attr.
alpha()));
851 g4->SetLineStyle(G4VisAttributes::unbroken);
852 g4->SetForceWireframe(
false);
853 g4->SetForceSolid(
true);
856 g4->SetLineStyle(G4VisAttributes::dashed);
857 g4->SetForceSolid(
false);
858 g4->SetForceWireframe(
true);
860 info.
g4Vis[attr] = g4;
867 map < string, string > processors;
868 static int s_idd = 9999999;
870 for (LCDD::Properties::const_iterator i = prp.begin(); i != prp.end(); ++i) {
871 const string& nam = (*i).first;
873 if (nam.substr(0, 6) ==
"geant4") {
874 LCDD::PropertyValues::const_iterator id_it = vals.find(
"id");
875 if (id_it != vals.end()) {
876 id = (*id_it).second;
880 ::snprintf(txt,
sizeof(txt),
"%d", ++s_idd);
883 processors.insert(make_pair(
id, nam));
886 for (map<string, string>::const_iterator i = processors.begin(); i != processors.end(); ++i) {
888 string nam = (*i).second;
890 string type = vals.find(
"type")->second;
891 string tag = type +
"_Geant4_action";
892 long result = PluginService::Create<long>(tag, &
m_lcdd, hdlr, &vals);
894 throw runtime_error(
"Failed to locate plugin to interprete files of type"
895 " \"" + tag +
"\" - no factory:" + type);
897 result = *(
long*) result;
899 throw runtime_error(
"Failed to invoke the plugin " + tag +
" of type " + type);
901 printout(
m_outputLevel,
"Geant4Converter",
"+++++ Executed Successfully Geant4 setup module *%s*.", type.c_str());
912 printout(
INFO,
"Geant4Converter",
"++ SensitiveDetector: %-18s %-20s Hits:%-16s", sd.
name(), (
"[" + sd.
type() +
"]").c_str(),
914 str <<
" | " <<
"Cutoff:" << setw(6) << left << sd.
energyCutoff() << setw(5) << right << volset.size()
917 str <<
" Region:" << setw(12) << left << sd.
region().
name();
919 str <<
" Limits:" << setw(12) << left << sd.
limits().
name();
923 for (ConstVolumeSet::iterator i = volset.begin(); i != volset.end(); ++i) {
924 map<Volume, G4LogicalVolume*>::iterator v = info.
g4Volumes.find(*i);
925 G4LogicalVolume* vol = (*v).second;
927 str <<
" | " <<
"Volume:" << setw(24) << left << vol->GetName() <<
" "
928 << vol->GetNoDaughters() <<
" daughters.";
935 if (
typeid(*sol) ==
typeid(G4Box)) {
936 const G4Box* b = (G4Box*) sol;
937 str <<
"++ Box: x=" << b->GetXHalfLength() <<
" y=" << b->GetYHalfLength() <<
" z=" << b->GetZHalfLength();
939 else if (
typeid(*sol) ==
typeid(G4Tubs)) {
940 const G4Tubs* t = (
const G4Tubs*) sol;
941 str <<
" Tubs: Ri=" << t->GetInnerRadius() <<
" Ra=" << t->GetOuterRadius() <<
" z/2=" << t->GetZHalfLength() <<
" Phi="
942 << t->GetStartPhiAngle() <<
"..." << t->GetDeltaPhiAngle();
951 G4LogicalVolume* vol = info.
g4Volumes[node->GetVolume()];
952 G4LogicalVolume* mot = info.
g4Volumes[node->GetMotherVolume()];
953 G4VSolid* sol = vol->GetSolid();
954 G4ThreeVector tr = g4->GetObjectTranslation();
961 str <<
"G4Cnv::placement: + " << name <<
" No:" << node->GetNumber() <<
" Vol:" << vol->GetName() <<
" Solid:"
965 str <<
" |" <<
" Loc: x=" << tr.x() <<
" y=" << tr.y() <<
" z=" << tr.z();
969 str <<
" |" <<
" Ndau:" << vol->GetNoDaughters() <<
" physvols." <<
" Mat:" << vol->GetMaterial()->GetName()
970 <<
" Mother:" << (
char*) (mot ? mot->GetName().c_str() :
"---");
973 str <<
" |" <<
" SD:" << sd->GetName();
978 template <
typename O,
typename C,
typename F>
void handleRefs(
const O* o,
const C& c, F pmf) {
979 for (
typename C::const_iterator i = c.begin(); i != c.end(); ++i) {
984 template <
typename O,
typename C,
typename F>
void handle(
const O* o,
const C& c, F pmf) {
985 for (
typename C::const_iterator i = c.begin(); i != c.end(); ++i) {
986 (o->*pmf)((*i)->GetName(), *i);
990 template <
typename O,
typename C,
typename F>
void handleMap(
const O* o,
const C& c, F pmf) {
991 for (
typename C::const_iterator i = c.begin(); i != c.end(); ++i)
992 (o->*pmf)((*i).first, (*i).second);
995 template <
typename O,
typename C,
typename F>
void handleRMap(
const O* o,
const C& c, F pmf) {
996 for (
typename C::const_reverse_iterator i = c.rbegin(); i != c.rend(); ++i) {
998 handle(o, (*i).second, pmf);
1041 printout(
INFO,
"Geant4Converter",
"+++ Successfully converted geometry to Geant4.");
Geant4GeometryMaps::LimitMap g4Limits
Handle class to hold the information of a sensitive detector.
std::string toString() const
Conversion to a string representation.
void setWorld(const TGeoNode *node)
Set the world volume.
Hack! Wrapper around G4AssemblyVolume to access protected members.
Ref_t sensitiveDetector() const
Access to the handle to the sensitive detector.
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
void handleRefs(const O *o, const C &c, F pmf)
const char * name() const
Access the object name (or "" if not supported by the object)
Handle class describing a material.
bool storeSecondaries() const
Access secondaries flag.
bool isValid() const
Check the validity of the object held by the handle.
Handle class describing an element in the periodic table.
const std::string & hitsCollection() const
Access the hits collection name.
LimitSet limitSet() const
Access to the limit set.
const std::set< DD4hep::Geometry::Limit > & limits() const
Accessor to limits container.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Geant4GeometryMaps::AssemblyMap g4AssemblyVolumes
double cut() const
Access cut value.
virtual void * handleAssembly(const std::string &name, const TGeoNode *node) const
Dump volume placement in GDML format to output stream.
const char * yes_no(bool value)
Helper function to print booleans in format YES/NO.
LimitSet limits() const
Access to the limit set of the sensitive detector (not mandatory).
Geant4GeometryInfo & init()
Create and attach new data block. Delete old data block if present.
string printSolid(G4VSolid *sol)
virtual ~Geant4Converter()
Standard destructor.
VisAttr visAttributes() const
Access the visualisation attributes.
virtual void * handleLimitSet(LimitSet limitset, const std::set< const TGeoVolume * > &volumes) const
Convert the geometry type LimitSet into the corresponding Geant4 object(s).
PrintLevel printLevel()
Access the current printer level.
virtual void * handleElement(const std::string &name, Atom element) const
Convert the geometry type element into the corresponding Geant4 object(s).
virtual void * handleVolume(const std::string &name, const TGeoVolume *volume) const
Convert the geometry type logical volume into the corresponding Geant4 object(s). ...
T * ptr() const
Access to the held object.
Geant4GeometryMaps::RegionVolumes regions
Handle class holding a placed volume (also called physical volume)
void handleRMap(const O *o, const C &c, F pmf)
std::vector< const TGeoNode * > m_entries
bool rgb(float &red, float &green, float &blue) const
Get RGB values of the color (if valid)
virtual LimitSet limitSet(const std::string &name) const =0
Retrieve a limitset by it's name from the detector description.
GeoHandler & collect(DetElement top)
Collect geometry information from traversal.
std::vector< std::string > & limits() const
Access references to user limits.
The base class for all DD4hep geometry crawlers.
bool visible() const
Get visibility flag.
virtual void * handleRegion(Region region, const std::set< const TGeoVolume * > &volumes) const
Convert the geometry type region into the corresponding Geant4 object(s).
long placeAssembly(const TGeoNode *n, Geant4AssemblyVolume *pPlacedVolume, G4Transform3D &transformation)
virtual void * handleMaterial(const std::string &name, Material medium) const
Convert the geometry type material into the corresponding Geant4 object(s).
double threshold() const
Access production threshold.
Geant4GeometryMaps::VolumeMap g4Volumes
Geant4GeometryMaps::MaterialMap g4Materials
virtual void * handleVis(const std::string &name, VisAttr vis) const
Convert the geometry visualisation attributes to the corresponding Geant4 object(s).
long placeVolume(const TGeoNode *n, G4LogicalVolume *pPlacedVolume, G4Transform3D &transformation)
Geant4GeometryMaps::VolumeImprintMap g4VolumeImprints
Geometry::Material Material
std::set< const TGeoVolume * > ConstVolumeSet
int lineStyle() const
Get line style.
std::vector< const TGeoNode * > Chain
virtual void printSensitive(SensitiveDetector sens_det, const std::set< const TGeoVolume * > &volumes) const
Print the geometry type SensitiveDetector.
Geant4GeometryMaps::VisMap g4Vis
PlacedVolume placement() const
Access to the physical volume of this detector element.
Region region() const
Access to the handle to the region structure.
Geant4Converter(LCDD &lcdd)
Initializing Constructor.
Geant4GeometryMaps::LimitVolumes limits
virtual void * printPlacement(const std::string &name, const TGeoNode *node) const
Print Geant4 placement.
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Geant4GeometryMaps::SensitiveVolumes sensitives
Geant4Converter & create(DetElement top)
Create geometry conversion.
Geant4GeometryMaps::RegionMap g4Regions
Small object describing a limit structure acting on a particle type.
std::map< std::string, PropertyValues > Properties
virtual void * collectVolume(const std::string &name, const TGeoVolume *volume) const
Dump logical volume in GDML format to output stream.
virtual Properties & properties() const =0
Access to properties map.
Handle class describing visualization attributes.
Handle class describing a detector element.
void handleProperties(LCDD::Properties &prp) const
Handle the geant 4 specific properties.
Geant4GeometryMaps::ElementMap g4Elements
Geant4GeometryMaps::PlacementMap g4Placements
void handleMap(const O *o, const C &c, F pmf)
Geometry converter from DD4hep to Geant 4.
Handle class describing a set of limits as they are used for simulation.
Handle class describing a region as used in simulation.
void imprint(Geant4GeometryInfo &info, const TGeoNode *n, Chain chain, Geant4AssemblyVolume *pAssembly, G4LogicalVolume *pMotherLV, G4Transform3D &transformation, G4int copyNumBase, G4bool surfCheck)
The main interface to the DD4hep detector description package.
Concreate class holding the relation information between geant4 objects and dd4hep objects...
Geometry mapping from DD4hep to Geant 4.
virtual void * handlePlacement(const std::string &name, const TGeoNode *node) const
Convert the geometry type volume placement into the corresponding Geant4 object(s).
virtual Material material(const std::string &name) const =0
Retrieve a matrial by it's name from the detector description.
float alpha() const
Get alpha value.
void handle(const O *o, const C &c, F pmf)
Geant4GeometryMaps::SolidMap g4Solids
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
std::string type() const
Access the type of the sensitive detector.
std::map< LimitSet, G4UserLimits * > LimitMap
Region region() const
Access to the region setting of the sensitive detector (not mandatory)
Geant4GeometryInfo & data() const
Access to the data pointer.
std::map< std::string, std::string > PropertyValues
bool showDaughters() const
Get Flag to show/hide daughter elements.
virtual void * handleSolid(const std::string &name, const TGeoShape *volume) const
Convert the geometry type solid into the corresponding Geant4 object(s).
double energyCutoff() const
Access energy cut off.