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>
24 #include <G4Polycone.hh>
25 #include <G4Polyhedra.hh>
27 #include <g4std/iostream>
28 #include <g4std/iomanip>
30 const G4int TG4XMLConvertor::fgkMaxVolumeNameLength = 10;
31 const G4int TG4XMLConvertor::fgkMaxMaterialNameLength = 20;
32 const G4int TG4XMLConvertor::fgkDefaultNumWidth = 7;
33 const G4int TG4XMLConvertor::fgkDefaultNumPrecision = 4;
35 //_____________________________________________________________________________
36 TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile)
38 fkBasicIndention(" "),
39 fNW(fgkDefaultNumWidth),
40 fNP(fgkDefaultNumPrecision),
41 fIndention(fkBasicIndention),
44 fOutFile.width(fgkDefaultNumWidth);
45 fOutFile.precision(fgkDefaultNumPrecision);
48 //_____________________________________________________________________________
49 TG4XMLConvertor::~TG4XMLConvertor() {
55 //_____________________________________________________________________________
56 void TG4XMLConvertor::CutName(G4String& name) const
58 // Removes spaces after the name if present.
61 G4int i = name.length();
62 while (name(--i) == ' ') name = name(0,i);
65 //_____________________________________________________________________________
66 void TG4XMLConvertor::CutName(G4String& name, G4int size) const
68 // Cuts name to given size.
71 if (name.length() > size) name = name(0, size);
74 //_____________________________________________________________________________
75 void TG4XMLConvertor::PutName(G4String& element, G4String name,
78 // Replaces given template in string element with a give name.
84 CutName(name, fgkMaxVolumeNameLength);
85 else if (templ == "!")
86 CutName(name, fgkMaxMaterialNameLength);
88 element.replace(element.find(templ), name.size(), name);
89 element.replace(element.find(templ), 1, "\"");
90 while (element.contains(templ)) element.replace(element.find(templ), 1 , " ");
93 //_____________________________________________________________________________
94 void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box,
95 G4String materialName)
97 // Writes G4box solid.
101 G4double x = box->GetXHalfLength()/TG4G3Units::Length()*2.;
102 G4double y = box->GetYHalfLength()/TG4G3Units::Length()*2.;
103 G4double z = box->GetZHalfLength()/TG4G3Units::Length()*2.;
105 // compose element string template
106 G4String quota = "\"";
107 G4String element1 = "<box name=\"" + lvName + quota;
108 G4String element2 = "material=\"" + materialName + quota;
109 G4String element3 = "X_Y_Z=\"";
110 G4String element4 = "\" />";
111 G4String indention = fkBasicIndention + fkBasicIndention;
114 fOutFile << fkBasicIndention << element1 << G4endl
115 << indention << element2 << G4endl
116 << indention << element3
117 << G4std::setw(fNW) << G4std::setprecision(fNP) << x << " "
118 << G4std::setw(fNW) << G4std::setprecision(fNP) << y << " "
119 << G4std::setw(fNW) << G4std::setprecision(fNP) << z
120 << element4 << G4endl << G4endl;
123 //_____________________________________________________________________________
124 void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs,
125 G4String materialName)
127 // Writes G4tubs solid.
131 G4double rmin = tubs->GetInnerRadius()/TG4G3Units::Length();
132 G4double rmax = tubs->GetOuterRadius()/TG4G3Units::Length();
133 G4double hz = tubs->GetZHalfLength()/TG4G3Units::Length()*2.;
134 G4double sphi = tubs->GetStartPhiAngle()/TG4G3Units::Angle();
135 G4double dphi = tubs->GetDeltaPhiAngle()/TG4G3Units::Angle();
137 // compose element string template
138 G4String quota = "\"";
139 G4String element1 = "<tubs name=\"" + lvName + quota;
140 G4String element2 = "material=\"" + materialName + quota;
141 G4String element3 = "profile=\"";
142 G4String element4 = "Rio_Z =\"";
143 G4String element5 = "\" />";
144 G4String indention = fkBasicIndention + fkBasicIndention;
147 fOutFile << fkBasicIndention << element1 << G4endl
148 << indention << element2 << G4endl
149 << indention << element3
150 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
151 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
153 << indention << element4
154 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
155 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
156 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
157 << element5 << G4endl << G4endl;
160 //_____________________________________________________________________________
161 void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons,
162 G4String materialName)
164 // Writes G4cons solid.
168 G4double rmin1 = cons->GetInnerRadiusMinusZ()/TG4G3Units::Length();
169 G4double rmax1 = cons->GetOuterRadiusMinusZ()/TG4G3Units::Length();
170 G4double rmin2 = cons->GetInnerRadiusPlusZ()/TG4G3Units::Length();
171 G4double rmax2 = cons->GetOuterRadiusPlusZ()/TG4G3Units::Length();
172 G4double hz = cons->GetZHalfLength()/TG4G3Units::Length()*2.;
173 G4double sphi = cons->GetStartPhiAngle()/TG4G3Units::Angle();
174 G4double dphi = cons->GetDeltaPhiAngle()/TG4G3Units::Angle();
176 // compose element string template
177 G4String quota = "\"";
178 G4String element1 = "<cons name=\"" + lvName + quota;
179 G4String element2 = "material=\"" + materialName + quota;
180 G4String element3 = "profile=\"";
181 G4String element4 = "Rio1_Rio2_Z =\"";
182 G4String element5 = "\" />";
183 G4String indention = fkBasicIndention + fkBasicIndention;
186 fOutFile << fkBasicIndention << element1 << G4endl
187 << indention << element2 << G4endl
188 << indention << element3
189 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
190 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
192 << indention << element4
193 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin1 << " "
194 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin2 << " "
195 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax1 << " "
196 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax2 << " "
197 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
198 << element5 << G4endl << G4endl;
201 //_____________________________________________________________________________
202 void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd,
203 G4String materialName)
205 // Writes G4Trd solid.
209 G4double x1 = trd->GetXHalfLength1()/TG4G3Units::Length()*2;
210 G4double x2 = trd->GetXHalfLength2()/TG4G3Units::Length()*2;
211 G4double y1 = trd->GetYHalfLength1()/TG4G3Units::Length()*2;
212 G4double y2 = trd->GetYHalfLength2()/TG4G3Units::Length()*2;
213 G4double hz = trd->GetZHalfLength()/TG4G3Units::Length()*2;
215 // compose element string template
216 G4String quota = "\"";
217 G4String element1 = "<trd name=\"" + lvName + quota;
218 G4String element2 = "material=\"" + materialName + quota;
219 G4String element3 = "Xmp_Ymp_Z=\"";
220 G4String element4 = "\" />";
221 G4String indention = fkBasicIndention + fkBasicIndention;
224 fOutFile << fkBasicIndention << element1 << G4endl
225 << indention << element2 << G4endl
226 << indention << element3
227 << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
228 << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
229 << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
230 << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
231 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
232 << element4 << G4endl << G4endl;
235 //_____________________________________________________________________________
236 void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap,
237 G4String materialName)
239 // Writes G4Trap solid.
243 G4double dz = trap->GetZHalfLength()/TG4G3Units::Length()*2.;
244 G4ThreeVector symAxis = trap->GetSymAxis();
245 G4double y1 = trap->GetYHalfLength1()/TG4G3Units::Length()*2.;
246 G4double x1 = trap->GetXHalfLength1()/TG4G3Units::Length()*2.;
247 G4double x2 = trap->GetXHalfLength2()/TG4G3Units::Length()*2.;
248 G4double tanAlpha1 = trap->GetTanAlpha1();
249 G4double y2 = trap->GetYHalfLength2()/TG4G3Units::Length()*2.;
250 G4double x3 = trap->GetXHalfLength3()/TG4G3Units::Length()*2.;
251 G4double x4 = trap->GetXHalfLength4()/TG4G3Units::Length()*2.;
252 G4double tanAlpha2 = trap->GetTanAlpha2();
254 // ordering of parameters in XML element
255 // Xmumdpupd_Ymp_Z: 2x2 2x1 2x4 2x3 2y2 2y1 2dz
256 // inclination: atan(symAxis.x/symAxis.z), atan(symAxis.y/symAxis.z)
257 // declination: alpha1, alpha2
260 G4double inc1 = atan(symAxis.x()/symAxis.z()) / deg;
261 G4double inc2 = atan(symAxis.y()/symAxis.z()) / deg;
262 G4double alpha1 = atan(tanAlpha1) / deg;
263 G4double alpha2 = atan(tanAlpha2) / deg;
265 // compose element string template
266 G4String quota = "\"";
267 G4String element1 = "<trap name=\"" + lvName + quota;
268 G4String element2 = "material=\"" + materialName + quota;
269 G4String element3 = "Xmumdpupd_Ymp_Z=\"";
270 G4String element4 = "inclination=\"";
271 G4String element5 = "declination=\"";
272 G4String element6 = "\" />";
273 G4String indention = fkBasicIndention + fkBasicIndention;
276 fOutFile << fkBasicIndention << element1 << G4endl
277 << indention << element2 << G4endl
278 << indention << element3
279 << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
280 << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
281 << G4std::setw(fNW) << G4std::setprecision(fNP) << x4 << " "
282 << G4std::setw(fNW) << G4std::setprecision(fNP) << x3 << " "
283 << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
284 << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
285 << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
287 << indention << element4
288 << G4std::setw(fNW) << G4std::setprecision(fNP) << inc1 << " "
289 << G4std::setw(fNW) << G4std::setprecision(fNP) << inc2
291 << indention << element5
292 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha1 << " "
293 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha2
294 << element6 << G4endl << G4endl;
297 //_____________________________________________________________________________
298 void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para,
299 G4String materialName)
301 // Writes G4Para solid.
305 G4double dx = para->GetXHalfLength()/TG4G3Units::Length()*2.;
306 G4double dy = para->GetYHalfLength()/TG4G3Units::Length()*2.;
307 G4double dz = para->GetZHalfLength()/TG4G3Units::Length()*2.;
308 G4double tanAlpha = para->GetTanAlpha();
309 G4ThreeVector symAxis = para->GetSymAxis();
311 G4double alpha = atan(tanAlpha) / deg;
312 G4double theta = acos(symAxis.z()) / deg;
317 phi = atan(symAxis.y()/symAxis.x()) / deg;
319 // compose element string template
320 G4String quota = "\"";
321 G4String element1 = "<para name=\"" + lvName + quota;
322 G4String element2 = "material=\"" + materialName + quota;
323 G4String element3 = "X_Y_Z=\"";
324 G4String element4 = "alpha=\"";
325 G4String element5 = "theta=\"";
326 G4String element6 = "phi= \"";
327 G4String element7 = "\" />";
328 G4String indention = fkBasicIndention + fkBasicIndention;
331 fOutFile << fkBasicIndention << element1 << G4endl
332 << indention << element2 << G4endl
333 << indention << element3
334 << G4std::setw(fNW) << G4std::setprecision(fNP) << dx << " "
335 << G4std::setw(fNW) << G4std::setprecision(fNP) << dy << " "
336 << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
338 << indention << element4
339 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha
341 << indention << element5
342 << G4std::setw(fNW) << G4std::setprecision(fNP) << theta
344 << indention << element6
345 << G4std::setw(fNW) << G4std::setprecision(fNP) << phi
346 << element7 << G4endl << G4endl;
349 //_____________________________________________________________________________
350 void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone,
351 G4String materialName)
353 // Writes G4Polycone solid.
356 // get profile parameters
357 G4double sphi = polycone->GetStartPhi()/TG4G3Units::Angle();
358 G4double ephi = polycone->GetEndPhi()/TG4G3Units::Angle();
360 // get polycone Z planes parameters
361 TG4Polycone historicalPolycone = TG4Polycone(*polycone);
363 G4int nofZPlanes = historicalPolycone.GetNofZPlanes();
364 G4double* rminArray = historicalPolycone.GetRmin();
365 G4double* rmaxArray = historicalPolycone.GetRmax();
366 G4double* zArray = historicalPolycone.GetZ();
368 // compose element string template
369 G4String quota = "\"";
370 G4String element1 = "<pcon name=\"" + lvName + quota;
371 G4String element2 = "material=\"" + materialName + quota;
372 G4String element3 = "profile=\"";
373 G4String element4 = "\" >";
374 G4String element5 = "<polyplane Rio_Z=\"";
375 G4String element6 = "\" />";
376 G4String element7 = "</pcon>";
377 G4String indention = fkBasicIndention + fkBasicIndention;
379 // write pcon element
380 fOutFile << fkBasicIndention << element1 << G4endl
381 << indention << element2 << G4endl
382 << indention << element3
383 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
384 << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
385 << element4 << G4endl;
387 // write polyplane elements
388 for (G4int i=0; i<nofZPlanes; i++) {
391 G4double rmin = rminArray[i]/TG4G3Units::Length();
392 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
393 G4double z = zArray[i]/TG4G3Units::Length();
395 fOutFile << indention << element5
396 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
397 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
398 << G4std::setw(fNW) << G4std::setprecision(fNP) << z
403 // close pcon element
404 fOutFile << fkBasicIndention
405 << element7 << G4endl << G4endl;
408 //_____________________________________________________________________________
409 void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra,
410 G4String materialName)
412 // Writes G4Polycone solid.
416 G4int nofSides = polyhedra->GetNumSide();
417 G4double sphi = polyhedra->GetStartPhi()/TG4G3Units::Angle();
418 G4double ephi = polyhedra->GetEndPhi()/TG4G3Units::Angle();
420 // get polyhedra Z planes parameters
421 TG4Polyhedra historicalPolyhedra = TG4Polyhedra(*polyhedra);
423 G4int nofZPlanes = historicalPolyhedra.GetNofZPlanes();
424 G4double* rminArray = historicalPolyhedra.GetRmin();
425 G4double* rmaxArray = historicalPolyhedra.GetRmax();
426 G4double* zArray = historicalPolyhedra.GetZ();
428 // compose element string template
429 G4String quota = "\"";
430 G4String element1 = "<phedra name=\"" + lvName + quota;
431 G4String element2 = "material=\"" + materialName + quota;
432 G4String element3 = "profile=\"";
433 G4String element4 = "sides =\"";
434 G4String element5 = "Ris=\"";
435 G4String element6 = "Ros=\"";
436 G4String element7 = "Zs =\"";
437 G4String element8 = "\" />";
438 G4String indention = fkBasicIndention + fkBasicIndention;
441 fOutFile << fkBasicIndention << element1 << G4endl
442 << indention << element2 << G4endl
443 << indention << element3
444 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
445 << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
447 << indention << element4
451 fOutFile << indention << element5;
453 for (i=0; i<nofZPlanes; i++) {
455 G4double rmin = rminArray[i]/TG4G3Units::Length();
456 if (i>0) fOutFile << " ";
457 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin;
459 fOutFile << quota << G4endl;
461 fOutFile << indention << element6;
462 for (i=0; i<nofZPlanes; i++) {
464 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
465 if (i>0) fOutFile << " ";
466 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax;
468 fOutFile << quota << G4endl;
470 fOutFile << indention << element7;
471 for (i=0; i<nofZPlanes; i++) {
473 G4double z = zArray[i]/TG4G3Units::Length();
474 if (i>0) fOutFile << " ";
475 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << z;
477 fOutFile << element8 << G4endl << G4endl;
483 //_____________________________________________________________________________
484 void TG4XMLConvertor::OpenMaterials(const G4String& version,
485 const G4String& date, const G4String& author,
486 const G4String dtdVersion)
488 // Writes section opening.
491 G4String element1 = "<materials version = \"";
492 G4String element2 = " date = \"";
493 G4String element3 = " author = \"";
494 G4String element4 = " DTD_version=\"";
495 G4String element5 = " >";
496 G4String quota = "\"";
499 fOutFile << element1 << version << quota << G4endl
500 << element2 << date << quota << G4endl
501 << element3 << author << quota << G4endl
502 << element4 << dtdVersion << quota
503 << element5 << G4endl;
506 //_____________________________________________________________________________
507 void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version,
508 const G4String& date, const G4String& author,
509 const G4String& topVolume)
511 // Writes section opening.
514 G4String element1 = "<section name = \"";
515 G4String element2 = " version = \"";
516 G4String element3 = " date = \"";
517 G4String element4 = " author = \"";
518 G4String element5 = " topVolume = \"";
519 G4String element6 = " >";
520 G4String quota = "\"";
523 fOutFile << element1 << name << quota << G4endl
524 << element2 << version << quota << G4endl
525 << element3 << date << quota << G4endl
526 << element4 << author << quota << G4endl
527 << element5 << topVolume << quota
528 << element6 << G4endl;
531 void TG4XMLConvertor::OpenComposition(const G4String& name)
533 // Writes composition opening.
536 G4String element = "<composition name=\"";
537 element.append(name);
538 element.append("\">");
541 fOutFile << fIndention
545 // increase indention
549 //_____________________________________________________________________________
550 void TG4XMLConvertor::CloseMaterials()
552 // Writes materials closing.
556 G4String element = "</materials>";
563 //_____________________________________________________________________________
564 void TG4XMLConvertor::CloseSection()
566 // Writes section closing.
570 G4String element = "</section>";
577 //_____________________________________________________________________________
578 void TG4XMLConvertor::CloseComposition()
580 // Writes composition closing.
583 // decrease indention
587 G4String element = "</composition>";
590 fOutFile << fIndention
595 //_____________________________________________________________________________
596 void TG4XMLConvertor::WriteMaterial(const G4Material* material)
598 // Writes G4Material.
599 // Not yet implemented, only XML comment element is written.
602 G4String name = material->GetName();
606 G4String element1 = "<!-- material = \"";
607 G4String element2 = "\" -->";
610 fOutFile << fkBasicIndention
616 //_____________________________________________________________________________
617 void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid,
618 G4String materialName)
620 // Finds G4Solid concrete type and calls writing function.
621 // For not yet implemented solids, only XML comment element is written.
624 // to be removed when materials are supported
625 materialName = "Hydrogen";
627 const G4Box* box = dynamic_cast<const G4Box*>(solid);
629 WriteBox(lvName, box, materialName);
633 const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(solid);
635 WriteTubs(lvName, tubs, materialName);
639 const G4Cons* cons = dynamic_cast<const G4Cons*>(solid);
641 WriteCons(lvName, cons, materialName);
645 const G4Trd* trd = dynamic_cast<const G4Trd*>(solid);
647 WriteTrd(lvName, trd, materialName);
651 const G4Trap* trap = dynamic_cast<const G4Trap*>(solid);
653 WriteTrap(lvName, trap, materialName);
657 const G4Para* para = dynamic_cast<const G4Para*>(solid);
659 WritePara(lvName, para, materialName);
663 const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(solid);
665 WritePolycone(lvName, polycone, materialName);
669 const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(solid);
671 WritePolyhedra(lvName, polyhedra, materialName);
675 // write comment line in case of unsupported
679 G4String element1 = "<!-- unsupported shape name= \"";
680 G4String element2 = "\" -->";
683 fOutFile << fkBasicIndention
684 << element1 << lvName
689 //_____________________________________________________________________________
690 void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation)
692 // Writes G4RotationMatrix.
693 // Not yet implemented, only XML comment element is written.
696 // return if this rotation was already written
697 G4int nofRotations = fRotations.size();
699 for (G4int i=0; i<nofRotations; i++)
700 if (fRotations[i] == rotation) return;
702 fRotations.push_back(rotation);
706 G4double xx = rotation->xx();
707 G4double xy = rotation->xy();
708 G4double xz = rotation->xz();
709 G4double yx = rotation->yx();
710 G4double yy = rotation->yy();
711 G4double yz = rotation->yz();
712 G4double zx = rotation->zx();
713 G4double zy = rotation->zy();
714 G4double zz = rotation->zz();
716 TG4Globals::AppendNumberToString(id, ++fRotationCounter);
718 // compose element string template
719 G4String quota = "\"\n";
720 G4String element1 = "<rot_matrix id=\"####### XX_XY_XZ=\"";
721 G4String element2 = " YX_YY_YZ=\"";
722 G4String element3 = " ZX_ZY_ZZ=\"";
723 G4String element4 = "\" />";
726 PutName(element1, id, "#");
729 fOutFile << fkBasicIndention
731 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
732 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
733 << G4std::setw(8) << G4std::setprecision(5) << xz << quota
736 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
737 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
738 << G4std::setw(8) << G4std::setprecision(5) << yz << quota
741 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
742 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
743 << G4std::setw(8) << G4std::setprecision(5) << zz
748 //_____________________________________________________________________________
749 void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position)
751 // Writes position without rotation with a given solid name.
755 G4double x = position.x()/TG4G3Units::Length();
756 G4double y = position.y()/TG4G3Units::Length();
757 G4double z = position.z()/TG4G3Units::Length();
759 // compose element string template
760 G4String element1 = "<posXYZ volume=\"########### X_Y_Z=\"";
761 G4String element2 = "\" />";
764 PutName(element1, lvName, "#");
767 fOutFile << fIndention
769 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
770 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
771 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z
776 //_____________________________________________________________________________
777 void TG4XMLConvertor::WritePositionWithRotation(
778 G4String lvName, G4ThreeVector position,
779 const G4RotationMatrix* rotation)
781 // Writes position with rotation with a given solid name.
782 // Not yet implemented, only XML comment element is written.
786 G4double x = position.x()/TG4G3Units::Length();
787 G4double y = position.y()/TG4G3Units::Length();
788 G4double z = position.z()/TG4G3Units::Length();
789 G4double xx = rotation->xx();
790 G4double xy = rotation->xy();
791 G4double xz = rotation->xz();
792 G4double yx = rotation->yx();
793 G4double yy = rotation->yy();
794 G4double yz = rotation->yz();
795 G4double zx = rotation->zx();
796 G4double zy = rotation->zy();
797 G4double zz = rotation->zz();
802 while (i<fRotations.size() && fRotations[i] != rotation) i++;
803 if (i==fRotations.size()) {
804 G4String text = "TG4XMLConvertor::WritePositionWithRotation: ";
805 text = text + " Unknown rotation - fatal error.";
806 TG4Globals::Exception(text);
809 TG4Globals::AppendNumberToString(id, i);
812 // compose element string template
813 G4String quota = "\"\n";
814 G4String element1 = "<transform volume=\"########### pos=\"";
815 G4String element2 = " rot=\"";
816 G4String element3 = " ";
817 G4String element4 = "\" />";
820 PutName(element1, lvName, "#");
823 fOutFile << fIndention
825 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
826 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
827 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z << quota
830 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
831 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
832 << G4std::setw(8) << G4std::setprecision(5) << xz << G4endl
835 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
836 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
837 << G4std::setw(8) << G4std::setprecision(5) << yz << G4endl
840 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
841 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
842 << G4std::setw(8) << G4std::setprecision(5) << zz
847 //_____________________________________________________________________________
848 void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr)
850 // Writes position without rotation with a given solid name.
859 pvr->GetReplicationData(axis, nReplicas, width, offset, consuming);
863 case kXAxis: tag = "X"; break;
864 case kYAxis: tag = "Y"; break;
865 case kZAxis: tag = "Z"; break;
866 case kRho: tag = "R"; break;
867 case kPhi: tag = "Phi"; break;
871 G4double value0 = offset;
872 G4double dValue = width;
874 value0 = value0/TG4G3Units::Length();
875 dValue = dValue/TG4G3Units::Length();
878 value0 = value0/TG4G3Units::Angle();
879 dValue = dValue/TG4G3Units::Angle();
882 // set tag and attributes names
883 G4String a0 = "mpos"; a0 = a0 + tag;
884 G4String a1 = tag; a1 = a1 + "0";
885 G4String a2 = "d"; a2 = a2 + tag;
887 // compose element string template
888 G4String element1 = "<" + a0 + " volume=\"########### ncopy=\"";
889 G4String element2 = "\" " + a1 + "=\"";
890 G4String element3 = "\" " + a2 + "=\"";
891 G4String element4 = "\" />";
894 PutName(element1, lvName, "#");
897 fOutFile << fIndention
899 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << nReplicas
901 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << value0
903 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << dValue
908 //_____________________________________________________________________________
909 void TG4XMLConvertor::WriteEmptyLine()
911 // Writes empty line.
917 //_____________________________________________________________________________
918 void TG4XMLConvertor::IncreaseIndention()
920 // increase indention
921 fIndention.append(fkBasicIndention);
924 //_____________________________________________________________________________
925 void TG4XMLConvertor::DecreaseIndention()
927 // decrease indention
928 fIndention.replace(fIndention.find(fkBasicIndention), 3 , "");