4 // Author: I. Hrivnacova, 27.07.2000
6 // Class TG4XMLConvertor
7 // ---------------------
8 // See the class description in the header file.
10 #include "TG4XMLConvertor.h"
11 #include "TG4Polycone.h"
12 #include "TG4Polyhedra.h"
13 #include "TG4G3Units.h"
15 #include <G4PVReplica.hh>
16 #include <G4Material.hh>
17 #include <G4VSolid.hh>
18 #include <G4ReflectedSolid.hh>
25 #include <G4Polycone.hh>
26 #include <G4Polyhedra.hh>
28 #include <g4std/iostream>
29 #include <g4std/iomanip>
31 const G4int TG4XMLConvertor::fgkMaxVolumeNameLength = 10;
32 const G4int TG4XMLConvertor::fgkMaxMaterialNameLength = 20;
33 const G4int TG4XMLConvertor::fgkDefaultNumWidth = 7;
34 const G4int TG4XMLConvertor::fgkDefaultNumPrecision = 4;
36 //_____________________________________________________________________________
37 TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile)
39 fkBasicIndention(" "),
40 fNW(fgkDefaultNumWidth),
41 fNP(fgkDefaultNumPrecision),
42 fIndention(fkBasicIndention),
45 fOutFile.width(fgkDefaultNumWidth);
46 fOutFile.precision(fgkDefaultNumPrecision);
49 //_____________________________________________________________________________
50 TG4XMLConvertor::~TG4XMLConvertor() {
56 //_____________________________________________________________________________
57 void TG4XMLConvertor::CutName(G4String& name) const
59 // Removes spaces after the name if present.
62 G4int i = name.length();
63 while (name(--i) == ' ') name = name(0,i);
66 //_____________________________________________________________________________
67 void TG4XMLConvertor::CutName(G4String& name, G4int size) const
69 // Cuts name to given size.
72 if (name.length() > size) name = name(0, size);
75 //_____________________________________________________________________________
76 void TG4XMLConvertor::PutName(G4String& element, G4String name,
79 // Replaces given template in string element with a give name.
85 CutName(name, fgkMaxVolumeNameLength);
86 else if (templ == "!")
87 CutName(name, fgkMaxMaterialNameLength);
89 element.replace(element.find(templ), name.size(), name);
90 element.replace(element.find(templ), 1, "\"");
91 while (element.contains(templ)) element.replace(element.find(templ), 1 , " ");
94 //_____________________________________________________________________________
95 void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box,
96 G4String materialName)
98 // Writes G4box solid.
102 G4double x = box->GetXHalfLength()/TG4G3Units::Length()*2.;
103 G4double y = box->GetYHalfLength()/TG4G3Units::Length()*2.;
104 G4double z = box->GetZHalfLength()/TG4G3Units::Length()*2.;
106 // compose element string template
107 G4String quota = "\"";
108 G4String element1 = "<box name=\"" + lvName + quota;
109 G4String element2 = "material=\"" + materialName + quota;
110 G4String element3 = "X_Y_Z=\"";
111 G4String element4 = "\" />";
112 G4String indention = fkBasicIndention + fkBasicIndention;
115 fOutFile << fkBasicIndention << element1 << G4endl
116 << indention << element2 << G4endl
117 << indention << element3
118 << G4std::setw(fNW) << G4std::setprecision(fNP) << x << " "
119 << G4std::setw(fNW) << G4std::setprecision(fNP) << y << " "
120 << G4std::setw(fNW) << G4std::setprecision(fNP) << z
121 << element4 << G4endl << G4endl;
124 //_____________________________________________________________________________
125 void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs,
126 G4String materialName)
128 // Writes G4tubs solid.
132 G4double rmin = tubs->GetInnerRadius()/TG4G3Units::Length();
133 G4double rmax = tubs->GetOuterRadius()/TG4G3Units::Length();
134 G4double hz = tubs->GetZHalfLength()/TG4G3Units::Length()*2.;
135 G4double sphi = tubs->GetStartPhiAngle()/TG4G3Units::Angle();
136 G4double dphi = tubs->GetDeltaPhiAngle()/TG4G3Units::Angle();
138 // compose element string template
139 G4String quota = "\"";
140 G4String element1 = "<tubs name=\"" + lvName + quota;
141 G4String element2 = "material=\"" + materialName + quota;
142 G4String element3 = "profile=\"";
143 G4String element4 = "Rio_Z =\"";
144 G4String element5 = "\" />";
145 G4String indention = fkBasicIndention + fkBasicIndention;
148 fOutFile << fkBasicIndention << element1 << G4endl
149 << indention << element2 << G4endl
150 << indention << element3
151 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
152 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
154 << indention << element4
155 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
156 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
157 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
158 << element5 << G4endl << G4endl;
161 //_____________________________________________________________________________
162 void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons,
163 G4String materialName)
165 // Writes G4cons solid.
169 G4double rmin1 = cons->GetInnerRadiusMinusZ()/TG4G3Units::Length();
170 G4double rmax1 = cons->GetOuterRadiusMinusZ()/TG4G3Units::Length();
171 G4double rmin2 = cons->GetInnerRadiusPlusZ()/TG4G3Units::Length();
172 G4double rmax2 = cons->GetOuterRadiusPlusZ()/TG4G3Units::Length();
173 G4double hz = cons->GetZHalfLength()/TG4G3Units::Length()*2.;
174 G4double sphi = cons->GetStartPhiAngle()/TG4G3Units::Angle();
175 G4double dphi = cons->GetDeltaPhiAngle()/TG4G3Units::Angle();
177 // compose element string template
178 G4String quota = "\"";
179 G4String element1 = "<cons name=\"" + lvName + quota;
180 G4String element2 = "material=\"" + materialName + quota;
181 G4String element3 = "profile=\"";
182 G4String element4 = "Rio1_Rio2_Z =\"";
183 G4String element5 = "\" />";
184 G4String indention = fkBasicIndention + fkBasicIndention;
187 fOutFile << fkBasicIndention << element1 << G4endl
188 << indention << element2 << G4endl
189 << indention << element3
190 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
191 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
193 << indention << element4
194 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin1 << " "
195 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin2 << " "
196 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax1 << " "
197 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax2 << " "
198 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
199 << element5 << G4endl << G4endl;
202 //_____________________________________________________________________________
203 void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd,
204 G4String materialName)
206 // Writes G4Trd solid.
210 G4double x1 = trd->GetXHalfLength1()/TG4G3Units::Length()*2;
211 G4double x2 = trd->GetXHalfLength2()/TG4G3Units::Length()*2;
212 G4double y1 = trd->GetYHalfLength1()/TG4G3Units::Length()*2;
213 G4double y2 = trd->GetYHalfLength2()/TG4G3Units::Length()*2;
214 G4double hz = trd->GetZHalfLength()/TG4G3Units::Length()*2;
216 // compose element string template
217 G4String quota = "\"";
218 G4String element1 = "<trd name=\"" + lvName + quota;
219 G4String element2 = "material=\"" + materialName + quota;
220 G4String element3 = "Xmp_Ymp_Z=\"";
221 G4String element4 = "\" />";
222 G4String indention = fkBasicIndention + fkBasicIndention;
225 fOutFile << fkBasicIndention << element1 << G4endl
226 << indention << element2 << G4endl
227 << indention << element3
228 << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
229 << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
230 << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
231 << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
232 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
233 << element4 << G4endl << G4endl;
236 //_____________________________________________________________________________
237 void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap,
238 G4String materialName)
240 // Writes G4Trap solid.
244 G4double dz = trap->GetZHalfLength()/TG4G3Units::Length()*2.;
245 G4ThreeVector symAxis = trap->GetSymAxis();
246 G4double y1 = trap->GetYHalfLength1()/TG4G3Units::Length()*2.;
247 G4double x1 = trap->GetXHalfLength1()/TG4G3Units::Length()*2.;
248 G4double x2 = trap->GetXHalfLength2()/TG4G3Units::Length()*2.;
249 G4double tanAlpha1 = trap->GetTanAlpha1();
250 G4double y2 = trap->GetYHalfLength2()/TG4G3Units::Length()*2.;
251 G4double x3 = trap->GetXHalfLength3()/TG4G3Units::Length()*2.;
252 G4double x4 = trap->GetXHalfLength4()/TG4G3Units::Length()*2.;
253 G4double tanAlpha2 = trap->GetTanAlpha2();
255 // ordering of parameters in XML element
256 // Xmumdpupd_Ymp_Z: 2x2 2x1 2x4 2x3 2y2 2y1 2dz
257 // inclination: atan(symAxis.x/symAxis.z), atan(symAxis.y/symAxis.z)
258 // declination: alpha1, alpha2
261 G4double inc1 = atan(symAxis.x()/symAxis.z()) / deg;
262 G4double inc2 = atan(symAxis.y()/symAxis.z()) / deg;
263 G4double alpha1 = atan(tanAlpha1) / deg;
264 G4double alpha2 = atan(tanAlpha2) / deg;
266 // compose element string template
267 G4String quota = "\"";
268 G4String element1 = "<trap name=\"" + lvName + quota;
269 G4String element2 = "material=\"" + materialName + quota;
270 G4String element3 = "Xmumdpupd_Ymp_Z=\"";
271 G4String element4 = "inclination=\"";
272 G4String element5 = "declination=\"";
273 G4String element6 = "\" />";
274 G4String indention = fkBasicIndention + fkBasicIndention;
277 fOutFile << fkBasicIndention << element1 << G4endl
278 << indention << element2 << G4endl
279 << indention << element3
280 << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
281 << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
282 << G4std::setw(fNW) << G4std::setprecision(fNP) << x4 << " "
283 << G4std::setw(fNW) << G4std::setprecision(fNP) << x3 << " "
284 << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
285 << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
286 << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
288 << indention << element4
289 << G4std::setw(fNW) << G4std::setprecision(fNP) << inc1 << " "
290 << G4std::setw(fNW) << G4std::setprecision(fNP) << inc2
292 << indention << element5
293 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha1 << " "
294 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha2
295 << element6 << G4endl << G4endl;
298 //_____________________________________________________________________________
299 void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para,
300 G4String materialName)
302 // Writes G4Para solid.
306 G4double dx = para->GetXHalfLength()/TG4G3Units::Length()*2.;
307 G4double dy = para->GetYHalfLength()/TG4G3Units::Length()*2.;
308 G4double dz = para->GetZHalfLength()/TG4G3Units::Length()*2.;
309 G4double tanAlpha = para->GetTanAlpha();
310 G4ThreeVector symAxis = para->GetSymAxis();
312 G4double alpha = atan(tanAlpha) / deg;
313 G4double theta = acos(symAxis.z()) / deg;
318 phi = atan(symAxis.y()/symAxis.x()) / deg;
320 // compose element string template
321 G4String quota = "\"";
322 G4String element1 = "<para name=\"" + lvName + quota;
323 G4String element2 = "material=\"" + materialName + quota;
324 G4String element3 = "X_Y_Z=\"";
325 G4String element4 = "alpha=\"";
326 G4String element5 = "theta=\"";
327 G4String element6 = "phi= \"";
328 G4String element7 = "\" />";
329 G4String indention = fkBasicIndention + fkBasicIndention;
332 fOutFile << fkBasicIndention << element1 << G4endl
333 << indention << element2 << G4endl
334 << indention << element3
335 << G4std::setw(fNW) << G4std::setprecision(fNP) << dx << " "
336 << G4std::setw(fNW) << G4std::setprecision(fNP) << dy << " "
337 << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
339 << indention << element4
340 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha
342 << indention << element5
343 << G4std::setw(fNW) << G4std::setprecision(fNP) << theta
345 << indention << element6
346 << G4std::setw(fNW) << G4std::setprecision(fNP) << phi
347 << element7 << G4endl << G4endl;
350 //_____________________________________________________________________________
351 void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone,
352 G4String materialName)
354 // Writes G4Polycone solid.
357 // get profile parameters
358 G4double sphi = polycone->GetStartPhi()/TG4G3Units::Angle();
359 G4double ephi = polycone->GetEndPhi()/TG4G3Units::Angle();
361 // get polycone Z planes parameters
362 TG4Polycone historicalPolycone = TG4Polycone(*polycone);
364 G4int nofZPlanes = historicalPolycone.GetNofZPlanes();
365 G4double* rminArray = historicalPolycone.GetRmin();
366 G4double* rmaxArray = historicalPolycone.GetRmax();
367 G4double* zArray = historicalPolycone.GetZ();
369 // compose element string template
370 G4String quota = "\"";
371 G4String element1 = "<pcon name=\"" + lvName + quota;
372 G4String element2 = "material=\"" + materialName + quota;
373 G4String element3 = "profile=\"";
374 G4String element4 = "\" >";
375 G4String element5 = "<polyplane Rio_Z=\"";
376 G4String element6 = "\" />";
377 G4String element7 = "</pcon>";
378 G4String indention = fkBasicIndention + fkBasicIndention;
380 // write pcon element
381 fOutFile << fkBasicIndention << element1 << G4endl
382 << indention << element2 << G4endl
383 << indention << element3
384 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
385 << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
386 << element4 << G4endl;
388 // write polyplane elements
389 for (G4int i=0; i<nofZPlanes; i++) {
392 G4double rmin = rminArray[i]/TG4G3Units::Length();
393 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
394 G4double z = zArray[i]/TG4G3Units::Length();
396 fOutFile << indention << element5
397 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
398 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
399 << G4std::setw(fNW) << G4std::setprecision(fNP) << z
404 // close pcon element
405 fOutFile << fkBasicIndention
406 << element7 << G4endl << G4endl;
409 //_____________________________________________________________________________
410 void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra,
411 G4String materialName)
413 // Writes G4Polycone solid.
417 G4int nofSides = polyhedra->GetNumSide();
418 G4double sphi = polyhedra->GetStartPhi()/TG4G3Units::Angle();
419 G4double ephi = polyhedra->GetEndPhi()/TG4G3Units::Angle();
421 // get polyhedra Z planes parameters
422 TG4Polyhedra historicalPolyhedra = TG4Polyhedra(*polyhedra);
424 G4int nofZPlanes = historicalPolyhedra.GetNofZPlanes();
425 G4double* rminArray = historicalPolyhedra.GetRmin();
426 G4double* rmaxArray = historicalPolyhedra.GetRmax();
427 G4double* zArray = historicalPolyhedra.GetZ();
429 // compose element string template
430 G4String quota = "\"";
431 G4String element1 = "<phedra name=\"" + lvName + quota;
432 G4String element2 = "material=\"" + materialName + quota;
433 G4String element3 = "profile=\"";
434 G4String element4 = "sides =\"";
435 G4String element5 = "Ris=\"";
436 G4String element6 = "Ros=\"";
437 G4String element7 = "Zs =\"";
438 G4String element8 = "\" />";
439 G4String indention = fkBasicIndention + fkBasicIndention;
442 fOutFile << fkBasicIndention << element1 << G4endl
443 << indention << element2 << G4endl
444 << indention << element3
445 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
446 << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
448 << indention << element4
452 fOutFile << indention << element5;
454 for (i=0; i<nofZPlanes; i++) {
456 G4double rmin = rminArray[i]/TG4G3Units::Length();
457 if (i>0) fOutFile << " ";
458 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin;
460 fOutFile << quota << G4endl;
462 fOutFile << indention << element6;
463 for (i=0; i<nofZPlanes; i++) {
465 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
466 if (i>0) fOutFile << " ";
467 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax;
469 fOutFile << quota << G4endl;
471 fOutFile << indention << element7;
472 for (i=0; i<nofZPlanes; i++) {
474 G4double z = zArray[i]/TG4G3Units::Length();
475 if (i>0) fOutFile << " ";
476 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << z;
478 fOutFile << element8 << G4endl << G4endl;
484 //_____________________________________________________________________________
485 void TG4XMLConvertor::OpenMaterials(const G4String& version,
486 const G4String& date, const G4String& author,
487 const G4String dtdVersion)
489 // Writes section opening.
492 G4String element1 = "<materials version = \"";
493 G4String element2 = " date = \"";
494 G4String element3 = " author = \"";
495 G4String element4 = " DTD_version=\"";
496 G4String element5 = " >";
497 G4String quota = "\"";
500 fOutFile << element1 << version << quota << G4endl
501 << element2 << date << quota << G4endl
502 << element3 << author << quota << G4endl
503 << element4 << dtdVersion << quota
504 << element5 << G4endl;
507 //_____________________________________________________________________________
508 void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version,
509 const G4String& date, const G4String& author,
510 const G4String& topVolume)
512 // Writes section opening.
515 G4String element1 = "<section name = \"";
516 G4String element2 = " version = \"";
517 G4String element3 = " date = \"";
518 G4String element4 = " author = \"";
519 G4String element5 = " topVolume = \"";
520 G4String element6 = " >";
521 G4String quota = "\"";
524 fOutFile << element1 << name << quota << G4endl
525 << element2 << version << quota << G4endl
526 << element3 << date << quota << G4endl
527 << element4 << author << quota << G4endl
528 << element5 << topVolume << quota
529 << element6 << G4endl;
532 void TG4XMLConvertor::OpenComposition(const G4String& name)
534 // Writes composition opening.
537 G4String element = "<composition name=\"";
538 element.append(name);
539 element.append("\">");
542 fOutFile << fIndention
546 // increase indention
550 //_____________________________________________________________________________
551 void TG4XMLConvertor::CloseMaterials()
553 // Writes materials closing.
557 G4String element = "</materials>";
564 //_____________________________________________________________________________
565 void TG4XMLConvertor::CloseSection()
567 // Writes section closing.
571 G4String element = "</section>";
578 //_____________________________________________________________________________
579 void TG4XMLConvertor::CloseComposition()
581 // Writes composition closing.
584 // decrease indention
588 G4String element = "</composition>";
591 fOutFile << fIndention
596 //_____________________________________________________________________________
597 void TG4XMLConvertor::WriteMaterial(const G4Material* material)
599 // Writes G4Material.
600 // Not yet implemented, only XML comment element is written.
603 G4String name = material->GetName();
607 G4String element1 = "<!-- material = \"";
608 G4String element2 = "\" -->";
611 fOutFile << fkBasicIndention
617 //_____________________________________________________________________________
618 void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid,
619 G4String materialName)
621 // Finds G4Solid concrete type and calls writing function.
622 // For not yet implemented solids, only XML comment element is written.
625 // to be removed when materials are supported
626 materialName = "Hydrogen";
628 const G4ReflectedSolid* reflSolid
629 = dynamic_cast<const G4ReflectedSolid*>(solid);
631 const G4VSolid* consSolid;
633 consSolid = reflSolid->GetConstituentMovedSolid();
637 const G4Box* box = dynamic_cast<const G4Box*>(consSolid);
639 WriteBox(lvName, box, materialName);
643 const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(consSolid);
645 WriteTubs(lvName, tubs, materialName);
649 const G4Cons* cons = dynamic_cast<const G4Cons*>(consSolid);
651 WriteCons(lvName, cons, materialName);
655 const G4Trd* trd = dynamic_cast<const G4Trd*>(consSolid);
657 WriteTrd(lvName, trd, materialName);
661 const G4Trap* trap = dynamic_cast<const G4Trap*>(consSolid);
663 WriteTrap(lvName, trap, materialName);
667 const G4Para* para = dynamic_cast<const G4Para*>(consSolid);
669 WritePara(lvName, para, materialName);
673 const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(consSolid);
675 WritePolycone(lvName, polycone, materialName);
679 const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(consSolid);
681 WritePolyhedra(lvName, polyhedra, materialName);
685 // write comment line in case of unsupported
689 G4String element1 = "<!-- unsupported shape name= \"";
690 G4String element2 = "\" -->";
693 fOutFile << fkBasicIndention
694 << element1 << lvName
699 //_____________________________________________________________________________
700 void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation)
702 // Writes G4RotationMatrix.
703 // Not yet implemented, only XML comment element is written.
706 // return if this rotation was already written
707 G4int nofRotations = fRotations.size();
709 for (G4int i=0; i<nofRotations; i++)
710 if (fRotations[i] == rotation) return;
712 fRotations.push_back(rotation);
716 G4double xx = rotation->xx();
717 G4double xy = rotation->xy();
718 G4double xz = rotation->xz();
719 G4double yx = rotation->yx();
720 G4double yy = rotation->yy();
721 G4double yz = rotation->yz();
722 G4double zx = rotation->zx();
723 G4double zy = rotation->zy();
724 G4double zz = rotation->zz();
726 TG4Globals::AppendNumberToString(id, ++fRotationCounter);
728 // compose element string template
729 G4String quota = "\"\n";
730 G4String element1 = "<rot_matrix id=\"####### XX_XY_XZ=\"";
731 G4String element2 = " YX_YY_YZ=\"";
732 G4String element3 = " ZX_ZY_ZZ=\"";
733 G4String element4 = "\" />";
736 PutName(element1, id, "#");
739 fOutFile << fkBasicIndention
741 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
742 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
743 << G4std::setw(8) << G4std::setprecision(5) << xz << quota
746 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
747 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
748 << G4std::setw(8) << G4std::setprecision(5) << yz << quota
751 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
752 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
753 << G4std::setw(8) << G4std::setprecision(5) << zz
758 //_____________________________________________________________________________
759 void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position)
761 // Writes position without rotation with a given solid name.
765 G4double x = position.x()/TG4G3Units::Length();
766 G4double y = position.y()/TG4G3Units::Length();
767 G4double z = position.z()/TG4G3Units::Length();
769 // compose element string template
770 G4String element1 = "<posXYZ volume=\"########### X_Y_Z=\"";
771 G4String element2 = "\" />";
774 PutName(element1, lvName, "#");
777 fOutFile << fIndention
779 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
780 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
781 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z
786 //_____________________________________________________________________________
787 void TG4XMLConvertor::WritePositionWithRotation(
788 G4String lvName, G4ThreeVector position,
789 const G4RotationMatrix* rotation)
791 // Writes position with rotation with a given solid name.
792 // Not yet implemented, only XML comment element is written.
796 G4double x = position.x()/TG4G3Units::Length();
797 G4double y = position.y()/TG4G3Units::Length();
798 G4double z = position.z()/TG4G3Units::Length();
799 G4double xx = rotation->xx();
800 G4double xy = rotation->xy();
801 G4double xz = rotation->xz();
802 G4double yx = rotation->yx();
803 G4double yy = rotation->yy();
804 G4double yz = rotation->yz();
805 G4double zx = rotation->zx();
806 G4double zy = rotation->zy();
807 G4double zz = rotation->zz();
812 while (i<fRotations.size() && fRotations[i] != rotation) i++;
813 if (i==fRotations.size()) {
814 G4String text = "TG4XMLConvertor::WritePositionWithRotation: ";
815 text = text + " Unknown rotation - fatal error.";
816 TG4Globals::Exception(text);
819 TG4Globals::AppendNumberToString(id, i);
822 // compose element string template
823 G4String quota = "\"\n";
824 G4String element1 = "<transform volume=\"########### pos=\"";
825 G4String element2 = " rot=\"";
826 G4String element3 = " ";
827 G4String element4 = "\" />";
830 PutName(element1, lvName, "#");
833 fOutFile << fIndention
835 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
836 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
837 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z << quota
840 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
841 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
842 << G4std::setw(8) << G4std::setprecision(5) << xz << G4endl
845 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
846 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
847 << G4std::setw(8) << G4std::setprecision(5) << yz << G4endl
850 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
851 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
852 << G4std::setw(8) << G4std::setprecision(5) << zz
857 //_____________________________________________________________________________
858 void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr)
860 // Writes position without rotation with a given solid name.
869 pvr->GetReplicationData(axis, nReplicas, width, offset, consuming);
873 case kXAxis: tag = "X"; break;
874 case kYAxis: tag = "Y"; break;
875 case kZAxis: tag = "Z"; break;
876 case kRho: tag = "R"; break;
877 case kPhi: tag = "Phi"; break;
881 G4double value0 = offset;
882 G4double dValue = width;
884 value0 = value0/TG4G3Units::Length();
885 dValue = dValue/TG4G3Units::Length();
888 value0 = value0/TG4G3Units::Angle();
889 dValue = dValue/TG4G3Units::Angle();
892 // set tag and attributes names
893 G4String a0 = "mpos"; a0 = a0 + tag;
894 G4String a1 = tag; a1 = a1 + "0";
895 G4String a2 = "d"; a2 = a2 + tag;
897 // compose element string template
898 G4String element1 = "<" + a0 + " volume=\"########### ncopy=\"";
899 G4String element2 = "\" " + a1 + "=\"";
900 G4String element3 = "\" " + a2 + "=\"";
901 G4String element4 = "\" />";
904 PutName(element1, lvName, "#");
907 fOutFile << fIndention
909 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << nReplicas
911 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << value0
913 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << dValue
918 //_____________________________________________________________________________
919 void TG4XMLConvertor::WriteEmptyLine()
921 // Writes empty line.
927 //_____________________________________________________________________________
928 void TG4XMLConvertor::IncreaseIndention()
930 // increase indention
931 fIndention.append(fkBasicIndention);
934 //_____________________________________________________________________________
935 void TG4XMLConvertor::DecreaseIndention()
937 // decrease indention
938 fIndention.replace(fIndention.find(fkBasicIndention), 3 , "");