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;
28 const G4int TG4XMLConvertor::fgkDefaultNumWidth = 7;
29 const G4int TG4XMLConvertor::fgkDefaultNumPrecision = 4;
31 //_____________________________________________________________________________
32 TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile)
34 fkBasicIndention(" "),
35 fNW(fgkDefaultNumWidth),
36 fNP(fgkDefaultNumPrecision),
37 fIndention(fkBasicIndention),
40 fOutFile.width(fgkDefaultNumWidth);
41 fOutFile.precision(fgkDefaultNumPrecision);
44 //_____________________________________________________________________________
45 TG4XMLConvertor::~TG4XMLConvertor() {
51 //_____________________________________________________________________________
52 void TG4XMLConvertor::CutName(G4String& name) const
54 // Removes spaces after the name if present.
57 G4int i = name.length();
58 while (name(--i) == ' ') name = name(0,i);
61 //_____________________________________________________________________________
62 void TG4XMLConvertor::CutName(G4String& name, G4int size) const
64 // Cuts name to given size.
67 if (name.length() > size) name = name(0, size);
70 //_____________________________________________________________________________
71 void TG4XMLConvertor::PutName(G4String& element, G4String name,
74 // Replaces given template in string element with a give name.
80 CutName(name, fgkMaxVolumeNameLength);
81 else if (templ == "!")
82 CutName(name, fgkMaxMaterialNameLength);
84 element.replace(element.find(templ), name.size(), name);
85 element.replace(element.find(templ), 1, "\"");
86 while (element.contains(templ)) element.replace(element.find(templ), 1 , " ");
89 //_____________________________________________________________________________
90 void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box,
91 G4String materialName)
93 // Writes G4box solid.
97 G4double x = box->GetXHalfLength()/TG4G3Units::Length()*2.;
98 G4double y = box->GetYHalfLength()/TG4G3Units::Length()*2.;
99 G4double z = box->GetZHalfLength()/TG4G3Units::Length()*2.;
101 // compose element string template
102 G4String quota = "\"";
103 G4String element1 = "<box name=\"" + lvName + quota;
104 G4String element2 = "material=\"" + materialName + quota;
105 G4String element3 = "X_Y_Z=\"";
106 G4String element4 = "\" />";
107 G4String indention = fkBasicIndention + fkBasicIndention;
110 fOutFile << fkBasicIndention << element1 << G4endl
111 << indention << element2 << G4endl
112 << indention << element3
113 << G4std::setw(fNW) << G4std::setprecision(fNP) << x << " "
114 << G4std::setw(fNW) << G4std::setprecision(fNP) << y << " "
115 << G4std::setw(fNW) << G4std::setprecision(fNP) << z
116 << element4 << G4endl << G4endl;
119 //_____________________________________________________________________________
120 void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs,
121 G4String materialName)
123 // Writes G4tubs solid.
127 G4double rmin = tubs->GetInnerRadius()/TG4G3Units::Length();
128 G4double rmax = tubs->GetOuterRadius()/TG4G3Units::Length();
129 G4double hz = tubs->GetZHalfLength()/TG4G3Units::Length()*2.;
130 G4double sphi = tubs->GetStartPhiAngle()/TG4G3Units::Angle();
131 G4double dphi = tubs->GetDeltaPhiAngle()/TG4G3Units::Angle();
133 // compose element string template
134 G4String quota = "\"";
135 G4String element1 = "<tubs name=\"" + lvName + quota;
136 G4String element2 = "material=\"" + materialName + quota;
137 G4String element3 = "profile=\"";
138 G4String element4 = "Rio_Z =\"";
139 G4String element5 = "\" />";
140 G4String indention = fkBasicIndention + fkBasicIndention;
143 fOutFile << fkBasicIndention << element1 << G4endl
144 << indention << element2 << G4endl
145 << indention << element3
146 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
147 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
149 << indention << element4
150 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
151 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
152 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
153 << element5 << G4endl << G4endl;
156 //_____________________________________________________________________________
157 void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons,
158 G4String materialName)
160 // Writes G4cons solid.
164 G4double rmin1 = cons->GetInnerRadiusMinusZ()/TG4G3Units::Length();
165 G4double rmax1 = cons->GetOuterRadiusMinusZ()/TG4G3Units::Length();
166 G4double rmin2 = cons->GetInnerRadiusPlusZ()/TG4G3Units::Length();
167 G4double rmax2 = cons->GetOuterRadiusPlusZ()/TG4G3Units::Length();
168 G4double hz = cons->GetZHalfLength()/TG4G3Units::Length()*2.;
169 G4double sphi = cons->GetStartPhiAngle()/TG4G3Units::Angle();
170 G4double dphi = cons->GetDeltaPhiAngle()/TG4G3Units::Angle();
172 // compose element string template
173 G4String quota = "\"";
174 G4String element1 = "<cons name=\"" + lvName + quota;
175 G4String element2 = "material=\"" + materialName + quota;
176 G4String element3 = "profile=\"";
177 G4String element4 = "Rio1_Rio2_Z =\"";
178 G4String element5 = "\" />";
179 G4String indention = fkBasicIndention + fkBasicIndention;
182 fOutFile << fkBasicIndention << element1 << G4endl
183 << indention << element2 << G4endl
184 << indention << element3
185 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
186 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi
188 << indention << element4
189 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin1 << " "
190 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin2 << " "
191 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax1 << " "
192 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax2 << " "
193 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
194 << element5 << G4endl << G4endl;
197 //_____________________________________________________________________________
198 void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd,
199 G4String materialName)
201 // Writes G4Trd solid.
205 G4double x1 = trd->GetXHalfLength1()/TG4G3Units::Length()*2;
206 G4double x2 = trd->GetXHalfLength2()/TG4G3Units::Length()*2;
207 G4double y1 = trd->GetYHalfLength1()/TG4G3Units::Length()*2;
208 G4double y2 = trd->GetYHalfLength2()/TG4G3Units::Length()*2;
209 G4double hz = trd->GetZHalfLength()/TG4G3Units::Length()*2;
211 // compose element string template
212 G4String quota = "\"";
213 G4String element1 = "<trd name=\"" + lvName + quota;
214 G4String element2 = "material=\"" + materialName + quota;
215 G4String element3 = "Xmp_Ymp_Z=\"";
216 G4String element4 = "\" />";
217 G4String indention = fkBasicIndention + fkBasicIndention;
220 fOutFile << fkBasicIndention << element1 << G4endl
221 << indention << element2 << G4endl
222 << indention << element3
223 << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
224 << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
225 << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
226 << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
227 << G4std::setw(fNW) << G4std::setprecision(fNP) << hz
228 << element4 << G4endl << G4endl;
231 //_____________________________________________________________________________
232 void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap,
233 G4String materialName)
235 // Writes G4Trap solid.
239 G4double dz = trap->GetZHalfLength()/TG4G3Units::Length()*2.;
240 G4ThreeVector symAxis = trap->GetSymAxis();
241 G4double y1 = trap->GetYHalfLength1()/TG4G3Units::Length()*2.;
242 G4double x1 = trap->GetXHalfLength1()/TG4G3Units::Length()*2.;
243 G4double x2 = trap->GetXHalfLength2()/TG4G3Units::Length()*2.;
244 G4double tanAlpha1 = trap->GetTanAlpha1();
245 G4double y2 = trap->GetYHalfLength2()/TG4G3Units::Length()*2.;
246 G4double x3 = trap->GetXHalfLength3()/TG4G3Units::Length()*2.;
247 G4double x4 = trap->GetXHalfLength4()/TG4G3Units::Length()*2.;
248 G4double tanAlpha2 = trap->GetTanAlpha2();
250 // ordering of parameters in XML element
251 // Xmumdpupd_Ymp_Z: 2x2 2x1 2x4 2x3 2y2 2y1 2dz
252 // inclination: atan(symAxis.x/symAxis.z), atan(symAxis.y/symAxis.z)
253 // declination: alpha1, alpha2
256 G4double inc1 = atan(symAxis.x()/symAxis.z()) / deg;
257 G4double inc2 = atan(symAxis.y()/symAxis.z()) / deg;
258 G4double alpha1 = atan(tanAlpha1) / deg;
259 G4double alpha2 = atan(tanAlpha2) / deg;
261 // compose element string template
262 G4String quota = "\"";
263 G4String element1 = "<trap name=\"" + lvName + quota;
264 G4String element2 = "material=\"" + materialName + quota;
265 G4String element3 = "Xmumdpupd_Ymp_Z=\"";
266 G4String element4 = "inclination=\"";
267 G4String element5 = "declination=\"";
268 G4String element6 = "\" />";
269 G4String indention = fkBasicIndention + fkBasicIndention;
272 fOutFile << fkBasicIndention << element1 << G4endl
273 << indention << element2 << G4endl
274 << indention << element3
275 << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " "
276 << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " "
277 << G4std::setw(fNW) << G4std::setprecision(fNP) << x4 << " "
278 << G4std::setw(fNW) << G4std::setprecision(fNP) << x3 << " "
279 << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " "
280 << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " "
281 << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
283 << indention << element4
284 << G4std::setw(fNW) << G4std::setprecision(fNP) << inc1 << " "
285 << G4std::setw(fNW) << G4std::setprecision(fNP) << inc2
287 << indention << element5
288 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha1 << " "
289 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha2
290 << element6 << G4endl << G4endl;
293 //_____________________________________________________________________________
294 void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para,
295 G4String materialName)
297 // Writes G4Para solid.
301 G4double dx = para->GetXHalfLength()/TG4G3Units::Length()*2.;
302 G4double dy = para->GetYHalfLength()/TG4G3Units::Length()*2.;
303 G4double dz = para->GetZHalfLength()/TG4G3Units::Length()*2.;
304 G4double tanAlpha = para->GetTanAlpha();
305 G4ThreeVector symAxis = para->GetSymAxis();
307 G4double alpha = atan(tanAlpha) / deg;
308 G4double theta = acos(symAxis.z()) / deg;
313 phi = atan(symAxis.y()/symAxis.x()) / deg;
315 // compose element string template
316 G4String quota = "\"";
317 G4String element1 = "<para name=\"" + lvName + quota;
318 G4String element2 = "material=\"" + materialName + quota;
319 G4String element3 = "X_Y_Z=\"";
320 G4String element4 = "alpha=\"";
321 G4String element5 = "theta=\"";
322 G4String element6 = "phi= \"";
323 G4String element7 = "\" />";
324 G4String indention = fkBasicIndention + fkBasicIndention;
327 fOutFile << fkBasicIndention << element1 << G4endl
328 << indention << element2 << G4endl
329 << indention << element3
330 << G4std::setw(fNW) << G4std::setprecision(fNP) << dx << " "
331 << G4std::setw(fNW) << G4std::setprecision(fNP) << dy << " "
332 << G4std::setw(fNW) << G4std::setprecision(fNP) << dz
334 << indention << element4
335 << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha
337 << indention << element5
338 << G4std::setw(fNW) << G4std::setprecision(fNP) << theta
340 << indention << element6
341 << G4std::setw(fNW) << G4std::setprecision(fNP) << phi
342 << element7 << G4endl << G4endl;
345 //_____________________________________________________________________________
346 void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone,
347 G4String materialName)
349 // Writes G4Polycone solid.
352 // get profile parameters
353 G4double sphi = polycone->GetStartPhi()/TG4G3Units::Angle();
354 G4double ephi = polycone->GetEndPhi()/TG4G3Units::Angle();
356 // get polycone Z planes parameters
357 TG4Polycone historicalPolycone = TG4Polycone(*polycone);
359 G4int nofZPlanes = historicalPolycone.GetNofZPlanes();
360 G4double* rminArray = historicalPolycone.GetRmin();
361 G4double* rmaxArray = historicalPolycone.GetRmax();
362 G4double* zArray = historicalPolycone.GetZ();
364 // compose element string template
365 G4String quota = "\"";
366 G4String element1 = "<pcon name=\"" + lvName + quota;
367 G4String element2 = "material=\"" + materialName + quota;
368 G4String element3 = "profile=\"";
369 G4String element4 = "\" >";
370 G4String element5 = "<polyplane Rio_Z=\"";
371 G4String element6 = "\" />";
372 G4String element7 = "</pcon>";
373 G4String indention = fkBasicIndention + fkBasicIndention;
375 // write pcon element
376 fOutFile << fkBasicIndention << element1 << G4endl
377 << indention << element2 << G4endl
378 << indention << element3
379 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
380 << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
381 << element4 << G4endl;
383 // write polyplane elements
384 for (G4int i=0; i<nofZPlanes; i++) {
387 G4double rmin = rminArray[i]/TG4G3Units::Length();
388 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
389 G4double z = zArray[i]/TG4G3Units::Length();
391 fOutFile << indention << element5
392 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " "
393 << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " "
394 << G4std::setw(fNW) << G4std::setprecision(fNP) << z
399 // close pcon element
400 fOutFile << fkBasicIndention
401 << element7 << G4endl << G4endl;
404 //_____________________________________________________________________________
405 void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra,
406 G4String materialName)
408 // Writes G4Polycone solid.
412 G4int nofSides = polyhedra->GetNumSide();
413 G4double sphi = polyhedra->GetStartPhi()/TG4G3Units::Angle();
414 G4double ephi = polyhedra->GetEndPhi()/TG4G3Units::Angle();
416 // get polyhedra Z planes parameters
417 TG4Polyhedra historicalPolyhedra = TG4Polyhedra(*polyhedra);
419 G4int nofZPlanes = historicalPolyhedra.GetNofZPlanes();
420 G4double* rminArray = historicalPolyhedra.GetRmin();
421 G4double* rmaxArray = historicalPolyhedra.GetRmax();
422 G4double* zArray = historicalPolyhedra.GetZ();
424 // compose element string template
425 G4String quota = "\"";
426 G4String element1 = "<phedra name=\"" + lvName + quota;
427 G4String element2 = "material=\"" + materialName + quota;
428 G4String element3 = "profile=\"";
429 G4String element4 = "sides =\"";
430 G4String element5 = "Ris=\"";
431 G4String element6 = "Ros=\"";
432 G4String element7 = "Zs =\"";
433 G4String element8 = "\" />";
434 G4String indention = fkBasicIndention + fkBasicIndention;
437 fOutFile << fkBasicIndention << element1 << G4endl
438 << indention << element2 << G4endl
439 << indention << element3
440 << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " "
441 << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi
443 << indention << element4
447 fOutFile << indention << element5;
449 for (i=0; i<nofZPlanes; i++) {
451 G4double rmin = rminArray[i]/TG4G3Units::Length();
452 if (i>0) fOutFile << " ";
453 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin;
455 fOutFile << quota << G4endl;
457 fOutFile << indention << element6;
458 for (i=0; i<nofZPlanes; i++) {
460 G4double rmax = rmaxArray[i]/TG4G3Units::Length();
461 if (i>0) fOutFile << " ";
462 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax;
464 fOutFile << quota << G4endl;
466 fOutFile << indention << element7;
467 for (i=0; i<nofZPlanes; i++) {
469 G4double z = zArray[i]/TG4G3Units::Length();
470 if (i>0) fOutFile << " ";
471 fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << z;
473 fOutFile << element8 << G4endl << G4endl;
479 //_____________________________________________________________________________
480 void TG4XMLConvertor::OpenMaterials(const G4String& version,
481 const G4String& date, const G4String& author,
482 const G4String dtdVersion)
484 // Writes section opening.
487 G4String element1 = "<materials version = \"";
488 G4String element2 = " date = \"";
489 G4String element3 = " author = \"";
490 G4String element4 = " DTD_version=\"";
491 G4String element5 = " >";
492 G4String quota = "\"";
495 fOutFile << element1 << version << quota << G4endl
496 << element2 << date << quota << G4endl
497 << element3 << author << quota << G4endl
498 << element4 << dtdVersion << quota
499 << element5 << G4endl;
502 //_____________________________________________________________________________
503 void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version,
504 const G4String& date, const G4String& author,
505 const G4String& topVolume)
507 // Writes section opening.
510 G4String element1 = "<section name = \"";
511 G4String element2 = " version = \"";
512 G4String element3 = " date = \"";
513 G4String element4 = " author = \"";
514 G4String element5 = " topVolume = \"";
515 G4String element6 = " >";
516 G4String quota = "\"";
519 fOutFile << element1 << name << quota << G4endl
520 << element2 << version << quota << G4endl
521 << element3 << date << quota << G4endl
522 << element4 << author << quota << G4endl
523 << element5 << topVolume << quota
524 << element6 << G4endl;
527 void TG4XMLConvertor::OpenComposition(const G4String& name)
529 // Writes composition opening.
532 G4String element = "<composition name=\"";
533 element.append(name);
534 element.append("\">");
537 fOutFile << fIndention
541 // increase indention
545 //_____________________________________________________________________________
546 void TG4XMLConvertor::CloseMaterials()
548 // Writes materials closing.
552 G4String element = "</materials>";
559 //_____________________________________________________________________________
560 void TG4XMLConvertor::CloseSection()
562 // Writes section closing.
566 G4String element = "</section>";
573 //_____________________________________________________________________________
574 void TG4XMLConvertor::CloseComposition()
576 // Writes composition closing.
579 // decrease indention
583 G4String element = "</composition>";
586 fOutFile << fIndention
591 //_____________________________________________________________________________
592 void TG4XMLConvertor::WriteMaterial(const G4Material* material)
594 // Writes G4Material.
595 // Not yet implemented, only XML comment element is written.
598 G4String name = material->GetName();
602 G4String element1 = "<!-- material = \"";
603 G4String element2 = "\" -->";
606 fOutFile << fkBasicIndention
612 //_____________________________________________________________________________
613 void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid,
614 G4String materialName)
616 // Finds G4Solid concrete type and calls writing function.
617 // For not yet implemented solids, only XML comment element is written.
620 // to be removed when materials are supported
621 materialName = "Hydrogen";
623 const G4Box* box = dynamic_cast<const G4Box*>(solid);
625 WriteBox(lvName, box, materialName);
629 const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(solid);
631 WriteTubs(lvName, tubs, materialName);
635 const G4Cons* cons = dynamic_cast<const G4Cons*>(solid);
637 WriteCons(lvName, cons, materialName);
641 const G4Trd* trd = dynamic_cast<const G4Trd*>(solid);
643 WriteTrd(lvName, trd, materialName);
647 const G4Trap* trap = dynamic_cast<const G4Trap*>(solid);
649 WriteTrap(lvName, trap, materialName);
653 const G4Para* para = dynamic_cast<const G4Para*>(solid);
655 WritePara(lvName, para, materialName);
659 const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(solid);
661 WritePolycone(lvName, polycone, materialName);
665 const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(solid);
667 WritePolyhedra(lvName, polyhedra, materialName);
671 // write comment line in case of unsupported
675 G4String element1 = "<!-- unsupported shape name= \"";
676 G4String element2 = "\" -->";
679 fOutFile << fkBasicIndention
680 << element1 << lvName
685 //_____________________________________________________________________________
686 void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation)
688 // Writes G4RotationMatrix.
689 // Not yet implemented, only XML comment element is written.
692 // return if this rotation was already written
693 G4int nofRotations = fRotations.size();
695 for (G4int i=0; i<nofRotations; i++)
696 if (fRotations[i] == rotation) return;
698 fRotations.push_back(rotation);
702 G4double xx = rotation->xx();
703 G4double xy = rotation->xy();
704 G4double xz = rotation->xz();
705 G4double yx = rotation->yx();
706 G4double yy = rotation->yy();
707 G4double yz = rotation->yz();
708 G4double zx = rotation->zx();
709 G4double zy = rotation->zy();
710 G4double zz = rotation->zz();
712 TG4Globals::AppendNumberToString(id, ++fRotationCounter);
714 // compose element string template
715 G4String quota = "\"\n";
716 G4String element1 = "<rot_matrix id=\"####### XX_XY_XZ=\"";
717 G4String element2 = " YX_YY_YZ=\"";
718 G4String element3 = " ZX_ZY_ZZ=\"";
719 G4String element4 = "\" />";
722 PutName(element1, id, "#");
725 fOutFile << fkBasicIndention
727 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
728 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
729 << G4std::setw(8) << G4std::setprecision(5) << xz << quota
732 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
733 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
734 << G4std::setw(8) << G4std::setprecision(5) << yz << quota
737 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
738 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
739 << G4std::setw(8) << G4std::setprecision(5) << zz
744 //_____________________________________________________________________________
745 void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position)
747 // Writes position without rotation with a given solid name.
751 G4double x = position.x()/TG4G3Units::Length();
752 G4double y = position.y()/TG4G3Units::Length();
753 G4double z = position.z()/TG4G3Units::Length();
755 // compose element string template
756 G4String element1 = "<posXYZ volume=\"########### X_Y_Z=\"";
757 G4String element2 = "\" />";
760 PutName(element1, lvName, "#");
763 fOutFile << fIndention
765 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
766 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
767 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z
772 //_____________________________________________________________________________
773 void TG4XMLConvertor::WritePositionWithRotation(
774 G4String lvName, G4ThreeVector position,
775 const G4RotationMatrix* rotation)
777 // Writes position with rotation with a given solid name.
778 // Not yet implemented, only XML comment element is written.
782 G4double x = position.x()/TG4G3Units::Length();
783 G4double y = position.y()/TG4G3Units::Length();
784 G4double z = position.z()/TG4G3Units::Length();
785 G4double xx = rotation->xx();
786 G4double xy = rotation->xy();
787 G4double xz = rotation->xz();
788 G4double yx = rotation->yx();
789 G4double yy = rotation->yy();
790 G4double yz = rotation->yz();
791 G4double zx = rotation->zx();
792 G4double zy = rotation->zy();
793 G4double zz = rotation->zz();
798 while (i<fRotations.size() && fRotations[i] != rotation) i++;
799 if (i==fRotations.size()) {
800 G4String text = "TG4XMLConvertor::WritePositionWithRotation: ";
801 text = text + " Unknown rotation - fatal error.";
802 TG4Globals::Exception(text);
805 TG4Globals::AppendNumberToString(id, i);
808 // compose element string template
809 G4String quota = "\"\n";
810 G4String element1 = "<transform volume=\"########### pos=\"";
811 G4String element2 = " rot=\"";
812 G4String element3 = " ";
813 G4String element4 = "\" />";
816 PutName(element1, lvName, "#");
819 fOutFile << fIndention
821 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " "
822 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " "
823 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z << quota
826 << G4std::setw(8) << G4std::setprecision(5) << xx << " "
827 << G4std::setw(8) << G4std::setprecision(5) << xy << " "
828 << G4std::setw(8) << G4std::setprecision(5) << xz << G4endl
831 << G4std::setw(8) << G4std::setprecision(5) << yx << " "
832 << G4std::setw(8) << G4std::setprecision(5) << yy << " "
833 << G4std::setw(8) << G4std::setprecision(5) << yz << G4endl
836 << G4std::setw(8) << G4std::setprecision(5) << zx << " "
837 << G4std::setw(8) << G4std::setprecision(5) << zy << " "
838 << G4std::setw(8) << G4std::setprecision(5) << zz
843 //_____________________________________________________________________________
844 void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr)
846 // Writes position without rotation with a given solid name.
855 pvr->GetReplicationData(axis, nReplicas, width, offset, consuming);
859 case kXAxis: tag = "X"; break;
860 case kYAxis: tag = "Y"; break;
861 case kZAxis: tag = "Z"; break;
862 case kRho: tag = "R"; break;
863 case kPhi: tag = "Phi"; break;
867 G4double value0 = offset;
868 G4double dValue = width;
870 value0 = value0/TG4G3Units::Length();
871 dValue = dValue/TG4G3Units::Length();
874 value0 = value0/TG4G3Units::Angle();
875 dValue = dValue/TG4G3Units::Angle();
878 // set tag and attributes names
879 G4String a0 = "mpos"; a0 = a0 + tag;
880 G4String a1 = tag; a1 = a1 + "0";
881 G4String a2 = "d"; a2 = a2 + tag;
883 // compose element string template
884 G4String element1 = "<" + a0 + " volume=\"########### ncopy=\"";
885 G4String element2 = "\" " + a1 + "=\"";
886 G4String element3 = "\" " + a2 + "=\"";
887 G4String element4 = "\" />";
890 PutName(element1, lvName, "#");
893 fOutFile << fIndention
895 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << nReplicas
897 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << value0
899 << G4std::setw(fNW+1) << G4std::setprecision(fNP) << dValue
904 //_____________________________________________________________________________
905 void TG4XMLConvertor::WriteEmptyLine()
907 // Writes empty line.
913 //_____________________________________________________________________________
914 void TG4XMLConvertor::IncreaseIndention()
916 // increase indention
917 fIndention.append(fkBasicIndention);
920 //_____________________________________________________________________________
921 void TG4XMLConvertor::DecreaseIndention()
923 // decrease indention
924 fIndention.replace(fIndention.find(fkBasicIndention), 3 , "");