4 // See the class description in the header file.
6 #include "TG4XMLConvertor.h"
7 #include "TG4Polycone.h"
8 #include "TG4Polyhedra.h"
9 #include "TG4G3Units.h"
11 #include <G4PVReplica.hh>
12 #include <G4Material.hh>
13 #include <G4VSolid.hh>
20 #include <G4Polycone.hh>
21 #include <G4Polyhedra.hh>
23 #include <g4std/iostream>
24 #include <g4std/iomanip>
26 const G4int TG4XMLConvertor::fgkMaxVolumeNameLength = 10;
27 const G4int TG4XMLConvertor::fgkMaxMaterialNameLength = 20;
29 TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile)
31 fkBasicIndention(" "),
32 fIndention(fkBasicIndention),
38 TG4XMLConvertor::~TG4XMLConvertor() {
44 void TG4XMLConvertor::CutName(G4String& name) const
46 // Removes spaces after the name if present.
49 G4int i = name.length();
50 while (name(--i) == ' ') name = name(0,i);
53 void TG4XMLConvertor::CutName(G4String& name, G4int size) const
55 // Cuts name to given size.
58 if (name.length() > size) name = name(0, size);
61 void TG4XMLConvertor::PutName(G4String& element, G4String name,
64 // Replaces given template in string element with a give name.
70 CutName(name, fgkMaxVolumeNameLength);
71 else if (templ == "!")
72 CutName(name, fgkMaxMaterialNameLength);
74 element.replace(element.find(templ), name.size(), name);
75 element.replace(element.find(templ), 1, "\"");
76 while (element.contains(templ)) element.replace(element.find(templ), 1 , " ");
79 void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box,
80 G4String materialName)
82 // Writes G4box solid.
86 G4double x = box->GetXHalfLength()/TG4G3Units::Length()*2.;
87 G4double y = box->GetYHalfLength()/TG4G3Units::Length()*2.;
88 G4double z = box->GetZHalfLength()/TG4G3Units::Length()*2.;
90 // compose element string template
91 G4String quota = "\"";
92 G4String element1 = "<box name=\"" + lvName + quota;
93 G4String element2 = "material=\"" + materialName + quota;
94 G4String element3 = "X_Y_Z=\"";
95 G4String element4 = "\" />";
96 G4String indention = fkBasicIndention + fkBasicIndention;
99 fOutFile << fkBasicIndention << element1 << G4endl
100 << indention << element2 << G4endl
101 << indention << element3
102 << G4std::setw(7) << G4std::setprecision(2) << x << " "
103 << G4std::setw(7) << G4std::setprecision(2) << y << " "
104 << G4std::setw(7) << G4std::setprecision(2) << z
105 << element4 << G4endl << G4endl;
108 void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs,
109 G4String materialName)
111 // Writes G4tubs solid.
115 G4double rmin = tubs->GetInnerRadius()/TG4G3Units::Length();
116 G4double rmax = tubs->GetOuterRadius()/TG4G3Units::Length();
117 G4double hz = tubs->GetZHalfLength()/TG4G3Units::Length()*2.;
118 G4double sphi = tubs->GetStartPhiAngle()/TG4G3Units::Angle();
119 G4double dphi = tubs->GetDeltaPhiAngle()/TG4G3Units::Angle();
121 // compose element string template
122 G4String quota = "\"";
123 G4String element1 = "<tubs name=\"" + lvName + quota;
124 G4String element2 = "material=\"" + materialName + quota;
125 G4String element3 = "profile=\"";
126 G4String element4 = "Rio_Z =\"";
127 G4String element5 = "\" />";
128 G4String indention = fkBasicIndention + fkBasicIndention;
131 fOutFile << fkBasicIndention << element1 << G4endl
132 << indention << element2 << G4endl
133 << indention << element3
134 << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
135 << G4std::setw(7) << G4std::setprecision(2) << sphi+dphi
137 << indention << element4
138 << G4std::setw(7) << G4std::setprecision(2) << rmin << " "
139 << G4std::setw(7) << G4std::setprecision(2) << rmax << " "
140 << G4std::setw(7) << G4std::setprecision(2) << hz
141 << element5 << G4endl << G4endl;
145 void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons,
146 G4String materialName)
148 // Writes G4cons solid.
152 G4double rmin1 = cons->GetInnerRadiusMinusZ()/TG4G3Units::Length();
153 G4double rmax1 = cons->GetOuterRadiusMinusZ()/TG4G3Units::Length();
154 G4double rmin2 = cons->GetInnerRadiusPlusZ()/TG4G3Units::Length();
155 G4double rmax2 = cons->GetOuterRadiusPlusZ()/TG4G3Units::Length();
156 G4double hz = cons->GetZHalfLength()/TG4G3Units::Length()*2.;
157 G4double sphi = cons->GetStartPhiAngle()/TG4G3Units::Angle();
158 G4double dphi = cons->GetDeltaPhiAngle()/TG4G3Units::Angle();
160 // compose element string template
161 G4String quota = "\"";
162 G4String element1 = "<cons name=\"" + lvName + quota;
163 G4String element2 = "material=\"" + materialName + quota;
164 G4String element3 = "profile=\"";
165 G4String element4 = "Rio1_Rio2_Z =\"";
166 G4String element5 = "\" />";
167 G4String indention = fkBasicIndention + fkBasicIndention;
170 fOutFile << fkBasicIndention << element1 << G4endl
171 << indention << element2 << G4endl
172 << indention << element3
173 << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
174 << G4std::setw(7) << G4std::setprecision(2) << sphi+dphi
176 << indention << element4
177 << G4std::setw(7) << G4std::setprecision(2) << rmin1 << " "
178 << G4std::setw(7) << G4std::setprecision(2) << rmax1 << " "
179 << G4std::setw(7) << G4std::setprecision(2) << rmin2 << " "
180 << G4std::setw(7) << G4std::setprecision(2) << rmax2 << " "
181 << G4std::setw(7) << G4std::setprecision(2) << hz
182 << element5 << G4endl << G4endl;
186 void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd,
187 G4String materialName)
189 // Writes G4Trd solid.
193 G4double x1 = trd->GetXHalfLength1()/TG4G3Units::Length()*2;
194 G4double x2 = trd->GetXHalfLength2()/TG4G3Units::Length()*2;
195 G4double y1 = trd->GetYHalfLength1()/TG4G3Units::Length()*2;
196 G4double y2 = trd->GetYHalfLength2()/TG4G3Units::Length()*2;
197 G4double hz = trd->GetZHalfLength()/TG4G3Units::Length()*2;
199 // compose element string template
200 G4String quota = "\"";
201 G4String element1 = "<trd name=\"" + lvName + quota;
202 G4String element2 = "material=\"" + materialName + quota;
203 G4String element3 = "Xmp_Ymp_Z=\"";
204 G4String element4 = "\" />";
205 G4String indention = fkBasicIndention + fkBasicIndention;
208 fOutFile << fkBasicIndention << element1 << G4endl
209 << indention << element2 << G4endl
210 << indention << element3
211 << G4std::setw(7) << G4std::setprecision(2) << x1 << " "
212 << G4std::setw(7) << G4std::setprecision(2) << x2 << " "
213 << G4std::setw(7) << G4std::setprecision(2) << y1 << " "
214 << G4std::setw(7) << G4std::setprecision(2) << y2 << " "
215 << G4std::setw(7) << G4std::setprecision(2) << hz
216 << element4 << G4endl << G4endl;
220 void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap,
221 G4String materialName)
223 // Writes G4Trap solid.
227 G4double dz = trap->GetZHalfLength()/TG4G3Units::Length()*2.;
228 G4ThreeVector symAxis = trap->GetSymAxis();
229 G4double y1 = trap->GetYHalfLength1()/TG4G3Units::Length()*2.;
230 G4double x1 = trap->GetXHalfLength1()/TG4G3Units::Length()*2.;
231 G4double x2 = trap->GetXHalfLength2()/TG4G3Units::Length()*2.;
232 G4double tanAlpha1 = trap->GetTanAlpha1();
233 G4double y2 = trap->GetYHalfLength2()/TG4G3Units::Length()*2.;
234 G4double x3 = trap->GetXHalfLength3()/TG4G3Units::Length()*2.;
235 G4double x4 = trap->GetXHalfLength4()/TG4G3Units::Length()*2.;
236 G4double tanAlpha2 = trap->GetTanAlpha2();
238 // ordering of parameters in XML element
239 // Xmumdpupd_Ymp_Z: 2x2 2x1 2x4 2x3 2y2 2y1 2dz
240 // inclination: atan(symAxis.x/symAxis.z), atan(symAxis.y/symAxis.z)
241 // declination: alpha1, alpha2
244 G4double inc1 = atan(symAxis.x()/symAxis.z()) / deg;
245 G4double inc2 = atan(symAxis.y()/symAxis.z()) / deg;
246 G4double alpha1 = atan(tanAlpha1) / deg;
247 G4double alpha2 = atan(tanAlpha2) / deg;
249 // compose element string template
250 G4String quota = "\"";
251 G4String element1 = "<trap name=\"" + lvName + quota;
252 G4String element2 = "material=\"" + materialName + quota;
253 G4String element3 = "Xmumdpupd_Ymp_Z=\"";
254 G4String element4 = "inclination=\"";
255 G4String element5 = "declination=\"";
256 G4String element6 = "\" />";
257 G4String indention = fkBasicIndention + fkBasicIndention;
260 fOutFile << fkBasicIndention << element1 << G4endl
261 << indention << element2 << G4endl
262 << indention << element3
263 << G4std::setw(7) << G4std::setprecision(2) << x2 << " "
264 << G4std::setw(7) << G4std::setprecision(2) << x1 << " "
265 << G4std::setw(7) << G4std::setprecision(2) << x4 << " "
266 << G4std::setw(7) << G4std::setprecision(2) << x3 << " "
267 << G4std::setw(7) << G4std::setprecision(2) << y2 << " "
268 << G4std::setw(7) << G4std::setprecision(2) << y1 << " "
269 << G4std::setw(7) << G4std::setprecision(2) << dz
271 << indention << element4
272 << G4std::setw(7) << G4std::setprecision(2) << inc1 << " "
273 << G4std::setw(7) << G4std::setprecision(2) << inc2
275 << indention << element5
276 << G4std::setw(7) << G4std::setprecision(2) << alpha1 << " "
277 << G4std::setw(7) << G4std::setprecision(2) << alpha2
278 << element6 << G4endl << G4endl;
281 void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para,
282 G4String materialName)
284 // Writes G4Para solid.
288 G4double dx = para->GetXHalfLength()/TG4G3Units::Length()*2.;
289 G4double dy = para->GetYHalfLength()/TG4G3Units::Length()*2.;
290 G4double dz = para->GetZHalfLength()/TG4G3Units::Length()*2.;
291 G4double tanAlpha = para->GetTanAlpha();
292 G4ThreeVector symAxis = para->GetSymAxis();
294 G4double alpha = atan(tanAlpha) / deg;
295 G4double theta = acos(symAxis.z()) / deg;
300 phi = atan(symAxis.y()/symAxis.x()) / deg;
302 // compose element string template
303 G4String quota = "\"";
304 G4String element1 = "<para name=\"" + lvName + quota;
305 G4String element2 = "material=\"" + materialName + quota;
306 G4String element3 = "X_Y_Z=\"";
307 G4String element4 = "alpha=\"";
308 G4String element5 = "theta=\"";
309 G4String element6 = "phi= \"";
310 G4String element7 = "\" />";
311 G4String indention = fkBasicIndention + fkBasicIndention;
314 fOutFile << fkBasicIndention << element1 << G4endl
315 << indention << element2 << G4endl
316 << indention << element3
317 << G4std::setw(7) << G4std::setprecision(2) << dx << " "
318 << G4std::setw(7) << G4std::setprecision(2) << dy << " "
319 << G4std::setw(7) << G4std::setprecision(2) << dz
321 << indention << element4
322 << G4std::setw(7) << G4std::setprecision(2) << alpha
324 << indention << element5
325 << G4std::setw(7) << G4std::setprecision(2) << theta
327 << indention << element6
328 << G4std::setw(7) << G4std::setprecision(2) << phi
329 << element7 << G4endl << G4endl;
332 void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone,
333 G4String materialName)
335 // Writes G4Polycone solid.
338 // get profile parameters
339 G4double sphi = polycone->GetStartPhi()/TG4G3Units::Angle();
340 G4double ephi = polycone->GetEndPhi()/TG4G3Units::Angle();
342 // get polycone Z planes parameters
343 TG4Polycone historicalPolycone = TG4Polycone(*polycone);
345 G4int nofZPlanes = historicalPolycone.GetNofZPlanes();
346 G4double* rminArray = historicalPolycone.GetRmin();
347 G4double* rmaxArray = historicalPolycone.GetRmax();
348 G4double* zArray = historicalPolycone.GetZ();
350 // compose element string template
351 G4String quota = "\"";
352 G4String element1 = "<pcon name=\"" + lvName + quota;
353 G4String element2 = "material=\"" + materialName + quota;
354 G4String element3 = "profile=\"";
355 G4String element4 = "\" >";
356 G4String element5 = "<polyplane Rio_Z=\"";
357 G4String element6 = "\" />";
358 G4String element7 = "</pcon>";
359 G4String indention = fkBasicIndention + fkBasicIndention;
361 // write pcon element
362 fOutFile << fkBasicIndention << element1 << G4endl
363 << indention << element2 << G4endl
364 << indention << element3
365 << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
366 << G4std::setw(7) << G4std::setprecision(2) << ephi
367 << element4 << G4endl;
369 // write polyplane elements
370 for (G4int i=0; i<nofZPlanes; i++) {
373 G4double rmin = rminArray[i]/TG4G3Units::Length();
374 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
375 G4double z = zArray[i]/TG4G3Units::Length();
377 fOutFile << indention << element5
378 << G4std::setw(7) << G4std::setprecision(2) << rmin << " "
379 << G4std::setw(7) << G4std::setprecision(2) << rmax << " "
380 << G4std::setw(7) << G4std::setprecision(2) << z
385 // close pcon element
386 fOutFile << fkBasicIndention
387 << element7 << G4endl << G4endl;
391 void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra,
392 G4String materialName)
394 // Writes G4Polycone solid.
398 G4int nofSides = polyhedra->GetNumSide();
399 G4double sphi = polyhedra->GetStartPhi()/TG4G3Units::Angle();
400 G4double ephi = polyhedra->GetEndPhi()/TG4G3Units::Angle();
402 // get polyhedra Z planes parameters
403 TG4Polyhedra historicalPolyhedra = TG4Polyhedra(*polyhedra);
405 G4int nofZPlanes = historicalPolyhedra.GetNofZPlanes();
406 G4double* rminArray = historicalPolyhedra.GetRmin();
407 G4double* rmaxArray = historicalPolyhedra.GetRmax();
408 G4double* zArray = historicalPolyhedra.GetZ();
410 // compose element string template
411 G4String quota = "\"";
412 G4String element1 = "<phedra name=\"" + lvName + quota;
413 G4String element2 = "material=\"" + materialName + quota;
414 G4String element3 = "profile=\"";
415 G4String element4 = "sides =\"";
416 G4String element5 = "Ris=\"";
417 G4String element6 = "Ros=\"";
418 G4String element7 = "Zs =\"";
419 G4String element8 = "\" />";
420 G4String indention = fkBasicIndention + fkBasicIndention;
423 fOutFile << fkBasicIndention << element1 << G4endl
424 << indention << element2 << G4endl
425 << indention << element3
426 << G4std::setw(7) << G4std::setprecision(2) << sphi << " "
427 << G4std::setw(7) << G4std::setprecision(2) << ephi
429 << indention << element4
433 fOutFile << indention << element5;
435 for (i=0; i<nofZPlanes; i++) {
437 G4double rmin = rminArray[i]/TG4G3Units::Length();
438 if (i>0) fOutFile << " ";
439 fOutFile << G4std::setw(7) << G4std::setprecision(2) << rmin;
441 fOutFile << quota << G4endl;
443 fOutFile << indention << element6;
444 for (i=0; i<nofZPlanes; i++) {
446 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
447 if (i>0) fOutFile << " ";
448 fOutFile << G4std::setw(7) << G4std::setprecision(2) << rmax;
450 fOutFile << quota << G4endl;
452 fOutFile << indention << element7;
453 for (i=0; i<nofZPlanes; i++) {
455 G4double z = zArray[i]/TG4G3Units::Length();
456 if (i>0) fOutFile << " ";
457 fOutFile << G4std::setw(7) << G4std::setprecision(2) << z;
459 fOutFile << element8 << G4endl << G4endl;
465 void TG4XMLConvertor::OpenMaterials(const G4String& version,
466 const G4String& date, const G4String& author,
467 const G4String dtdVersion)
469 // Writes section opening.
472 G4String element1 = "<materials version = \"";
473 G4String element2 = " date = \"";
474 G4String element3 = " author = \"";
475 G4String element4 = " DTD_version=\"";
476 G4String element5 = " >";
477 G4String quota = "\"";
480 fOutFile << element1 << version << quota << G4endl
481 << element2 << date << quota << G4endl
482 << element3 << author << quota << G4endl
483 << element4 << dtdVersion << quota
484 << element5 << G4endl;
487 void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version,
488 const G4String& date, const G4String& author,
489 const G4String& topVolume)
491 // Writes section opening.
494 G4String element1 = "<section name = \"";
495 G4String element2 = " version = \"";
496 G4String element3 = " date = \"";
497 G4String element4 = " author = \"";
498 G4String element5 = " topVolume = \"";
499 G4String element6 = " >";
500 G4String quota = "\"";
503 fOutFile << element1 << name << quota << G4endl
504 << element2 << version << quota << G4endl
505 << element3 << date << quota << G4endl
506 << element4 << author << quota << G4endl
507 << element5 << topVolume << quota
508 << element6 << G4endl;
511 void TG4XMLConvertor::OpenComposition(const G4String& name)
513 // Writes composition opening.
516 G4String element = "<composition name=\"";
517 element.append(name);
518 element.append("\">");
521 fOutFile << fIndention
525 // increase indention
529 void TG4XMLConvertor::CloseMaterials()
531 // Writes materials closing.
535 G4String element = "</materials>";
542 void TG4XMLConvertor::CloseSection()
544 // Writes section closing.
548 G4String element = "</section>";
555 void TG4XMLConvertor::CloseComposition()
557 // Writes composition closing.
560 // decrease indention
564 G4String element = "</composition>";
567 fOutFile << fIndention
572 void TG4XMLConvertor::WriteMaterial(const G4Material* material)
574 // Writes G4Material.
575 // Not yet implemented, only XML comment element is written.
578 G4String name = material->GetName();
582 G4String element1 = "<!-- material = \"";
583 G4String element2 = "\" -->";
586 fOutFile << fkBasicIndention
592 void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid,
593 G4String materialName)
595 // Finds G4Solid concrete type and calls writing function.
596 // For not yet implemented solids, only XML comment element is written.
599 // to be removed when materials are supported
600 materialName = "Hydrogen";
602 const G4Box* box = dynamic_cast<const G4Box*>(solid);
604 WriteBox(lvName, box, materialName);
608 const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(solid);
610 WriteTubs(lvName, tubs, materialName);
614 const G4Cons* cons = dynamic_cast<const G4Cons*>(solid);
616 WriteCons(lvName, cons, materialName);
620 const G4Trd* trd = dynamic_cast<const G4Trd*>(solid);
622 WriteTrd(lvName, trd, materialName);
626 const G4Trap* trap = dynamic_cast<const G4Trap*>(solid);
628 WriteTrap(lvName, trap, materialName);
632 const G4Para* para = dynamic_cast<const G4Para*>(solid);
634 WritePara(lvName, para, materialName);
638 const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(solid);
640 WritePolycone(lvName, polycone, materialName);
644 const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(solid);
646 WritePolyhedra(lvName, polyhedra, materialName);
650 // write comment line in case of unsupported
654 G4String element1 = "<!-- unsupported shape name= \"";
655 G4String element2 = "\" -->";
658 fOutFile << fkBasicIndention
659 << element1 << lvName
664 void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation)
666 // Writes G4RotationMatrix.
667 // Not yet implemented, only XML comment element is written.
670 // return if this rotation was already written
671 G4int nofRotations = fRotations.size();
673 for (G4int i=0; i<nofRotations; i++)
674 if (fRotations[i] == rotation) return;
676 fRotations.push_back(rotation);
680 G4double xx = rotation->xx();
681 G4double xy = rotation->xy();
682 G4double xz = rotation->xz();
683 G4double yx = rotation->yx();
684 G4double yy = rotation->yy();
685 G4double yz = rotation->yz();
686 G4double zx = rotation->zx();
687 G4double zy = rotation->zy();
688 G4double zz = rotation->zz();
690 TG4Globals::AppendNumberToString(id, ++fRotationCounter);
692 // compose element string template
693 G4String quota = "\"\n";
694 G4String element1 = "<rot_matrix id=\"####### XX_XY_XZ=\"";
695 G4String element2 = " YX_YY_YZ=\"";
696 G4String element3 = " ZX_ZY_ZZ=\"";
697 G4String element4 = "\" />";
700 PutName(element1, id, "#");
703 fOutFile << fkBasicIndention
705 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
706 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
707 << G4std::setw(8) << G4std::setprecision(5) << xz << quota
710 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
711 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
712 << G4std::setw(8) << G4std::setprecision(5) << yz << quota
715 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
716 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
717 << G4std::setw(8) << G4std::setprecision(5) << zz
722 void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position)
724 // Writes position without rotation with a given solid name.
728 G4double x = position.x()/TG4G3Units::Length();
729 G4double y = position.y()/TG4G3Units::Length();
730 G4double z = position.z()/TG4G3Units::Length();
732 // compose element string template
733 G4String element1 = "<posXYZ volume=\"########### X_Y_Z=\"";
734 G4String element2 = "\" />";
737 PutName(element1, lvName, "#");
740 fOutFile << fIndention
742 << G4std::setw(8) << G4std::setprecision(2) << x << " "
743 << G4std::setw(8) << G4std::setprecision(2) << y << " "
744 << G4std::setw(8) << G4std::setprecision(2) << z
749 void TG4XMLConvertor::WritePositionWithRotation(
750 G4String lvName, G4ThreeVector position,
751 const G4RotationMatrix* rotation)
753 // Writes position with rotation with a given solid name.
754 // Not yet implemented, only XML comment element is written.
758 G4double x = position.x()/TG4G3Units::Length();
759 G4double y = position.y()/TG4G3Units::Length();
760 G4double z = position.z()/TG4G3Units::Length();
761 G4double xx = rotation->xx();
762 G4double xy = rotation->xy();
763 G4double xz = rotation->xz();
764 G4double yx = rotation->yx();
765 G4double yy = rotation->yy();
766 G4double yz = rotation->yz();
767 G4double zx = rotation->zx();
768 G4double zy = rotation->zy();
769 G4double zz = rotation->zz();
774 while (i<fRotations.size() && fRotations[i] != rotation) i++;
775 if (i==fRotations.size()) {
776 G4String text = "TG4XMLConvertor::WritePositionWithRotation: ";
777 text = text + " Unknown rotation - fatal error.";
778 TG4Globals::Exception(text);
781 TG4Globals::AppendNumberToString(id, i);
784 // compose element string template
785 G4String quota = "\"\n";
786 G4String element1 = "<transform volume=\"########### pos=\"";
787 G4String element2 = " rot=\"";
788 G4String element3 = " ";
789 G4String element4 = "\" />";
792 PutName(element1, lvName, "#");
795 fOutFile << fIndention
797 << G4std::setw(8) << G4std::setprecision(2) << x << " "
798 << G4std::setw(8) << G4std::setprecision(2) << y << " "
799 << G4std::setw(8) << G4std::setprecision(2) << z << quota
802 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
803 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
804 << G4std::setw(8) << G4std::setprecision(5) << xz << G4endl
807 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
808 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
809 << G4std::setw(8) << G4std::setprecision(5) << yz << G4endl
812 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
813 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
814 << G4std::setw(8) << G4std::setprecision(5) << zz
819 void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr)
821 // Writes position without rotation with a given solid name.
830 pvr->GetReplicationData(axis, nReplicas, width, offset, consuming);
834 case kXAxis: tag = "X"; break;
835 case kYAxis: tag = "Y"; break;
836 case kZAxis: tag = "Z"; break;
837 case kRho: tag = "R"; break;
838 case kPhi: tag = "Phi"; break;
842 G4double value0 = offset;
843 G4double dValue = width;
845 value0 = value0/TG4G3Units::Length();
846 dValue = dValue/TG4G3Units::Length();
849 value0 = value0/TG4G3Units::Angle();
850 dValue = dValue/TG4G3Units::Angle();
853 // set tag and attributes names
854 G4String a0 = "mpos"; a0 = a0 + tag;
855 G4String a1 = tag; a1 = a1 + "0";
856 G4String a2 = "d"; a2 = a2 + tag;
858 // compose element string template
859 G4String element1 = "<" + a0 + " volume=\"########### ncopy=\"";
860 G4String element2 = "\" " + a1 + "=\"";
861 G4String element3 = "\" " + a2 + "=\"";
862 G4String element4 = "\" />";
865 PutName(element1, lvName, "#");
868 fOutFile << fIndention
870 << G4std::setw(8) << G4std::setprecision(2) << nReplicas
872 << G4std::setw(8) << G4std::setprecision(2) << value0
874 << G4std::setw(8) << G4std::setprecision(2) << dValue
879 void TG4XMLConvertor::WriteEmptyLine()
881 // Writes empty line.
887 void TG4XMLConvertor::IncreaseIndention()
889 // increase indention
890 fIndention.append(fkBasicIndention);
893 void TG4XMLConvertor::DecreaseIndention()
895 // decrease indention
896 fIndention.replace(fIndention.find(fkBasicIndention), 3 , "");