31 #include "TGeoManager.h"
32 #include "TGeoMatrix.h"
33 #include "TGeoCompositeShape.h"
37 #include "TGeoBoolNode.h"
43 #include "Math/GenVector/RotationX.h"
45 #include "CLHEP/Units/GlobalSystemOfUnits.h"
59 : m_level(
pset.getUntrackedParameter<
int>(
"level", 10)),
60 m_verbose(
pset.getUntrackedParameter<
bool>(
"verbose",
false)),
61 m_eventSetup(nullptr),
62 m_geoManager(nullptr) {
78 printf(
"TGeoFromDddService::postBeginRun\n");
84 printf(
"TGeoFromDddService::postEndRun\n");
100 edm::LogError(
"TGeoFromDddService") <<
"getGeoManager() -- EventSetup not present.\n";
104 edm::LogError(
"TGeoFromDddService") <<
"getGeoManager() -- creation failed.\n";
123 TGeoTranslation
t(iTrans.x() / cm, iTrans.y() / cm, iTrans.z() / cm);
125 return new TGeoCombiTrans(
t,
r);
143 TGeoManager* geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
145 if (gGeoIdentity ==
nullptr) {
146 gGeoIdentity =
new TGeoIdentity(
"Identity");
149 std::cout <<
"about to initialize the DDCompactView walker" << std::endl;
151 auto info = walker.current();
158 if (top ==
nullptr) {
162 geo_mgr->SetTopVolume(top);
164 top->SetVisibility(kFALSE);
165 top->SetLineColor(kBlue);
167 std::vector<TGeoVolume*> parentStack;
168 parentStack.push_back(top);
170 if (!walker.firstChild()) {
175 auto info = walker.current();
178 for (
unsigned int i = 0;
i < parentStack.size(); ++
i) {
185 bool childAlreadyExists = (
nullptr !=
nameToVolume_[
info.first.name().fullname()]);
187 if (
nullptr !=
child &&
info.second !=
nullptr) {
188 parentStack.back()->AddNode(
190 child->SetLineColor(kBlue);
192 if (
info.second ==
nullptr) {
196 if (
nullptr ==
child || childAlreadyExists ||
level ==
int(parentStack.size())) {
197 if (
nullptr !=
child) {
198 child->SetLineColor(kRed);
201 if (!walker.nextSibling()) {
202 while (walker.parent()) {
203 parentStack.pop_back();
204 if (walker.nextSibling()) {
210 if (walker.firstChild()) {
211 parentStack.push_back(
child);
213 if (!walker.nextSibling()) {
214 while (walker.parent()) {
215 parentStack.pop_back();
216 if (walker.nextSibling()) {
223 }
while (!parentStack.empty());
225 geo_mgr->CloseGeometry();
227 geo_mgr->DefaultColors();
239 if (rSolid ==
nullptr) {
242 switch (iSolid.
shape()) {
247 rSolid =
new TGeoConeSeg(iName.c_str(),
258 rSolid =
new TGeoTubeSeg(iName.c_str(),
267 rSolid =
new TGeoCtub(iName.c_str(),
281 rSolid =
new TGeoTrap(iName.c_str(),
295 rSolid =
new TGeoPcon(iName.c_str(),
params[0] / deg,
params[1] / deg, (
params.size() - 2) / 3);
303 for (std::vector<double>::iterator it =
temp.begin() + 3; it !=
temp.end(); ++it) {
306 rSolid->SetDimensions(&(*(
temp.begin())));
310 rSolid =
new TGeoPgon(
319 for (std::vector<double>::iterator it =
temp.begin() + 4; it !=
temp.end(); ++it) {
322 rSolid->SetDimensions(&(*(
temp.begin())));
327 std::vector<double>
x = extrPgon.
xVec();
329 std::vector<double>
y = extrPgon.
yVec();
331 std::vector<double>
z = extrPgon.
zVec();
332 std::vector<double> zx = extrPgon.
zxVec();
333 std::vector<double> zy = extrPgon.
zyVec();
334 std::vector<double> zscale = extrPgon.
zscaleVec();
336 TGeoXtru* mySolid =
new TGeoXtru(
z.size());
337 mySolid->DefinePolygon(
x.size(), &(*
x.begin()), &(*
y.begin()));
339 mySolid->DefineSection(
i,
z[
i] / cm, zx[
i] / cm, zy[
i] / cm, zscale[
i]);
350 double r = fabs(
pt.radius());
356 double openingAngle = 2.0 * asin(
x /
r);
357 double h =
pt.y1() <
pt.y2() ?
pt.y2() :
pt.y1();
359 double displacement = 0;
363 displacement = -
pt.halfZ() -
delta;
364 startPhi = 270. - openingAngle / deg / 2.0;
366 displacement =
pt.halfZ() +
delta;
367 startPhi = 90. - openingAngle / deg / 2.;
369 std::unique_ptr<TGeoShape> trap(
new TGeoTrd2(
370 pt.name().name().c_str(),
pt.x1() / cm,
pt.x2() / cm,
pt.y1() / cm,
pt.y2() / cm,
pt.halfZ() / cm));
371 std::unique_ptr<TGeoShape> tubs(
372 new TGeoTubeSeg(
pt.name().name().c_str(), 0.,
r / cm,
h / cm, startPhi, openingAngle));
373 TGeoSubtraction* sub =
new TGeoSubtraction(
375 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
382 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
387 if (
nullptr != left.get() &&
nullptr != right.get()) {
388 TGeoSubtraction* sub =
389 new TGeoSubtraction(left.release(),
393 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
400 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
407 if (
nullptr != left.get() &&
nullptr != right.get()) {
408 TGeoUnion* boolS =
new TGeoUnion(left.release(),
412 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
419 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
424 if (
nullptr != left.get() &&
nullptr != right.get()) {
425 TGeoIntersection* boolS =
426 new TGeoIntersection(left.release(),
430 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
439 if (rSolid ==
nullptr) {
440 std::cerr <<
"COULD NOT MAKE " << iName << std::endl;
453 if (geo_med ==
nullptr) {
455 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
459 v =
new TGeoVolume(iName.c_str(), solid, geo_med);
470 if (mat ==
nullptr) {
478 mat =
new TGeoMaterial(mat_name.c_str(), iMaterial.
a() * mole /
g, iMaterial.
z(), iMaterial.
density() * cm3 /
g);