29 #include "TGeoManager.h"
30 #include "TGeoMatrix.h"
31 #include "TGeoCompositeShape.h"
35 #include "TGeoBoolNode.h"
39 #include "TGeoTorus.h"
43 #include "Math/GenVector/RotationX.h"
44 #include "Math/GenVector/RotationZ.h"
46 #include "CLHEP/Units/GlobalSystemOfUnits.h"
91 : m_level(
pset.getUntrackedParameter<
int>(
"level")),
92 m_verbose(
pset.getUntrackedParameter<
bool>(
"verbose")),
93 m_fullname(
pset.getUntrackedParameter<
bool>(
"fullName")),
94 viewToken_(setWhatProduced(this).consumes()) {}
98 desc.addUntracked<
int>(
"level", 10)->setComment(
"How deep into the geometry hierarchy should the conversion go.");
99 desc.addUntracked<
bool>(
"verbose",
false);
100 desc.addUntracked<
bool>(
"fullName",
true)->setComment(
"use fillname() instead of name() when generating node names");
102 conf.
add(
"TGeoMgrFromDdd",
desc);
116 TGeoTranslation
t(iTrans.x() / cm, iTrans.y() / cm, iTrans.z() / cm);
118 return new TGeoCombiTrans(
t,
r);
132 return std::unique_ptr<TGeoManager>();
135 TGeoManager* geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
137 if (gGeoIdentity ==
nullptr) {
138 gGeoIdentity =
new TGeoIdentity(
"Identity");
141 std::cout <<
"about to initialize the DDCompactView walker"
142 <<
" with a root node " << viewH->
root() << std::endl;
144 auto walker = viewH->
walker();
145 auto info = walker.current();
150 if (!walker.firstChild()) {
151 return std::unique_ptr<TGeoManager>();
157 if (top ==
nullptr) {
158 return std::unique_ptr<TGeoManager>();
161 geo_mgr->SetTopVolume(top);
163 top->SetVisibility(kFALSE);
164 top->SetLineColor(kBlue);
166 std::vector<TGeoVolume*> parentStack;
167 parentStack.push_back(top);
170 auto info = walker.current();
173 for (
unsigned int i = 0;
i < parentStack.size(); ++
i) {
183 if (
nullptr !=
child &&
info.second !=
nullptr) {
184 parentStack.back()->AddNode(
186 child->SetLineColor(kBlue);
188 if (
info.second ==
nullptr) {
192 if (
nullptr ==
child || childAlreadyExists ||
m_level ==
int(parentStack.size())) {
193 if (
nullptr !=
child) {
194 child->SetLineColor(kRed);
197 if (!walker.nextSibling()) {
198 while (walker.parent()) {
199 parentStack.pop_back();
200 if (walker.nextSibling()) {
206 if (walker.firstChild()) {
207 parentStack.push_back(
child);
209 if (!walker.nextSibling()) {
210 while (walker.parent()) {
211 parentStack.pop_back();
212 if (walker.nextSibling()) {
219 }
while (!parentStack.empty());
221 geo_mgr->CloseGeometry();
223 geo_mgr->DefaultColors();
230 return std::unique_ptr<TGeoManager>(geo_mgr);
238 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"with name: " << iName <<
" and solid: " << iSolid;
242 throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + iName +
" is not declared * ");
244 throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + defined.first->name() +
" is not defined *");
247 if (rSolid ==
nullptr) {
248 const std::vector<double>&
params = iSolid.parameters();
249 switch (iSolid.shape()) {
254 rSolid =
new TGeoConeSeg(iName.c_str(),
265 rSolid =
new TGeoTubeSeg(iName.c_str(),
274 rSolid =
new TGeoCtub(iName.c_str(),
288 rSolid =
new TGeoTrap(iName.c_str(),
302 rSolid =
new TGeoPcon(iName.c_str(),
params[0] / deg,
params[1] / deg, (
params.size() - 2) / 3);
310 for (std::vector<double>::iterator it =
temp.begin() + 3; it !=
temp.end(); ++it) {
313 rSolid->SetDimensions(&(*(
temp.begin())));
317 rSolid =
new TGeoPgon(
326 for (std::vector<double>::iterator it =
temp.begin() + 4; it !=
temp.end(); ++it) {
329 rSolid->SetDimensions(&(*(
temp.begin())));
334 std::vector<double>
x = extrPgon.
xVec();
336 std::vector<double>
y = extrPgon.
yVec();
338 std::vector<double>
z = extrPgon.
zVec();
339 std::vector<double> zx = extrPgon.
zxVec();
340 std::vector<double> zy = extrPgon.
zyVec();
341 std::vector<double> zscale = extrPgon.
zscaleVec();
343 TGeoXtru* mySolid =
new TGeoXtru(
z.size());
344 mySolid->DefinePolygon(
x.size(), &(*
x.begin()), &(*
y.begin()));
346 mySolid->DefineSection(
i,
z[
i] / cm, zx[
i] / cm, zy[
i] / cm, zscale[
i]);
356 double r =
pt.radius();
357 bool atMinusZ =
pt.atMinusZ();
360 bool intersec =
false;
367 double halfOpeningAngle = asin(
x /
std::abs(
r)) / deg;
368 double displacement = 0;
377 h =
pt.y1() <
pt.y2() ?
pt.y2() :
pt.y1();
380 displacement = -
pt.halfZ() -
delta;
381 startPhi = 90. - halfOpeningAngle;
383 displacement =
pt.halfZ() +
delta;
384 startPhi = -90. - halfOpeningAngle;
388 displacement = -
pt.halfZ() +
delta;
389 startPhi = 270. - halfOpeningAngle;
392 displacement =
pt.halfZ() -
delta;
393 startPhi = 90. - halfOpeningAngle;
400 std::unique_ptr<TGeoShape> trap(
401 new TGeoTrd2(
name.c_str(),
pt.x1() / cm,
pt.x2() / cm,
pt.y1() / cm,
pt.y2() / cm,
pt.halfZ() / cm));
403 std::unique_ptr<TGeoShape> tubs(
new TGeoTubeSeg(
name.c_str(),
408 startPhi + halfOpeningAngle * 2.));
410 TGeoSubtraction* sub =
new TGeoSubtraction(
412 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
414 std::unique_ptr<TGeoShape> box(
new TGeoBBox(1.1 *
x / cm, 1.1 *
h / cm,
sqrt(
r *
r -
x *
x) / cm));
416 TGeoSubtraction* sub =
new TGeoSubtraction(
419 std::unique_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape(iName.c_str(), sub));
421 TGeoUnion* boolS =
new TGeoUnion(
424 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
431 rSolid =
new TGeoTorus(iName.c_str(),
442 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
449 if (
nullptr != left.get() &&
nullptr != right.get()) {
450 TGeoSubtraction* sub =
451 new TGeoSubtraction(left.release(),
455 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
462 throw cms::Exception(
"GeomConvert") <<
"conversion to DDTruncTubs failed";
464 double rIn(
tt.rIn());
465 double rOut(
tt.rOut());
466 double zHalf(
tt.zHalf());
467 double startPhi(
tt.startPhi());
469 double cutAtStart(
tt.cutAtStart());
470 double cutAtDelta(
tt.cutAtDelta());
471 bool cutInside(
bool(
tt.cutInside()));
475 if (rIn <= 0 || rOut <= 0 || cutAtStart <= 0 || cutAtDelta <= 0) {
476 std::string s =
"TruncTubs " +
name +
": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!";
483 if (startPhi != 0.) {
489 double r(cutAtStart);
490 double R(cutAtDelta);
493 std::unique_ptr<TGeoShape> tubs(
494 new TGeoTubeSeg(
name.c_str(), rIn / cm, rOut / cm, zHalf / cm, startPhi,
deltaPhi / deg));
496 double boxX(rOut), boxY(rOut);
499 double boxZ(1.1 * zHalf);
504 double cos_alpha = cath / hypo;
505 double alpha = -acos(cos_alpha);
519 std::unique_ptr<TGeoShape> box(
new TGeoBBox(
name.c_str(), boxX / cm, boxZ / cm, boxY / cm));
521 TGeoTranslation trans(xBox / cm, 0., 0.);
523 TGeoSubtraction* sub =
524 new TGeoSubtraction(tubs.release(), box.release(),
nullptr,
new TGeoCombiTrans(trans,
rot));
526 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
532 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
541 if (
nullptr != left.get() &&
nullptr != right.get()) {
542 TGeoUnion* boolS =
new TGeoUnion(left.release(),
546 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
553 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
560 if (
nullptr != left.get() &&
nullptr != right.get()) {
561 TGeoIntersection* boolS =
562 new TGeoIntersection(left.release(),
566 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
573 throw cms::Exception(
"GeomConvert") <<
"conversion to DDEllipticalTube failed";
583 if (rSolid ==
nullptr) {
584 std::cerr <<
"COULD NOT MAKE " << iName <<
" of a shape " << iSolid << std::endl;
587 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
599 if (geo_med ==
nullptr) {
601 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
605 v =
new TGeoVolume(iName.c_str(), solid, geo_med);
616 if (mat ==
nullptr) {
624 mat =
new TGeoMaterial(mat_name.c_str(), iMaterial.
a() * mole /
g, iMaterial.
z(), iMaterial.
density() * cm3 /
g);