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/SystemOfUnits.h> 94 : m_level(
pset.getUntrackedParameter<
int>(
"level")),
95 m_verbose(
pset.getUntrackedParameter<
bool>(
"verbose")),
96 m_fullname(
pset.getUntrackedParameter<
bool>(
"fullName")),
97 viewToken_(setWhatProduced(this).consumes()) {}
101 desc.addUntracked<
int>(
"level", 10)->setComment(
"How deep into the geometry hierarchy should the conversion go.");
102 desc.addUntracked<
bool>(
"verbose",
false);
103 desc.addUntracked<
bool>(
"fullName",
true)->setComment(
"use fillname() instead of name() when generating node names");
105 conf.
add(
"TGeoMgrFromDdd",
desc);
119 TGeoTranslation
t(iTrans.x() / cm, iTrans.y() / cm, iTrans.z() / cm);
121 return new TGeoCombiTrans(
t,
r);
135 return std::unique_ptr<TGeoManager>();
138 TGeoManager* geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
140 if (gGeoIdentity ==
nullptr) {
141 gGeoIdentity =
new TGeoIdentity(
"Identity");
144 edm::LogVerbatim(
"TGeoMgrFromDdd") <<
"about to initialize the DDCompactView walker with a root node " 145 << viewH->
root() << std::endl;
147 auto walker = viewH->
walker();
148 auto info = walker.current();
153 if (!walker.firstChild()) {
154 return std::unique_ptr<TGeoManager>();
160 if (top ==
nullptr) {
161 return std::unique_ptr<TGeoManager>();
164 geo_mgr->SetTopVolume(top);
166 top->SetVisibility(kFALSE);
167 top->SetLineColor(kBlue);
169 std::vector<TGeoVolume*> parentStack;
170 parentStack.push_back(top);
173 auto info = walker.current();
176 edm::LogVerbatim(
"TGeoMgrFromDdd") <<
"parentStack of size " << parentStack.size();
177 auto num = (
info.second !=
nullptr) ?
info.second->copyno() : 0;
185 if (
nullptr !=
child &&
info.second !=
nullptr) {
186 parentStack.back()->AddNode(
188 child->SetLineColor(kBlue);
190 if (
info.second ==
nullptr) {
194 if (
nullptr ==
child || childAlreadyExists ||
m_level ==
int(parentStack.size())) {
195 if (
nullptr !=
child) {
196 child->SetLineColor(kRed);
199 if (!walker.nextSibling()) {
200 while (walker.parent()) {
201 parentStack.pop_back();
202 if (walker.nextSibling()) {
208 if (walker.firstChild()) {
209 parentStack.push_back(
child);
211 if (!walker.nextSibling()) {
212 while (walker.parent()) {
213 parentStack.pop_back();
214 if (walker.nextSibling()) {
221 }
while (!parentStack.empty());
223 geo_mgr->CloseGeometry();
225 geo_mgr->DefaultColors();
232 return std::unique_ptr<TGeoManager>(geo_mgr);
245 throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + iName +
" is not declared * ");
247 throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + defined.first->name() +
" is not defined *");
250 if (rSolid ==
nullptr) {
252 switch (iSolid.
shape()) {
257 rSolid =
new TGeoConeSeg(iName.c_str(),
268 rSolid =
new TGeoTubeSeg(iName.c_str(),
277 rSolid =
new TGeoCtub(iName.c_str(),
291 rSolid =
new TGeoTrap(iName.c_str(),
305 rSolid =
new TGeoPcon(iName.c_str(),
params[0] / deg,
params[1] / deg, (
params.size() - 2) / 3);
313 for (std::vector<double>::iterator
it =
temp.begin() + 3;
it !=
temp.end(); ++
it) {
316 rSolid->SetDimensions(&(*(
temp.begin())));
320 rSolid =
new TGeoPgon(
329 for (std::vector<double>::iterator
it =
temp.begin() + 4;
it !=
temp.end(); ++
it) {
332 rSolid->SetDimensions(&(*(
temp.begin())));
337 std::vector<double>
x = extrPgon.
xVec();
339 std::vector<double>
y = extrPgon.
yVec();
341 std::vector<double>
z = extrPgon.
zVec();
342 std::vector<double> zx = extrPgon.
zxVec();
343 std::vector<double> zy = extrPgon.
zyVec();
344 std::vector<double> zscale = extrPgon.
zscaleVec();
346 TGeoXtru* mySolid =
new TGeoXtru(
z.size());
347 mySolid->DefinePolygon(
x.size(), &(*
x.begin()), &(*
y.begin()));
349 mySolid->DefineSection(
i,
z[
i] / cm, zx[
i] / cm, zy[
i] / cm, zscale[
i]);
359 double r =
pt.radius();
360 bool atMinusZ =
pt.atMinusZ();
363 bool intersec =
false;
370 double halfOpeningAngle = asin(
x /
std::abs(
r)) / deg;
371 double displacement = 0;
380 h =
pt.y1() <
pt.y2() ?
pt.y2() :
pt.y1();
383 displacement = -
pt.halfZ() -
delta;
384 startPhi = 90. - halfOpeningAngle;
386 displacement =
pt.halfZ() +
delta;
387 startPhi = -90. - halfOpeningAngle;
391 displacement = -
pt.halfZ() +
delta;
392 startPhi = 270. - halfOpeningAngle;
395 displacement =
pt.halfZ() -
delta;
396 startPhi = 90. - halfOpeningAngle;
403 std::unique_ptr<TGeoShape> trap(
404 new TGeoTrd2(
name.c_str(),
pt.x1() / cm,
pt.x2() / cm,
pt.y1() / cm,
pt.y2() / cm,
pt.halfZ() / cm));
406 std::unique_ptr<TGeoShape> tubs(
new TGeoTubeSeg(
name.c_str(),
411 startPhi + halfOpeningAngle * 2.));
413 TGeoSubtraction* sub =
new TGeoSubtraction(
415 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
417 std::unique_ptr<TGeoShape> box(
new TGeoBBox(1.1 *
x / cm, 1.1 *
h / cm,
sqrt(
r *
r -
x *
x) / cm));
419 TGeoSubtraction* sub =
new TGeoSubtraction(
422 std::unique_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape(iName.c_str(), sub));
424 TGeoUnion* boolS =
new TGeoUnion(
427 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
434 rSolid =
new TGeoTorus(iName.c_str(),
445 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
452 if (
nullptr != left.get() &&
nullptr != right.get()) {
453 TGeoSubtraction* sub =
454 new TGeoSubtraction(left.release(),
458 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
465 throw cms::Exception(
"GeomConvert") <<
"conversion to DDTruncTubs failed";
467 double rIn(
tt.rIn());
468 double rOut(
tt.rOut());
469 double zHalf(
tt.zHalf());
470 double startPhi(
tt.startPhi());
472 double cutAtStart(
tt.cutAtStart());
473 double cutAtDelta(
tt.cutAtDelta());
474 bool cutInside(
bool(
tt.cutInside()));
478 if (rIn <= 0 || rOut <= 0 || cutAtStart <= 0 || cutAtDelta <= 0) {
479 std::string s =
"TruncTubs " +
name +
": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!";
486 if (startPhi != 0.) {
492 double r(cutAtStart);
493 double R(cutAtDelta);
496 std::unique_ptr<TGeoShape> tubs(
497 new TGeoTubeSeg(
name.c_str(), rIn / cm, rOut / cm, zHalf / cm, startPhi,
deltaPhi / deg));
499 double boxX(rOut), boxY(rOut);
502 double boxZ(1.1 * zHalf);
507 double cos_alpha = cath / hypo;
508 double alpha = -acos(cos_alpha);
522 std::unique_ptr<TGeoShape> box(
new TGeoBBox(
name.c_str(), boxX / cm, boxZ / cm, boxY / cm));
524 TGeoTranslation trans(xBox / cm, 0., 0.);
526 TGeoSubtraction* sub =
527 new TGeoSubtraction(tubs.release(), box.release(),
nullptr,
new TGeoCombiTrans(trans,
rot));
529 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
535 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
544 if (
nullptr != left.get() &&
nullptr != right.get()) {
545 TGeoUnion* boolS =
new TGeoUnion(left.release(),
549 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
556 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
563 if (
nullptr != left.get() &&
nullptr != right.get()) {
564 TGeoIntersection* boolS =
565 new TGeoIntersection(left.release(),
569 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
576 throw cms::Exception(
"GeomConvert") <<
"conversion to DDEllipticalTube failed";
586 if (rSolid ==
nullptr) {
587 edm::LogError(
"TGeoMgrFromDdd") <<
"COULD NOT MAKE " << iName <<
" of a shape " << iSolid;
590 edm::LogVerbatim(
"TGeoMgrFromDdd") <<
"solid " << iName <<
" has been created.";
597 <<
" and solid: " << iSolid.
name().
fullname() <<
" and material " 605 if (geo_med ==
nullptr) {
607 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
611 v =
new TGeoVolume(iName.c_str(), solid, geo_med);
620 edm::LogVerbatim(
"TGeoMgrFromDdd") <<
"createMaterial with name: " << mat_name;
623 if (mat ==
nullptr) {
632 mat =
new TGeoMaterial(mat_name.c_str(),
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
Log< level::Info, true > LogVerbatim
DDSolid solidA(void) const
DDRotation rotation(void) const
std::vector< double > yVec(void) const
std::vector< double > zscaleVec(void) const
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
GraphWalker walker() const
A truncated tube section.
DDMaterial is used to define and access material information.
const TGeoMgrFromDdd & operator=(const TGeoMgrFromDdd &)=delete
std::unique_ptr< TGeoManager > ReturnType
std::vector< double > xVec(void) const
Sin< T >::type sin(const T &t)
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Log< level::Error, false > LogError
TGeoCombiTrans * createPlacement(const Rotation3D &iRot, const Position &iTrans)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
A DDSolid represents the shape of a part.
std::vector< double > zVec(void) const
double startPhi(void) const
const edm::ESGetToken< DDCompactView, IdealGeometryRecord > viewToken_
static const char *const name(DDSolidShape s)
DDTranslation translation(void) const
const std::string & name() const
Returns the name.
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
TGeoVolume * createVolume(const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
Cos< T >::type cos(const T &t)
std::map< std::string, TGeoShape * > nameToShape_
Abs< T >::type abs(const T &t)
double deltaPhi(void) const
DDSolid solidB(void) const
ReturnType produce(const DisplayGeomRecord &)
std::vector< double > zxVec(void) const
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
double density() const
returns the density
DDSolidShape shape(void) const
The type of the solid.
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
double z() const
retruns the atomic number
TGeoMgrFromDdd(const edm::ParameterSet &)
std::vector< double > zyVec(void) const
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
std::map< std::string, TGeoMaterial * > nameToMaterial_
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
std::map< std::string, TGeoVolume * > nameToVolume_
const std::string fullname() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TGeoManager * createManager(int level)
std::map< std::string, TGeoMedium * > nameToMedium_
std::pair< const N *, bool > def_type
static void fillDescriptions(edm::ConfigurationDescriptions &)
double a() const
returns the atomic mass
double rTorus(void) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
def_type isDefined() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
DDRotationMatrix & matrix()