DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
LCDDConverter.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework includes
15 #include "LCDDConverter.h"
16 #include <DD4hep/Plugins.h>
17 #include <DD4hep/Printout.h>
18 #include <DD4hep/Volumes.h>
19 #include <DD4hep/FieldTypes.h>
20 #include <DD4hep/DD4hepUnits.h>
21 #include <DD4hep/Segmentations.h>
24 #include <XML/DocumentHandler.h>
25 
26 // ROOT includes
27 #include <TROOT.h>
28 #include <TColor.h>
29 #include <TGeoShape.h>
30 
31 #include <TGeoArb8.h>
32 #include <TGeoBoolNode.h>
33 #include <TGeoCompositeShape.h>
34 #include <TGeoCone.h>
35 #include <TGeoEltu.h>
36 #include <TGeoHype.h>
37 #include <TGeoMatrix.h>
38 #include <TGeoParaboloid.h>
39 #include <TGeoPara.h>
40 #include <TGeoPcon.h>
41 #include <TGeoPgon.h>
42 #include <TGeoShapeAssembly.h>
43 #include <TGeoSphere.h>
44 #include <TGeoTorus.h>
45 #include <TGeoTrd1.h>
46 #include <TGeoTrd2.h>
47 #include <TGeoTube.h>
48 #include <TGeoScaledShape.h>
49 
50 #include <TGeoNode.h>
51 #include <TClass.h>
52 #include <TMath.h>
53 
55 #include <fstream>
56 #include <iostream>
57 #include <sstream>
58 #include <iomanip>
59 
60 using namespace dd4hep;
61 using namespace dd4hep::detail;
62 
63 namespace {
64  typedef Position XYZRotation;
65 
66  XYZRotation getXYZangles(const Double_t* r) {
67  Double_t cosb = std::sqrt(r[0]*r[0] + r[1]*r[1]);
68  if (cosb > 0.00001) {
69  return XYZRotation(atan2(r[5], r[8]), atan2(-r[2], cosb), atan2(r[1], r[0]));
70  }
71  return XYZRotation(atan2(-r[7], r[4]),atan2(-r[2], cosb),0);
72  }
73 
74 #if 0
75  XYZRotation getXYZangles(const Double_t* rotationMatrix) {
76  Double_t a, b, c;
77  Double_t rad = 1.0; // RAD by default! 180.0 / TMath::ACos(-1.0);
78  const Double_t *r = rotationMatrix;
79  Double_t cosb = TMath::Sqrt(r[0] * r[0] + r[1] * r[1]);
80  if (cosb > 0.00001) {
81  a = TMath::ATan2(r[5], r[8]) * rad;
82  b = TMath::ATan2(-r[2], cosb) * rad;
83  c = TMath::ATan2(r[1], r[0]) * rad;
84  }
85  else {
86  a = TMath::ATan2(-r[7], r[4]) * rad;
87  b = TMath::ATan2(-r[2], cosb) * rad;
88  c = 0;
89  }
90  XYZRotation rr(a, b, c);
91  std::cout << " X:" << a << " " << rr.X() << " Y:" << b << " " << rr.Y() << " Z:" << c << " " << rr.Z()
92  << " lx:" << r[0] << " ly:" << r[4] << " lz:" << r[8] << std::endl;
93  return XYZRotation(a, b, c);
94  }
95 #endif
96 
97  bool is_volume(const TGeoVolume* volume) {
98  Volume v(volume);
99  return v.data() != 0;
100  }
101  bool is_placement(PlacedVolume node) {
102  return node.data() != 0;
103  }
104 
105  std::string genName(const std::string& n) { return n; }
106  std::string genName(const std::string& n, const void* ptr) {
107  std::string nn = genName(n);
108  char text[32];
109  ::snprintf(text,sizeof(text),"%p",ptr);
110  nn += "_";
111  nn += text;
112  return nn;
113  }
114 }
115 
116 void LCDDConverter::GeometryInfo::check(const std::string& name, const TNamed* _n, std::map<std::string, const TNamed*>& _m) const {
117  std::map<std::string, const TNamed*>::const_iterator i = _m.find(name);
118  if (i != _m.end()) {
119  const char* isa = _n ? _n->IsA()->GetName() : (*i).second ? (*i).second->IsA()->GetName() : "Unknown";
120  std::cout << isa << "(position): duplicate entry with name:" << name << " " << (void*) _n << " " << (void*) (*i).second << std::endl;
121  }
122  _m.insert(make_pair(name, _n));
123 }
124 
127  : m_detDesc(description), m_dataPtr(0) {
128 }
129 
131  if (m_dataPtr)
132  delete m_dataPtr;
133  m_dataPtr = 0;
134 }
135 
137 xml_h LCDDConverter::handleElement(const std::string& /* name */, Atom element) const {
138  GeometryInfo& geo = data();
139  xml_h e = geo.xmlElements[element];
140  if (!e) {
141  int Z = element->Z();
142  double A = element->A();
143  xml_elt_t atom(geo.doc, _U(atom));
144  // If we got an unphysical material (Z<1 or A<1)
145  // We pretend it is hydrogen and force Z=1 or A=1.00794 g/mole
146  geo.doc_materials.append(e = xml_elt_t(geo.doc, _U(element)));
147  e.append(atom);
148  e.setAttr(_U(name), element->GetName());
149  e.setAttr(_U(formula), element->GetName());
150  e.setAttr(_U(Z), Z>0 ? Z : 1);
151  atom.setAttr(_U(type), "A");
152  atom.setAttr(_U(unit), "g/mol");
153  atom.setAttr(_U(value), A>0.99 ? A : 1.00794 /* *(g/mole) */);
154  geo.xmlElements[element] = e;
155  }
156  return e;
157 }
158 
160 xml_h LCDDConverter::handleMaterial(const std::string& name, Material medium) const {
161  GeometryInfo& geo = data();
162  xml_h mat = geo.xmlMaterials[medium];
163  if (!mat) {
164  xml_h obj;
165  TGeoMaterial* geo_mat = medium->GetMaterial();
166  double d = geo_mat->GetDensity(); //*(gram/cm3);
167  if (d < 1e-10) d = 1e-10;
168  mat = xml_elt_t(geo.doc, _U(material));
169  mat.setAttr(_U(name), medium->GetName());
170  mat.append(obj = xml_elt_t(geo.doc, _U(D)));
171  obj.setAttr(_U(value), d /* *(g/cm3) */);
172  obj.setAttr(_U(unit), "g/cm3");
173  obj.setAttr(_U(type), "density");
174 
175  geo.checkMaterial(name, medium);
176 
177  if (geo_mat->IsMixture()) {
178  TGeoMixture *mix = (TGeoMixture*)geo_mat;
179  const double *wmix = mix->GetWmixt();
180  const int *nmix = mix->GetNmixt();
181  double sum = 0e0;
182  for (int i = 0, n = mix->GetNelements(); i < n; i++) {
183  TGeoElement *elt = mix->GetElement(i);
184  handleElement(elt->GetName(), Atom(elt));
185  sum += wmix[i];
186  }
187  for (int i = 0, n = mix->GetNelements(); i < n; i++) {
188  TGeoElement *elt = mix->GetElement(i);
189  //std::string formula = elt->GetTitle() + std::string("_elm");
190  if (nmix) {
191  mat.append(obj = xml_elt_t(geo.doc, _U(composite)));
192  obj.setAttr(_U(n), nmix[i]);
193  }
194  else {
195  mat.append(obj = xml_elt_t(geo.doc, _U(fraction)));
196  obj.setAttr(_U(n), wmix[i] / sum);
197  }
198  obj.setAttr(_U(ref), elt->GetName());
199  }
200  }
201  else if ( name != "dummy" ) {
202  // Do not exactly know where dummy comes from,
203  // but it causes havoc in Geant4 later
204  TGeoElement *elt = geo_mat->GetElement(0);
205  printout(INFO,"++ Converting non mixing material: %s",name.c_str());
206  xml_elt_t atom(geo.doc, _U(atom));
207  handleElement(elt->GetName(), Atom(elt));
208  mat.append(atom);
209  mat.setAttr(_U(Z), geo_mat->GetZ());
210  atom.setAttr(_U(type), "A");
211  atom.setAttr(_U(unit), "g/mol");
212  atom.setAttr(_U(value), geo_mat->GetA() /* *(g/mole) */);
213  }
214  geo.doc_materials.append(mat);
215  geo.xmlMaterials[medium] = mat;
216  }
217  return mat;
218 }
219 
221 xml_h LCDDConverter::handleSolid(const std::string& name, const TGeoShape* shape) const {
222  GeometryInfo& geo = data();
223  SolidMap::iterator sit = geo.xmlSolids.find(shape);
224  if (!shape) {
225  // This is an invalid volume. Let's pray returning nothing will work,
226  // and the non-existing solid is also nowhere referenced in the GDML.
227  return xml_h(0);
228  }
229  else if (sit != geo.xmlSolids.end()) {
230  // The solidis already registered. Return the reference
231  return (*sit).second;
232  }
233  else if (shape->IsA() == TGeoShapeAssembly::Class()) {
234  // Assemblies have no shape in GDML. Hence, return nothing.
235  return xml_h(0);
236  }
237  else {
238  xml_h solid(0);
239  xml_h zplane(0);
240  TClass* isa = shape->IsA();
241  std::string shape_name = shape->GetName(); //genName(shape->GetName(),shape);
242  geo.checkShape(name, shape);
243  if (isa == TGeoBBox::Class()) {
244  const TGeoBBox* sh = (const TGeoBBox*) shape;
245  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(box)));
246  solid.setAttr(_U(name), Unicode(shape_name));
247  solid.setAttr(_U(x), 2 * sh->GetDX());
248  solid.setAttr(_U(y), 2 * sh->GetDY());
249  solid.setAttr(_U(z), 2 * sh->GetDZ());
250  solid.setAttr(_U(lunit), "cm");
251  }
252  else if (isa == TGeoTube::Class()) {
253  const TGeoTube* sh = (const TGeoTube*) shape;
254  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(tube)));
255  solid.setAttr(_U(name), Unicode(shape_name));
256  solid.setAttr(_U(rmin), sh->GetRmin());
257  solid.setAttr(_U(rmax), sh->GetRmax());
258  solid.setAttr(_U(z), 2 * sh->GetDz());
259  solid.setAttr(_U(startphi), 0e0);
260  solid.setAttr(_U(deltaphi), 360.0);
261  solid.setAttr(_U(aunit), "deg");
262  solid.setAttr(_U(lunit), "cm");
263  }
264  else if (isa == TGeoTubeSeg::Class()) {
265  const TGeoTubeSeg* sh = (const TGeoTubeSeg*) shape;
266  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(tube)));
267  solid.setAttr(_U(name), Unicode(shape_name));
268  solid.setAttr(_U(rmin), sh->GetRmin());
269  solid.setAttr(_U(rmax), sh->GetRmax());
270  solid.setAttr(_U(z), 2 * sh->GetDz()); // Full zlen in GDML, half zlen in TGeo
271  solid.setAttr(_U(startphi), sh->GetPhi1());
272  solid.setAttr(_U(deltaphi), sh->GetPhi2());
273  solid.setAttr(_U(aunit), "deg");
274  solid.setAttr(_U(lunit), "cm");
275  }
276  else if (isa == TGeoEltu::Class()) {
277  const TGeoEltu* sh = (const TGeoEltu*) shape;
278  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(eltube)));
279  solid.setAttr(_U(name), Unicode(shape_name));
280  solid.setAttr(_U(dx), sh->GetA());
281  solid.setAttr(_U(dy), sh->GetB());
282  solid.setAttr(_U(dz), sh->GetDz());
283  solid.setAttr(_U(lunit), "cm");
284  }
285  else if (isa == TGeoTrd1::Class()) {
286  const TGeoTrd1* sh = (const TGeoTrd1*) shape;
287  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(trd)));
288  solid.setAttr(_U(name), Unicode(shape_name));
289  solid.setAttr(_U(x1), 2 * sh->GetDx1());
290  solid.setAttr(_U(x2), 2 * sh->GetDx2());
291  solid.setAttr(_U(y1), 2 * sh->GetDy());
292  solid.setAttr(_U(y2), 2 * sh->GetDy());
293  solid.setAttr(_U(z), 2 * sh->GetDz()); // Full zlen in GDML, half zlen in TGeo
294  solid.setAttr(_U(lunit), "cm");
295  }
296  else if (isa == TGeoTrd2::Class()) {
297  const TGeoTrd2* sh = (const TGeoTrd2*) shape;
298  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(trd)));
299  solid.setAttr(_U(name), Unicode(shape_name));
300  solid.setAttr(_U(x1), 2 * sh->GetDx1());
301  solid.setAttr(_U(x2), 2 * sh->GetDx2());
302  solid.setAttr(_U(y1), 2 * sh->GetDy1());
303  solid.setAttr(_U(y2), 2 * sh->GetDy2());
304  solid.setAttr(_U(z), 2 * sh->GetDz()); // Full zlen in GDML, half zlen in TGeo
305  solid.setAttr(_U(lunit), "cm");
306  }
307  else if (isa == TGeoHype::Class()) {
308  const TGeoHype* sh = (const TGeoHype*) shape;
309  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(hype)));
310  solid.setAttr(_U(name), Unicode(shape_name));
311  solid.setAttr(_U(rmin), sh->GetRmin());
312  solid.setAttr(_U(rmax), sh->GetRmax());
313  solid.setAttr(Unicode("inst"), sh->GetStIn());
314  solid.setAttr(_U(outst), sh->GetStOut());
315  solid.setAttr(_U(z), sh->GetDz()); // Full zlen in GDML, half zlen in TGeo
316  solid.setAttr(_U(aunit), "deg");
317  solid.setAttr(_U(lunit), "cm");
318  }
319  else if (isa == TGeoPgon::Class()) {
320  const TGeoPgon* sh = (const TGeoPgon*) shape;
321  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(polyhedra)));
322  solid.setAttr(_U(name), Unicode(shape_name));
323  solid.setAttr(_U(startphi), sh->GetPhi1());
324  solid.setAttr(_U(deltaphi), sh->GetDphi());
325  solid.setAttr(_U(numsides), sh->GetNedges());
326  solid.setAttr(_U(aunit), "deg");
327  solid.setAttr(_U(lunit), "cm");
328  for (Int_t i = 0; i < sh->GetNz(); ++i) {
329  zplane = xml_elt_t(geo.doc, _U(zplane));
330  zplane.setAttr(_U(z), sh->GetZ(i));
331  zplane.setAttr(_U(rmin), sh->GetRmin(i));
332  zplane.setAttr(_U(rmax), sh->GetRmax(i));
333  solid.append(zplane);
334  }
335  }
336  else if (isa == TGeoPcon::Class()) {
337  const TGeoPcon* sh = (const TGeoPcon*) shape;
338  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(polycone)));
339  solid.setAttr(_U(name), Unicode(shape_name));
340  solid.setAttr(_U(startphi), sh->GetPhi1());
341  solid.setAttr(_U(deltaphi), sh->GetDphi());
342  solid.setAttr(_U(aunit), "deg");
343  solid.setAttr(_U(lunit), "cm");
344  for (Int_t i = 0; i < sh->GetNz(); ++i) {
345  zplane = xml_elt_t(geo.doc, _U(zplane));
346  zplane.setAttr(_U(z), sh->GetZ(i));
347  zplane.setAttr(_U(rmin), sh->GetRmin(i));
348  zplane.setAttr(_U(rmax), sh->GetRmax(i));
349  solid.append(zplane);
350  }
351  solid.setAttr(_U(lunit), "cm");
352  }
353  else if (isa == TGeoCone::Class()) {
354  const TGeoCone* sh = (const TGeoCone*) shape;
355  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(cone)));
356  solid.setAttr(_U(name), Unicode(shape_name));
357  solid.setAttr(_U(z), 2 * sh->GetDz());
358  solid.setAttr(_U(rmin1), sh->GetRmin1());
359  solid.setAttr(_U(rmax1), sh->GetRmax1());
360  solid.setAttr(_U(rmin2), sh->GetRmin2());
361  solid.setAttr(_U(rmax2), sh->GetRmax2());
362  solid.setAttr(_U(startphi), 0e0);
363  solid.setAttr(_U(deltaphi), 360.0);
364  solid.setAttr(_U(aunit), "deg");
365  solid.setAttr(_U(lunit), "cm");
366  }
367  else if (isa == TGeoConeSeg::Class()) {
368  const TGeoConeSeg* sh = (const TGeoConeSeg*) shape;
369  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(cone)));
370  solid.setAttr(_U(name), Unicode(shape_name));
371  solid.setAttr(_U(z), 2*sh->GetDz());
372  solid.setAttr(_U(rmin1), sh->GetRmin1());
373  solid.setAttr(_U(rmin2), sh->GetRmin2());
374  solid.setAttr(_U(rmax1), sh->GetRmax1());
375  solid.setAttr(_U(rmax2), sh->GetRmax2());
376  solid.setAttr(_U(startphi), sh->GetPhi1());
377  solid.setAttr(_U(deltaphi), sh->GetPhi2() - sh->GetPhi1());
378  solid.setAttr(_U(aunit), "deg");
379  solid.setAttr(_U(lunit), "cm");
380  }
381  else if (isa == TGeoParaboloid::Class()) {
382  const TGeoParaboloid* sh = (const TGeoParaboloid*) shape;
383  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(paraboloid)));
384  solid.setAttr(_U(name), Unicode(shape_name));
385  solid.setAttr(_U(rlo), sh->GetRlo());
386  solid.setAttr(_U(rhi), sh->GetRhi());
387  solid.setAttr(_U(dz), sh->GetDz());
388  solid.setAttr(_U(lunit), "cm");
389  }
390 #if 0
391  else if (isa == TGeoEllipsoid::Class()) {
392  const TGeoEllipsoid* sh = (const TGeoEllipsoid*) shape;
393  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(ellipsoid)));
394  solid.setAttr(_U(lunit), "cm");
395  }
396 #endif
397  else if (isa == TGeoSphere::Class()) {
398  const TGeoSphere* sh = (const TGeoSphere*) shape;
399  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(sphere)));
400  solid.setAttr(_U(name), Unicode(shape_name));
401  solid.setAttr(_U(rmin), sh->GetRmin());
402  solid.setAttr(_U(rmax), sh->GetRmax());
403  solid.setAttr(_U(startphi), sh->GetPhi1());
404  solid.setAttr(_U(deltaphi), (sh->GetPhi2() - sh->GetPhi1()));
405  solid.setAttr(_U(starttheta), sh->GetTheta1());
406  solid.setAttr(_U(deltatheta), (sh->GetTheta2() - sh->GetTheta1()));
407  solid.setAttr(_U(aunit), "deg");
408  solid.setAttr(_U(lunit), "cm");
409  }
410  else if (isa == TGeoTorus::Class()) {
411  const TGeoTorus* sh = (const TGeoTorus*) shape;
412  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(torus)));
413  solid.setAttr(_U(name), Unicode(shape_name));
414  solid.setAttr(_U(rtor), sh->GetR());
415  solid.setAttr(_U(rmin), sh->GetRmin());
416  solid.setAttr(_U(rmax), sh->GetRmax());
417  solid.setAttr(_U(startphi), sh->GetPhi1());
418  solid.setAttr(_U(deltaphi), sh->GetDphi());
419  solid.setAttr(_U(aunit), "deg");
420  solid.setAttr(_U(lunit), "cm");
421  }
422  else if (isa == TGeoTrap::Class()) {
423  const TGeoTrap* sh = (const TGeoTrap*) shape;
424  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(trap)));
425  solid.setAttr(_U(name), Unicode(shape_name));
426  solid.setAttr(_U(z), 2 * sh->GetDz()); // Full zlen in GDML, half zlen in TGeo
427  solid.setAttr(_U(x1), 2 * sh->GetBl1());
428  solid.setAttr(_U(x2), 2 * sh->GetTl1());
429  solid.setAttr(_U(x3), 2 * sh->GetBl2());
430  solid.setAttr(_U(x4), 2 * sh->GetTl2());
431  solid.setAttr(_U(y1), 2 * sh->GetH1());
432  solid.setAttr(_U(y2), 2 * sh->GetH2());
433  solid.setAttr(_U(alpha1), sh->GetAlpha1());
434  solid.setAttr(_U(alpha2), sh->GetAlpha2());
435  solid.setAttr(_U(theta), sh->GetTheta());
436  solid.setAttr(_U(phi), sh->GetPhi());
437  solid.setAttr(_U(aunit), "deg");
438  solid.setAttr(_U(lunit), "cm");
439  }
440  else if (isa == TGeoPara::Class()) {
441  const TGeoPara* sh = (const TGeoPara*) shape;
442  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(para)));
443  solid.setAttr(_U(name), Unicode(shape_name));
444  solid.setAttr(_U(x), sh->GetX());
445  solid.setAttr(_U(y), sh->GetY());
446  solid.setAttr(_U(z), sh->GetZ());
447  solid.setAttr(_U(alpha), sh->GetAlpha());
448  solid.setAttr(_U(theta), sh->GetTheta());
449  solid.setAttr(_U(phi), sh->GetPhi());
450  solid.setAttr(_U(aunit), "deg");
451  solid.setAttr(_U(lunit), "cm");
452  }
453  else if (isa == TGeoArb8::Class()) {
454  TGeoArb8* sh = (TGeoArb8*) shape;
455  const double* vtx = sh->GetVertices();
456  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(arb8)));
457  solid.setAttr(_U(name), Unicode(shape_name));
458  solid.setAttr(_U(v1x), vtx[0]);
459  solid.setAttr(_U(v1y), vtx[1]);
460  solid.setAttr(_U(v2x), vtx[2]);
461  solid.setAttr(_U(v2y), vtx[3]);
462  solid.setAttr(_U(v3x), vtx[4]);
463  solid.setAttr(_U(v3y), vtx[5]);
464  solid.setAttr(_U(v4x), vtx[6]);
465  solid.setAttr(_U(v4y), vtx[7]);
466  solid.setAttr(_U(v5x), vtx[8]);
467  solid.setAttr(_U(v5y), vtx[9]);
468  solid.setAttr(_U(v6x), vtx[10]);
469  solid.setAttr(_U(v6y), vtx[11]);
470  solid.setAttr(_U(v7x), vtx[12]);
471  solid.setAttr(_U(v7y), vtx[13]);
472  solid.setAttr(_U(v8x), vtx[14]);
473  solid.setAttr(_U(v8y), vtx[15]);
474  solid.setAttr(_U(dz), sh->GetDz());
475  solid.setAttr(_U(lunit), "cm");
476  }
477  else if (isa == TGeoScaledShape::Class()) {
478  TGeoScaledShape* sh = (TGeoScaledShape*) shape;
479  const double* vals = sh->GetScale()->GetScale();
480  Solid s_sh(sh->GetShape());
481  handleSolid(s_sh.name(), s_sh.ptr());
482  geo.doc_solids.append(solid = xml_elt_t(geo.doc, _U(scale)));
483  solid.setAttr(_U(name), Unicode(shape_name));
484  solid.setAttr(_U(shape), s_sh.name());
485  solid.setAttr(_U(x), vals[0]);
486  solid.setAttr(_U(y), vals[1]);
487  solid.setAttr(_U(z), vals[2]);
488  solid.setAttr(_U(aunit), "deg");
489  solid.setAttr(_U(lunit), "cm");
490  }
491  else if (isa == TGeoCompositeShape::Class() ||
492  isa == TGeoUnion::Class() ||
493  isa == TGeoIntersection::Class() ||
494  isa == TGeoSubtraction::Class() ) {
495  const TGeoCompositeShape* sh = (const TGeoCompositeShape*) shape;
496  const TGeoBoolNode* boolean = sh->GetBoolNode();
497  TGeoBoolNode::EGeoBoolType oper = boolean->GetBooleanOperator();
498  TGeoMatrix* rm = boolean->GetRightMatrix();
499  TGeoMatrix* lm = boolean->GetLeftMatrix();
500  TGeoShape* ls = boolean->GetLeftShape();
501  TGeoShape* rs = boolean->GetRightShape();
502  xml_h left = handleSolid(ls->GetName(), ls);
503  xml_h right = handleSolid(rs->GetName(), rs);
504  xml_h first_solid(0), second_solid(0);
505  if (!left) {
506  throw std::runtime_error("G4Converter: No left Detector Solid present for composite shape:" + name);
507  }
508  if (!right) {
509  throw std::runtime_error("G4Converter: No right Detector Solid present for composite shape:" + name);
510  }
511 
512  //specific case!
513  //Ellipsoid tag preparing
514  //if left == TGeoScaledShape AND right == TGeoBBox
515  // AND if TGeoScaledShape->GetShape == TGeoSphere
516  if (strcmp(ls->ClassName(), "TGeoScaledShape") == 0 &&
517  strcmp(rs->ClassName(), "TGeoBBox") == 0) {
518  if (strcmp(((TGeoScaledShape *)ls)->GetShape()->ClassName(), "TGeoSphere") == 0) {
519  if (oper == TGeoBoolNode::kGeoIntersection) {
520  TGeoScaledShape* lls = (TGeoScaledShape *)ls;
521  TGeoBBox* rrs = (TGeoBBox*)rs;
522  solid = xml_elt_t(geo.doc,Unicode("ellipsoid"));
523  solid.setAttr(_U(name), Unicode(shape_name));
524  double sx = lls->GetScale()->GetScale()[0];
525  double sy = lls->GetScale()->GetScale()[1];
526  double radius = ((TGeoSphere *)lls->GetShape())->GetRmax();
527  double dz = rrs->GetDZ();
528  double zorig = rrs->GetOrigin()[2];
529  double zcut2 = dz + zorig;
530  double zcut1 = 2 * zorig - zcut2;
531  solid.setAttr(Unicode("ax"),sx * radius);
532  solid.setAttr(Unicode("by"),sy * radius);
533  solid.setAttr(Unicode("cz"),radius);
534  solid.setAttr(Unicode("zcut1"),zcut1);
535  solid.setAttr(Unicode("zcut2"),zcut2);
536  solid.setAttr(_U(lunit), "cm");
537  return data().xmlSolids[shape] = solid;
538  }
539  }
540  }
541 
542  if ( oper == TGeoBoolNode::kGeoSubtraction )
543  solid = xml_elt_t(geo.doc,_U(subtraction));
544  else if ( oper == TGeoBoolNode::kGeoUnion )
545  solid = xml_elt_t(geo.doc,_U(union));
546  else if ( oper == TGeoBoolNode::kGeoIntersection )
547  solid = xml_elt_t(geo.doc,_U(intersection));
548 
549  xml_h obj;
550  std::string lnam = left.attr<std::string>(_U(name));
551  std::string rnam = right.attr<std::string>(_U(name));
552 
553  geo.doc_solids.append(solid);
554  solid.append(first_solid = xml_elt_t(geo.doc, _U(first)));
555  solid.setAttr(_U(name), Unicode(shape_name));
556  first_solid.setAttr(_U(ref), lnam);
557  const double *tr = lm->GetTranslation();
558 
559  if ((tr[0] != 0.0) || (tr[1] != 0.0) || (tr[2] != 0.0)) {
560  first_solid.append(obj = xml_elt_t(geo.doc, _U(firstposition)));
561  obj.setAttr(_U(name), name+"_"+lnam+"_pos");
562  obj.setAttr(_U(x), tr[0]);
563  obj.setAttr(_U(y), tr[1]);
564  obj.setAttr(_U(z), tr[2]);
565  obj.setAttr(_U(unit), "cm");
566  }
567  if (lm->IsRotation()) {
568  TGeoMatrix const & linv = lm->Inverse();
569  XYZRotation rot = getXYZangles(linv.GetRotationMatrix());
570  if ((rot.X() != 0.0) || (rot.Y() != 0.0) || (rot.Z() != 0.0)) {
571  first_solid.append(obj = xml_elt_t(geo.doc, _U(firstrotation)));
572  obj.setAttr(_U(name), name+"_"+lnam+"_rot");
573  obj.setAttr(_U(x), rot.X());
574  obj.setAttr(_U(y), rot.Y());
575  obj.setAttr(_U(z), rot.Z());
576  obj.setAttr(_U(unit), "rad");
577  }
578  }
579  tr = rm->GetTranslation();
580  solid.append(second_solid = xml_elt_t(geo.doc, _U(second)));
581  second_solid.setAttr(_U(ref), rnam);
582  if ((tr[0] != 0.0) || (tr[1] != 0.0) || (tr[2] != 0.0)) {
583  xml_ref_t pos = handlePosition(rnam+"_pos", rm);
584  solid.setRef(_U(positionref), pos.name());
585  }
586  if (rm->IsRotation()) {
587  TGeoMatrix const & rinv = rm->Inverse();
588  XYZRotation rot = getXYZangles(rinv.GetRotationMatrix());
589  if ((rot.X() != 0.0) || (rot.Y() != 0.0) || (rot.Z() != 0.0)) {
590  xml_ref_t xml_rot = handleRotation(rnam+"_rot", &rinv);
591  solid.setRef(_U(rotationref), xml_rot.name());
592  }
593  }
594  }
595  if (!solid) {
596  std::string err = "Failed to handle unknown solid shape:" + name + " of type " + std::string(shape->IsA()->GetName());
597  throw std::runtime_error(err);
598  }
599  return data().xmlSolids[shape] = solid;
600  }
601 }
602 
604 xml_h LCDDConverter::handlePosition(const std::string& name, const TGeoMatrix* trafo) const {
605  GeometryInfo& geo = data();
606  xml_h pos = geo.xmlPositions[trafo];
607  if (!pos) {
608  const double* tr = trafo->GetTranslation();
609  if (tr[0] != 0.0 || tr[1] != 0.0 || tr[2] != 0.0) {
610  std::string gen_name = genName(name,trafo);
611  geo.checkPosition(gen_name, trafo);
612  geo.doc_define.append(pos = xml_elt_t(geo.doc, _U(position)));
613  pos.setAttr(_U(name), gen_name);
614  pos.setAttr(_U(x), tr[0]);
615  pos.setAttr(_U(y), tr[1]);
616  pos.setAttr(_U(z), tr[2]);
617  pos.setAttr(_U(unit), "cm");
618  }
619  else if (geo.identity_pos) {
620  pos = geo.identity_pos;
621  }
622  else {
623  geo.doc_define.append(geo.identity_pos = xml_elt_t(geo.doc, _U(position)));
624  geo.identity_pos.setAttr(_U(name), "identity_pos");
625  geo.identity_pos.setAttr(_U(x), 0);
626  geo.identity_pos.setAttr(_U(y), 0);
627  geo.identity_pos.setAttr(_U(z), 0);
628  geo.identity_pos.setAttr(_U(unit), "cm");
629  pos = geo.identity_pos;
630  geo.checkPosition("identity_pos", 0);
631  }
632  geo.xmlPositions[trafo] = pos;
633  }
634  return pos;
635 }
636 
638 xml_h LCDDConverter::handleRotation(const std::string& name, const TGeoMatrix* trafo) const {
639  GeometryInfo& geo = data();
640  xml_h rot = geo.xmlRotations[trafo];
641  if (!rot) {
642  XYZRotation r = getXYZangles(trafo->GetRotationMatrix());
643  if (!(r.X() == 0.0 && r.Y() == 0.0 && r.Z() == 0.0)) {
644  std::string gen_name = genName(name,trafo);
645  geo.checkRotation(gen_name, trafo);
646  geo.doc_define.append(rot = xml_elt_t(geo.doc, _U(rotation)));
647  rot.setAttr(_U(name), gen_name);
648  rot.setAttr(_U(x), r.X());
649  rot.setAttr(_U(y), r.Y());
650  rot.setAttr(_U(z), r.Z());
651  rot.setAttr(_U(unit), "rad");
652  }
653  else if (geo.identity_rot) {
654  rot = geo.identity_rot;
655  }
656  else {
657  geo.doc_define.append(geo.identity_rot = xml_elt_t(geo.doc, _U(rotation)));
658  geo.identity_rot.setAttr(_U(name), "identity_rot");
659  geo.identity_rot.setAttr(_U(x), 0);
660  geo.identity_rot.setAttr(_U(y), 0);
661  geo.identity_rot.setAttr(_U(z), 0);
662  geo.identity_rot.setAttr(_U(unit), "rad");
663  rot = geo.identity_rot;
664  geo.checkRotation("identity_rot", 0);
665  }
666  geo.xmlRotations[trafo] = rot;
667  }
668  return rot;
669 }
670 
672 xml_h LCDDConverter::handleVolume(const std::string& /* name */, Volume volume) const {
673  GeometryInfo& geo = data();
674  xml_h vol = geo.xmlVolumes[volume];
675  if (!vol) {
676  const TGeoVolume* v = volume;
677  Volume _v(v);
678  std::string n = genName(v->GetName(),v);
679  TGeoMedium* medium = v->GetMedium();
680  TGeoShape* sh = v->GetShape();
681  xml_ref_t sol = handleSolid(sh->GetName(), sh);
682 
683  geo.checkVolume(n, volume);
684  if (v->IsAssembly()) {
685  vol = xml_elt_t(geo.doc, _U(assembly));
686  vol.setAttr(_U(name), n);
687  }
688  else {
689  if (!sol)
690  throw std::runtime_error("G4Converter: No Detector Solid present for volume:" + n);
691  else if (!m)
692  throw std::runtime_error("G4Converter: No Detector material present for volume:" + n);
693 
694  vol = xml_elt_t(geo.doc, _U(volume));
695  vol.setAttr(_U(name), n);
696  if (m) {
697  std::string mat_name = medium->GetName();
698  xml_ref_t med = handleMaterial(mat_name, Material(medium));
699  vol.setRef(_U(materialref), med.name());
700  }
701  vol.setRef(_U(solidref), sol.name());
702  }
703  geo.doc_structure.append(vol);
704  geo.xmlVolumes[v] = vol;
705  const TObjArray* dau = const_cast<TGeoVolume*>(v)->GetNodes();
706  if (dau && dau->GetEntries() > 0) {
707  for (Int_t i = 0, n_dau = dau->GetEntries(); i < n_dau; ++i) {
708  TGeoNode* node = reinterpret_cast<TGeoNode*>(dau->At(i));
709  handlePlacement(node->GetName(), node);
710  }
711  }
712  if (geo.doc_header && is_volume(volume)) {
713  Region reg = _v.region();
714  LimitSet lim = _v.limitSet();
715  VisAttr vis = _v.visAttributes();
717  if (det.isValid()) {
718  xml_ref_t xml_data = handleSensitive(det.name(), det);
719  vol.setRef(_U(sdref), xml_data.name());
720  }
721  if (reg.isValid()) {
722  xml_ref_t xml_data = handleRegion(reg.name(), reg);
723  vol.setRef(_U(regionref), xml_data.name());
724  }
725  if (lim.isValid()) {
726  xml_ref_t xml_data = handleLimitSet(lim.name(), lim);
727  vol.setRef(_U(limitsetref), xml_data.name());
728  }
729  if (vis.isValid()) {
730  xml_ref_t xml_data = handleVis(vis.name(), vis);
731  vol.setRef(_U(visref), xml_data.name());
732  }
733  }
734  }
735  return vol;
736 }
737 
739 xml_h LCDDConverter::handleVolumeVis(const std::string& /* name */, const TGeoVolume* volume) const {
740  GeometryInfo& geo = data();
741  xml_h vol = geo.xmlVolumes[volume];
742  if (!vol) {
743  const TGeoVolume* v = volume;
744  Volume _v(volume);
745  if (is_volume(volume)) {
746  VisAttr vis = _v.visAttributes();
747  if (vis.isValid()) {
748  geo.doc_structure.append(vol = xml_elt_t(geo.doc, _U(volume)));
749  vol.setAttr(_U(name), v->GetName());
750  xml_ref_t xml_data = handleVis(vis.name(), vis);
751  vol.setRef(_U(visref), xml_data.name());
752  geo.xmlVolumes[v] = vol;
753  }
754  }
755  }
756  return vol;
757 }
758 
760 void LCDDConverter::collectVolume(const std::string& /* name */, const TGeoVolume* volume) const {
761  Volume v(volume);
762  if ( is_volume(volume) ) {
763  GeometryInfo& geo = data();
764  Region reg = v.region();
765  LimitSet lim = v.limitSet();
766  SensitiveDetector det = v.sensitiveDetector();
767  if (lim.isValid())
768  geo.limits.insert(lim);
769  if (reg.isValid())
770  geo.regions.insert(reg);
771  if (det.isValid())
772  geo.sensitives.insert(det);
773  }
774  else {
775  printout(WARNING,"LCDDConverter","++ CollectVolume: Skip volume: %s",volume->GetName());
776  }
777 }
778 
779 void LCDDConverter::checkVolumes(const std::string& /* name */, Volume v) const {
780  std::string n = v.name()+_toString(v.ptr(),"_%p");
781  NameSet::const_iterator i = m_checkNames.find(n);
782  if (i != m_checkNames.end()) {
783  std::stringstream str;
784  str << "++ CheckVolumes: Volume " << n << " ";
785  if (is_volume(v.ptr())) {
786  SensitiveDetector sd = v.sensitiveDetector();
787  VisAttr vis = v.visAttributes();
788  if (sd.isValid()) {
789  str << "of " << sd.name() << " ";
790  }
791  else if (vis.isValid()) {
792  str << "with VisAttrs " << vis.name() << " ";
793  }
794  }
795  str << "has duplicate entries." << std::endl;
796  printout(ERROR,"LCDDConverter",str.str().c_str());
797  return;
798  }
799  m_checkNames.insert(n);
800 }
801 
803 xml_h LCDDConverter::handlePlacement(const std::string& name,PlacedVolume node) const {
804  GeometryInfo& geo = data();
805  xml_h place = geo.xmlPlacements[node];
806  if (!place) {
807  TGeoMatrix* matrix = node->GetMatrix();
808  TGeoVolume* volume = node->GetVolume();
809  xml_ref_t vol = xml_h(geo.xmlVolumes[volume]);
810  xml_h mot = geo.xmlVolumes[node->GetMotherVolume()];
811 
812  place = xml_elt_t(geo.doc, _U(physvol));
813  if (mot) { // Beware of top level volume!
814  mot.append(place);
815  }
816  place.setRef(_U(volumeref), vol.name());
817  if (m) {
818  xml_ref_t pos = handlePosition(name+"_pos", matrix);
819  place.setRef(_U(positionref), pos.name());
820  if ( matrix->IsRotation() ) {
821  xml_ref_t rot = handleRotation(name+"_rot", matrix);
822  place.setRef(_U(rotationref), rot.name());
823  }
824  }
825  if (geo.doc_root.tag() != "gdml") {
826  if (is_placement(node)) {
827  const PlacedVolume::VolIDs& ids = node.volIDs();
828  for (PlacedVolume::VolIDs::const_iterator i = ids.begin(); i != ids.end(); ++i) {
829  xml_h pvid = xml_elt_t(geo.doc, _U(physvolid));
830  pvid.setAttr(_U(field_name), (*i).first);
831  pvid.setAttr(_U(value), (*i).second);
832  place.append(pvid);
833  }
834  }
835  }
836  geo.xmlPlacements[node] = place;
837  }
838  else {
839  std::cout << "Attempt to DOUBLE-place physical volume:" << name << " No:" << node->GetNumber() << std::endl;
840  }
841  return place;
842 }
843 
845 xml_h LCDDConverter::handleRegion(const std::string& /* name */, Region region) const {
846  GeometryInfo& geo = data();
847  xml_h reg = geo.xmlRegions[region];
848  if (!reg) {
849  geo.doc_regions.append(reg = xml_elt_t(geo.doc, _U(region)));
850  reg.setAttr(_U(name), region.name());
851  reg.setAttr(_U(cut), region.cut());
852  reg.setAttr(_U(eunit), "GeV"); // TGeo has energy in GeV
853  reg.setAttr(_U(lunit), "cm"); // TGeo has lengths in cm
854  reg.setAttr(_U(store_secondaries), region.storeSecondaries());
855  geo.xmlRegions[region] = reg;
856  }
857  return reg;
858 }
859 
861 xml_h LCDDConverter::handleLimitSet(const std::string& /* name */, LimitSet lim) const {
862  GeometryInfo& geo = data();
863  xml_h xml = geo.xmlLimits[lim];
864  if (!xml) {
865  geo.doc_limits.append(xml = xml_elt_t(geo.doc, _U(limitset)));
866  xml.setAttr(_U(name), lim.name());
867  const std::set<Limit>& obj = lim.limits();
868  for (std::set<Limit>::const_iterator i = obj.begin(); i != obj.end(); ++i) {
869  xml_h x = xml_elt_t(geo.doc, _U(limit));
870  const Limit& l = *i;
871  xml.append(x);
872  x.setAttr(_U(name), l.name);
873  x.setAttr(_U(unit), l.unit);
874  x.setAttr(_U(value), l.value);
875  x.setAttr(_U(particles), l.particles);
876  }
877  geo.xmlLimits[lim] = xml;
878  }
879  return xml;
880 }
881 
884  xml_h xml;
885  if (seg.isValid()) {
886  typedef DDSegmentation::Parameters _P;
887  std::string typ = seg.type();
888  _P p = seg.parameters();
889  xml = xml_elt_t(data().doc, Unicode(typ));
890  for (_P::const_iterator i = p.begin(); i != p.end(); ++i) {
891  const _P::value_type& v = *i;
892  if (v->name() == "lunit") {
893  std::string val = v->value() == _toDouble("mm") ? "mm" : v->value() == _toDouble("cm") ? "cm" :
894  v->value() == _toDouble("m") ? "m" : v->value() == _toDouble("micron") ? "micron" :
895  v->value() == _toDouble("nanometer") ? "namometer" : "??";
896  xml.setAttr(Unicode(v->name()), Unicode(val));
897  continue;
898  }
899  // translate from TGeo units to Geant4 units if necessary
901  double value = _toDouble(v->value()) / dd4hep::mm;
902  xml.setAttr(Unicode(v->name()), value);
903  } else if (v->unitType() == DDSegmentation::SegmentationParameter::AngleUnit) {
904  double value = _toDouble(v->value()) * DEGREE_2_RAD;
905  xml.setAttr(Unicode(v->name()), value);
906  } else {
907  xml.setAttr(Unicode(v->name()), v->value());
908  }
909  }
910  }
911  return xml;
912 }
913 
915 xml_h LCDDConverter::handleSensitive(const std::string& /* name */, SensitiveDetector sd) const {
916  GeometryInfo& geo = data();
917  xml_h sensdet = geo.xmlSensDets[sd];
918  if (!sensdet) {
919  geo.doc_detectors.append(sensdet = xml_elt_t(geo.doc, Unicode(sd.type())));
920  sensdet.setAttr(_U(name), sd.name());
921  sensdet.setAttr(_U(ecut), sd.energyCutoff());
922  sensdet.setAttr(_U(eunit), "MeV");
923  sensdet.setAttr(_U(verbose), int(sd.verbose() ? 1 : 0));
924  sensdet.setAttr(_U(hits_collection), sd.hitsCollection());
925  if (sd.combineHits())
926  sensdet.setAttr(_U(combine_hits), sd.combineHits());
927  Readout ro = sd.readout();
928  if (ro.isValid()) {
929  xml_ref_t ref = handleIdSpec(ro.idSpec().name(), ro.idSpec());
930  sensdet.setRef(_U(idspecref), ref.name());
932  if (seg)
933  sensdet.append(seg);
934  }
935  geo.xmlSensDets[sd] = sensdet;
936  }
937  return sensdet;
938 }
939 
941 xml_h LCDDConverter::handleIdSpec(const std::string& name, IDDescriptor id_spec) const {
942  GeometryInfo& geo = data();
943  xml_h id = geo.xmlIdSpecs[id_spec];
944  if (!id) {
945  int length = 0, start = 0;
946  IDDescriptor desc = id_spec;
947  geo.doc_idDict.append(id = xml_elt_t(geo.doc, _U(idspec)));
948  id.setAttr(_U(name), name);
949  const IDDescriptor::FieldMap& fm = desc.fields();
950  for (const auto& i : fm ) {
951  xml_h idfield = xml_elt_t(geo.doc, _U(idfield));
952 #if 0
953  const BitFieldElement* f = i.second;
954  start = f.first;
955  length = f.second<0 ? -f.second : f.second;
956  idfield.setAttr(_U(signed),f.second<0 ? true : false);
957  idfield.setAttr(_U(label),(*i).first);
958  idfield.setAttr(_U(length),length);
959  idfield.setAttr(_U(start),start);
960 #else
961  const BitFieldElement* f = i.second;
962  idfield.setAttr(_U(signed),f->isSigned() ? true : false);
963  idfield.setAttr(_U(label), f->name());
964  idfield.setAttr(_U(length), (int) f->width());
965  idfield.setAttr(_U(start), (int) f->offset());
966 #endif
967  id.append(idfield);
968  }
969  id.setAttr(_U(length), length + start);
970  geo.xmlIdSpecs[id_spec] = id;
971  }
972  return id;
973 }
974 
976 xml_h LCDDConverter::handleVis(const std::string& /* name */, VisAttr attr) const {
977  GeometryInfo& geo = data();
978  xml_h vis = geo.xmlVis[attr];
979  if (!vis) {
980  float red = 0, green = 0, blue = 0;
981  int style = attr.lineStyle();
982  int draw = attr.drawingStyle();
983 
984  geo.doc_display.append(vis = xml_elt_t(geo.doc, _U(vis)));
985  vis.setAttr(_U(name), attr.name());
986  vis.setAttr(_U(visible), attr.visible());
987  vis.setAttr(_U(show_daughters), attr.showDaughters());
988  if (style == VisAttr::SOLID)
989  vis.setAttr(_U(line_style), "unbroken");
990  else if (style == VisAttr::DASHED)
991  vis.setAttr(_U(line_style), "broken");
992  if (draw == VisAttr::SOLID)
993  vis.setAttr(_U(drawing_style), "solid");
994  else if (draw == VisAttr::WIREFRAME)
995  vis.setAttr(_U(drawing_style), "wireframe");
996 
997  xml_h col = xml_elt_t(geo.doc, _U(color));
998  attr.rgb(red, green, blue);
999  col.setAttr(_U(alpha), attr.alpha());
1000  col.setAttr(_U(R), red);
1001  col.setAttr(_U(B), blue);
1002  col.setAttr(_U(G), green);
1003  vis.append(col);
1004  geo.xmlVis[attr] = vis;
1005  }
1006  return vis;
1007 }
1008 
1010 xml_h LCDDConverter::handleField(const std::string& /* name */, OverlayedField f) const {
1011  GeometryInfo& geo = data();
1012  xml_h field = geo.xmlFields[f];
1013  if (!field) {
1014  Handle<NamedObject> fld(f);
1015  std::string type = f->GetTitle();
1016  field = xml_elt_t(geo.doc, Unicode(type));
1017  field.setAttr(_U(name), f->GetName());
1018  fld = PluginService::Create<NamedObject*>(type + "_Convert2Detector", &m_detDesc, &field, &fld);
1019  printout(ALWAYS,"LCDDConverter","++ %s electromagnetic field:%s of type %s",
1020  (fld.isValid() ? "Converted" : "FAILED to convert "), f->GetName(), type.c_str());
1021  if (!fld.isValid()) {
1022  PluginDebug dbg;
1023  PluginService::Create<NamedObject*>(type + "_Convert2Detector", &m_detDesc, &field, &fld);
1024  except("LCDDConverter", "Failed to locate plugin to convert electromagnetic field:"
1025  + std::string(f->GetName()) + " of type " + type + ". "
1026  + dbg.missingFactory(type));
1027  }
1028  geo.doc_fields.append(field);
1029  }
1030  return field;
1031 }
1032 
1035  std::map<std::string, std::string> processors;
1036  static int s_idd = 9999999;
1037  std::string id;
1038  for (Detector::Properties::const_iterator i = prp.begin(); i != prp.end(); ++i) {
1039  const std::string& nam = (*i).first;
1040  const Detector::PropertyValues& vals = (*i).second;
1041  if (nam.substr(0, 6) == "geant4") {
1042  Detector::PropertyValues::const_iterator id_it = vals.find("id");
1043  if (id_it != vals.end()) {
1044  id = (*id_it).second;
1045  }
1046  else {
1047  char text[32];
1048  ::snprintf(text, sizeof(text), "%d", ++s_idd);
1049  id = text;
1050  }
1051  processors.insert(make_pair(id, nam));
1052  }
1053  }
1054  for (std::map<std::string, std::string>::const_iterator i = processors.begin(); i != processors.end(); ++i) {
1055  const GeoHandler* ptr = this;
1056  std::string nam = (*i).second;
1057  const Detector::PropertyValues& vals = prp[nam];
1058  auto iter = vals.find("type");
1059  if ( iter != vals.end() ) {
1060  std::string type = iter->second;
1061  std::string tag = type + "_Geant4_action";
1062  long result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals);
1063  if (0 == result) {
1064  PluginDebug dbg;
1065  result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals);
1066  if (0 == result) {
1067  except("LCDDConverter", "Failed to locate plugin to interprete files of type"
1068  " \"" + tag + "\" - no factory:" + type + ". " +
1069  dbg.missingFactory(tag));
1070  }
1071  }
1072  result = *(long*) result;
1073  if (result != 1) {
1074  except("LCDDConverter", "Failed to invoke the plugin " + tag + " of type " + type);
1075  }
1076  printout(INFO,"","+++ Executed Successfully Detector setup module %s.", type.c_str());
1077  continue;
1078  }
1079  printout(INFO,"","+++ FAILED to execute Detector setup module %s.", nam.c_str());
1080  }
1081 }
1082 
1085  GeometryInfo& geo = data();
1086  Header hdr = m_detDesc.header();
1087  if ( hdr.isValid() ) {
1088  xml_h obj;
1089  geo.doc_header.append(obj = xml_elt_t(geo.doc, _U(detector)));
1090  obj.setAttr(_U(name), hdr.name());
1091  geo.doc_header.append(obj = xml_elt_t(geo.doc, _U(generator)));
1092  obj.setAttr(_U(name), "LCDDConverter");
1093  obj.setAttr(_U(version), hdr.version());
1094  obj.setAttr(_U(file), hdr.url());
1095  obj.setAttr(_U(checksum), Unicode(m_detDesc.constantAsString("compact_checksum")));
1096  geo.doc_header.append(obj = xml_elt_t(geo.doc, _U(author)));
1097  obj.setAttr(_U(name), hdr.author());
1098  geo.doc_header.append(obj = xml_elt_t(geo.doc, _U(comment)));
1099  obj.setText(hdr.comment());
1100  return;
1101  }
1102  printout(WARNING,"LCDDConverter","+++ No Detector header information availible from the geometry description.");
1103 }
1104 
1105 template <typename O, typename C, typename F> void handle(const O* o, const C& c, F pmf) {
1106  for (typename C::const_iterator i = c.begin(); i != c.end(); ++i) {
1107  std::string n = (*i)->GetName();
1108  (o->*pmf)(n, *i);
1109  }
1110 }
1111 
1112 template <typename O, typename C, typename F> void handleMap(const O* o, const C& c, F pmf) {
1113  for (typename C::const_iterator i = c.begin(); i != c.end(); ++i)
1114  (o->*pmf)((*i).first, (*i).second);
1115 }
1116 
1117 template <typename O, typename C, typename F> void handleRMap(const O* o, const C& c, F pmf) {
1118  for (typename C::const_reverse_iterator i = c.rbegin(); i != c.rend(); ++i)
1119  handle(o, (*i).second, pmf);
1120 }
1121 
1124  Detector& description = m_detDesc;
1125  if (!top.isValid()) {
1126  throw std::runtime_error("Attempt to call createGDML with an invalid geometry!");
1127  }
1128  GeometryInfo& geo = *(m_dataPtr = new GeometryInfo);
1129  m_data->clear();
1130  collect(top, geo);
1131 
1132  printout(ALWAYS,"LCDDConverter","++ ==> Converting in memory detector description to GDML format...");
1133  xml::DocumentHandler docH;
1134  geo.doc = docH.create("gdml", docH.defaultComment());
1135  geo.doc_root = geo.doc.root();
1136  geo.doc_root.setAttr(Unicode("xmlns:xs"), "http://www.w3.org/2001/XMLSchema-instance");
1137  geo.doc_root.setAttr(Unicode("xs:noNamespaceSchemaLocation"),
1138  "http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd");
1139  // geo.doc = docH.create("gdml_simple_extension",comment);
1140  // geo.doc_root.setAttr(Unicode("xmlns:gdml_simple_extension"),"http://www.example.org");
1141  // geo.doc_root.setAttr(Unicode("xs:noNamespaceSchemaLocation"),
1142  // "http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd");
1143  Volume world_vol = description.worldVolume();
1144  geo.doc_root.append(geo.doc_define = xml_elt_t(geo.doc, _U(define)));
1145  geo.doc_root.append(geo.doc_materials = xml_elt_t(geo.doc, _U(materials)));
1146  geo.doc_root.append(geo.doc_solids = xml_elt_t(geo.doc, _U(solids)));
1147  geo.doc_root.append(geo.doc_structure = xml_elt_t(geo.doc, _U(structure)));
1148  geo.doc_root.append(geo.doc_setup = xml_elt_t(geo.doc, _U(setup)));
1149  geo.doc_setup.setRef(_U(world), genName(world_vol.name(),world_vol.ptr()));
1150  geo.doc_setup.setAttr(_U(name), Unicode("default"));
1151  geo.doc_setup.setAttr(_U(version), Unicode("1.0"));
1152 
1153  // Ensure that all required materials are present in the Detector material table
1154 #if 0
1155  const Detector::HandleMap& mat = description.materials();
1156  for(Detector::HandleMap::const_iterator i=mat.begin(); i!=mat.end(); ++i)
1157  geo.materials.insert(dynamic_cast<TGeoMedium*>((*i).second.ptr()));
1158 #endif
1159 
1160  // Start creating the objects for materials, solids and log volumes.
1162  printout(ALWAYS,"LCDDConverter","++ Handled %ld materials.",geo.materials.size());
1163 
1165  printout(ALWAYS,"LCDDConverter","++ Collected %ld volumes.",geo.volumes.size());
1166 
1168  printout(ALWAYS,"LCDDConverter","++ Handled %ld solids.",geo.solids.size());
1169 
1171  printout(ALWAYS,"LCDDConverter","++ Handled %ld volumes.",geo.volumes.size());
1172 
1173  m_checkNames.clear();
1175  return geo.doc;
1176 }
1177 
1180  if (!top.isValid()) {
1181  throw std::runtime_error("Attempt to call createDetector with an invalid geometry!");
1182  }
1183 
1184  GeometryInfo& geo = *(m_dataPtr = new GeometryInfo);
1185  m_data->clear();
1186  collect(top, geo);
1187  printout(ALWAYS,"LCDDConverter","++ ==> Dump visualisation attributes "
1188  "from in memory detector description...");
1189  xml::DocumentHandler docH;
1190  xml_elt_t elt(0);
1191  geo.doc = docH.create("visualization", docH.defaultComment());
1192  geo.doc_root = geo.doc.root();
1193  geo.doc_root.append(geo.doc_display = xml_elt_t(geo.doc, _U(display)));
1194  geo.doc_root.append(geo.doc_structure = xml_elt_t(geo.doc, _U(structure)));
1195 
1198  printout(ALWAYS,"LCDDConverter","++ Handled %ld volumes.",geo.volumes.size());
1199  return geo.doc;
1200 }
1201 
1204  Detector& description = m_detDesc;
1205  if (!top.isValid()) {
1206  throw std::runtime_error("Attempt to call createDetector with an invalid geometry!");
1207  }
1208 
1209  GeometryInfo& geo = *(m_dataPtr = new GeometryInfo);
1210  m_data->clear();
1211  collect(top, geo);
1212  xml::DocumentHandler docH;
1213  xml_elt_t elt(0);
1214  Volume world_vol = description.worldVolume();
1215  geo.doc = docH.create("description", docH.defaultComment());
1216  geo.doc_root = geo.doc.root();
1217  geo.doc_root.setAttr(Unicode("xmlns:description"), "http://www.lcsim.org/schemas/description/1.0");
1218  geo.doc_root.setAttr(Unicode("xmlns:xs"), "http://www.w3.org/2001/XMLSchema-instance");
1219  geo.doc_root.setAttr(Unicode("xs:noNamespaceSchemaLocation"),
1220  "http://www.lcsim.org/schemas/description/1.0/description.xsd");
1221 
1222  geo.doc_root.append(geo.doc_header = xml_elt_t(geo.doc, _U(header)));
1223  geo.doc_root.append(geo.doc_idDict = xml_elt_t(geo.doc, _U(iddict)));
1224  geo.doc_root.append(geo.doc_detectors = xml_elt_t(geo.doc, _U(sensitive_detectors)));
1225  geo.doc_root.append(geo.doc_limits = xml_elt_t(geo.doc, _U(limits)));
1226  geo.doc_root.append(geo.doc_regions = xml_elt_t(geo.doc, _U(regions)));
1227  geo.doc_root.append(geo.doc_display = xml_elt_t(geo.doc, _U(display)));
1228  geo.doc_root.append(geo.doc_gdml = xml_elt_t(geo.doc, _U(gdml)));
1229  geo.doc_root.append(geo.doc_fields = xml_elt_t(geo.doc, _U(fields)));
1230 
1231  geo.doc_gdml.append(geo.doc_define = xml_elt_t(geo.doc, _U(define)));
1232  geo.doc_gdml.append(geo.doc_materials = xml_elt_t(geo.doc, _U(materials)));
1233  geo.doc_gdml.append(geo.doc_solids = xml_elt_t(geo.doc, _U(solids)));
1234  geo.doc_gdml.append(geo.doc_structure = xml_elt_t(geo.doc, _U(structure)));
1235  geo.doc_gdml.append(geo.doc_setup = xml_elt_t(geo.doc, _U(setup)));
1236  geo.doc_setup.setRef(_U(world), genName(world_vol.name(),world_vol.ptr()));
1237  geo.doc_setup.setAttr(_U(name), Unicode("default"));
1238  geo.doc_setup.setAttr(_U(version), Unicode("1.0"));
1239 
1240  // Ensure that all required materials are present in the Detector material table
1241  const Detector::HandleMap& fld = description.fields();
1242  for (Detector::HandleMap::const_iterator i = fld.begin(); i != fld.end(); ++i)
1243  geo.fields.insert((*i).second);
1244 
1245  printout(ALWAYS,"LCDDConverter","++ ==> Converting in memory detector description to Detector format...");
1246  handleHeader();
1247  // Start creating the objects for materials, solids and log volumes.
1249  printout(ALWAYS,"LCDDConverter","++ Handled %ld materials.",geo.materials.size());
1250 
1252  printout(ALWAYS,"LCDDConverter","++ Collected %ld volumes.",geo.volumes.size());
1253 
1255  printout(ALWAYS,"LCDDConverter","++ Handled %ld solids.",geo.solids.size());
1256 
1257  handle(this, geo.vis, &LCDDConverter::handleVis);
1258  printout(ALWAYS,"LCDDConverter","++ Handled %ld visualization attributes.",geo.vis.size());
1259 
1261  printout(ALWAYS,"LCDDConverter","++ Handled %ld sensitive detectors.",geo.sensitives.size());
1262 
1264  printout(ALWAYS,"LCDDConverter","++ Handled %ld limit sets.",geo.limits.size());
1265 
1267  printout(ALWAYS,"LCDDConverter","++ Handled %ld regions.",geo.regions.size());
1268 
1270  printout(ALWAYS,"LCDDConverter","++ Handled %ld volumes.",geo.volumes.size());
1271 
1273  printout(ALWAYS,"LCDDConverter","++ Handled %ld fields.",geo.fields.size());
1274 
1275  m_checkNames.clear();
1277 #if 0
1278  //==================== Fields
1280 #endif
1281  return geo.doc;
1282 }
1283 
1286  : doc(0), doc_root(0), doc_header(0), doc_idDict(0), doc_detectors(0), doc_limits(0),
1287  doc_regions(0), doc_display(0), doc_gdml(0), doc_fields(0), doc_define(0),
1288  doc_materials(0), doc_solids(0), doc_structure(0), doc_setup(0)
1289 {
1290 }
1291 
1292 static long dump_output(xml_doc_t doc, int argc, char** argv) {
1293  xml::DocumentHandler docH;
1294  return docH.output(doc, argc > 0 ? argv[0] : "");
1295 }
1296 
1297 long create_gdml_from_dd4hep(Detector& description, int argc, char** argv) {
1298  LCDDConverter wr(description);
1299  return dump_output(wr.createGDML(description.world()), argc, argv);
1300 }
1301 
1302 static long create_description(Detector& description, int argc, char** argv) {
1303  LCDDConverter wr(description);
1304  return dump_output(wr.createDetector(description.world()), argc, argv);
1305 }
1306 
1307 static long create_vis(Detector& description, int argc, char** argv) {
1308  LCDDConverter wr(description);
1309  return dump_output(wr.createVis(description.world()), argc, argv);
1310 }
1311 
1312 static long create_visASCII(Detector& description, int /* argc */, char** argv) {
1313  LCDDConverter wr(description);
1314  /* xml_doc_t doc = */ wr.createVis(description.world());
1315  LCDDConverter::GeometryInfo& geo = wr.data();
1316  std::map<std::string, xml_comp_t> vis_map;
1317  for (xml_coll_t c(geo.doc_display, _U(vis)); c; ++c)
1318  vis_map.insert(make_pair(xml_comp_t(c).nameStr(), xml_comp_t(c)));
1319 
1320  const char* sep = ";";
1321  std::ofstream os(argv[0]);
1322  for (xml_coll_t c(geo.doc_structure, _U(volume)); c; ++c) {
1323  xml_comp_t vol = c;
1324  xml_comp_t ref = c.child(_U(visref));
1325  auto iter = vis_map.find(ref.refStr());
1326  if ( iter != vis_map.end() ) {
1327  xml_comp_t vis = iter->second;
1328  xml_comp_t col = vis.child(_U(color));
1329  os << "vol:" << vol.nameStr() << sep << "vis:" << vis.nameStr() << sep
1330  << "visible:" << vis.visible() << sep << "r:"
1331  << col.R() << sep << "g:" << col.G() << sep << "b:" << col.B() << sep
1332  << "alpha:" << col.alpha() << sep << "line_style:"
1333  << vis.attr < std::string > (_U(line_style)) << sep
1334  << "drawing_style:" << vis.attr < std::string> (_U(drawing_style)) << sep
1335  << "show_daughters:" << vis.show_daughters() << sep << std::endl;
1336  }
1337  }
1338  os.close();
1339  return 1;
1340 }
1341 
1342 DECLARE_APPLY(DD4hepGeometry2VIS, create_vis)
1343 DECLARE_APPLY(DD4hepGeometry2VISASCII, create_visASCII)
1344 //DECLARE_APPLY(DD4hepGeometry2GDML, create_gdml_from_dd4hep)
1345 DECLARE_APPLY(DD4hepGeometry2Detector, create_description)
dd4hep::xml::DocumentHandler::create
Document create(const char *tag, const char *comment=0) const
Create new XML document by parsing empty xml buffer.
Definition: DocumentHandler.cpp:681
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::DDSegmentation::BitFieldElement::offset
unsigned offset() const
Definition: BitFieldCoder.h:64
dd4hep::Header::comment
const std::string & comment() const
Accessor to object comment.
Definition: Objects.cpp:128
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
dd4hep::detail::GeoHandlerTypes::GeometryInfo::solids
std::vector< TGeoShape * > solids
Definition: GeoHandler.h:62
dd4hep::Atom
Handle class describing an element in the periodic table.
Definition: Objects.h:242
Segmentations.h
dd4hep::detail::LCDDConverter::GeometryInfo::doc_regions
xml_elt_t doc_regions
Definition: LCDDConverter.h:114
dd4hep::DDSegmentation::BitFieldElement
Helper class for BitFieldCoder that corresponds to one field value.
Definition: BitFieldCoder.h:32
Volumes.h
dd4hep::IDDescriptor::FieldMap
std::vector< std::pair< std::string, const Field * > > FieldMap
Definition: IDDescriptor.h:40
dd4hep::xml::Element::append
void append(Handle_t handle) const
Append a new element to the existing tree.
Definition: XMLElements.h:839
v
View * v
Definition: MultiView.cpp:28
dd4hep::detail::LCDDConverter::m_detDesc
Detector & m_detDesc
Reference to detector description.
Definition: LCDDConverter.h:121
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
dd4hep::DDSegmentation::BitFieldElement::isSigned
bool isSigned() const
Definition: BitFieldCoder.h:70
dd4hep::Limit::particles
std::string particles
Particle the limit should be applied to.
Definition: Objects.h:392
dd4hep::detail::LCDDConverter::m_checkNames
NameSet m_checkNames
Definition: LCDDConverter.h:122
dd4hep::Detector::Properties
std::map< std::string, PropertyValues > Properties
Definition: Detector.h:95
dd4hep::DDSegmentation::SegmentationParameter::LengthUnit
@ LengthUnit
Definition: SegmentationParameter.h:111
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::VisAttr
Handle class describing visualization attributes.
Definition: Objects.h:324
dd4hep::Region::storeSecondaries
bool storeSecondaries() const
Access secondaries flag.
Definition: Objects.cpp:525
dd4hep::DDSegmentation::SegmentationParameter::AngleUnit
@ AngleUnit
Definition: SegmentationParameter.h:111
dd4hep::xml::Element::tag
std::string tag() const
Access the tag name of this DOM element.
Definition: XMLElements.h:823
dd4hep::detail::LCDDConverter::GeometryInfo::doc_gdml
xml_elt_t doc_gdml
Definition: LCDDConverter.h:114
dd4hep::xml::Handle_t::setRef
Handle_t setRef(const XmlChar *tag, const XmlChar *ref)
Add reference child as a new child node. The obj must have the "name" attribute!
Definition: XMLElements.cpp:937
dd4hep::xml::Handle_t::append
void append(Handle_t e) const
Append a DOM element to the current node.
Definition: XMLElements.cpp:727
dd4hep::LimitSet::limits
const std::set< Limit > & limits() const
Accessor to limits container.
Definition: Objects.cpp:464
dd4hep::detail::LCDDConverter::GeometryInfo::xmlSensDets
SensDetMap xmlSensDets
Definition: LCDDConverter.h:82
dd4hep::Limit
Small object describing a limit structure acting on a particle type.
Definition: Objects.h:389
dd4hep::IDDescriptor
Class implementing the ID encoding of the detector response.
Definition: IDDescriptor.h:37
DECLARE_APPLY
#define DECLARE_APPLY(name, func)
Definition: Factories.h:281
dd4hep::detail::LCDDConverter::createDetector
xml_doc_t createDetector(DetElement top)
Create geometry conversion in Detector format.
Definition: LCDDConverter.cpp:1203
dd4hep::detail::LCDDConverter::handleField
virtual xml_h handleField(const std::string &name, OverlayedField field) const
Convert the electric or magnetic fields into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:1010
dd4hep::detail::LCDDConverter::GeometryInfo::doc_solids
xml_elt_t doc_solids
Definition: LCDDConverter.h:115
dd4hep::Detector::PropertyValues
std::map< std::string, std::string > PropertyValues
Definition: Detector.h:94
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::Handle< NamedObject >
DetectorInterna.h
dd4hep::_toString
std::string _toString(bool value)
String conversions: boolean value to string.
Definition: Handle.cpp:332
dd4hep::detail::LCDDConverter::GeometryInfo::limits
std::set< LimitSet > limits
Definition: LCDDConverter.h:88
dd4hep::detail::LCDDConverter::handleRotation
virtual xml_h handleRotation(const std::string &name, const TGeoMatrix *trafo) const
Convert the Rotation into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:638
dd4hep::Solid_type< TGeoShape >
dd4hep::Detector::fields
virtual const HandleMap & fields() const =0
Accessor to the map of field entries, which together form the global field.
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::Header::url
const std::string & url() const
Accessor to object url.
Definition: Objects.cpp:88
dd4hep::detail::LCDDConverter::GeometryInfo::xmlFields
FieldMap xmlFields
Definition: LCDDConverter.h:85
dd4hep::Detector::worldVolume
virtual Volume worldVolume() const =0
Return handle to the world volume containing everything.
dd4hep::detail::LCDDConverter::handleElement
virtual xml_h handleElement(const std::string &name, Atom element) const
Convert the geometry type element into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:137
dd4hep::detail::GeoHandlerTypes::GeometryInfo::vis
std::set< VisAttr > vis
Definition: GeoHandler.h:66
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::detail::LCDDConverter::data
GeometryInfo & data() const
Definition: LCDDConverter.h:125
dd4hep::detail::LCDDConverter
Geometry converter from dd4hep to Geant 4 in Detector format.
Definition: LCDDConverter.h:50
dd4hep::detail::LCDDConverter::GeometryInfo::doc_display
xml_elt_t doc_display
Definition: LCDDConverter.h:114
dd4hep::detail::LCDDConverter::handleSolid
virtual xml_h handleSolid(const std::string &name, const TGeoShape *volume) const
Convert the geometry type solid into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:221
dd4hep::VisAttr::alpha
float alpha() const
Get alpha value.
Definition: Objects.cpp:371
dd4hep::detail::LCDDConverter::GeometryInfo::xmlRegions
RegionMap xmlRegions
Definition: LCDDConverter.h:78
dd4hep::OverlayedField
Class describing a field overlay with several sources.
Definition: Fields.h:138
dd4hep::detail::LCDDConverter::handleMaterial
virtual xml_h handleMaterial(const std::string &name, Material medium) const
Convert the geometry type material into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:160
xml_comp_t
dd4hep::xml::Component xml_comp_t
Definition: XML.h:33
dd4hep::detail::LCDDConverter::GeometryInfo::doc_fields
xml_elt_t doc_fields
Definition: LCDDConverter.h:114
dd4hep::detail::LCDDConverter::handlePlacement
virtual xml_h handlePlacement(const std::string &name, PlacedVolume node) const
Convert the geometry type volume placement into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:803
dd4hep::detail::LCDDConverter::createVis
xml_doc_t createVis(DetElement top)
Create geometry conversion in Vis format.
Definition: LCDDConverter.cpp:1179
dd4hep::Header::name
const std::string name() const
Accessor to object name.
Definition: Objects.cpp:68
DocumentHandler.h
dd4hep::detail::LCDDConverter::GeometryInfo::doc_idDict
xml_elt_t doc_idDict
Definition: LCDDConverter.h:114
dd4hep::VisAttr::lineStyle
int lineStyle() const
Get line style.
Definition: Objects.cpp:351
dd4hep::detail::LCDDConverter::GeometryInfo::checkPosition
void checkPosition(const std::string &name, const TNamed *n) const
Definition: LCDDConverter.h:96
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::VisAttr::drawingStyle
int drawingStyle() const
Get drawing style.
Definition: Objects.cpp:361
dd4hep::VisAttr::showDaughters
bool showDaughters() const
Get Flag to show/hide daughter elements.
Definition: Objects.cpp:331
dd4hep::detail::LCDDConverter::GeometryInfo::xmlSolids
SolidMap xmlSolids
Definition: LCDDConverter.h:75
dd4hep::detail::LCDDConverter::collectVolume
virtual void collectVolume(const std::string &name, const TGeoVolume *volume) const
Dump logical volume in GDML format to output stream.
Definition: LCDDConverter.cpp:760
dd4hep::detail::LCDDConverter::GeometryInfo::identity_pos
xml_h identity_pos
Definition: LCDDConverter.h:113
dd4hep::detail::LCDDConverter::GeometryInfo::xmlLimits
LimitMap xmlLimits
Definition: LCDDConverter.h:80
dd4hep::View::name
const std::string & name() const
Access to the view name/title.
Definition: View.h:81
dd4hep::detail::LCDDConverter::GeometryInfo::checkMaterial
void checkMaterial(const std::string &name, Material n) const
Definition: LCDDConverter.h:108
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::detail::LCDDConverter::GeometryInfo::doc_define
xml_elt_t doc_define
Definition: LCDDConverter.h:115
dd4hep::PlacedVolumeExtension::VolIDs
Volume ID container.
Definition: Volumes.h:88
dd4hep::detail::LCDDConverter::createGDML
xml_doc_t createGDML(DetElement top)
Create geometry conversion in GDML format.
Definition: LCDDConverter.cpp:1123
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:378
dd4hep::Solid_type::name
const char * name() const
Access to shape name.
Definition: Shapes.cpp:54
dd4hep::detail::GeoHandler
The base class for all dd4hep geometry crawlers.
Definition: GeoHandler.h:87
dd4hep::detail::LCDDConverter::GeometryInfo::xmlVis
VisMap xmlVis
Definition: LCDDConverter.h:79
dd4hep::detail
DD4hep internal namespace.
Definition: Alignments.h:32
dd4hep::DDSegmentation::BitFieldElement::name
const std::string & name() const
Definition: BitFieldCoder.h:61
mix
#define mix(a, b, c)
Definition: Geant4EventSeed.h:113
dd4hep::LimitSet
Handle class describing a set of limits as they are used for simulation.
Definition: Objects.h:425
dd4hep::SensitiveDetector::hitsCollection
const std::string & hitsCollection() const
Access the hits collection name.
Definition: DetElement.cpp:447
dd4hep::Volume::limitSet
LimitSet limitSet() const
Access to the limit set.
Definition: Volumes.cpp:1275
dd4hep::Limit::name
std::string name
Limit name.
Definition: Objects.h:394
dd4hep::detail::LCDDConverter::GeometryInfo::doc_header
xml_elt_t doc_header
Definition: LCDDConverter.h:114
dd4hep::VisAttr::DASHED
@ DASHED
Definition: Objects.h:327
dd4hep::detail::LCDDConverter::GeometryInfo
Data structure of the geometry converter from dd4hep to Geant 4 in Detector format.
Definition: LCDDConverter.h:71
dd4hep::DDSegmentation::Parameters
std::vector< Parameter > Parameters
Definition: SegmentationsInterna.h:35
dd4hep::detail::LCDDConverter::GeometryInfo::checkVolume
void checkVolume(const std::string &name, const TNamed *n) const
Definition: LCDDConverter.h:102
dd4hep::detail::LCDDConverter::checkVolumes
void checkVolumes(const std::string &name, Volume volume) const
Data integrity checker.
Definition: LCDDConverter.cpp:779
dd4hep::Volume::region
Region region() const
Access to the handle to the region structure.
Definition: Volumes.cpp:1256
Unicode
dd4hep::xml::Strng_t Unicode
Definition: XML.h:24
dd4hep::xml
Namespace for the AIDA detector description toolkit supporting XML utilities.
Definition: ConditionsTags.h:27
dd4hep::Detector::constantAsString
virtual std::string constantAsString(const std::string &name) const =0
Typed access to constants: access string values.
dd4hep::detail::LCDDConverter::GeometryInfo::doc_detectors
xml_elt_t doc_detectors
Definition: LCDDConverter.h:114
dd4hep::detail::LCDDConverter::GeometryInfo::regions
std::set< Region > regions
Definition: LCDDConverter.h:87
dd4hep::xml::Element::setRef
Attribute setRef(const XmlChar *tag, const XmlChar *refname) const
Set the reference attribute to the node (adds attribute ref="ref-name")
Definition: XMLElements.cpp:1106
dd4hep::detail::LCDDConverter::handleVolume
virtual xml_h handleVolume(const std::string &name, Volume volume) const
Convert the geometry type logical volume into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:672
dd4hep::detail::LCDDConverter::GeometryInfo::identity_rot
xml_h identity_rot
Definition: LCDDConverter.h:113
dd4hep::detail::LCDDConverter::m_dataPtr
GeometryInfo * m_dataPtr
Definition: LCDDConverter.h:123
dd4hep::DDSegmentation::BitFieldElement::width
unsigned width() const
Definition: BitFieldCoder.h:67
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::SensitiveDetector::combineHits
bool combineHits() const
Access flag to combine hist.
Definition: DetElement.cpp:471
TNamed
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:37
dd4hep::Header::author
const std::string & author() const
Accessor to object author.
Definition: Objects.cpp:98
dd4hep::xml::RefElement::name
const XmlChar * name() const
Access the object's name in unicode.
Definition: XMLElements.cpp:1177
Plugins.h
dd4hep::Region
Handle class describing a region as used in simulation.
Definition: Objects.h:462
dd4hep::PluginDebug
Helper to debug plugin manager calls.
Definition: Plugins.h:74
dd4hep::VisAttr::rgb
bool rgb(float &red, float &green, float &blue) const
Get RGB values of the color (if valid)
Definition: Objects.cpp:396
dd4hep::detail::GeoHandler::m_data
std::map< int, std::vector< const TGeoNode * > > * m_data
actual container with std::vector (preserves order)
Definition: GeoHandler.h:93
dd4hep::Header
Handle class describing the basic information about geometry objects as it is defined in Detector.
Definition: Objects.h:158
dd4hep::Readout::segmentation
Segmentation segmentation() const
Access segmentation structure.
Definition: Readout.cpp:134
dd4hep::detail::LCDDConverter::GeometryInfo::xmlVolumes
VolumeMap xmlVolumes
Definition: LCDDConverter.h:76
dd4hep::Limit::unit
std::string unit
Units.
Definition: Objects.h:396
dd4hep::detail::LCDDConverter::~LCDDConverter
virtual ~LCDDConverter()
Standard destructor.
Definition: LCDDConverter.cpp:130
dd4hep::xml::Strng_t
Helper class to encapsulate a unicode string.
Definition: XMLElements.h:170
dd4hep::PluginDebug::missingFactory
std::string missingFactory(const std::string &name) const
Helper to check factory existence.
Definition: Plugins.cpp:147
dd4hep::xml::DocumentHandler::defaultComment
static std::string defaultComment()
Default comment string.
Definition: DocumentHandler.cpp:630
dd4hep::detail::GeoHandlerTypes::GeometryInfo::fields
std::set< Ref_t > fields
Definition: GeoHandler.h:67
dd4hep::verbose
std::size_t verbose(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:63
dd4hep::Limit::value
double value
Double value.
Definition: Objects.h:400
dd4hep::detail::LCDDConverter::GeometryInfo::doc
xml_doc_t doc
Definition: LCDDConverter.h:112
dd4hep::detail::LCDDConverter::handleProperties
void handleProperties(Detector::Properties &prp) const
Handle the geant 4 specific properties.
Definition: LCDDConverter.cpp:1034
dd4hep::xml::Handle_t::setText
void setText(const XmlChar *text) const
Set the element's text.
Definition: XMLElements.cpp:783
dd4hep::detail::LCDDConverter::GeometryInfo::xmlElements
ElementMap xmlElements
Definition: LCDDConverter.h:73
dd4hep::Region::cut
double cut() const
Access cut value.
Definition: Objects.cpp:515
dd4hep::detail::LCDDConverter::GeometryInfo::doc_limits
xml_elt_t doc_limits
Definition: LCDDConverter.h:114
dd4hep::SensitiveDetector::type
std::string type() const
Access the type of the sensitive detector.
Definition: DetElement.cpp:409
dd4hep::IDDescriptor::fields
const FieldMap & fields() const
Access the fieldmap container.
Definition: IDDescriptor.cpp:87
dd4hep::xml::Document
Class supporting the basic functionality of an XML document.
Definition: XMLElements.h:697
dd4hep::Detector::HandleMap
std::map< std::string, Handle< NamedObject > > HandleMap
Type definition of a map of named handles.
Definition: Detector.h:93
dd4hep::detail::LCDDConverter::handleRegion
virtual xml_h handleRegion(const std::string &name, Region region) const
Convert the geometry type region into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:845
dd4hep::SensitiveDetector::verbose
bool verbose() const
Access flag to combine hist.
Definition: DetElement.cpp:459
xml_h
dd4hep::xml::Handle_t xml_h
Definition: ConditionsRepository.cpp:32
dd4hep::detail::LCDDConverter::GeometryInfo::sensitives
std::set< SensitiveDetector > sensitives
Definition: LCDDConverter.h:86
dd4hep::detail::LCDDConverter::GeometryInfo::xmlPositions
TrafoMap xmlPositions
Definition: LCDDConverter.h:83
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::xml::RefElement
User abstraction class to manipulate named XML elements (references) within a document.
Definition: XMLElements.h:953
dd4hep::Segmentation::type
std::string type() const
Accessor: Segmentation type.
Definition: Segmentations.cpp:50
dd4hep::detail::LCDDConverter::GeometryInfo::checkShape
void checkShape(const std::string &name, const TNamed *n) const
Definition: LCDDConverter.h:105
dd4hep::detail::LCDDConverter::handleIdSpec
virtual xml_h handleIdSpec(const std::string &name, IDDescriptor idspec) const
Convert the geometry id dictionary entry to the corresponding Xml object(s).
Definition: LCDDConverter.cpp:941
dd4hep::detail::LCDDConverter::GeometryInfo::doc_setup
xml_elt_t doc_setup
Definition: LCDDConverter.h:115
dd4hep::_toDouble
double _toDouble(const std::string &value)
String conversions: string to double value.
Definition: Handle.cpp:116
dd4hep::xml::DocumentHandler::output
virtual int output(Document doc, const std::string &fname) const
Write xml document to output file (stdout if file name empty)
Definition: DocumentHandler.cpp:396
DEGREE_2_RAD
#define DEGREE_2_RAD
Definition: Handle.h:29
dd4hep::detail::LCDDConverter::handleLimitSet
virtual xml_h handleLimitSet(const std::string &name, LimitSet limitset) const
Convert the geometry type LimitSet into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:861
dd4hep::VisAttr::visible
bool visible() const
Get visibility flag.
Definition: Objects.cpp:341
dd4hep::detail::LCDDConverter::handleVolumeVis
virtual xml_h handleVolumeVis(const std::string &name, const TGeoVolume *volume) const
Dump logical volume in GDML format to output stream.
Definition: LCDDConverter.cpp:739
dd4hep::xml::DocumentHandler
Class supporting to read and parse XML documents.
Definition: DocumentHandler.h:39
dd4hep::VisAttr::SOLID
@ SOLID
Definition: Objects.h:327
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep::detail::LCDDConverter::handleHeader
virtual void handleHeader() const
Add header information in Detector format.
Definition: LCDDConverter.cpp:1084
ObjectsInterna.h
dd4hep::detail::LCDDConverter::GeometryInfo::xmlIdSpecs
IdSpecMap xmlIdSpecs
Definition: LCDDConverter.h:81
dd4hep::xml::Element
User abstraction class to manipulate XML elements within a document.
Definition: XMLElements.h:769
dd4hep::Segmentation::parameters
DDSegmentation::Parameters parameters() const
Access to the parameters.
Definition: Segmentations.cpp:59
dd4hep::SensitiveDetector::energyCutoff
double energyCutoff() const
Access energy cut off.
Definition: DetElement.cpp:436
dd4hep::detail::LCDDConverter::GeometryInfo::check
void check(const std::string &name, const TNamed *n, std::map< std::string, const TNamed * > &array) const
Definition: LCDDConverter.cpp:116
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::VisAttr::WIREFRAME
@ WIREFRAME
Definition: Objects.h:327
dd4hep::xml::Element::setAttr
Attribute setAttr(const XmlChar *nam, const T &val) const
Set single attribute.
Definition: XMLElements.h:900
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::SensitiveDetector::readout
Readout readout() const
Access readout structure of the sensitive detector.
Definition: DetElement.cpp:420
xml_elt_t
dd4hep::xml::Element xml_elt_t
Definition: ConditionsRepository.cpp:33
dd4hep::PlacedVolume::data
Object * data() const
Check if placement is properly instrumented.
Definition: Volumes.cpp:431
dd4hep::detail::LCDDConverter::GeometryInfo::xmlPlacements
PlacementMap xmlPlacements
Definition: LCDDConverter.h:77
dd4hep::detail::LCDDConverter::LCDDConverter
LCDDConverter(Detector &description)
Initializing Constructor.
Definition: LCDDConverter.cpp:126
LCDDConverter.h
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::detail::LCDDConverter::handleSensitive
virtual xml_h handleSensitive(const std::string &name, SensitiveDetector sens_det) const
Convert the geometry type SensitiveDetector into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:915
TGeoConeSeg
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:17
dd4hep::Readout
Handle to the implementation of the readout structure of a subdetector.
Definition: Readout.h:38
dd4hep::Segmentation
Handle class supporting generic Segmentations of sensitive detectors.
Definition: Segmentations.h:41
dd4hep::detail::LCDDConverter::GeometryInfo::xmlMaterials
MaterialMap xmlMaterials
Definition: LCDDConverter.h:74
dd4hep::xml::Handle_t::setAttr
Attribute setAttr(const XmlChar *t, const XmlChar *v) const
Generic attribute setter with unicode value.
Definition: XMLElements.cpp:919
dd4hep::detail::LCDDConverter::handleSegmentation
virtual xml_h handleSegmentation(Segmentation seg) const
Convert the segmentation of a SensitiveDetector into the corresponding Detector object.
Definition: LCDDConverter.cpp:883
dd4hep::detail::LCDDConverter::GeometryInfo::doc_root
xml_elt_t doc_root
Definition: LCDDConverter.h:114
dd4hep::detail::LCDDConverter::GeometryInfo::doc_structure
xml_elt_t doc_structure
Definition: LCDDConverter.h:115
dd4hep::Readout::idSpec
IDDescriptor idSpec() const
Access IDDescription structure.
Definition: Readout.cpp:112
create_gdml_from_dd4hep
long create_gdml_from_dd4hep(Detector &description, int argc, char **argv)
Definition: LCDDConverter.cpp:1297
dd4hep::PlacedVolume::volIDs
const PlacedVolumeExtension::VolIDs & volIDs() const
Access to the volume IDs.
Definition: Volumes.cpp:480
dd4hep::Volume::visAttributes
VisAttr visAttributes() const
Access the visualisation attributes.
Definition: Volumes.cpp:1210
DD4hepUnits.h
dd4hep::detail::GeoHandlerTypes::GeometryInfo::volumes
std::vector< Volume > volumes
Definition: GeoHandler.h:65
FieldTypes.h
dd4hep::detail::LCDDConverter::GeometryInfo::GeometryInfo
GeometryInfo()
Helper constructor.
Definition: LCDDConverter.cpp:1285
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
dd4hep::detail::GeoHandlerTypes::GeometryInfo::materials
std::set< Material > materials
Definition: GeoHandler.h:68
Printout.h
dd4hep::detail::LCDDConverter::GeometryInfo::xmlRotations
TrafoMap xmlRotations
Definition: LCDDConverter.h:84
dd4hep::detail::LCDDConverter::handlePosition
virtual xml_h handlePosition(const std::string &name, const TGeoMatrix *trafo) const
Convert the Position into the corresponding Xml object(s).
Definition: LCDDConverter.cpp:604
dd4hep::detail::LCDDConverter::GeometryInfo::doc_materials
xml_elt_t doc_materials
Definition: LCDDConverter.h:115
dd4hep::Header::version
const std::string & version() const
Accessor to object version.
Definition: Objects.cpp:118
dd4hep::Detector::header
virtual Header header() const =0
Accessor to the map of header entries.
handle
void handle(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1105
dd4hep::detail::LCDDConverter::GeometryInfo::checkRotation
void checkRotation(const std::string &name, const TNamed *n) const
Definition: LCDDConverter.h:99
dd4hep::Volume::sensitiveDetector
Handle< NamedObject > sensitiveDetector() const
Access to the handle to the sensitive detector.
Definition: Volumes.cpp:1287
dd4hep::detail::LCDDConverter::handleVis
virtual xml_h handleVis(const std::string &name, VisAttr vis) const
Convert the geometry visualisation attributes to the corresponding Xml object(s).
Definition: LCDDConverter.cpp:976
handleRMap
void handleRMap(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1117
dd4hep::Detector::properties
virtual Properties & properties() const =0
Access to properties map.
dd4hep::detail::GeoHandler::collect
GeoHandler & collect(DetElement top)
Collect geometry information from traversal.
Definition: GeoHandler.cpp:101
handleMap
void handleMap(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1112
dd4hep::xml::Document::root
Handle_t root() const
Access the ROOT eleemnt of the DOM document.
Definition: XMLElements.cpp:1040