]>
Commit | Line | Data |
---|---|---|
240601e9 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
499b353a | 4 | // Author: I. Hrivnacova, 27.07.2000 |
5 | // | |
6 | // Class TG4XMLConvertor | |
7 | // --------------------- | |
240601e9 | 8 | // See the class description in the header file. |
9 | ||
10 | #include "TG4XMLConvertor.h" | |
2217607d | 11 | #include "TG4Polycone.h" |
12 | #include "TG4Polyhedra.h" | |
b009ffa0 | 13 | #include "TG4G3Units.h" |
240601e9 | 14 | |
2217607d | 15 | #include <G4PVReplica.hh> |
240601e9 | 16 | #include <G4Material.hh> |
17 | #include <G4VSolid.hh> | |
18 | #include <G4Box.hh> | |
19 | #include <G4Tubs.hh> | |
2217607d | 20 | #include <G4Cons.hh> |
240601e9 | 21 | #include <G4Trd.hh> |
4032dc03 | 22 | #include <G4Trap.hh> |
5d22ddb7 | 23 | #include <G4Para.hh> |
2217607d | 24 | #include <G4Polycone.hh> |
25 | #include <G4Polyhedra.hh> | |
240601e9 | 26 | |
27 | #include <g4std/iostream> | |
28 | #include <g4std/iomanip> | |
29 | ||
30 | const G4int TG4XMLConvertor::fgkMaxVolumeNameLength = 10; | |
31 | const G4int TG4XMLConvertor::fgkMaxMaterialNameLength = 20; | |
b7ee896b | 32 | const G4int TG4XMLConvertor::fgkDefaultNumWidth = 7; |
33 | const G4int TG4XMLConvertor::fgkDefaultNumPrecision = 4; | |
240601e9 | 34 | |
72095f7c | 35 | //_____________________________________________________________________________ |
240601e9 | 36 | TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile) |
37 | : fOutFile(outFile), | |
4b062c78 | 38 | fkBasicIndention(" "), |
b7ee896b | 39 | fNW(fgkDefaultNumWidth), |
40 | fNP(fgkDefaultNumPrecision), | |
4b062c78 | 41 | fIndention(fkBasicIndention), |
4032dc03 | 42 | fRotationCounter(0) |
240601e9 | 43 | { |
b7ee896b | 44 | fOutFile.width(fgkDefaultNumWidth); |
45 | fOutFile.precision(fgkDefaultNumPrecision); | |
240601e9 | 46 | } |
47 | ||
72095f7c | 48 | //_____________________________________________________________________________ |
240601e9 | 49 | TG4XMLConvertor::~TG4XMLConvertor() { |
50 | // | |
51 | } | |
52 | ||
53 | // private methods | |
54 | ||
72095f7c | 55 | //_____________________________________________________________________________ |
240601e9 | 56 | void TG4XMLConvertor::CutName(G4String& name) const |
57 | { | |
58 | // Removes spaces after the name if present. | |
59 | // --- | |
60 | ||
61 | G4int i = name.length(); | |
62 | while (name(--i) == ' ') name = name(0,i); | |
63 | } | |
64 | ||
72095f7c | 65 | //_____________________________________________________________________________ |
240601e9 | 66 | void TG4XMLConvertor::CutName(G4String& name, G4int size) const |
67 | { | |
68 | // Cuts name to given size. | |
69 | // --- | |
70 | ||
71 | if (name.length() > size) name = name(0, size); | |
72 | } | |
73 | ||
72095f7c | 74 | //_____________________________________________________________________________ |
240601e9 | 75 | void TG4XMLConvertor::PutName(G4String& element, G4String name, |
76 | G4String templ) const | |
77 | { | |
78 | // Replaces given template in string element with a give name. | |
79 | // --- | |
80 | ||
81 | CutName(name); | |
82 | // make better | |
83 | if (templ == "#") | |
84 | CutName(name, fgkMaxVolumeNameLength); | |
85 | else if (templ == "!") | |
86 | CutName(name, fgkMaxMaterialNameLength); | |
87 | ||
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 , " "); | |
91 | } | |
92 | ||
72095f7c | 93 | //_____________________________________________________________________________ |
4032dc03 | 94 | void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box, |
95 | G4String materialName) | |
240601e9 | 96 | { |
97 | // Writes G4box solid. | |
98 | // --- | |
99 | ||
100 | // get parameters | |
b009ffa0 | 101 | G4double x = box->GetXHalfLength()/TG4G3Units::Length()*2.; |
102 | G4double y = box->GetYHalfLength()/TG4G3Units::Length()*2.; | |
103 | G4double z = box->GetZHalfLength()/TG4G3Units::Length()*2.; | |
240601e9 | 104 | |
105 | // compose element string template | |
2217607d | 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 = "\" />"; | |
4b062c78 | 111 | G4String indention = fkBasicIndention + fkBasicIndention; |
240601e9 | 112 | |
113 | // write element | |
4b062c78 | 114 | fOutFile << fkBasicIndention << element1 << G4endl |
115 | << indention << element2 << G4endl | |
116 | << indention << element3 | |
b7ee896b | 117 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x << " " |
118 | << G4std::setw(fNW) << G4std::setprecision(fNP) << y << " " | |
119 | << G4std::setw(fNW) << G4std::setprecision(fNP) << z | |
2217607d | 120 | << element4 << G4endl << G4endl; |
240601e9 | 121 | } |
122 | ||
72095f7c | 123 | //_____________________________________________________________________________ |
4032dc03 | 124 | void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs, |
125 | G4String materialName) | |
240601e9 | 126 | { |
127 | // Writes G4tubs solid. | |
128 | // --- | |
129 | ||
130 | // get parameters | |
b009ffa0 | 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(); | |
240601e9 | 136 | |
137 | // compose element string template | |
2217607d | 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 = "\" />"; | |
4b062c78 | 144 | G4String indention = fkBasicIndention + fkBasicIndention; |
240601e9 | 145 | |
146 | // write element | |
4b062c78 | 147 | fOutFile << fkBasicIndention << element1 << G4endl |
148 | << indention << element2 << G4endl | |
149 | << indention << element3 | |
b7ee896b | 150 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
151 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi | |
2217607d | 152 | << quota << G4endl |
4b062c78 | 153 | << indention << element4 |
b7ee896b | 154 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " " |
155 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " " | |
156 | << G4std::setw(fNW) << G4std::setprecision(fNP) << hz | |
2217607d | 157 | << element5 << G4endl << G4endl; |
158 | } | |
159 | ||
72095f7c | 160 | //_____________________________________________________________________________ |
2217607d | 161 | void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons, |
162 | G4String materialName) | |
163 | { | |
164 | // Writes G4cons solid. | |
165 | // --- | |
166 | ||
167 | // get parameters | |
b009ffa0 | 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(); | |
2217607d | 175 | |
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 = "\" />"; | |
4b062c78 | 183 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 184 | |
185 | // write element | |
4b062c78 | 186 | fOutFile << fkBasicIndention << element1 << G4endl |
187 | << indention << element2 << G4endl | |
188 | << indention << element3 | |
b7ee896b | 189 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
190 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi | |
2217607d | 191 | << quota << G4endl |
4b062c78 | 192 | << indention << element4 |
b7ee896b | 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 | |
2217607d | 198 | << element5 << G4endl << G4endl; |
240601e9 | 199 | } |
200 | ||
72095f7c | 201 | //_____________________________________________________________________________ |
4032dc03 | 202 | void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd, |
203 | G4String materialName) | |
240601e9 | 204 | { |
205 | // Writes G4Trd solid. | |
206 | // --- | |
207 | ||
208 | // get parameters | |
b009ffa0 | 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; | |
240601e9 | 214 | |
215 | // compose element string template | |
2217607d | 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 = "\" />"; | |
4b062c78 | 221 | G4String indention = fkBasicIndention + fkBasicIndention; |
240601e9 | 222 | |
223 | // write element | |
4b062c78 | 224 | fOutFile << fkBasicIndention << element1 << G4endl |
225 | << indention << element2 << G4endl | |
226 | << indention << element3 | |
b7ee896b | 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 | |
2217607d | 232 | << element4 << G4endl << G4endl; |
240601e9 | 233 | } |
234 | ||
72095f7c | 235 | //_____________________________________________________________________________ |
4032dc03 | 236 | void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap, |
237 | G4String materialName) | |
238 | { | |
239 | // Writes G4Trap solid. | |
240 | // --- | |
241 | ||
242 | // get parameters | |
b009ffa0 | 243 | G4double dz = trap->GetZHalfLength()/TG4G3Units::Length()*2.; |
4032dc03 | 244 | G4ThreeVector symAxis = trap->GetSymAxis(); |
b009ffa0 | 245 | G4double y1 = trap->GetYHalfLength1()/TG4G3Units::Length()*2.; |
246 | G4double x1 = trap->GetXHalfLength1()/TG4G3Units::Length()*2.; | |
247 | G4double x2 = trap->GetXHalfLength2()/TG4G3Units::Length()*2.; | |
4032dc03 | 248 | G4double tanAlpha1 = trap->GetTanAlpha1(); |
b009ffa0 | 249 | G4double y2 = trap->GetYHalfLength2()/TG4G3Units::Length()*2.; |
250 | G4double x3 = trap->GetXHalfLength3()/TG4G3Units::Length()*2.; | |
251 | G4double x4 = trap->GetXHalfLength4()/TG4G3Units::Length()*2.; | |
4032dc03 | 252 | G4double tanAlpha2 = trap->GetTanAlpha2(); |
253 | ||
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 | |
258 | ||
259 | // get angles | |
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; | |
264 | ||
265 | // compose element string template | |
2217607d | 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 = "\" />"; | |
4b062c78 | 273 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 274 | |
4032dc03 | 275 | // write element |
4b062c78 | 276 | fOutFile << fkBasicIndention << element1 << G4endl |
277 | << indention << element2 << G4endl | |
278 | << indention << element3 | |
b7ee896b | 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 | |
2217607d | 286 | << quota << G4endl |
287 | << indention << element4 | |
b7ee896b | 288 | << G4std::setw(fNW) << G4std::setprecision(fNP) << inc1 << " " |
289 | << G4std::setw(fNW) << G4std::setprecision(fNP) << inc2 | |
2217607d | 290 | << quota << G4endl |
291 | << indention << element5 | |
b7ee896b | 292 | << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha1 << " " |
293 | << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha2 | |
2217607d | 294 | << element6 << G4endl << G4endl; |
4032dc03 | 295 | } |
296 | ||
72095f7c | 297 | //_____________________________________________________________________________ |
5d22ddb7 | 298 | void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para, |
299 | G4String materialName) | |
300 | { | |
301 | // Writes G4Para solid. | |
302 | // --- | |
303 | ||
304 | // get parameters | |
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(); | |
310 | ||
311 | G4double alpha = atan(tanAlpha) / deg; | |
312 | G4double theta = acos(symAxis.z()) / deg; | |
313 | G4double phi; | |
314 | if (theta == 0.) | |
315 | phi = 0; | |
316 | else | |
317 | phi = atan(symAxis.y()/symAxis.x()) / deg; | |
318 | ||
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; | |
329 | ||
330 | // write element | |
331 | fOutFile << fkBasicIndention << element1 << G4endl | |
332 | << indention << element2 << G4endl | |
333 | << indention << element3 | |
b7ee896b | 334 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dx << " " |
335 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dy << " " | |
336 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dz | |
5d22ddb7 | 337 | << quota << G4endl |
338 | << indention << element4 | |
b7ee896b | 339 | << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha |
5d22ddb7 | 340 | << quota << G4endl |
341 | << indention << element5 | |
b7ee896b | 342 | << G4std::setw(fNW) << G4std::setprecision(fNP) << theta |
5d22ddb7 | 343 | << quota << G4endl |
344 | << indention << element6 | |
b7ee896b | 345 | << G4std::setw(fNW) << G4std::setprecision(fNP) << phi |
5d22ddb7 | 346 | << element7 << G4endl << G4endl; |
347 | } | |
348 | ||
72095f7c | 349 | //_____________________________________________________________________________ |
2217607d | 350 | void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone, |
351 | G4String materialName) | |
352 | { | |
353 | // Writes G4Polycone solid. | |
354 | // --- | |
355 | ||
356 | // get profile parameters | |
b009ffa0 | 357 | G4double sphi = polycone->GetStartPhi()/TG4G3Units::Angle(); |
358 | G4double ephi = polycone->GetEndPhi()/TG4G3Units::Angle(); | |
2217607d | 359 | |
360 | // get polycone Z planes parameters | |
361 | TG4Polycone historicalPolycone = TG4Polycone(*polycone); | |
362 | ||
363 | G4int nofZPlanes = historicalPolycone.GetNofZPlanes(); | |
364 | G4double* rminArray = historicalPolycone.GetRmin(); | |
365 | G4double* rmaxArray = historicalPolycone.GetRmax(); | |
366 | G4double* zArray = historicalPolycone.GetZ(); | |
367 | ||
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>"; | |
4b062c78 | 377 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 378 | |
379 | // write pcon element | |
4b062c78 | 380 | fOutFile << fkBasicIndention << element1 << G4endl |
381 | << indention << element2 << G4endl | |
382 | << indention << element3 | |
b7ee896b | 383 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
384 | << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi | |
2217607d | 385 | << element4 << G4endl; |
386 | ||
387 | // write polyplane elements | |
388 | for (G4int i=0; i<nofZPlanes; i++) { | |
389 | ||
390 | // set units | |
b009ffa0 | 391 | G4double rmin = rminArray[i]/TG4G3Units::Length(); |
392 | G4double rmax = rmaxArray[i]/TG4G3Units::Length(); | |
393 | G4double z = zArray[i]/TG4G3Units::Length(); | |
2217607d | 394 | |
395 | fOutFile << indention << element5 | |
b7ee896b | 396 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " " |
397 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " " | |
398 | << G4std::setw(fNW) << G4std::setprecision(fNP) << z | |
2217607d | 399 | << element6 |
400 | << G4endl; | |
401 | } | |
402 | ||
403 | // close pcon element | |
4b062c78 | 404 | fOutFile << fkBasicIndention |
2217607d | 405 | << element7 << G4endl << G4endl; |
406 | } | |
407 | ||
72095f7c | 408 | //_____________________________________________________________________________ |
2217607d | 409 | void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra, |
410 | G4String materialName) | |
411 | { | |
412 | // Writes G4Polycone solid. | |
413 | // --- | |
414 | ||
415 | // get parameters | |
416 | G4int nofSides = polyhedra->GetNumSide(); | |
b009ffa0 | 417 | G4double sphi = polyhedra->GetStartPhi()/TG4G3Units::Angle(); |
418 | G4double ephi = polyhedra->GetEndPhi()/TG4G3Units::Angle(); | |
2217607d | 419 | |
420 | // get polyhedra Z planes parameters | |
421 | TG4Polyhedra historicalPolyhedra = TG4Polyhedra(*polyhedra); | |
422 | ||
423 | G4int nofZPlanes = historicalPolyhedra.GetNofZPlanes(); | |
424 | G4double* rminArray = historicalPolyhedra.GetRmin(); | |
425 | G4double* rmaxArray = historicalPolyhedra.GetRmax(); | |
426 | G4double* zArray = historicalPolyhedra.GetZ(); | |
427 | ||
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 = "\" />"; | |
4b062c78 | 438 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 439 | |
440 | // write element | |
4b062c78 | 441 | fOutFile << fkBasicIndention << element1 << G4endl |
442 | << indention << element2 << G4endl | |
443 | << indention << element3 | |
b7ee896b | 444 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
445 | << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi | |
2217607d | 446 | << quota << G4endl |
447 | << indention << element4 | |
448 | << nofSides | |
449 | << quota << G4endl; | |
450 | ||
451 | fOutFile << indention << element5; | |
452 | G4int i; | |
453 | for (i=0; i<nofZPlanes; i++) { | |
454 | // set units | |
b009ffa0 | 455 | G4double rmin = rminArray[i]/TG4G3Units::Length(); |
2217607d | 456 | if (i>0) fOutFile << " "; |
b7ee896b | 457 | fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin; |
2217607d | 458 | }; |
459 | fOutFile << quota << G4endl; | |
460 | ||
461 | fOutFile << indention << element6; | |
462 | for (i=0; i<nofZPlanes; i++) { | |
463 | // set units | |
b009ffa0 | 464 | G4double rmax = rmaxArray[i]/TG4G3Units::Length(); |
2217607d | 465 | if (i>0) fOutFile << " "; |
b7ee896b | 466 | fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax; |
2217607d | 467 | }; |
468 | fOutFile << quota << G4endl; | |
469 | ||
470 | fOutFile << indention << element7; | |
471 | for (i=0; i<nofZPlanes; i++) { | |
472 | // set units | |
b009ffa0 | 473 | G4double z = zArray[i]/TG4G3Units::Length(); |
2217607d | 474 | if (i>0) fOutFile << " "; |
b7ee896b | 475 | fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << z; |
2217607d | 476 | }; |
477 | fOutFile << element8 << G4endl << G4endl; | |
478 | } | |
479 | ||
480 | ||
240601e9 | 481 | // public methods |
482 | ||
72095f7c | 483 | //_____________________________________________________________________________ |
3716fae8 | 484 | void TG4XMLConvertor::OpenMaterials(const G4String& version, |
485 | const G4String& date, const G4String& author, | |
486 | const G4String dtdVersion) | |
487 | { | |
488 | // Writes section opening. | |
489 | // --- | |
490 | ||
491 | G4String element1 = "<materials version = \""; | |
492 | G4String element2 = " date = \""; | |
493 | G4String element3 = " author = \""; | |
494 | G4String element4 = " DTD_version=\""; | |
495 | G4String element5 = " >"; | |
496 | G4String quota = "\""; | |
497 | ||
498 | // write element | |
499 | fOutFile << element1 << version << quota << G4endl | |
500 | << element2 << date << quota << G4endl | |
501 | << element3 << author << quota << G4endl | |
502 | << element4 << dtdVersion << quota | |
503 | << element5 << G4endl; | |
504 | } | |
505 | ||
72095f7c | 506 | //_____________________________________________________________________________ |
240601e9 | 507 | void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version, |
508 | const G4String& date, const G4String& author, | |
509 | const G4String& topVolume) | |
510 | { | |
511 | // Writes section opening. | |
512 | // --- | |
513 | ||
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 = "\""; | |
521 | ||
522 | // write element | |
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; | |
529 | } | |
530 | ||
531 | void TG4XMLConvertor::OpenComposition(const G4String& name) | |
532 | { | |
533 | // Writes composition opening. | |
534 | // --- | |
535 | ||
536 | G4String element = "<composition name=\""; | |
537 | element.append(name); | |
4032dc03 | 538 | element.append("\">"); |
240601e9 | 539 | |
540 | // write element | |
541 | fOutFile << fIndention | |
542 | << element | |
543 | << G4endl; | |
544 | ||
545 | // increase indention | |
3716fae8 | 546 | IncreaseIndention(); |
547 | } | |
548 | ||
72095f7c | 549 | //_____________________________________________________________________________ |
3716fae8 | 550 | void TG4XMLConvertor::CloseMaterials() |
551 | { | |
552 | // Writes materials closing. | |
553 | // --- | |
554 | ||
555 | // define element | |
556 | G4String element = "</materials>"; | |
557 | ||
558 | // write element | |
559 | fOutFile << element | |
560 | << G4endl; | |
240601e9 | 561 | } |
562 | ||
72095f7c | 563 | //_____________________________________________________________________________ |
240601e9 | 564 | void TG4XMLConvertor::CloseSection() |
565 | { | |
566 | // Writes section closing. | |
567 | // --- | |
568 | ||
569 | // define element | |
570 | G4String element = "</section>"; | |
571 | ||
572 | // write element | |
573 | fOutFile << element | |
574 | << G4endl; | |
575 | } | |
576 | ||
72095f7c | 577 | //_____________________________________________________________________________ |
240601e9 | 578 | void TG4XMLConvertor::CloseComposition() |
579 | { | |
580 | // Writes composition closing. | |
581 | // --- | |
582 | ||
583 | // decrease indention | |
3716fae8 | 584 | DecreaseIndention(); |
240601e9 | 585 | |
586 | // define element | |
587 | G4String element = "</composition>"; | |
588 | ||
589 | // write element | |
590 | fOutFile << fIndention | |
591 | << element | |
592 | << G4endl; | |
593 | } | |
594 | ||
72095f7c | 595 | //_____________________________________________________________________________ |
240601e9 | 596 | void TG4XMLConvertor::WriteMaterial(const G4Material* material) |
597 | { | |
598 | // Writes G4Material. | |
599 | // Not yet implemented, only XML comment element is written. | |
600 | // --- | |
601 | ||
602 | G4String name = material->GetName(); | |
603 | CutName(name); | |
604 | ||
240601e9 | 605 | // only comment line |
606 | G4String element1 = "<!-- material = \""; | |
607 | G4String element2 = "\" -->"; | |
608 | ||
609 | // write element | |
4b062c78 | 610 | fOutFile << fkBasicIndention |
3716fae8 | 611 | << element1 << name |
240601e9 | 612 | << element2 |
613 | << G4endl; | |
614 | } | |
615 | ||
72095f7c | 616 | //_____________________________________________________________________________ |
4032dc03 | 617 | void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid, |
618 | G4String materialName) | |
240601e9 | 619 | { |
620 | // Finds G4Solid concrete type and calls writing function. | |
621 | // For not yet implemented solids, only XML comment element is written. | |
622 | // --- | |
623 | ||
4032dc03 | 624 | // to be removed when materials are supported |
625 | materialName = "Hydrogen"; | |
626 | ||
240601e9 | 627 | const G4Box* box = dynamic_cast<const G4Box*>(solid); |
628 | if (box) { | |
4032dc03 | 629 | WriteBox(lvName, box, materialName); |
240601e9 | 630 | return; |
631 | } | |
632 | ||
633 | const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(solid); | |
634 | if (tubs) { | |
4032dc03 | 635 | WriteTubs(lvName, tubs, materialName); |
240601e9 | 636 | return; |
637 | } | |
638 | ||
2217607d | 639 | const G4Cons* cons = dynamic_cast<const G4Cons*>(solid); |
640 | if (cons) { | |
641 | WriteCons(lvName, cons, materialName); | |
642 | return; | |
643 | } | |
644 | ||
240601e9 | 645 | const G4Trd* trd = dynamic_cast<const G4Trd*>(solid); |
646 | if (trd) { | |
4032dc03 | 647 | WriteTrd(lvName, trd, materialName); |
648 | return; | |
649 | } | |
650 | ||
651 | const G4Trap* trap = dynamic_cast<const G4Trap*>(solid); | |
652 | if (trap) { | |
653 | WriteTrap(lvName, trap, materialName); | |
240601e9 | 654 | return; |
655 | } | |
656 | ||
5d22ddb7 | 657 | const G4Para* para = dynamic_cast<const G4Para*>(solid); |
658 | if (para) { | |
659 | WritePara(lvName, para, materialName); | |
660 | return; | |
661 | } | |
662 | ||
2217607d | 663 | const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(solid); |
664 | if (polycone) { | |
665 | WritePolycone(lvName, polycone, materialName); | |
666 | return; | |
667 | } | |
668 | ||
669 | const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(solid); | |
670 | if (polyhedra) { | |
671 | WritePolyhedra(lvName, polyhedra, materialName); | |
672 | return; | |
673 | } | |
674 | ||
240601e9 | 675 | // write comment line in case of unsupported |
676 | // shape | |
677 | ||
678 | // only comment line | |
679 | G4String element1 = "<!-- unsupported shape name= \""; | |
680 | G4String element2 = "\" -->"; | |
681 | ||
682 | // write element | |
4b062c78 | 683 | fOutFile << fkBasicIndention |
4032dc03 | 684 | << element1 << lvName |
240601e9 | 685 | << element2 |
686 | << G4endl; | |
687 | } | |
688 | ||
72095f7c | 689 | //_____________________________________________________________________________ |
240601e9 | 690 | void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation) |
691 | { | |
692 | // Writes G4RotationMatrix. | |
693 | // Not yet implemented, only XML comment element is written. | |
694 | // --- | |
695 | ||
3716fae8 | 696 | // return if this rotation was already written |
697 | G4int nofRotations = fRotations.size(); | |
698 | if (nofRotations>0) | |
699 | for (G4int i=0; i<nofRotations; i++) | |
700 | if (fRotations[i] == rotation) return; | |
701 | ||
702 | fRotations.push_back(rotation); | |
703 | ||
4032dc03 | 704 | |
3716fae8 | 705 | // get parameters |
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(); | |
715 | G4String id = "RM"; | |
4032dc03 | 716 | TG4Globals::AppendNumberToString(id, ++fRotationCounter); |
3716fae8 | 717 | |
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 = "\" />"; | |
240601e9 | 724 | |
3716fae8 | 725 | // put identifier |
726 | PutName(element1, id, "#"); | |
727 | ||
240601e9 | 728 | // write element |
4b062c78 | 729 | fOutFile << fkBasicIndention |
3716fae8 | 730 | << element1 |
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 | |
4b062c78 | 734 | << fkBasicIndention |
3716fae8 | 735 | << element2 |
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 | |
4b062c78 | 739 | << fkBasicIndention |
3716fae8 | 740 | << element3 |
741 | << G4std::setw(8) << G4std::setprecision(5) << zx << " " | |
742 | << G4std::setw(8) << G4std::setprecision(5) << zy << " " | |
743 | << G4std::setw(8) << G4std::setprecision(5) << zz | |
744 | << element4 | |
240601e9 | 745 | << G4endl; |
746 | } | |
747 | ||
72095f7c | 748 | //_____________________________________________________________________________ |
4032dc03 | 749 | void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position) |
240601e9 | 750 | { |
751 | // Writes position without rotation with a given solid name. | |
752 | // --- | |
753 | ||
754 | // get parameters | |
b009ffa0 | 755 | G4double x = position.x()/TG4G3Units::Length(); |
756 | G4double y = position.y()/TG4G3Units::Length(); | |
757 | G4double z = position.z()/TG4G3Units::Length(); | |
240601e9 | 758 | |
759 | // compose element string template | |
3716fae8 | 760 | G4String element1 = "<posXYZ volume=\"########### X_Y_Z=\""; |
240601e9 | 761 | G4String element2 = "\" />"; |
762 | ||
763 | // put solid name | |
4032dc03 | 764 | PutName(element1, lvName, "#"); |
240601e9 | 765 | |
766 | // write element | |
767 | fOutFile << fIndention | |
768 | << element1 | |
b7ee896b | 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 | |
240601e9 | 772 | << element2 |
773 | << G4endl; | |
774 | } | |
775 | ||
72095f7c | 776 | //_____________________________________________________________________________ |
240601e9 | 777 | void TG4XMLConvertor::WritePositionWithRotation( |
4032dc03 | 778 | G4String lvName, G4ThreeVector position, |
240601e9 | 779 | const G4RotationMatrix* rotation) |
780 | { | |
781 | // Writes position with rotation with a given solid name. | |
782 | // Not yet implemented, only XML comment element is written. | |
783 | // --- | |
784 | ||
3716fae8 | 785 | // get parameters |
b009ffa0 | 786 | G4double x = position.x()/TG4G3Units::Length(); |
787 | G4double y = position.y()/TG4G3Units::Length(); | |
788 | G4double z = position.z()/TG4G3Units::Length(); | |
4032dc03 | 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(); | |
3716fae8 | 798 | |
4032dc03 | 799 | /* |
3716fae8 | 800 | // find rotation |
801 | G4int i=0; | |
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); | |
807 | } | |
808 | G4String id = "RM"; | |
809 | TG4Globals::AppendNumberToString(id, i); | |
4032dc03 | 810 | */ |
3716fae8 | 811 | |
812 | // compose element string template | |
4032dc03 | 813 | G4String quota = "\"\n"; |
814 | G4String element1 = "<transform volume=\"########### pos=\""; | |
815 | G4String element2 = " rot=\""; | |
816 | G4String element3 = " "; | |
817 | G4String element4 = "\" />"; | |
3716fae8 | 818 | |
819 | // put solid name | |
4032dc03 | 820 | PutName(element1, lvName, "#"); |
240601e9 | 821 | |
822 | // write element | |
823 | fOutFile << fIndention | |
3716fae8 | 824 | << element1 |
b7ee896b | 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 | |
4032dc03 | 828 | << fIndention |
829 | << element2 | |
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 | |
833 | << fIndention | |
834 | << element3 | |
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 | |
838 | << fIndention | |
839 | << element3 | |
840 | << G4std::setw(8) << G4std::setprecision(5) << zx << " " | |
841 | << G4std::setw(8) << G4std::setprecision(5) << zy << " " | |
842 | << G4std::setw(8) << G4std::setprecision(5) << zz | |
843 | << element4 | |
3716fae8 | 844 | << G4endl; |
240601e9 | 845 | } |
846 | ||
72095f7c | 847 | //_____________________________________________________________________________ |
2217607d | 848 | void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr) |
849 | { | |
850 | // Writes position without rotation with a given solid name. | |
851 | // --- | |
852 | ||
853 | // get parameters | |
854 | EAxis axis; | |
855 | G4int nReplicas; | |
856 | G4double width; | |
857 | G4double offset; | |
858 | G4bool consuming; | |
859 | pvr->GetReplicationData(axis, nReplicas, width, offset, consuming); | |
860 | ||
861 | G4String tag; | |
862 | switch (axis) { | |
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; | |
868 | } | |
869 | ||
870 | // set units | |
871 | G4double value0 = offset; | |
872 | G4double dValue = width; | |
873 | if (axis != kPhi) { | |
b009ffa0 | 874 | value0 = value0/TG4G3Units::Length(); |
875 | dValue = dValue/TG4G3Units::Length(); | |
2217607d | 876 | } |
877 | else { | |
b009ffa0 | 878 | value0 = value0/TG4G3Units::Angle(); |
879 | dValue = dValue/TG4G3Units::Angle(); | |
2217607d | 880 | } |
881 | ||
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; | |
886 | ||
887 | // compose element string template | |
888 | G4String element1 = "<" + a0 + " volume=\"########### ncopy=\""; | |
889 | G4String element2 = "\" " + a1 + "=\""; | |
890 | G4String element3 = "\" " + a2 + "=\""; | |
891 | G4String element4 = "\" />"; | |
892 | ||
893 | // put solid name | |
894 | PutName(element1, lvName, "#"); | |
895 | ||
896 | // write element | |
897 | fOutFile << fIndention | |
898 | << element1 | |
b7ee896b | 899 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << nReplicas |
2217607d | 900 | << element2 |
b7ee896b | 901 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << value0 |
2217607d | 902 | << element3 |
b7ee896b | 903 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << dValue |
2217607d | 904 | << element4 |
905 | << G4endl; | |
906 | } | |
907 | ||
72095f7c | 908 | //_____________________________________________________________________________ |
240601e9 | 909 | void TG4XMLConvertor::WriteEmptyLine() |
910 | { | |
911 | // Writes empty line. | |
912 | // --- | |
913 | ||
914 | fOutFile << G4endl; | |
915 | } | |
916 | ||
72095f7c | 917 | //_____________________________________________________________________________ |
3716fae8 | 918 | void TG4XMLConvertor::IncreaseIndention() |
919 | { | |
920 | // increase indention | |
4b062c78 | 921 | fIndention.append(fkBasicIndention); |
3716fae8 | 922 | } |
240601e9 | 923 | |
72095f7c | 924 | //_____________________________________________________________________________ |
3716fae8 | 925 | void TG4XMLConvertor::DecreaseIndention() |
926 | { | |
927 | // decrease indention | |
4b062c78 | 928 | fIndention.replace(fIndention.find(fkBasicIndention), 3 , ""); |
3716fae8 | 929 | } |