83 G4tgbGeometryDumper::G4tgbGeometryDumper()
84 : theFile(0), theRotationNumber(0)
91 if( theInstance == 0 ){
102 theFile =
new std::ofstream(fname);
112 G4PhysicalVolumeStore::const_iterator ite;
117 if( lv == 0 ) {
break; }
120 for( ite = pvstore->begin(); ite != pvstore->end(); ite++ )
156 G4bool bVolExists = CheckIfLogVolExists( lv->
GetName(), lv );
195 std::vector<G4VPhysicalVolume*> pvChildren = GetPVChildren( lv );
196 std::vector<G4VPhysicalVolume*>::const_iterator ite;
197 for( ite = pvChildren.begin(); ite != pvChildren.end(); ite++ )
222 G4cout <<
" G4tgbGeometryDumper::DumpPVPlacement() - Reflected volume: "
233 colx.
y(),coly.
y(),colz.
y(),
234 colx.
z(),coly.
z(),colz.
z());
237 *rotMat = (*rotMat).inverse();
252 if( !CheckIfPhysVolExists(fullname, pv ))
256 << SubstituteRefl(AddQuotes(lvName))
257 <<
" " << copyNo <<
" "
259 <<
" " << AddQuotes(rotName) <<
" "
260 << pos.
x() <<
" " << pos.
y() <<
" " << pos.
z() <<
G4endl;
262 thePhysVols[fullname] = pv;
285 std::vector<G4double> newParams;
289 for(
G4int ii = 0; ii < nReplicas; ii++ )
376 if( ii == 0 || mate1st != newMate || params1st[0] != newParams[0] )
384 lvName =
DumpLogVol( lv, extraName, newSolid, newMate );
423 G4String ErrMessage =
"Unknown axis of replication for volume"
433 if( !CheckIfPhysVolExists(fullname, pv ))
437 << SubstituteRefl(AddQuotes(lvName))
445 <<
" " << offset <<
G4endl;
450 <<
" " << width/
deg <<
"*deg"
451 <<
" " << offset/
deg <<
"*deg" <<
G4endl;
454 thePhysVols[fullname] = pv;
466 if( extraName ==
"" )
468 lvName = GetObjectName(lv,theLogVols);
472 lvName = lv->
GetName()+extraName;
475 if( theLogVols.find( lvName ) != theLogVols.end() )
480 if( !solid ) { solid = lv->
GetSolid(); }
490 (*theFile) <<
":VOLU " << SubstituteRefl(AddQuotes(lvName)) <<
" "
491 << SupressRefl(AddQuotes(solidName))
492 <<
" " << AddQuotes(mateName) <<
G4endl;
494 theLogVols[lvName] = lv;
503 G4String mateName = GetObjectName(mat,theMaterials);
504 if( theMaterials.find( mateName ) != theMaterials.end() )
515 if (numElements == 1)
517 (*theFile) <<
":MATE " << AddQuotes(mateName) <<
" "
525 for (
size_t ii = 0; ii < numElements; ii++)
530 (*theFile) <<
":MIXT "<< AddQuotes(mateName) <<
" "
531 << density <<
" " << numElements <<
G4endl;
533 for (
size_t ii = 0; ii < numElements; ii++)
536 << AddQuotes(GetObjectName((*elems)[ii],theElements)) <<
" "
537 << fractions[ii] <<
G4endl;
542 (*theFile) <<
":MATE_MEE " << AddQuotes(mateName) <<
" "
546 (*theFile) <<
":MATE_TEMPERATURE " << AddQuotes(mateName) <<
" "
549 (*theFile) <<
":MATE_PRESSURE " << AddQuotes(mateName) <<
" "
556 stateStr =
"Undefined";
569 (*theFile) <<
":MATE_STATE " << AddQuotes(mateName) <<
" "
572 theMaterials[mateName] =
mat;
581 G4String elemName = GetObjectName(ele,theElements);
583 if( theElements.find( elemName ) != theElements.end() )
592 if( symbol ==
"" || symbol ==
" " )
599 (*theFile) <<
":ELEM " << AddQuotes(elemName) <<
" "
600 << AddQuotes(symbol) <<
" " << ele->
GetZ() <<
" "
611 (*theFile) <<
":ELEM_FROM_ISOT " << AddQuotes(elemName) <<
" "
618 << AddQuotes(GetObjectName((*isots)[ii],theIsotopes)) <<
" "
619 << fractions[ii] <<
G4endl;
622 theElements[elemName] = ele;
629 G4String isotName = GetObjectName(isot,theIsotopes);
630 if( theIsotopes.find( isotName ) != theIsotopes.end() )
635 (*theFile) <<
":ISOT " << AddQuotes(isotName) <<
" "
636 << isot->
GetZ() <<
" " << isot->
GetN() <<
" "
639 theIsotopes[isotName] = isot;
648 if( extraName ==
"" )
650 solidName = GetObjectName(solid,theSolids);
654 solidName = solid->
GetName()+extraName;
657 if( theSolids.find( solidName ) != theSolids.end() )
663 solidType = GetTGSolidType( solidType );
665 if (solidType ==
"UNIONSOLID")
669 }
else if (solidType ==
"SUBTRACTIONSOLID") {
672 }
else if (solidType ==
"INTERSECTIONSOLID") {
675 }
else if (solidType ==
"REFLECTEDSOLID") {
688 (*theFile) <<
":SOLID " << AddQuotes(solidName) <<
" ";
689 (*theFile) << AddQuotes(solidType) <<
" ";
691 theSolids[solidName] = solid;
703 if (!bso) {
return; }
722 GetTransform().NetRotation()).inverse() ) );
730 G4String bsoName = GetObjectName(so,theSolids);
731 if( theSolids.find( bsoName ) != theSolids.end() )
return;
732 G4String solid0Name = FindSolidName( solid0 );
733 G4String solid1Name = FindSolidName( solid1 );
735 (*theFile) <<
":SOLID "
736 << AddQuotes(bsoName) <<
" "
737 << AddQuotes(solidType) <<
" "
738 << AddQuotes(solid0Name) <<
" "
739 << AddQuotes(solid1Name) <<
" "
740 << AddQuotes(rotName) <<
" "
741 << approxTo0(pos.
x()) <<
" "
742 << approxTo0(pos.
y()) <<
" "
743 << approxTo0(pos.
z()) <<
" " <<
G4endl;
745 theSolids[bsoName] = bso;
753 for(
size_t ii = 0 ; ii < params.size(); ii++ )
755 (*theFile) << params[ii] <<
" " ;
764 std::vector<G4double> params;
767 solidType = GetTGSolidType( solidType );
769 if (solidType ==
"BOX") {
770 const G4Box * sb = dynamic_cast <
const G4Box*>(so);
776 }
else if (solidType ==
"TUBS") {
777 const G4Tubs * tu = dynamic_cast <
const G4Tubs * > (so);
785 }
else if (solidType ==
"TRAP") {
786 const G4Trap * trp = dynamic_cast <
const G4Trap * > (so);
792 params.push_back( theta );
793 params.push_back( phi);
803 }
else if (solidType ==
"TRD") {
804 const G4Trd * tr = dynamic_cast <
const G4Trd * > (so);
812 }
else if (solidType ==
"PARA") {
813 const G4Para * para = dynamic_cast <
const G4Para * > (so);
823 params.push_back( phi/
deg);
825 }
else if (solidType ==
"CONS") {
826 const G4Cons * cn = dynamic_cast <
const G4Cons * > (so);
836 }
else if (solidType ==
"SPHERE") {
846 }
else if (solidType ==
"ORB") {
847 const G4Orb * orb = dynamic_cast <
const G4Orb * > (so);
851 }
else if (solidType ==
"TORUS") {
854 params.push_back( torus->
GetRmin());
855 params.push_back( torus->
GetRmax());
856 params.push_back( torus->
GetRtor());
860 }
else if (solidType ==
"POLYCONE") {
866 if( angphi > 180*
deg ) { angphi -= 360*
deg; }
868 params.push_back( angphi );
870 params.push_back( ncor );
872 for(
G4int ii = 0; ii < ncor; ii++ )
878 }
else if (solidType ==
"POLYHEDRA") {
884 if( angphi > 180*
deg ) angphi -= 360*
deg;
888 params.push_back( angphi );
891 params.push_back( ncor );
893 for(
G4int ii = 0; ii < ncor; ii++ )
899 }
else if (solidType ==
"ELLIPTICALTUBE") {
903 params.push_back( eltu->
GetDx());
904 params.push_back( eltu->
GetDy());
905 params.push_back( eltu->
GetDz());
907 }
else if (solidType ==
"ELLIPSOID" ){
916 }
else if (solidType ==
"ELLIPTICAL_CONE") {
920 params.push_back( elco-> GetSemiAxisX() );
921 params.push_back( elco-> GetSemiAxisY() );
922 params.push_back( elco-> GetZMax() );
923 params.push_back( elco-> GetZTopCut() );
925 }
else if (solidType ==
"HYPE") {
926 const G4Hype* hype = dynamic_cast <
const G4Hype * > (so);
936 }
else if( solidType ==
"TWISTEDBOX" ) {
944 }
else if( solidType ==
"TWISTEDTRAP" ) {
959 }
else if( solidType ==
"TWISTEDTRD" ) {
969 }
else if( solidType ==
"TWISTEDTUBS" ) {
981 G4String ErrMessage =
"Solid type not supported, sorry... " + solidType;
982 G4Exception(
"G4tgbGeometryDumpe::DumpSolidParams()",
996 G4String rotName = LookForExistingRotation( rotm );
997 if( rotName !=
"" ) {
return rotName; }
1002 (*theFile) <<
":ROTM ";
1006 (*theFile) << AddQuotes(rotName) << std::setprecision(9) <<
" "
1007 << approxTo0(rotm->
xx()) <<
" "
1008 << approxTo0(rotm->
yx()) <<
" "
1009 << approxTo0(rotm->
zx()) <<
" "
1010 << approxTo0(rotm->
xy()) <<
" "
1011 << approxTo0(rotm->
yy()) <<
" "
1012 << approxTo0(rotm->
zy()) <<
" "
1013 << approxTo0(rotm->
xz()) <<
" "
1014 << approxTo0(rotm->
yz()) <<
" "
1015 << approxTo0(rotm->
zz()) <<
G4endl;
1019 (*theFile) <<
":ROTM ";
1023 (*theFile) << AddQuotes(rotName) <<
" "
1025 << approxTo0(rotm->
phiX()/
deg) <<
" "
1027 << approxTo0(rotm->
phiY()/
deg) <<
" "
1032 theRotMats[rotName] = rotm;
1039 std::vector<G4VPhysicalVolume*>
1043 G4PhysicalVolumeStore::const_iterator ite;
1044 std::vector<G4VPhysicalVolume*> children;
1045 for( ite = pvstore->begin(); ite != pvstore->end(); ite++ )
1047 if( (*ite)->GetMotherLogical() == lv )
1049 children.push_back( *ite );
1053 G4cout <<
" G4tgbGeometryDumper::GetPVChildren() - adding children: "
1067 G4String newsolidType = solidType.substr(2,solidType.length() );
1068 for(
size_t ii = 0; ii < newsolidType.length(); ii++ )
1070 newsolidType[ii] = toupper(newsolidType[ii] );
1072 return newsolidType;
1092 if( std::fabs(val) < precision ) { val = 0; }
1103 size_t siz = str.length();
1104 for(
size_t ii = 0; ii < siz; ii++ )
1106 if( str.substr(ii,1) ==
" " )
1124 G4int irefl = name.rfind(
"_refl");
1127 name = name.substr( 0, irefl );
1135 G4int irefl = name.rfind(
"_refl");
1138 name = name.substr( 0, irefl ) +
"_REFL";
1151 std::map<G4String,G4Isotope*>::const_iterator ite;
1152 for( ite = theIsotopes.begin(); ite != theIsotopes.end(); ite++ )
1154 if( isot == (*ite).second ) {
return (*ite).
first; }
1160 ite = theIsotopes.find( isotName );
1161 if( ite != theIsotopes.end() )
1164 if( isot != isotold )
1166 if( !Same2G4Isotopes(isot, isotold))
1172 G4String newIsotName = isotName +
"_"
1174 std::map<G4String,G4Isotope*>::const_iterator ite2 =
1175 theIsotopes.find( newIsotName );
1176 if( ite2 == theIsotopes.end() )
1178 isotName = newIsotName;
1183 if( Same2G4Isotopes( isot, (*ite2).second ) )
1185 isotName = newIsotName;
1198 template<
class TYP >
G4String G4tgbGeometryDumper::
1199 GetObjectName( TYP* obj, std::map<G4String,TYP*> objectsDumped )
1206 typename std::map<G4String,TYP*>::const_iterator ite;
1207 for( ite = objectsDumped.begin(); ite != objectsDumped.end(); ite++ )
1209 if( obj == (*ite).second ) {
return (*ite).
first; }
1215 ite = objectsDumped.find( objName );
1217 if( ite != objectsDumped.end() )
1219 TYP* objold = (*ite).second;
1226 typename std::map<G4String,TYP*>::const_iterator ite2 =
1227 objectsDumped.find( newObjName );
1228 if( ite2 == objectsDumped.end() )
1230 objName = newObjName;
1241 G4bool G4tgbGeometryDumper::CheckIfLogVolExists(
const G4String& name,
1244 if( theLogVols.find( name ) != theLogVols.end() )
1271 G4bool G4tgbGeometryDumper::CheckIfPhysVolExists(
const G4String& name,
1277 G4cout <<
" G4tgbGeometryDumper::CheckIfPhysVolExists() - "
1281 if( thePhysVols.find( name ) != thePhysVols.end() )
1283 if( (*(thePhysVols.find(name))).second !=
pt )
1289 G4cerr <<
" G4tgbGeometryDumper::CheckIfPhysVolExists () -"
1290 <<
" Placement found but not same as before : " << name <<
G4endl;
1303 G4tgbGeometryDumper::LookForExistingRotation(
const G4RotationMatrix* rotm )
1307 std::map<G4String,G4RotationMatrix*>::const_iterator ite;
1308 for( ite = theRotMats.begin(); ite != theRotMats.end(); ite++ )
1310 if( (*ite).second->isNear( *rotm ) )
1312 rmName = (*ite).
first;
1324 if ( (isot1->
GetZ() != isot2->
GetZ())
1325 || (isot1->
GetN() != isot2->
GetN())
1326 || (isot1->
GetA() != isot2->
GetA()) )
1340 std::map<G4String,G4VSolid*>::const_iterator ite;
1341 for( ite = theSolids.begin(); ite != theSolids.end(); ite++ )
1343 if( solid == (*ite).second ) {
return (*ite).
first; }
1346 if( ite == theSolids.end() )
1348 G4Exception(
"G4tgbGeometryDumper::FindSolidName()",
"ReadError",
1351 return (*ite).first;