// $Id$
// Category: geometry
//
+// Author: I. Hrivnacova, 27.07.2000
+//
+// Class TG4XMLConvertor
+// ---------------------
// See the class description in the header file.
#include "TG4XMLConvertor.h"
#include <G4PVReplica.hh>
#include <G4Material.hh>
#include <G4VSolid.hh>
+#include <G4ReflectedSolid.hh>
#include <G4Box.hh>
#include <G4Tubs.hh>
#include <G4Cons.hh>
#include <G4Trd.hh>
#include <G4Trap.hh>
+#include <G4Para.hh>
#include <G4Polycone.hh>
#include <G4Polyhedra.hh>
const G4int TG4XMLConvertor::fgkMaxVolumeNameLength = 10;
const G4int TG4XMLConvertor::fgkMaxMaterialNameLength = 20;
+const G4int TG4XMLConvertor::fgkDefaultNumWidth = 7;
+const G4int TG4XMLConvertor::fgkDefaultNumPrecision = 4;
+//_____________________________________________________________________________
TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile)
: fOutFile(outFile),
fkBasicIndention(" "),
+ fNW(fgkDefaultNumWidth),
+ fNP(fgkDefaultNumPrecision),
fIndention(fkBasicIndention),
fRotationCounter(0)
{
-//
+ fOutFile.width(fgkDefaultNumWidth);
+ fOutFile.precision(fgkDefaultNumPrecision);
}
+//_____________________________________________________________________________
TG4XMLConvertor::~TG4XMLConvertor() {
//
}
// private methods
+//_____________________________________________________________________________
void TG4XMLConvertor::CutName(G4String& name) const
{
// Removes spaces after the name if present.
while (name(--i) == ' ') name = name(0,i);
}
+//_____________________________________________________________________________
void TG4XMLConvertor::CutName(G4String& name, G4int size) const
{
// Cuts name to given size.
if (name.length() > size) name = name(0, size);
}
+//_____________________________________________________________________________
void TG4XMLConvertor::PutName(G4String& element, G4String name,
G4String templ) const
{
while (element.contains(templ)) element.replace(element.find(templ), 1 , " ");
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << x << " "
- << G4std::setw(7) << G4std::setprecision(2) << y << " "
- << G4std::setw(7) << G4std::setprecision(2) << z
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << y << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << z
<< element4 << G4endl << G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
- << G4std::setw(7) << G4std::setprecision(2) << sphi+dphi
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
<< quota << G4endl
<< indention << element4
- << G4std::setw(7) << G4std::setprecision(2) << rmin << " "
- << G4std::setw(7) << G4std::setprecision(2) << rmax << " "
- << G4std::setw(7) << G4std::setprecision(2) << hz
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
<< element5 << G4endl << G4endl;
}
-
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
- << G4std::setw(7) << G4std::setprecision(2) << sphi+dphi
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
<< quota << G4endl
<< indention << element4
- << G4std::setw(7) << G4std::setprecision(2) << rmin1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << rmax1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << rmin2 << " "
- << G4std::setw(7) << G4std::setprecision(2) << rmax2 << " "
- << G4std::setw(7) << G4std::setprecision(2) << hz
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin2 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax2 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
<< element5 << G4endl << G4endl;
}
-
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << x1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << x2 << " "
- << G4std::setw(7) << G4std::setprecision(2) << y1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << y2 << " "
- << G4std::setw(7) << G4std::setprecision(2) << hz
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
<< element4 << G4endl << G4endl;
}
-
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << x2 << " "
- << G4std::setw(7) << G4std::setprecision(2) << x1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << x4 << " "
- << G4std::setw(7) << G4std::setprecision(2) << x3 << " "
- << G4std::setw(7) << G4std::setprecision(2) << y2 << " "
- << G4std::setw(7) << G4std::setprecision(2) << y1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << dz
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x4 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << x3 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
<< quota << G4endl
<< indention << element4
- << G4std::setw(7) << G4std::setprecision(2) << inc1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << inc2
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << inc1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << inc2
<< quota << G4endl
<< indention << element5
- << G4std::setw(7) << G4std::setprecision(2) << alpha1 << " "
- << G4std::setw(7) << G4std::setprecision(2) << alpha2
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha1 << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha2
<< element6 << G4endl << G4endl;
}
+//_____________________________________________________________________________
+void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para,
+ G4String materialName)
+{
+// Writes G4Para solid.
+// ---
+
+ // get parameters
+ G4double dx = para->GetXHalfLength()/TG4G3Units::Length()*2.;
+ G4double dy = para->GetYHalfLength()/TG4G3Units::Length()*2.;
+ G4double dz = para->GetZHalfLength()/TG4G3Units::Length()*2.;
+ G4double tanAlpha = para->GetTanAlpha();
+ G4ThreeVector symAxis = para->GetSymAxis();
+
+ G4double alpha = atan(tanAlpha) / deg;
+ G4double theta = acos(symAxis.z()) / deg;
+ G4double phi;
+ if (theta == 0.)
+ phi = 0;
+ else
+ phi = atan(symAxis.y()/symAxis.x()) / deg;
+
+ // compose element string template
+ G4String quota = "\"";
+ G4String element1 = "<para name=\"" + lvName + quota;
+ G4String element2 = "material=\"" + materialName + quota;
+ G4String element3 = "X_Y_Z=\"";
+ G4String element4 = "alpha=\"";
+ G4String element5 = "theta=\"";
+ G4String element6 = "phi= \"";
+ G4String element7 = "\" />";
+ G4String indention = fkBasicIndention + fkBasicIndention;
+
+ // write element
+ fOutFile << fkBasicIndention << element1 << G4endl
+ << indention << element2 << G4endl
+ << indention << element3
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << dx << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << dy << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
+ << quota << G4endl
+ << indention << element4
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha
+ << quota << G4endl
+ << indention << element5
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << theta
+ << quota << G4endl
+ << indention << element6
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << phi
+ << element7 << G4endl << G4endl;
+}
+
+//_____________________________________________________________________________
void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
- << G4std::setw(7) << G4std::setprecision(2) << ephi
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
<< element4 << G4endl;
// write polyplane elements
G4double z = zArray[i]/TG4G3Units::Length();
fOutFile << indention << element5
- << G4std::setw(7) << G4std::setprecision(2) << rmin << " "
- << G4std::setw(7) << G4std::setprecision(2) << rmax << " "
- << G4std::setw(7) << G4std::setprecision(2) << z
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << z
<< element6
<< G4endl;
}
<< element7 << G4endl << G4endl;
}
-
+//_____________________________________________________________________________
void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra,
G4String materialName)
{
fOutFile << fkBasicIndention << element1 << G4endl
<< indention << element2 << G4endl
<< indention << element3
- << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
- << G4std::setw(7) << G4std::setprecision(2) << ephi
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
+ << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
<< quota << G4endl
<< indention << element4
<< nofSides
// set units
G4double rmin = rminArray[i]/TG4G3Units::Length();
if (i>0) fOutFile << " ";
- fOutFile << G4std::setw(7) << G4std::setprecision(2) << rmin;
+ fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin;
};
fOutFile << quota << G4endl;
// set units
G4double rmax = rmaxArray[i]/TG4G3Units::Length();
if (i>0) fOutFile << " ";
- fOutFile << G4std::setw(7) << G4std::setprecision(2) << rmax;
+ fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax;
};
fOutFile << quota << G4endl;
// set units
G4double z = zArray[i]/TG4G3Units::Length();
if (i>0) fOutFile << " ";
- fOutFile << G4std::setw(7) << G4std::setprecision(2) << z;
+ fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << z;
};
fOutFile << element8 << G4endl << G4endl;
}
// public methods
+//_____________________________________________________________________________
void TG4XMLConvertor::OpenMaterials(const G4String& version,
const G4String& date, const G4String& author,
const G4String dtdVersion)
<< element5 << G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version,
const G4String& date, const G4String& author,
const G4String& topVolume)
IncreaseIndention();
}
+//_____________________________________________________________________________
void TG4XMLConvertor::CloseMaterials()
{
// Writes materials closing.
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::CloseSection()
{
// Writes section closing.
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::CloseComposition()
{
// Writes composition closing.
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteMaterial(const G4Material* material)
{
// Writes G4Material.
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid,
G4String materialName)
{
// to be removed when materials are supported
materialName = "Hydrogen";
- const G4Box* box = dynamic_cast<const G4Box*>(solid);
+ const G4ReflectedSolid* reflSolid
+ = dynamic_cast<const G4ReflectedSolid*>(solid);
+
+ const G4VSolid* consSolid;
+ if (reflSolid)
+ consSolid = reflSolid->GetConstituentMovedSolid();
+ else
+ consSolid = solid;
+
+ const G4Box* box = dynamic_cast<const G4Box*>(consSolid);
if (box) {
WriteBox(lvName, box, materialName);
return;
}
- const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(solid);
+ const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(consSolid);
if (tubs) {
WriteTubs(lvName, tubs, materialName);
return;
}
- const G4Cons* cons = dynamic_cast<const G4Cons*>(solid);
+ const G4Cons* cons = dynamic_cast<const G4Cons*>(consSolid);
if (cons) {
WriteCons(lvName, cons, materialName);
return;
}
- const G4Trd* trd = dynamic_cast<const G4Trd*>(solid);
+ const G4Trd* trd = dynamic_cast<const G4Trd*>(consSolid);
if (trd) {
WriteTrd(lvName, trd, materialName);
return;
}
- const G4Trap* trap = dynamic_cast<const G4Trap*>(solid);
+ const G4Trap* trap = dynamic_cast<const G4Trap*>(consSolid);
if (trap) {
WriteTrap(lvName, trap, materialName);
return;
}
- const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(solid);
+ const G4Para* para = dynamic_cast<const G4Para*>(consSolid);
+ if (para) {
+ WritePara(lvName, para, materialName);
+ return;
+ }
+
+ const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(consSolid);
if (polycone) {
WritePolycone(lvName, polycone, materialName);
return;
}
- const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(solid);
+ const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(consSolid);
if (polyhedra) {
WritePolyhedra(lvName, polyhedra, materialName);
return;
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation)
{
// Writes G4RotationMatrix.
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position)
{
// Writes position without rotation with a given solid name.
// write element
fOutFile << fIndention
<< element1
- << G4std::setw(8) << G4std::setprecision(2) << x << " "
- << G4std::setw(8) << G4std::setprecision(2) << y << " "
- << G4std::setw(8) << G4std::setprecision(2) << z
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z
<< element2
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WritePositionWithRotation(
G4String lvName, G4ThreeVector position,
const G4RotationMatrix* rotation)
// write element
fOutFile << fIndention
<< element1
- << G4std::setw(8) << G4std::setprecision(2) << x << " "
- << G4std::setw(8) << G4std::setprecision(2) << y << " "
- << G4std::setw(8) << G4std::setprecision(2) << z << quota
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z << quota
<< fIndention
<< element2
<< G4std::setw(8) << G4std::setprecision(5) << xx << " "
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr)
{
// Writes position without rotation with a given solid name.
// write element
fOutFile << fIndention
<< element1
- << G4std::setw(8) << G4std::setprecision(2) << nReplicas
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << nReplicas
<< element2
- << G4std::setw(8) << G4std::setprecision(2) << value0
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << value0
<< element3
- << G4std::setw(8) << G4std::setprecision(2) << dValue
+ << G4std::setw(fNW+1) << G4std::setprecision(fNP) << dValue
<< element4
<< G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::WriteEmptyLine()
{
// Writes empty line.
fOutFile << G4endl;
}
+//_____________________________________________________________________________
void TG4XMLConvertor::IncreaseIndention()
{
// increase indention
fIndention.append(fkBasicIndention);
}
+//_____________________________________________________________________________
void TG4XMLConvertor::DecreaseIndention()
{
// decrease indention