21 #include <TGeoShape.h>
23 #include <TGeoParaboloid.h>
26 #include <TGeoSphere.h>
27 #include <TGeoTorus.h>
32 #include <TGeoMatrix.h>
33 #include <TGeoBoolNode.h>
34 #include <TGeoCompositeShape.h>
36 #include <TGeoManager.h>
45 std::string indent =
"";
48 std::ostream& m_output = std::cout;
50 void getAngles(
const Double_t* m, Double_t &phi, Double_t &theta, Double_t &psi) {
53 if (TMath::Abs(1. - TMath::Abs(m[8])) < 1.e-9) {
60 phi = TMath::ATan2(m[2], -m[5]);
61 Double_t sphi = TMath::Sin(phi);
62 if (TMath::Abs(sphi) < 1.e-9)
63 theta = -TMath::ASin(m[5] / TMath::Cos(phi)) *
RAD_2_DEGREE;
74 TGeoShape* shape = vol->GetShape();
75 TGeoMedium* medium = vol->GetMedium();
76 int num = vol->GetNdaughters();
78 m_output <<
"\t\t<volume name=\"" << name <<
"\">" << std::endl;
79 m_output <<
"\t\t\t<solidref ref=\"" << shape->GetName() <<
"\"/>" << std::endl;
80 m_output <<
"\t\t\t<materialref ref=\"" << medium->GetName() <<
"\"/>" << std::endl;
82 m_output <<
"\t\t\t<visref ref=\"" << vis.
name() <<
"\"/>" << std::endl;
85 for (
int i = 0; i < num; ++i) {
86 TGeoNode* geo_nod = vol.
ptr()->GetNode(vol->GetNode(i)->GetName());
87 TGeoVolume* geo_vol = geo_nod->GetVolume();
88 TGeoMatrix* geo_mat = geo_nod->GetMatrix();
89 m_output <<
"\t\t\t<physvol>" << std::endl;
90 m_output <<
"\t\t\t\t<volumeref ref=\"" << geo_vol->GetName() <<
"\"/>" << std::endl;
92 if (geo_mat->IsTranslation()) {
93 m_output <<
"\t\t\t\t<positionref ref=\"" << geo_nod->GetName() <<
"_pos\"/>" << std::endl;
95 if (geo_mat->IsRotation()) {
96 m_output <<
"\t\t\t\t<rotationref ref=\"" << geo_nod->GetName() <<
"_rot\"/>" << std::endl;
99 m_output <<
"\t\t\t</physvol>" << std::endl;
102 m_output <<
"\t\t</volume>" << std::endl;
109 if (shape->IsA() == TGeoBBox::Class()) {
110 const TGeoBBox* sh = (
const TGeoBBox*) shape;
111 m_output <<
"\t\t<box name=\"" << name <<
"_shape\" x=\"" << sh->GetDX() <<
"\" y=\"" << sh->GetDY() <<
"\" z=\""
112 << sh->GetDZ() <<
"\" lunit=\"cm\"/>" << std::endl;
114 else if (shape->IsA() == TGeoTube::Class()) {
115 const TGeoTube* sh = (
const TGeoTube*) shape;
116 m_output <<
"\t\t<tube name=\"" << name <<
"_shape\" rmin=\"" << sh->GetRmin() <<
"\" rmax=\"" << sh->GetRmax() <<
"\" z=\""
117 << sh->GetDz() <<
"\" startphi=\"0.0\" deltaphi=\"360.0\" aunit=\"deg\" lunit=\"cm\"/>" << std::endl;
119 else if (shape->IsA() == TGeoTubeSeg::Class()) {
120 const TGeoTubeSeg* sh = (
const TGeoTubeSeg*) shape;
121 m_output <<
"\t\t<tube name=\"" << name <<
"_shape\" rmin=\"" << sh->GetRmin() <<
"\" rmax=\"" << sh->GetRmax() <<
"\" z=\""
122 << sh->GetDz() <<
"\" startphi=\"" << sh->GetPhi1() <<
"\" deltaphi=\"" << sh->GetPhi2()
123 <<
"\" aunit=\"deg\" lunit=\"cm\"/>" << std::endl;
125 else if (shape->IsA() == TGeoTrd1::Class()) {
126 const TGeoTrd1* sh = (
const TGeoTrd1*) shape;
127 m_output <<
"\t\t<tube name=\"" << name <<
"_shape\" x1=\"" << sh->GetDx1() <<
"\" x2=\"" << sh->GetDx2() <<
"\" y1=\""
128 << sh->GetDy() <<
"\" y2=\"" << sh->GetDy() <<
"\" z=\"" << sh->GetDz() <<
"\" lunit=\"cm\"/>" << std::endl;
130 else if (shape->IsA() == TGeoTrd2::Class()) {
131 const TGeoTrd2* sh = (
const TGeoTrd2*) shape;
132 m_output <<
"\t\t<tube name=\"" << name <<
"_shape\" x1=\"" << sh->GetDx1() <<
"\" x2=\"" << sh->GetDx2() <<
"\" y1=\""
133 << sh->GetDy1() <<
"\" y2=\"" << sh->GetDy2() <<
"\" z=\"" << sh->GetDz() <<
"\" lunit=\"cm\"/>" << std::endl;
135 else if (shape->IsA() == TGeoPgon::Class()) {
136 const TGeoPgon* sh = (
const TGeoPgon*) shape;
137 m_output <<
"\t\t<polyhedra name=\"" << name <<
"_shape\" startphi=\"" << sh->GetPhi1() <<
"\" deltaphi=\"" << sh->GetDphi()
138 <<
"\" numsides=\"" << sh->GetNedges() <<
"\" aunit=\"deg\" lunit=\"cm\">" << std::endl;
139 for (
int i = 0; i < sh->GetNz(); ++i) {
140 m_output <<
"\t\t\t<zplane z=\"" << sh->GetZ(i) <<
"\" rmin=\"" << sh->GetRmin(i) <<
"\" rmax=\"" << sh->GetRmax(i)
141 <<
"\" lunit=\"cm\"/>" << std::endl;
143 m_output <<
"\t\t</polyhedra>" << std::endl;
145 else if (shape->IsA() == TGeoPcon::Class()) {
146 const TGeoPcon* sh = (
const TGeoPcon*) shape;
147 m_output <<
"\t\t<polycone name=\"" << name <<
"_shape\" startphi=\"" << sh->GetPhi1() <<
"\" deltaphi=\"" << sh->GetDphi()
148 <<
"\" aunit=\"deg\" lunit=\"cm\">" << std::endl;
149 for (
int i = 0; i < sh->GetNz(); ++i) {
150 m_output <<
"\t\t\t<zplane z=\"" << sh->GetZ(i) <<
"\" rmin=\"" << sh->GetRmin(i) <<
"\" rmax=\"" << sh->GetRmax(i)
151 <<
"\" lunit=\"cm\"/>" << std::endl;
153 m_output <<
"\t\t</polycone>" << std::endl;
155 else if (shape->IsA() == TGeoCompositeShape::Class()) {
156 std::string nn = name;
157 const TGeoCompositeShape* sh = (
const TGeoCompositeShape*) shape;
158 const TGeoBoolNode*
boolean = sh->GetBoolNode();
159 TGeoBoolNode::EGeoBoolType oper =
boolean->GetBooleanOperator();
161 handleSolid(name +
"_left", boolean->GetLeftShape());
162 handleSolid(name +
"_right", boolean->GetRightShape());
164 if (oper == TGeoBoolNode::kGeoSubtraction)
165 m_output <<
"\t\t<subtraction name=\"" << nn <<
"\">" << std::endl;
166 else if (oper == TGeoBoolNode::kGeoUnion)
167 m_output <<
"\t\t<union name=\"" << nn <<
"\">" << std::endl;
168 else if (oper == TGeoBoolNode::kGeoIntersection)
169 m_output <<
"\t\t<intersection name=\"" << nn <<
"\">" << std::endl;
171 m_output <<
"\t\t\t<first ref=\"" << nn <<
"_left\"/>" << std::endl;
172 m_output <<
"\t\t\t<second ref=\"" << nn <<
"_right\"/>" << std::endl;
174 handleTransformation(
"", boolean->GetRightMatrix());
177 if (oper == TGeoBoolNode::kGeoSubtraction)
178 m_output <<
"\t\t</subtraction>" << std::endl;
179 else if (oper == TGeoBoolNode::kGeoUnion)
180 m_output <<
"\t\t</union>" << std::endl;
181 else if (oper == TGeoBoolNode::kGeoIntersection)
182 m_output <<
"\t\t</intersection>" << std::endl;
185 std::cerr <<
"Failed to handle unknwon solid shape:" << shape->IsA()->GetName() << std::endl;
193 m_output <<
"\t<structure>" << std::endl;
194 for (
const auto& vol : volset)
195 handleVolume(vol->GetName(), vol);
196 m_output <<
"\t</structure>" << std::endl;
202 if (mat->IsTranslation()) {
203 const Double_t* f = mat->GetTranslation();
204 m_output << indent <<
"\t\t<position ";
206 m_output <<
"name=\"" << name <<
"_pos\" ";
207 m_output <<
"x=\"" << f[0] <<
"\" " <<
"y=\"" << f[1] <<
"\" " <<
"z=\"" << f[2] <<
"\" unit=\"cm\"/>" << std::endl;
209 if (mat->IsRotation()) {
210 const Double_t* matrix = mat->GetRotationMatrix();
211 Double_t theta = 0.0, phi = 0.0, psi = 0.0;
212 getAngles(matrix, theta, phi, psi);
213 m_output << indent <<
"\t\t<rotation ";
215 m_output <<
"name=\"" << name <<
"_rot\" ";
216 m_output <<
"x=\"" << theta <<
"\" " <<
"y=\"" << psi <<
"\" " <<
"z=\"" << phi <<
"\" unit=\"deg\"/>" << std::endl;
224 m_output <<
"\t<define>" << std::endl;
225 for (
const auto& t : trafos )
226 handleTransformation(t.first, t.second);
227 m_output <<
"\t</define>" << std::endl;
232 m_output <<
"\t<solids>" << std::endl;
233 for (
const auto sh : solids )
234 handleSolid(sh->GetName(), sh);
235 m_output <<
"\t</solids>" << std::endl;
240 m_output <<
"\t<define>" << std::endl;
241 for (
const auto& def : defs )
242 m_output <<
"\t\t<constant name=\"" << def.second->name <<
"\" value=\"" << def.second->type <<
"\" />"
244 m_output <<
"\t</define>" << std::endl;
251 static std::string _path =
"";
253 TGeoNode* current = pv.
ptr();
254 TGeoVolume* volume = current->GetVolume();
255 TObjArray* nodes = volume->GetNodes();
256 int num_children = nodes ? nodes->GetEntriesFast() : 0;
260 _path += current->GetName();
261 ::snprintf(fmt,
sizeof(fmt),
"%%4d %%%ds %%7s %%s\n", level * 2 + 5);
262 ::printf(fmt, level,
"",
" ->LV: ", volume->GetName());
263 ::printf(fmt, level,
"",
" ->PV: ", current->GetName());
264 ::printf(fmt, level,
"",
" ->path:", _path.c_str());
265 if (num_children > 0) {
266 for (
int i = 0; i < num_children; ++i) {
267 TGeoNode* node =
static_cast<TGeoNode*
>(nodes->At(i));
271 _path = _path.substr(0, _path.length() - 1 - strlen(current->GetName()));
274 static void dumpDetectors(
DetElement parent,
int level) {
280 _path += parent.
name();
281 ::snprintf(fmt,
sizeof(fmt),
"%%4d %%%ds %%7s %%s\n", level * 2 + 5);
282 ::printf(fmt, level,
"",
"->path:", _path.c_str());
284 ::printf(fmt, level,
"",
" ->placement:", parent.
placementPath().c_str());
285 ::printf(fmt, level,
"",
" ->logvol: ", pl->GetVolume()->GetName());
286 ::printf(fmt, level,
"",
" ->shape: ", pl->GetVolume()->GetShape()->GetName());
288 for (
const auto& c : children)
289 dumpDetectors(c.second, level + 1);
291 _path = _path.substr(0, _path.length() - 1 - strlen(parent.
name()));
295 dumpDetectors(top, 0);