43#include "CLHEP/Geometry/Transform3D.h"
44#include "CLHEP/Units/SystemOfUnits.h"
45#include "CLHEP/Vector/Rotation.h"
46#include "CLHEP/Vector/ThreeVector.h"
57const int XmlVGM::AGDDWriter::fgkDefaultNumWidth = 7;
58const int XmlVGM::AGDDWriter::fgkDefaultNumPrecision = 4;
59const std::string XmlVGM::AGDDWriter::fgkCompNameExtension =
"_comp";
60const std::string XmlVGM::AGDDWriter::fgkElementNameExtension =
"_e";
61const std::string XmlVGM::AGDDWriter::fgkMaterialNameExtension =
"_mat";
62const double XmlVGM::AGDDWriter::fgkCarTolerance = 1e-10;
63const double XmlVGM::AGDDWriter::fgkAngTolerance = 1e-8;
67 const std::string& author,
const std::string dtdVersion)
72 fDtdVersion(dtdVersion),
73 fkBasicIndention(
" "),
74 fIndention(fkBasicIndention),
75 fNW(fgkDefaultNumWidth),
76 fNP(fgkDefaultNumPrecision)
83 fOutFile.width(fgkDefaultNumWidth);
84 fOutFile.precision(fgkDefaultNumPrecision);
104std::string XmlVGM::AGDDWriter::ElementSymbol(
110 std::string symbol = element->
Symbol();
112 symbol = element->
Name();
113 symbol.append(fgkElementNameExtension);
120void XmlVGM::AGDDWriter::RegisterName(
const std::string& name,
bool warning)
126 if (fAGDDNames.find(name) == fAGDDNames.end())
127 fAGDDNames.insert(name);
129 std::cerr <<
"+++ Warning +++: " << std::endl;
130 std::cerr <<
" Duplicated name has occured: \"" << name <<
"\""
131 <<
" in geometry." << std::endl;
132 std::cerr <<
" Duplicated names are not allowed in AGDD." << std::endl;
137double XmlVGM::AGDDWriter::Round2(
double number)
const
142 double precision = fNP;
143 return ClhepVGM::Round(number * pow(10., precision)) / pow(10., precision);
152 roundedRotation[0] = Round2(rotation[0] / AngleUnit());
153 roundedRotation[1] = Round2(rotation[1] / AngleUnit());
154 roundedRotation[2] = Round2(rotation[2] / AngleUnit());
156 if (roundedRotation[0] == 0. && roundedRotation[1] == 0. &&
157 roundedRotation[2] == 0.)
165void XmlVGM::AGDDWriter::WriteBooleanSolid(std::string volumeName,
175 std::string nameA = volumeName +
"_constA";
176 std::string nameB = volumeName +
"_constB";
177 WriteSolid(nameA, solidA, mediumName);
178 WriteSolid(nameB, solidB, mediumName);
206 std::string element1;
207 std::string element3;
210 element1 =
"<intersection name=\"";
211 element3 =
"</intersection>";
214 element1 =
"<subtraction name=\"";
215 element3 =
"</subtraction>";
218 element1 =
"<union name=\"";
219 element3 =
"</union>";
224 std::string element2 =
"\" >";
225 std::string indention = fIndention;
228 fOutFile << fIndention << element1 << volumeName << element2 << std::endl;
231 fIndention = fIndention + fkBasicIndention;
232 WritePlacement(nameA, position0);
236 WritePlacementWithRotationAndReflection(nameB, position, rotation);
237 else if (IsIdentity(rotation))
238 WritePlacement(nameB, position);
240 WritePlacementWithRotation(nameB, position, rotation);
242 fIndention = indention;
244 fOutFile << fIndention << element3 << std::endl << std::endl;
248void XmlVGM::AGDDWriter::WriteBox(std::string volumeName,
double hx,
double hy,
249 double hz, std::string mediumName)
254 double x = hx / LengthUnit() * 2.;
255 double y = hy / LengthUnit() * 2.;
256 double z = hz / LengthUnit() * 2.;
259 std::string quota =
"\"";
260 std::string element1 =
"<box name=\"" + volumeName + quota;
261 std::string element2 =
"medium=\"" + mediumName + quota;
262 std::string element3 =
"X_Y_Z=\"";
263 std::string element4 =
"\" />";
264 std::string indention = fkBasicIndention + fkBasicIndention;
267 fOutFile << fkBasicIndention << element1 << std::endl
268 << indention << element2 << std::endl
269 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
270 << x <<
"; " << std::setw(fNW) << std::setprecision(fNP) << y <<
"; "
271 << std::setw(fNW) << std::setprecision(fNP) << z << element4
277void XmlVGM::AGDDWriter::WriteBox(
278 std::string volumeName,
const VGM::IBox* box, std::string mediumName)
287void XmlVGM::AGDDWriter::WriteTubs(
288 std::string volumeName,
const VGM::ITubs* tubs, std::string mediumName)
295 double hz = tubs->
ZHalfLength() / LengthUnit() * 2.;
296 double sphi = tubs->
StartPhi() / AngleUnit();
297 double dphi = tubs->
DeltaPhi() / AngleUnit();
300 std::string quota =
"\"";
301 std::string element1 =
"<tubs name=\"" + volumeName + quota;
302 std::string element2 =
"medium=\"" + mediumName + quota;
303 std::string element3 =
"profile=\"";
304 std::string element4 =
"Rio_Z =\"";
305 std::string element5 =
"\" />";
306 std::string indention = fkBasicIndention + fkBasicIndention;
309 fOutFile << fkBasicIndention << element1 << std::endl
310 << indention << element2 << std::endl
311 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
312 << sphi <<
"; " << std::setw(fNW) << std::setprecision(fNP) << dphi
313 << quota << std::endl
314 << indention << element4 << std::setw(fNW) << std::setprecision(fNP)
315 << rmin <<
"; " << std::setw(fNW) << std::setprecision(fNP) << rmax
316 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << hz << element5
322void XmlVGM::AGDDWriter::WriteCons(
323 std::string volumeName,
const VGM::ICons* cons, std::string mediumName)
332 double hz = cons->
ZHalfLength() / LengthUnit() * 2.;
333 double sphi = cons->
StartPhi() / AngleUnit();
334 double dphi = cons->
DeltaPhi() / AngleUnit();
337 std::string quota =
"\"";
338 std::string element1 =
"<cons name=\"" + volumeName + quota;
339 std::string element2 =
"medium=\"" + mediumName + quota;
340 std::string element3 =
"profile=\"";
341 std::string element4 =
"Rio1_Rio2_Z =\"";
342 std::string element5 =
"\" />";
343 std::string indention = fkBasicIndention + fkBasicIndention;
346 fOutFile << fkBasicIndention << element1 << std::endl
347 << indention << element2 << std::endl
348 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
349 << sphi <<
"; " << std::setw(fNW) << std::setprecision(fNP) << dphi
350 << quota << std::endl
351 << indention << element4 << std::setw(fNW) << std::setprecision(fNP)
352 << rmin1 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << rmin2
353 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << rmax1 <<
"; "
354 << std::setw(fNW) << std::setprecision(fNP) << rmax2 <<
"; "
355 << std::setw(fNW) << std::setprecision(fNP) << hz << element5
361void XmlVGM::AGDDWriter::WriteTrd(
362 std::string volumeName,
const VGM::ITrd* trd, std::string mediumName)
374 std::string quota =
"\"";
375 std::string element1 =
"<trd name=\"" + volumeName + quota;
376 std::string element2 =
"medium=\"" + mediumName + quota;
377 std::string element3 =
"Xmp_Ymp_Z=\"";
378 std::string element4 =
"\" />";
379 std::string indention = fkBasicIndention + fkBasicIndention;
382 fOutFile << fkBasicIndention << element1 << std::endl
383 << indention << element2 << std::endl
384 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
385 << x1 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << x2
386 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << y1 <<
"; "
387 << std::setw(fNW) << std::setprecision(fNP) << y2 <<
"; "
388 << std::setw(fNW) << std::setprecision(fNP) << hz << element4
394void XmlVGM::AGDDWriter::WriteTrap(
395 std::string volumeName,
const VGM::ITrap* trap, std::string mediumName)
400 double dz = trap->
ZHalfLength() / LengthUnit() * 2.;
401 double theta = trap->
Theta() / AngleUnit();
402 double phi = trap->
Phi() / AngleUnit();
410 double alpha2 = trap->
AlphaPlusZ() / AngleUnit();
418 double thetaCphi = tan(theta * deg) * cos(phi * deg);
419 double thetaSphi = tan(theta * deg) * sin(phi * deg);
421 1.0 / sqrt(1 + thetaCphi * thetaCphi + thetaSphi * thetaSphi);
423 CLHEP::Hep3Vector symAxis(
424 thetaCphi * cosTheta, thetaSphi * cosTheta, cosTheta);
425 double inc1 = atan(symAxis.x() / symAxis.z()) / deg;
426 double inc2 = atan(symAxis.y() / symAxis.z()) / deg;
429 std::string quota =
"\"";
430 std::string element1 =
"<trap name=\"" + volumeName + quota;
431 std::string element2 =
"medium=\"" + mediumName + quota;
432 std::string element3 =
"Xmumdpupd_Ymp_Z=\"";
433 std::string element4 =
"inclination=\"";
434 std::string element5 =
"declination=\"";
435 std::string element6 =
"\" />";
436 std::string indention = fkBasicIndention + fkBasicIndention;
439 fOutFile << fkBasicIndention << element1 << std::endl
440 << indention << element2 << std::endl
441 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
442 << x2 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << x1
443 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << x4 <<
"; "
444 << std::setw(fNW) << std::setprecision(fNP) << x3 <<
"; "
445 << std::setw(fNW) << std::setprecision(fNP) << y2 <<
"; "
446 << std::setw(fNW) << std::setprecision(fNP) << y1 <<
"; "
447 << std::setw(fNW) << std::setprecision(fNP) << dz << quota
449 << indention << element4 << std::setw(fNW) << std::setprecision(fNP)
450 << inc1 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << inc2
451 << quota << std::endl
452 << indention << element5 << std::setw(fNW) << std::setprecision(fNP)
453 << alpha1 <<
"; " << std::setw(fNW) << std::setprecision(fNP)
454 << alpha2 << element6 << std::endl
459void XmlVGM::AGDDWriter::WritePara(
460 std::string volumeName,
const VGM::IPara* para, std::string mediumName)
465 double dx = para->
XHalfLength() / LengthUnit() * 2.;
466 double dy = para->
YHalfLength() / LengthUnit() * 2.;
467 double dz = para->
ZHalfLength() / LengthUnit() * 2.;
468 double alpha = para->
Alpha() / AngleUnit();
469 double theta = para->
Theta() / AngleUnit();
470 double phi = para->
Phi() / AngleUnit();
473 std::string quota =
"\"";
474 std::string element1 =
"<para name=\"" + volumeName + quota;
475 std::string element2 =
"medium=\"" + mediumName + quota;
476 std::string element3 =
"X_Y_Z=\"";
477 std::string element4 =
"alpha=\"";
478 std::string element5 =
"theta=\"";
479 std::string element6 =
"phi= \"";
480 std::string element7 =
"\" />";
481 std::string indention = fkBasicIndention + fkBasicIndention;
484 fOutFile << fkBasicIndention << element1 << std::endl
485 << indention << element2 << std::endl
486 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
487 << dx <<
"; " << std::setw(fNW) << std::setprecision(fNP) << dy
488 <<
"; " << std::setw(fNW) << std::setprecision(fNP) << dz << quota
490 << indention << element4 << std::setw(fNW) << std::setprecision(fNP)
491 << alpha << quota << std::endl
492 << indention << element5 << std::setw(fNW) << std::setprecision(fNP)
493 << theta << quota << std::endl
494 << indention << element6 << std::setw(fNW) << std::setprecision(fNP)
495 << phi << element7 << std::endl
500void XmlVGM::AGDDWriter::WritePolycone(std::string volumeName,
506 double sphi = polycone->
StartPhi() / AngleUnit();
507 double dphi = polycone->
DeltaPhi() / AngleUnit();
513 double* zArray = polycone->
ZValues();
516 std::string quota =
"\"";
517 std::string element1 =
"<pcon name=\"" + volumeName + quota;
518 std::string element2 =
"medium=\"" + mediumName + quota;
519 std::string element3 =
"profile=\"";
520 std::string element4 =
"\" >";
521 std::string element5 =
"<polyplane Rio_Z=\"";
522 std::string element6 =
"\" />";
523 std::string element7 =
"</pcon>";
524 std::string indention = fkBasicIndention + fkBasicIndention;
527 fOutFile << fkBasicIndention << element1 << std::endl
528 << indention << element2 << std::endl
529 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
530 << sphi <<
"; " << std::setw(fNW) << std::setprecision(fNP) << dphi
531 << element4 << std::endl;
534 for (
int i = 0; i < nofZPlanes; i++) {
537 double rmin = rminArray[i] / LengthUnit();
538 double rmax = rmaxArray[i] / LengthUnit();
539 double z = zArray[i] / LengthUnit();
541 fOutFile << indention << element5 << std::setw(fNW)
542 << std::setprecision(fNP) << rmin <<
"; " << std::setw(fNW)
543 << std::setprecision(fNP) << rmax <<
"; " << std::setw(fNW)
544 << std::setprecision(fNP) << z << element6 << std::endl;
548 fOutFile << fkBasicIndention << element7 << std::endl << std::endl;
552void XmlVGM::AGDDWriter::WritePolyhedra(std::string volumeName,
558 int nofSides = polyhedra->
NofSides();
559 double sphi = polyhedra->
StartPhi() / AngleUnit();
560 double dphi = polyhedra->
DeltaPhi() / AngleUnit();
566 double* zArray = polyhedra->
ZValues();
569 std::string quota =
"\"";
570 std::string element1 =
"<phedra name=\"" + volumeName + quota;
571 std::string element2 =
"medium=\"" + mediumName + quota;
572 std::string element3 =
"profile=\"";
573 std::string element4 =
"sides =\"";
574 std::string element5 =
"Ris=\"";
575 std::string element6 =
"Ros=\"";
576 std::string element7 =
"Zs =\"";
577 std::string element8 =
"\" />";
578 std::string indention = fkBasicIndention + fkBasicIndention;
581 fOutFile << fkBasicIndention << element1 << std::endl
582 << indention << element2 << std::endl
583 << indention << element3 << std::setw(fNW) << std::setprecision(fNP)
584 << sphi <<
"; " << std::setw(fNW) << std::setprecision(fNP) << dphi
585 << quota << std::endl
586 << indention << element4 << nofSides << quota << std::endl;
588 fOutFile << indention << element5;
590 for (i = 0; i < nofZPlanes; i++) {
592 double rmin = rminArray[i] / LengthUnit();
593 if (i > 0) fOutFile <<
"; ";
594 fOutFile << std::setw(fNW) << std::setprecision(fNP) << rmin;
596 fOutFile << quota << std::endl;
598 fOutFile << indention << element6;
599 for (i = 0; i < nofZPlanes; i++) {
601 double rmax = rmaxArray[i] / LengthUnit();
602 if (i > 0) fOutFile <<
"; ";
603 fOutFile << std::setw(fNW) << std::setprecision(fNP) << rmax;
605 fOutFile << quota << std::endl;
607 fOutFile << indention << element7;
608 for (i = 0; i < nofZPlanes; i++) {
610 double z = zArray[i] / LengthUnit();
611 if (i > 0) fOutFile <<
"; ";
612 fOutFile << std::setw(fNW) << std::setprecision(fNP) << z;
614 fOutFile << element8 << std::endl << std::endl;
618void XmlVGM::AGDDWriter::WriteNotSupportedSolid(
619 std::string name, std::string mediumName)
625 std::string element1 =
"<!-- !!! unsupported shape !!! name= \"";
626 std::string element2 =
"\" -->";
627 std::string element3 =
"<!-- dummy box is written instead -->";
630 fOutFile << fIndention << element1 << name << element2 << std::endl
631 << fIndention << element3 << std::endl;
634 WriteBox(name, 1.0, 1.0, 1.0, mediumName);
638void XmlVGM::AGDDWriter::WritePlacementWithRotation(std::string volumeName,
644 double x = position[0] / LengthUnit();
645 double y = position[1] / LengthUnit();
646 double z = position[2] / LengthUnit();
649 CLHEP::HepRotation hepRotation;
650 hepRotation.rotateX(rotation[0] * deg);
651 hepRotation.rotateY(rotation[1] * deg);
652 hepRotation.rotateZ(rotation[2] * deg);
654 double xx = hepRotation.xx();
655 double xy = hepRotation.xy();
656 double xz = hepRotation.xz();
657 double yx = hepRotation.yx();
658 double yy = hepRotation.yy();
659 double yz = hepRotation.yz();
660 double zx = hepRotation.zx();
661 double zy = hepRotation.zy();
662 double zz = hepRotation.zz();
665 std::string quota =
"\"\n";
666 std::string element1 =
"<transform pos=\"";
667 std::string element2 =
" matrix=\"";
668 std::string element3 =
" ";
669 std::string element4 =
"\"> <volume name=\"";
670 std::string element5 =
"\"/>";
671 std::string element6 =
"</transform>";
674 fOutFile << fIndention << element1;
676 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, x,
"; ");
677 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, y,
"; ");
678 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, z, quota);
680 fOutFile << fIndention << element2;
682 SmartPut(fOutFile, 8, 5, 0, xx,
"; ");
683 SmartPut(fOutFile, 8, 5, 0, xy,
"; ");
684 SmartPut(fOutFile, 8, 5, 0, xz,
"; ");
686 fOutFile << std::endl << fIndention << element3;
688 SmartPut(fOutFile, 8, 5, 0, yx,
"; ");
689 SmartPut(fOutFile, 8, 5, 0, yy,
"; ");
690 SmartPut(fOutFile, 8, 5, 0, yz,
"; ");
692 fOutFile << std::endl << fIndention << element3;
694 SmartPut(fOutFile, 8, 5, 0, zx,
"; ");
695 SmartPut(fOutFile, 8, 5, 0, zy,
"; ");
696 SmartPut(fOutFile, 8, 5, 0, zz,
"");
698 fOutFile << element4 << volumeName << element5 << std::endl
699 << fIndention << element6 << std::endl;
703void XmlVGM::AGDDWriter::WritePlacementWithRotationAndReflection(
711 HepGeom::Translate3D translate3D(position[0], position[1], position[2]);
714 CLHEP::HepRotation hepRotation;
715 hepRotation.rotateX(rotation[0] * deg);
716 hepRotation.rotateY(rotation[1] * deg);
717 hepRotation.rotateZ(rotation[2] * deg);
718 HepGeom::Rotate3D rotate3D(hepRotation);
720 HepGeom::ScaleZ3D scale3D(-1.0);
722 HepGeom::Transform3D transform3D = translate3D * rotate3D * scale3D;
724 CLHEP::Hep3Vector translation = transform3D.getTranslation();
725 double x = translation.x() / LengthUnit();
726 double y = translation.y() / LengthUnit();
727 double z = translation.z() / LengthUnit();
729 double xx = transform3D(0, 0);
730 double xy = transform3D(0, 1);
731 double xz = transform3D(0, 2);
732 double yx = transform3D(1, 0);
733 double yy = transform3D(1, 1);
734 double yz = transform3D(1, 2);
735 double zx = transform3D(2, 0);
736 double zy = transform3D(2, 1);
737 double zz = transform3D(2, 2);
740 std::string quota =
"\"\n";
741 std::string element1 =
"<transform pos=\"";
742 std::string element2 =
" matrix=\"";
743 std::string element3 =
" ";
744 std::string element4 =
"\"> <volume name=\"";
745 std::string element5 =
"\"/>";
746 std::string element6 =
"</transform>";
749 fOutFile << fIndention << element1;
751 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, x,
"; ");
752 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, y,
"; ");
753 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, z, quota);
755 fOutFile << fIndention << element2;
757 SmartPut(fOutFile, 8, 5, 0, xx,
"; ");
758 SmartPut(fOutFile, 8, 5, 0, xy,
"; ");
759 SmartPut(fOutFile, 8, 5, 0, xz,
"; ");
761 fOutFile << std::endl << fIndention << element3;
763 SmartPut(fOutFile, 8, 5, 0, yx,
"; ");
764 SmartPut(fOutFile, 8, 5, 0, yy,
"; ");
765 SmartPut(fOutFile, 8, 5, 0, yz,
"; ");
767 fOutFile << std::endl << fIndention << element3;
769 SmartPut(fOutFile, 8, 5, 0, zx,
"; ");
770 SmartPut(fOutFile, 8, 5, 0, zy,
"; ");
771 SmartPut(fOutFile, 8, 5, 0, zz,
"");
773 fOutFile << element4 << volumeName << element5 << std::endl
774 << fIndention << element6 << std::endl;
778void XmlVGM::AGDDWriter::WriteMultiplePlacement(
const std::string& volumeName,
779 VGM::Axis axis,
int nofReplicas,
double width,
double offset)
813 double value0 = -width * (nofReplicas - 1) * 0.5 + offset;
814 double dValue = width;
816 value0 = value0 / LengthUnit();
817 dValue = dValue / LengthUnit();
820 value0 = value0 / AngleUnit();
821 dValue = dValue / AngleUnit();
825 std::string a0 =
"mpos";
827 std::string a1 = tag;
829 std::string a2 =
"d";
833 std::string element1 =
"<" + a0 +
" ncopy=\"";
834 std::string element2 =
"\" " + a1 +
"=\"";
835 std::string element3 =
"\" " + a2 +
"=\"";
836 std::string element4 =
"\"> <volume name=\"";
837 std::string element5 =
"\"/>";
838 std::string element6 =
"</" + a0 +
">";
841 fOutFile << fIndention << element1 << std::setw(fNW + 1 - fNP) << nofReplicas
842 << element2 << std::setw(fNW + 1) << std::setprecision(fNP) << value0
843 << element3 << std::setw(fNW + 1) << std::setprecision(fNP) << dValue
844 << element4 << volumeName << element5 << std::endl
845 << fIndention << element6 << std::endl;
857 fOutFile.open(filePath.data(), std::ios::out);
860 std::cerr <<
" Cannot open " << filePath << std::endl;
861 std::cerr <<
"** Exception: Aborting execution **" << std::endl;
866 fOutFile.setf(std::ios::fixed, std::ios::floatfield);
876 fOutFile <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl
878 <<
"<AGDD DTD_version = \"v7\"" << std::endl
879 <<
" xmlns:xi=\"http://www.w3.org/2001/XInclude\">" << std::endl
881 <<
"<xi:include href=\"StandardColors.agdd\"/>" << std::endl
893 std::string element1 =
"<section DTD_version = \"";
894 std::string element2 =
" name = \"";
895 std::string element3 =
" version = \"";
896 std::string element4 =
" date = \"";
897 std::string element5 =
" author = \"";
898 std::string element6 =
" top_volume = \"";
899 std::string element7 =
" >";
900 std::string quota =
"\"";
902 std::string version = fVersion;
903 if (version ==
"Undefined") {
906 version = version.substr(1, version.size() - 2);
909 std::string name = topVolume;
910 name.append(fgkCompNameExtension);
912 std::string date =
Date();
915 fOutFile << element1 << fDtdVersion << quota << std::endl
916 << element2 << topVolume << quota << std::endl
917 << element3 << version << quota << std::endl
918 << element4 << date << quota << std::endl
919 << element5 << fAuthor << quota << std::endl
920 << element6 << name << quota << element7 << std::endl;
928 std::string element1 =
"<materials version = \"";
929 std::string element2 =
" date = \"";
930 std::string element3 =
" author = \"";
931 std::string element4 =
" DTD_version=\"";
932 std::string element5 =
" >";
933 std::string quota =
"\"";
935 std::string version = fVersion;
936 if (version ==
"Undefined") {
939 version = version.substr(1, version.size() - 2);
942 std::string date =
Date();
945 fOutFile << element1 << version << quota << std::endl
946 << element2 << date << quota << std::endl
947 << element3 << fAuthor << quota << std::endl
948 << element4 << fDtdVersion << quota << element5 << std::endl
957 std::string element1 =
"<media version = \"";
958 std::string element2 =
" date = \"";
959 std::string element3 =
" author = \"";
960 std::string element4 =
" DTD_version=\"";
961 std::string element5 =
" >";
962 std::string quota =
"\"";
964 std::string version = fVersion;
965 if (version ==
"Undefined") {
968 version = version.substr(1, version.size() - 2);
971 std::string date =
Date();
974 fOutFile << element1 << version << quota << std::endl
975 << element2 << date << quota << std::endl
976 << element3 << fAuthor << quota << std::endl
977 << element4 << fDtdVersion << quota << element5 << std::endl
983 const std::string& name,
const std::string& )
987 std::string compName = name;
988 compName.append(fgkCompNameExtension);
990 std::string element =
"<composition name=\"";
991 element.append(compName);
992 element.append(
"\">");
995 fOutFile << fIndention << element << std::endl;
1015 std::string element =
"</AGDD>";
1018 fOutFile << element << std::endl;
1027 std::string element =
"</section>";
1030 fOutFile << element << std::endl << std::endl;
1039 std::string element =
"</materials>";
1042 fOutFile << element << std::endl;
1051 std::string element =
"</media>";
1054 fOutFile << element << std::endl;
1063 DecreaseIndention();
1066 std::string element =
"</composition>";
1069 fOutFile << fIndention << element << std::endl;
1078 int theZ = isotope->
Z();
1079 int theN = isotope->
N();
1080 int theA = isotope->
N();
1090 if (theN == 0) theN = 1;
1093 std::string quota1 =
"\"";
1094 std::string quota2 =
"\" ";
1095 std::string element1 =
"<isotope name=\"";
1096 std::string element2 =
"z=\"";
1097 std::string element3 =
"n=\"";
1098 std::string element4 =
"a=\"";
1099 std::string element5 =
"\"/>";
1101 std::string indention = fIndention + fkBasicIndention;
1104 fOutFile << fIndention << element1 << name << quota1;
1105 for (
int i = 0; i < 8 - int(name.size()); i++) fOutFile <<
" ";
1107 fOutFile << element2 << std::setw(3) << theZ << quota2;
1110 fOutFile << element3 << std::setw(3) << theN << quota2;
1113 fOutFile << element4 << std::setw(3) << theA << element5;
1115 fOutFile << std::endl;
1123 std::string symbol = ElementSymbol(element);
1124 RegisterName(symbol);
1127 std::string quota1 =
"\"";
1128 std::string quota2 =
"\" ";
1129 std::string element1 =
"<element symbol=\"";
1130 std::string element2 =
"\">";
1131 std::string element6 =
"</element>";
1133 std::string indention = fIndention + fkBasicIndention;
1136 fOutFile << fIndention << element1 << symbol << element2 << std::endl;
1140 for (
int i = 0; i < element->
NofIsotopes(); i++) {
1144 int natomsInt = (int)(Round2(natoms * 100));
1146 std::string element3 =
"<addisotope name=\"";
1147 std::string element4 =
"natoms=\"";
1148 std::string element5 =
"\" />";
1150 fOutFile << indention << element3 << name << quota2;
1151 fOutFile << element4;
1153 fOutFile << std::setw(3) << natomsInt << element5;
1154 fOutFile << std::endl;
1158 double theZ = element->
Z();
1160 double theA = element->
A() / AtomicWeightUnit();
1164 if (theN == 0) theN = 1;
1166 std::string element3 =
"<atom zeff=\"";
1167 std::string element4 =
"aweight=\"";
1168 std::string element5 =
"\" />";
1170 fOutFile << indention << element3;
1171 SmartPut(fOutFile, fNW - 2, fNP, 0, theZ, quota2);
1173 fOutFile << element4;
1174 SmartPut(fOutFile, fNW - 2, fNP, 0, theA, element5);
1175 fOutFile << std::endl;
1178 fOutFile << fIndention << element6 << std::endl;
1186 std::string materialName =
1188 RegisterName(materialName);
1191 double density = material->
Density() / MassDensityUnit();
1194 std::string quota =
"\" ";
1195 std::string element1 =
"<material name=\"";
1196 std::string element2 =
"density=\"";
1197 std::string element3 =
"\">";
1198 std::string element4 =
"<addelement name=\"";
1199 std::string element5 =
"natoms=\"";
1200 std::string element6 =
"\"/>";
1201 std::string element7 =
"</material>";
1203 std::string indention = fIndention + fkBasicIndention;
1206 fOutFile << fIndention;
1207 fOutFile << element1 << materialName << quota;
1209 fOutFile << element2;
1210 SmartPut(fOutFile, fNW + 1, fNP, 0, density, element3);
1211 fOutFile << std::endl;
1213 for (
int i = 0; i < int(material->
NofElements()); i++) {
1214 double atomCount = material->
AtomCount(i);
1215 std::string elementSymbol = ElementSymbol(material->
Element(i));
1217 fOutFile << indention << element4 << elementSymbol << quota;
1218 fOutFile << element5;
1219 SmartPut(fOutFile, fNW, fNP, 0, atomCount, element6);
1220 fOutFile << std::endl;
1223 fOutFile << fIndention << element7 << std::endl;
1232 RegisterName(mediumName);
1235 std::string materialName =
1239 std::string quota =
"\" ";
1240 std::string element1 =
"<medium name=\"";
1241 std::string element2 =
"material=\"";
1242 std::string element3 =
"color=\"random\"";
1243 std::string element4 =
"sensitive=\"true\"";
1244 std::string element5 =
"parameters=\"";
1245 std::string element6 =
"; ";
1246 std::string element7 =
"\"/>";
1248 std::string indention = fIndention + fkBasicIndention;
1251 fOutFile << fIndention;
1252 fOutFile << element1 << mediumName << quota << std::endl;
1254 fOutFile << indention << element2 << materialName << quota << std::endl;
1255 fOutFile << indention << element3 << std::endl;
1256 fOutFile << indention << element4 << std::endl;
1257 fOutFile << indention << element5;
1260 double parameter = medium->
Parameter(i);
1261 std::string separator = element6;
1263 SmartPut(fOutFile, fNW, fNP, 0, parameter, separator);
1265 fOutFile << std::endl;
1274 RegisterName(mediumName);
1277 std::string materialName =
1281 std::string quota =
"\" ";
1282 std::string element1 =
"<medium name=\"";
1283 std::string element2 =
"material=\"";
1284 std::string element3 =
"color=\"random\"";
1285 std::string element4 =
"sensitive=\"true\"";
1286 std::string element5 =
"parameters=\"\"/>";
1288 std::string indention = fIndention + fkBasicIndention;
1291 fOutFile << fIndention;
1292 fOutFile << element1 << mediumName << quota << std::endl;
1294 fOutFile << indention << element2 << materialName << quota << std::endl;
1295 fOutFile << indention << element3 << std::endl;
1296 fOutFile << indention << element4 << std::endl;
1297 fOutFile << indention << element5 << std::endl;
1302 std::string volumeName,
const VGM::ISolid* solid, std::string mediumName)
1310 WriteBox(volumeName, box,
UpdateName(mediumName));
1315 WriteCons(volumeName, cons,
UpdateName(mediumName));
1328 WritePara(volumeName, para,
UpdateName(mediumName));
1333 WritePolycone(volumeName, polycone,
UpdateName(mediumName));
1339 WritePolyhedra(volumeName, polyhedra,
UpdateName(mediumName));
1356 WriteTrap(volumeName, trap,
UpdateName(mediumName));
1361 WriteTrd(volumeName, trd,
UpdateName(mediumName));
1366 WriteTubs(volumeName, tubs,
UpdateName(mediumName));
1372 WriteBooleanSolid(volumeName,
boolean,
UpdateName(mediumName));
1377 WriteNotSupportedSolid(volumeName,
UpdateName(mediumName));
1387 double x = position[0] / LengthUnit();
1388 double y = position[1] / LengthUnit();
1389 double z = position[2] / LengthUnit();
1392 std::string element1 =
"<posXYZ X_Y_Z=\"";
1393 std::string element2 =
"\"> <volume name=\"";
1394 std::string element3 =
"\"/>";
1395 std::string element4 =
"</posXYZ>";
1398 fOutFile << fIndention << element1;
1400 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, x,
"; ");
1401 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, y,
"; ");
1402 SmartPut(fOutFile, fNW + 1, fNP, fgkCarTolerance, z,
"");
1404 fOutFile << element2 << volumeName << element3 << std::endl
1405 << fIndention << element4 << std::endl;
1412 std::string volumeName = placement.
Volume()->
Name();
1413 std::string compName = volumeName;
1414 compName.append(fgkCompNameExtension);
1443 WritePlacementWithRotationAndReflection(volumeName, position, rotation);
1446 WritePlacementWithRotationAndReflection(compName, position, rotation);
1449 if (IsIdentity(rotation)) {
1450 WritePlacement(volumeName, position);
1452 if (nd > 0) WritePlacement(compName, position);
1455 WritePlacementWithRotation(volumeName, position, rotation);
1456 if (nd > 0) WritePlacementWithRotation(compName, position, rotation);
1470 if (halfGap != 0.) {
1471 std::cerr <<
"+++ Warning +++" << std::endl;
1472 std::cerr <<
" XmlVGM::Writer::WritePlacement: " << std::endl;
1473 std::cerr <<
" Multiple placement with a half gap is not supported. "
1475 std::cerr <<
" The half gap parameter will be ignored. " << std::endl;
1479 WriteMultiplePlacement(volumeName, axis, nReplicas, width, offset);
1483 WriteMultiplePlacement(compName, axis, nReplicas, width, offset);
1488 std::vector<VGM::Transform> transforms;
1489 std::vector<VGM::IVolume*> volumes;
1493 for (
size_t i=0; i<transforms.size(); ++i) {
1495 auto transform = transforms[i];
1496 auto volumeName = volumes[i]->Name();
1510 if (IsIdentity(rotation)) {
1511 WritePlacement(volumeName, position);
1513 WritePlacement(compName, position);
1517 WritePlacementWithRotation(volumeName, position, rotation);
1519 WritePlacementWithRotation(compName, position, rotation);
1525 std::cerr <<
"+++ Warning +++" << std::endl;
1526 std::cerr <<
" XmlVGM::Writer::WritePlacement: " << std::endl;
1527 std::cerr <<
" Unknown placement type. " << std::endl;
1528 std::cerr <<
" Volume \"" << placement.
Name() <<
"\" was not converted."
1538 fOutFile << std::endl;
1546 fIndention.append(fkBasicIndention);
1554 fIndention.replace(fIndention.find(fkBasicIndention), 3,
"");
The VGM interface to Boolean solids.
virtual ISolid * ConstituentSolidB() const =0
Return the second constituent solid.
virtual bool ToBeReflected() const =0
Return true if the solid has to be first reflected before being placed.
virtual ISolid * ConstituentSolidA() const =0
Return the first constituent solid.
virtual BooleanType BoolType() const =0
Return the Boolean type of this solid.
virtual Transform Displacement() const =0
Return the 3D displacement of the second constituent solid with respect to the first one.
The VGM interface to box solids.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double YHalfLength() const =0
Return the half-length along the y axis in mm.
virtual double XHalfLength() const =0
Return the half-length along the x axis in mm.
The VGM interface to cons solids.
virtual double DeltaPhi() const =0
Return the opening phi angle of the segment in deg.
virtual double OuterRadiusPlusZ() const =0
Return the outer radius at -z in mm.
virtual double OuterRadiusMinusZ() const =0
Return the outer radius at -z in mm.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double InnerRadiusMinusZ() const =0
Return the innner radius at -z in mm.
virtual double InnerRadiusPlusZ() const =0
Return the innner radius at +z in mm.
virtual double StartPhi() const =0
Return the starting phi angle of the segment in deg.
The VGM interface to elements.
virtual IIsotope * Isotope(int i) const =0
Return the i-th isotope constituing this element.
virtual int NofIsotopes() const =0
Return the number of isotopes constituing this element.
virtual double Z() const =0
Return the effective atomic number.
virtual double RelAbundance(int i) const =0
Return the relative abundance (the fraction of nb of atomes per volume) of the i-th isotope constitui...
virtual std::string Name() const =0
Return the name of this element.
virtual std::string Symbol() const =0
Return the symbol of this element.
virtual double A() const =0
Return the effective effective mass of a mole in g/mole.
virtual double N() const =0
Return the effective number of nucleons.
The VGM interface to elements.
virtual int N() const =0
Return the effective number of nucleons.
virtual int Z() const =0
Return the effective atomic number.
The VGM interface to materials.
virtual IElement * Element(int iel) const =0
Return the i-th element constituing this material.
virtual double AtomCount(int iel) const =0
Return the atom count of the i-th element constituing this material.
virtual double Density() const =0
Return the density in g/cm3.
virtual std::string Name() const =0
Return the name of this element.
virtual int NofElements() const =0
Return the number of elements constituing this material.
The VGM interface to tracking medium.
virtual IMaterial * Material() const =0
Return its associated material.
virtual int NofParameters() const =0
Return the number of defined parameters.
virtual double Parameter(int i) const =0
Return the i-th parameter.
virtual std::string Name() const =0
Return its name.
The VGM interface to para solids.
virtual double Alpha() const =0
Return angle formed by the y axis and by the plane joining the centre of the faces parallel to the z-...
virtual double Theta() const =0
Return polar angle of the line joining the centres of the faces at -hz and +hz in deg.
virtual double YHalfLength() const =0
Return half-length along the y axis in mm.
virtual double ZHalfLength() const =0
Return half-length along the z axis in mm.
virtual double XHalfLength() const =0
Return half-length along the x axis in mm.
virtual double Phi() const =0
Return azimuthal angle of the line joining the centres of the faces at -hz and +hz in deg.
The VGM interface to positions of volumes.
virtual PlacementType Type() const =0
Return the type of this placement.
virtual Transform Transformation() const =0
Return the 3D transformation (if simple placement)
virtual bool MultiplePlacementData(VGM::Axis &axis, int &nofItems, double &width, double &offset, double &halfGap) const =0
Fill the multiple placement data if relevant and return true; return false if not multiple placement.
virtual bool ParameterisedPlacementData(std::vector< VGM::Transform > &transforms, std::vector< VGM::IVolume * > &volumes) const =0
Fill the parameterised placement data if relevant and return true; return false if not parameterised ...
virtual std::string Name() const =0
Return the name of this placement.
virtual IVolume * Volume() const =0
Return the associated volume.
The VGM interface to polycone solids.
virtual double StartPhi() const =0
Return starting phi angle of the segment in deg.
virtual int NofZPlanes() const =0
Return number of planes perpendicular to the z axis.
virtual double * ZValues() const =0
Return the array of z positions of the planes in mm.
virtual double DeltaPhi() const =0
Return opening phi angle of the segment in deg.
virtual double * InnerRadiusValues() const =0
Return the array of inner radius of the planes in mm.
virtual double * OuterRadiusValues() const =0
Return the array of outer radius of the planes in mm.
The VGM interface to polyhedra solids.
virtual double * OuterRadiusValues() const =0
Return the array of outer radius of the planes in mm.
virtual int NofSides() const =0
Return number of sides of the cross section between the given phi limits.
virtual double StartPhi() const =0
Return starting phi angle of the segment in deg.
virtual double * InnerRadiusValues() const =0
Return the array of innner radius of the planes in mm.
virtual double * ZValues() const =0
Return the array of z positions of the planes in mm.
virtual double DeltaPhi() const =0
Return opening phi angle of the segment in deg.
virtual int NofZPlanes() const =0
Return number of planes perpendicular to the z axis.
The VGM interface to solids.
virtual SolidType Type() const =0
Return the type of this solid.
The VGM interface to trap solids.
virtual double Phi() const =0
Return the azimuthal angle of the line joining the centres of the faces at -hz and +hz in deg.
virtual double XHalfLengthPlusZMinusY() const =0
Return the half-length along x of the side at -hy of the face at +hz in m.
virtual double AlphaPlusZ() const =0
Return the angle with respect to the y axis from the centre of the side at -hy to the centre at +hy o...
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double YHalfLengthMinusZ() const =0
Return the half-length along y of the face at -hz in mm.
virtual double XHalfLengthMinusZMinusY() const =0
Return the half-length along x of the side at -hy of the face at -hz in mm.
virtual double YHalfLengthPlusZ() const =0
Return the half-length along y of the face at +hz in m.
virtual double XHalfLengthPlusZPlusY() const =0
Return the half-length along x of the side at +hy of the face at +hz in m.
virtual double Theta() const =0
Return the polar angle of the line joining the centres of the faces at -hz and +hz in deg.
virtual double AlphaMinusZ() const =0
Return the angle with respect to the y axis from the centre of the side at -hy to the centre at +hy o...
virtual double XHalfLengthMinusZPlusY() const =0
Return the half-length along x of the side at +hy of the face at +hz in mm.
The VGM interface to trd solids.
virtual double XHalfLengthPlusZ() const =0
Return the half-length along x at the surface positioned at +hz in mm.
virtual double YHalfLengthPlusZ() const =0
Return thehalf-length along y at the surface positioned at +hz in mm.
virtual double XHalfLengthMinusZ() const =0
Return the half-length along x at the surface positioned at -hz in mm.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double YHalfLengthMinusZ() const =0
Return the half-length along y at the surface positioned at -hz in mm.
The VGM interface to tubs solids.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in m.
virtual double StartPhi() const =0
Return the starting angle of the segment in deg.
virtual double DeltaPhi() const =0
Return the opening angle of the segment in deg.
virtual double InnerRadius() const =0
Return the inside radius in mm.
virtual double OuterRadius() const =0
Return the outside radius in mm.
virtual std::string Name() const =0
Return the name of this volume.
virtual int NofDaughters() const =0
Return the number of volume daughters.
The implementation of the interface for the XML writer that writes VGM geometry objects to XML define...
virtual void CloseMedia()
Write media definitions closing.
virtual void WriteMaterial(const VGM::IMaterial *material)
Write VGM material.
virtual void CloseSection(const std::string &)
Write the section closing (if present)
virtual void WriteMedium(const VGM::IMedium *medium)
Write VGM medium.
virtual void IncreaseIndention()
Increase indention.
virtual void OpenMaterials()
Write materials definitions opening.
virtual void CloseFile()
Close output file.
virtual void WriteSolid(std::string lvName, const VGM::ISolid *solid, std::string mediumName)
Write VGM solid.
virtual void CloseDocument()
Write XML document closing.
virtual void WriteElement(const VGM::IElement *element)
Write VGM element.
virtual void DecreaseIndention()
Decrease indention.
virtual void WriteEmptyLine()
Write empty line.
virtual void OpenMedia()
Write media definitions opening.
void WritePlacement(const std::string &lvName, const VGM::ThreeVector &position)
virtual void CloseComposition()
Write composition definition closing (if present)
AGDDWriter(const std::string &version="Undefined", const std::string &author="VGM AGGD Writer", const std::string dtdVersion="v7")
virtual void CloseMaterials()
Write materials definitions closing.
virtual void OpenDocument()
Write XML document opening.
virtual void OpenSection(const std::string &topVolume)
Write the section opening (if present)
virtual void WriteIsotope(const VGM::IIsotope *isotope)
Write VGM isotope.
virtual void OpenComposition(const std::string &name, const std::string &)
Write composition definition opening (if present)
virtual void OpenFile(std::string filePath)
Open output file.
The interface for the XML writer that writes VGM geometry objects to XML:
bool HasReflection(const HepGeom::Transform3D &transform)
std::vector< double > Transform
std::vector< double > ThreeVector
std::string IsotopeName(const VGM::IIsotope *isotope)
std::ostream & SmartPut(std::ostream &out, int size, int precision, double tolerance, double number, const std::string &separator)
std::string UpdateName(const std::string &name, const std::string &extension="")