80G4tgbGeometryDumper::G4tgbGeometryDumper()
87 if(theInstance ==
nullptr)
97 theFile =
new std::ofstream(fname);
117 for(
auto ite = pvstore->cbegin(); ite != pvstore->cend(); ++ite)
190 std::vector<G4VPhysicalVolume*> pvChildren = GetPVChildren(lv);
191 for(
auto ite = pvChildren.cbegin(); ite != pvChildren.cend(); ++ite)
205 if(rotMat ==
nullptr)
216 G4cout <<
" G4tgbGeometryDumper::DumpPVPlacement() - Reflected volume: "
226 G4Rep3x3 rottemp(colx.
x(), coly.
x(), colz.
x(), colx.
y(), coly.
y(), colz.
y(),
227 colx.
z(), coly.
z(), colz.
z());
244 if(!CheckIfPhysVolExists(fullname, pv))
246 (*theFile) <<
":PLACE " << SubstituteRefl(AddQuotes(lvName)) <<
" "
249 <<
" " << AddQuotes(rotName) <<
" " << pos.x() <<
" " << pos.y()
250 <<
" " << pos.z() <<
G4endl;
252 thePhysVols[fullname] = pv;
274 std::vector<G4double> newParams;
278 for(
G4int ii = 0; ii < nReplicas; ++ii)
365 if(ii == 0 || mate1st != newMate || params1st[0] != newParams[0])
373 lvName =
DumpLogVol(lv, extraName, newSolid, newMate);
411 "Unknown axis of replication for volume" + pv->
GetName();
412 G4Exception(
"G4tgbGeometryDumper::DumpPVReplica",
"Wrong axis ",
419 if(!CheckIfPhysVolExists(fullname, pv))
421 (*theFile) <<
":REPL " << SubstituteRefl(AddQuotes(lvName)) <<
" "
423 <<
" " << axisName <<
" " << nReplicas;
426 (*theFile) <<
" " << width <<
" " << offset <<
G4endl;
430 (*theFile) <<
" " << width / deg <<
"*deg"
431 <<
" " << offset / deg <<
"*deg" <<
G4endl;
434 thePhysVols[fullname] = pv;
448 lvName = GetObjectName(lv, theLogVols);
452 lvName = lv->
GetName() + extraName;
455 if(theLogVols.find(lvName) != theLogVols.cend())
476 (*theFile) <<
":VOLU " << SubstituteRefl(AddQuotes(lvName)) <<
" "
477 << SupressRefl(AddQuotes(solidName)) <<
" " << AddQuotes(mateName)
480 theLogVols[lvName] = lv;
488 G4String mateName = GetObjectName(mat, theMaterials);
489 if(theMaterials.find(mateName) != theMaterials.cend())
501 (*theFile) <<
":MATE " << AddQuotes(mateName) <<
" " << mat->
GetZ() <<
" "
502 << mat->
GetA() / (g / mole) <<
" " << density <<
G4endl;
508 for(std::size_t ii = 0; ii < numElements; ++ii)
513 (*theFile) <<
":MIXT " << AddQuotes(mateName) <<
" " << density <<
" "
516 for(std::size_t ii = 0; ii < numElements; ++ii)
518 (*theFile) <<
" " << AddQuotes(GetObjectName(
const_cast<G4Element*
>((*elems)[ii]), theElements))
519 <<
" " << fractions[ii] <<
G4endl;
523 (*theFile) <<
":MATE_MEE " << AddQuotes(mateName) <<
" "
527 (*theFile) <<
":MATE_TEMPERATURE " << AddQuotes(mateName) <<
" "
530 (*theFile) <<
":MATE_PRESSURE " << AddQuotes(mateName) <<
" "
538 stateStr =
"Undefined";
551 (*theFile) <<
":MATE_STATE " << AddQuotes(mateName) <<
" " << stateStr
554 theMaterials[mateName] = mat;
562 G4String elemName = GetObjectName(ele, theElements);
564 if(theElements.find(elemName) != theElements.cend())
573 if(symbol ==
"" || symbol ==
" ")
578 if(ele->GetNumberOfIsotopes() == 0)
580 (*theFile) <<
":ELEM " << AddQuotes(elemName) <<
" " << AddQuotes(symbol)
581 <<
" " << ele->GetZ() <<
" " << ele->GetA() / (g / mole) <<
" "
587 for(std::size_t ii = 0; ii < ele->GetNumberOfIsotopes(); ++ii)
592 (*theFile) <<
":ELEM_FROM_ISOT " << AddQuotes(elemName) <<
" "
593 << AddQuotes(symbol) <<
" " << ele->GetNumberOfIsotopes()
595 const G4double* fractions = ele->GetRelativeAbundanceVector();
596 for(std::size_t ii = 0; ii < ele->GetNumberOfIsotopes(); ++ii)
598 (*theFile) <<
" " << AddQuotes(GetObjectName((*isots)[ii], theIsotopes))
599 <<
" " << fractions[ii] <<
G4endl;
602 theElements[elemName] = ele;
608 G4String isotName = GetObjectName(isot, theIsotopes);
609 if(theIsotopes.find(isotName) != theIsotopes.cend())
614 (*theFile) <<
":ISOT " << AddQuotes(isotName) <<
" " << isot->
GetZ() <<
" "
615 << isot->
GetN() <<
" " << isot->
GetA() / (g / mole) <<
" "
618 theIsotopes[isotName] = isot;
628 solidName = GetObjectName(solid, theSolids);
632 solidName = solid->
GetName() + extraName;
635 if(theSolids.find(solidName) != theSolids.cend())
641 solidType = GetTGSolidType(solidType);
643 if(solidType ==
"UNIONSOLID")
647 else if(solidType ==
"SUBTRACTIONSOLID")
651 else if(solidType ==
"INTERSECTIONSOLID")
655 else if(solidType ==
"REFLECTEDSOLID")
658 if(solidrefl ==
nullptr)
660 G4Exception(
"G4tgbGeometryDumper::DumpSolid()",
"InvalidType",
667 else if(solidType ==
"MULTIUNION")
671 else if(solidType ==
"SCALEDSOLID")
677 (*theFile) <<
":SOLID " << AddQuotes(solidName) <<
" ";
678 (*theFile) << AddQuotes(solidType) <<
" ";
680 theSolids[solidName] = solid;
702 if(solid1Disp !=
nullptr)
728 G4String bsoName = GetObjectName(so, theSolids);
729 if(theSolids.find(bsoName) != theSolids.cend())
731 G4String solid0Name = FindSolidName(solid0);
732 G4String solid1Name = FindSolidName(solid1);
734 (*theFile) <<
":SOLID " << AddQuotes(bsoName) <<
" " << AddQuotes(solidType)
735 <<
" " << AddQuotes(solid0Name) <<
" " << AddQuotes(solid1Name)
736 <<
" " << AddQuotes(rotName) <<
" " << approxTo0(pos.x()) <<
" "
737 << approxTo0(pos.y()) <<
" " << approxTo0(pos.z()) <<
" "
740 theSolids[bsoName] = bso;
750 std::vector<G4String> rotList;
751 for(
G4int iso = 0; iso < nSolids; iso++ ) {
754 rotList.push_back(rotName);
759 (*theFile) <<
":SOLID " << AddQuotes(bsoName) <<
" MULTIUNION "
762 for(
G4int iso = 0; iso < nSolids; iso++ ) {
766 (*theFile) <<
" " << solN->
GetName()
767 <<
" " <<
" " << rotList[iso]
768 <<
" " << approxTo0(pos.x())
769 <<
" " << approxTo0(pos.y())
770 <<
" " << approxTo0(pos.z());
786 (*theFile) <<
":SOLID " << AddQuotes(bsoName) <<
" SCALED "
787 << unscaledSolid->
GetName() <<
" "
788 << scaleTransf.
xx() <<
" "
789 << scaleTransf.
yy() <<
" "
798 for(std::size_t ii = 0; ii < params.size(); ++ii)
800 (*theFile) << params[ii] <<
" ";
808 std::vector<G4double> params;
811 solidType = GetTGSolidType(solidType);
813 if(solidType ==
"BOX")
815 const G4Box* sb =
dynamic_cast<const G4Box*
>(so);
823 else if(solidType ==
"TUBS")
835 else if(solidType ==
"TRAP")
842 params.push_back(symAxis.
theta() / deg);
843 params.push_back(symAxis.
phi() / deg);
854 else if(solidType ==
"TRD")
856 const G4Trd* tr =
dynamic_cast<const G4Trd*
>(so);
866 else if(solidType ==
"PARA")
875 params.push_back(std::atan(para->
GetTanAlpha()) / deg);
876 params.push_back(symAxis.
theta() / deg);
877 params.push_back(symAxis.
phi() / deg);
880 else if(solidType ==
"CONS")
894 else if(solidType ==
"SPHERE")
897 if(sphere !=
nullptr)
907 else if(solidType ==
"ORB")
909 const G4Orb* orb =
dynamic_cast<const G4Orb*
>(so);
915 else if(solidType ==
"TORUS")
920 params.push_back(torus->
GetRmin());
921 params.push_back(torus->
GetRmax());
922 params.push_back(torus->
GetRtor());
923 params.push_back(torus->
GetSPhi() / deg);
924 params.push_back(torus->
GetDPhi() / deg);
927 else if(solidType ==
"POLYCONE")
935 if(angphi > 180 * deg)
940 if(endphi > 180 * deg)
944 params.push_back(angphi);
945 params.push_back(endphi - angphi);
948 params.push_back(ncor);
950 for(
G4int ii = 0; ii < ncor; ++ii)
957 else if(solidType ==
"GENERICPOLYCONE")
964 if(angphi > 180 * deg)
969 if(endphi > 180 * deg)
973 params.push_back(angphi);
974 params.push_back(endphi - angphi);
976 params.push_back(ncor);
978 for(
G4int ii = 0; ii < ncor; ++ii)
985 else if(solidType ==
"POLYHEDRA")
993 if(angphi > 180 * deg)
998 params.push_back(angphi);
1001 params.push_back(ncor);
1003 for(
G4int ii = 0; ii < ncor; ++ii)
1010 else if(solidType ==
"ELLIPTICALTUBE")
1015 params.push_back(eltu->
GetDx());
1016 params.push_back(eltu->
GetDy());
1017 params.push_back(eltu->
GetDz());
1020 else if(solidType ==
"ELLIPSOID")
1032 else if(solidType ==
"ELLIPTICAL_CONE")
1039 params.push_back(elco->
GetZMax());
1043 else if(solidType ==
"HYPE")
1056 else if(solidType ==
"TWISTEDBOX")
1067 else if(solidType ==
"TWISTEDTRAP")
1070 if(ttrap !=
nullptr)
1085 else if(solidType ==
"TWISTEDTRD")
1098 else if(solidType ==
"TWISTEDTUBS")
1106 params.push_back(ttub->
GetDPhi() / deg);
1112 G4String ErrMessage =
"Solid type not supported, sorry... " + solidType;
1113 G4Exception(
"G4tgbGeometryDumper::DumpSolidParams()",
"NotImplemented",
1128 G4double de = MatDeterminant(rotm);
1129 G4String rotName = LookForExistingRotation(rotm);
1138 (*theFile) <<
":ROTM ";
1142 (*theFile) << AddQuotes(rotName) << std::setprecision(9) <<
" "
1143 << approxTo0(rotm->
xx()) <<
" " << approxTo0(rotm->
yx()) <<
" "
1144 << approxTo0(rotm->
zx()) <<
" " << approxTo0(rotm->
xy()) <<
" "
1145 << approxTo0(rotm->
yy()) <<
" " << approxTo0(rotm->
zy()) <<
" "
1146 << approxTo0(rotm->
xz()) <<
" " << approxTo0(rotm->
yz()) <<
" "
1147 << approxTo0(rotm->
zz()) <<
G4endl;
1151 (*theFile) <<
":ROTM ";
1155 (*theFile) << AddQuotes(rotName) <<
" " << approxTo0(rotm->
thetaX() / deg)
1156 <<
" " << approxTo0(rotm->
phiX() / deg) <<
" "
1157 << approxTo0(rotm->
thetaY() / deg) <<
" "
1158 << approxTo0(rotm->
phiY() / deg) <<
" "
1159 << approxTo0(rotm->
thetaZ() / deg) <<
" "
1163 theRotMats[rotName] = rotm;
1169std::vector<G4VPhysicalVolume*>
1173 std::vector<G4VPhysicalVolume*> children;
1174 for(
auto ite = pvstore->cbegin(); ite != pvstore->cend(); ++ite)
1176 if((*ite)->GetMotherLogical() == lv)
1178 children.push_back(*ite);
1182 G4cout <<
" G4tgbGeometryDumper::GetPVChildren() - adding children: "
1195 G4String newsolidType = solidType.substr(2, solidType.length());
1196 for(
G4int ii = 0; ii < (
G4int)newsolidType.length(); ++ii)
1198 newsolidType[ii] = (char)std::toupper(newsolidType[ii]);
1200 return newsolidType;
1218 if(std::fabs(val) < precision)
1231 std::size_t siz = str.length();
1232 for(std::size_t ii = 0; ii < siz; ++ii)
1234 if(str.substr(ii, 1) ==
" ")
1251 std::size_t irefl =
name.rfind(
"_refl");
1252 if(irefl != G4String::npos)
1262 std::size_t irefl =
name.rfind(
"_refl");
1263 if(irefl != G4String::npos)
1265 name =
name.substr(0, irefl) +
"_REFL";
1277 std::map<G4String, G4Isotope*>::const_iterator ite;
1278 for(ite = theIsotopes.cbegin(); ite != theIsotopes.cend(); ++ite)
1280 if(isot == (*ite).second)
1282 return (*ite).first;
1289 ite = theIsotopes.find(isotName);
1290 if(ite != theIsotopes.cend())
1295 if(!Same2G4Isotopes(isot, isotold))
1303 std::map<G4String, G4Isotope*>::const_iterator ite2 =
1304 theIsotopes.find(newIsotName);
1305 if(ite2 == theIsotopes.cend())
1307 isotName = newIsotName;
1312 if(Same2G4Isotopes(isot, (*ite2).second))
1314 isotName = newIsotName;
1327G4String G4tgbGeometryDumper::GetObjectName(
1328 TYP* obj, std::map<G4String, TYP*> objectsDumped)
1335 typename std::map<G4String, TYP*>::const_iterator ite;
1336 for(ite = objectsDumped.cbegin(); ite != objectsDumped.cend(); ++ite)
1338 if(obj == (*ite).second)
1340 return (*ite).first;
1347 ite = objectsDumped.find(objName);
1349 if(ite != objectsDumped.cend())
1351 TYP* objold = (*ite).second;
1358 typename std::map<G4String, TYP*>::const_iterator ite2 =
1359 objectsDumped.find(newObjName);
1360 if(ite2 == objectsDumped.cend())
1362 objName = newObjName;
1372G4bool G4tgbGeometryDumper::CheckIfLogVolExists(
const G4String& name,
1375 if(theLogVols.find(name) != theLogVols.cend())
1401G4bool G4tgbGeometryDumper::CheckIfPhysVolExists(
const G4String& name,
1407 G4cout <<
" G4tgbGeometryDumper::CheckIfPhysVolExists() - " <<
name
1411 if(thePhysVols.find(name) != thePhysVols.cend())
1413 if((*(thePhysVols.find(name))).second != pt)
1419 G4cerr <<
" G4tgbGeometryDumper::CheckIfPhysVolExists () -"
1420 <<
" Placement found but not same as before : " <<
name <<
G4endl;
1436 for(
auto ite = theRotMats.cbegin(); ite != theRotMats.cend(); ++ite)
1438 if((*ite).second->isNear(*rotm))
1440 rmName = (*ite).first;
1464 std::map<G4String, G4VSolid*>::const_iterator ite;
1465 for(ite = theSolids.cbegin(); ite != theSolids.cend(); ++ite)
1467 if(solid == (*ite).second)
1469 return (*ite).first;
1473 if(ite == theSolids.cend())
1475 G4Exception(
"G4tgbGeometryDumper::FindSolidName()",
"ReadError",
1478 return (*ite).first;
std::vector< const G4Element * > G4ElementVector
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4Isotope * > G4IsotopeVector
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
HepRotation inverse() const
virtual const G4VSolid * GetConstituentSolid(G4int no) const
G4double GetYHalfLength() const
G4double GetZHalfLength() const
G4double GetXHalfLength() const
G4double GetOuterRadiusPlusZ() const
G4double GetStartPhiAngle() const
G4double GetDeltaPhiAngle() const
G4double GetInnerRadiusMinusZ() const
G4double GetInnerRadiusPlusZ() const
G4double GetOuterRadiusMinusZ() const
G4double GetZHalfLength() const
G4VSolid * GetConstituentMovedSolid() const
G4AffineTransform GetTransform() const
G4ThreeVector GetObjectTranslation() const
G4double GetSemiAxisMax(G4int i) const
G4double GetZTopCut() const
G4double GetZBottomCut() const
G4double GetSemiAxisX() const
G4double GetSemiAxisY() const
G4double GetZTopCut() const
G4double GetStartPhi() const
G4double GetEndPhi() const
G4int GetNumRZCorner() const
G4PolyconeSideRZ GetCorner(G4int index) const
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4double GetInnerStereo() const
G4double GetZHalfLength() const
G4double GetOuterStereo() const
G4double GetOuterRadius() const
G4double GetInnerRadius() const
G4double GetMeanExcitationEnergy() const
const G4String & GetName() const
G4VSolid * GetSolid() const
G4Material * GetMaterial() const
const G4String & GetName() const
G4double GetPressure() const
G4double GetDensity() const
const G4ElementVector * GetElementVector() const
G4double GetTemperature() const
const G4double * GetFractionVector() const
G4IonisParamMat * GetIonisation() const
size_t GetNumberOfElements() const
const G4Transform3D & GetTransformation(G4int index) const
G4int GetNumberOfSolids() const
G4VSolid * GetSolid(G4int index) const
G4double GetRadius() const
void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const
G4VPVParameterisation * GetParameterisation() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const
G4double GetTanAlpha() const
G4ThreeVector GetSymAxis() const
G4double GetYHalfLength() const
G4double GetZHalfLength() const
G4double GetXHalfLength() const
static G4PhysicalVolumeStore * GetInstance()
G4double GetEndPhi() const
G4double GetStartPhi() const
G4int GetNumRZCorner() const
G4PolyconeSideRZ GetCorner(G4int index) const
G4int GetNumRZCorner() const
G4PolyhedraHistorical * GetOriginalParameters() const
G4PolyhedraSideRZ GetCorner(const G4int index) const
G4double GetStartPhi() const
G4VSolid * GetConstituentMovedSolid() const
G4bool IsReflected(G4LogicalVolume *lv) const
static G4ReflectionFactory * Instance()
G4VSolid * GetUnscaledSolid() const
G4Scale3D GetScaleTransform() const
G4double GetStartPhiAngle() const
G4double GetDeltaPhiAngle() const
G4double GetInnerRadius() const
G4double GetOuterRadius() const
G4double GetDeltaThetaAngle() const
G4double GetStartThetaAngle() const
G4double GetYHalfLength1() const
G4double GetTanAlpha2() const
G4double GetXHalfLength2() const
G4ThreeVector GetSymAxis() const
G4double GetXHalfLength4() const
G4double GetZHalfLength() const
G4double GetYHalfLength2() const
G4double GetTanAlpha1() const
G4double GetXHalfLength3() const
G4double GetXHalfLength1() const
G4double GetXHalfLength2() const
G4double GetYHalfLength2() const
G4double GetXHalfLength1() const
G4double GetYHalfLength1() const
G4double GetZHalfLength() const
G4double GetZHalfLength() const
G4double GetInnerRadius() const
G4double GetOuterRadius() const
G4double GetStartPhiAngle() const
G4double GetDeltaPhiAngle() const
G4double GetPhiTwist() const
G4double GetXHalfLength() const
G4double GetZHalfLength() const
G4double GetYHalfLength() const
G4double GetPolarAngleTheta() const
G4double GetAzimuthalAnglePhi() const
G4double GetTiltAngleAlpha() const
G4double GetZHalfLength() const
G4double GetX1HalfLength() const
G4double GetX2HalfLength() const
G4double GetX3HalfLength() const
G4double GetX4HalfLength() const
G4double GetY2HalfLength() const
G4double GetPhiTwist() const
G4double GetY1HalfLength() const
G4double GetX2HalfLength() const
G4double GetY2HalfLength() const
G4double GetY1HalfLength() const
G4double GetZHalfLength() const
G4double GetPhiTwist() const
G4double GetX1HalfLength() const
G4double GetOuterRadius() const
G4double GetZHalfLength() const
G4double GetPhiTwist() const
G4double GetInnerRadius() const
static G4String ConvertToString(G4bool boolVal)
virtual G4VSolid * ComputeSolid(const G4int, G4VPhysicalVolume *)
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=nullptr)
virtual void ComputeTransformation(const G4int, G4VPhysicalVolume *) const =0
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4LogicalVolume * GetMotherLogical() const
virtual G4bool IsReplicated() const =0
const G4RotationMatrix * GetRotation() const
const G4ThreeVector GetTranslation() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
virtual G4bool IsParameterised() const =0
virtual G4GeometryType GetEntityType() const =0
static G4tgbGeometryDumper * GetInstance()
void DumpIsotope(G4Isotope *ele)
void DumpScaledVolume(G4VSolid *so)
void DumpGeometry(const G4String &fname)
G4String DumpLogVol(G4LogicalVolume *lv, const G4String &extraName="", G4VSolid *solid=nullptr, G4Material *mate=nullptr)
void DumpPhysVol(G4VPhysicalVolume *pv)
G4String DumpRotationMatrix(G4RotationMatrix *rotm)
void DumpBooleanVolume(const G4String &solidType, G4VSolid *so)
G4String DumpMaterial(G4Material *mat)
void DumpPVReplica(G4PVReplica *pv, const G4String &lvName)
void DumpPVParameterised(G4PVParameterised *pv)
void DumpMultiUnionVolume(G4VSolid *so)
G4VPhysicalVolume * GetTopPhysVol()
G4String DumpSolid(G4VSolid *solid, const G4String &extraName="")
void DumpElement(G4Element *ele)
void DumpSolidParams(G4VSolid *so)
void DumpPVPlacement(G4VPhysicalVolume *pv, const G4String &lvName, G4int copyNo=-999)
std::vector< G4double > GetSolidParams(const G4VSolid *so)
static G4int GetVerboseLevel()
const char * name(G4int ptype)