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")),
101 desc.
addUntracked<
int>(
"level", 10)->setComment(
"How deep into the geometry hierarchy should the conversion go.");
103 desc.
addUntracked<
bool>(
"fullName",
true)->setComment(
"use fillname() instead of name() when generating node names");
105 conf.
add(
"TGeoMgrFromDdd", desc);
115 iRot.GetComponents(elements);
117 r.SetMatrix(elements);
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 std::cout <<
"about to initialize the DDCompactView walker" 145 <<
" with a root node " << 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 for (
unsigned int i = 0;
i < parentStack.size(); ++
i) {
186 if (
nullptr != child &&
info.second !=
nullptr) {
187 parentStack.back()->AddNode(
189 child->SetLineColor(kBlue);
191 if (
info.second ==
nullptr) {
195 if (
nullptr == child || childAlreadyExists ||
m_level ==
int(parentStack.size())) {
196 if (
nullptr != child) {
197 child->SetLineColor(kRed);
200 if (!walker.nextSibling()) {
201 while (walker.parent()) {
202 parentStack.pop_back();
203 if (walker.nextSibling()) {
209 if (walker.firstChild()) {
210 parentStack.push_back(child);
212 if (!walker.nextSibling()) {
213 while (walker.parent()) {
214 parentStack.pop_back();
215 if (walker.nextSibling()) {
222 }
while (!parentStack.empty());
224 geo_mgr->CloseGeometry();
226 geo_mgr->DefaultColors();
233 return std::unique_ptr<TGeoManager>(geo_mgr);
241 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"with name: " << iName <<
" and solid: " << iSolid;
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) {
251 const std::vector<double>&
params = iSolid.parameters();
252 switch (iSolid.shape()) {
254 rSolid =
new TGeoBBox(iName.c_str(), params[0] / cm, params[1] / cm, params[2] / cm);
257 rSolid =
new TGeoConeSeg(iName.c_str(),
264 params[6] / deg + params[5] / deg);
268 rSolid =
new TGeoTubeSeg(iName.c_str(),
273 params[3] / deg + params[4] / deg);
277 rSolid =
new TGeoCtub(iName.c_str(),
282 params[3] / deg + params[4] / deg,
291 rSolid =
new TGeoTrap(iName.c_str(),
305 rSolid =
new TGeoPcon(iName.c_str(), params[0] / deg, params[1] / deg, (params.size() - 2) / 3);
307 std::vector<double>
temp(params.size() + 1);
308 temp.reserve(params.size() + 1);
309 temp[0] = params[0] / deg;
310 temp[1] = params[1] / deg;
311 temp[2] = (params.size() - 2) / 3;
312 std::copy(params.begin() + 2, params.end(),
temp.begin() + 3);
313 for (std::vector<double>::iterator it =
temp.begin() + 3; it !=
temp.end(); ++it) {
316 rSolid->SetDimensions(&(*(
temp.begin())));
320 rSolid =
new TGeoPgon(
321 iName.c_str(), params[1] / deg, params[2] / deg,
static_cast<int>(params[0]), (params.size() - 3) / 3);
323 std::vector<double>
temp(params.size() + 1);
324 temp[0] = params[1] / deg;
325 temp[1] = params[2] / deg;
327 temp[3] = (params.size() - 3) / 3;
328 std::copy(params.begin() + 3, params.end(), temp.begin() + 4);
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();
338 std::transform(x.begin(), x.end(), x.begin(), [](
double d) {
return d / cm; });
339 std::vector<double>
y = extrPgon.
yVec();
340 std::transform(y.begin(), y.end(), y.begin(), [](
double d) {
return d / cm; });
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()));
348 for (
size_t i = 0;
i < params[0]; ++
i) {
349 mySolid->DefineSection(
i, z[
i] / cm, zx[
i] / cm, zy[
i] / cm, zscale[
i]);
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();
384 startPhi = 90. - halfOpeningAngle;
387 startPhi = -90. - halfOpeningAngle;
389 }
else if (r > 0 &&
std::abs(r) >= x) {
392 startPhi = 270. - halfOpeningAngle;
396 startPhi = 90. - halfOpeningAngle;
400 throw cms::Exception(
"Check parameters of the PseudoTrap! name=" + name);
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());
478 if (rIn <= 0 || rOut <= 0 || cutAtStart <= 0 || cutAtDelta <= 0) {
479 std::string s =
"TruncTubs " + name +
": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!";
483 std::string s =
"TruncTubs " + name +
": rIn<rOut violated!";
486 if (startPhi != 0.) {
487 std::string s =
"TruncTubs " + name +
": startPhi != 0 not supported!";
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);
513 rot.RotateZ(alpha / deg);
518 xBox = r + boxX /
sin(fabs(alpha));
520 xBox = -(boxX /
sin(fabs(alpha)) -
r);
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";
578 rSolid =
new TGeoEltu(iName.c_str(), params[0] / cm, params[1] / cm, params[2] / cm);
586 if (rSolid ==
nullptr) {
587 std::cerr <<
"COULD NOT MAKE " << iName <<
" of a shape " << iSolid << std::endl;
590 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
602 if (geo_med ==
nullptr) {
604 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
608 v =
new TGeoVolume(iName.c_str(), solid, geo_med);
619 if (mat ==
nullptr) {
627 mat =
new TGeoMaterial(mat_name.c_str(), iMaterial.
a() * mole /
g, iMaterial.
z(), iMaterial.
density() * cm3 /
g);
double a() const
returns the atomic mass
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
double cutAtStart(void) const
truncation at begin of the tube-section
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
bool cutInside(void) const
true, if truncation is on the inner side of the tube-section
A truncated tube section.
double zHalf(void) const
half of the z-Axis
double y2(void) const
half length along y on +z
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
GraphWalker walker() const
double deltaPhi(void) const
angular span of the tube-section
DDMaterial is used to define and access material information.
const TGeoMgrFromDdd & operator=(const TGeoMgrFromDdd &)=delete
std::unique_ptr< TGeoManager > ReturnType
Sin< T >::type sin(const T &t)
double rTorus(void) const
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
double cutAtDelta(void) const
truncation at end of the tube-section
std::vector< double > yVec(void) const
double rIn(void) const
inner radius
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< double > zyVec(void) const
DDTranslation translation(void) const
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.
double y1(void) const
half length along y on -z
DDSolid solidB(void) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
std::vector< double > xVec(void) const
double z() const
retruns the atomic number
static const char *const name(DDSolidShape s)
DDRotation rotation(void) const
TGeoVolume * createVolume(const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
bool atMinusZ(void) const
true, if cut-out or rounding is on the -z side
double halfZ(void) const
half of the z-Axis
Cos< T >::type cos(const T &t)
std::map< std::string, TGeoShape * > nameToShape_
const std::string fullname() const
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Abs< T >::type abs(const T &t)
ReturnType produce(const DisplayGeomRecord &)
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
DDSolid solidA(void) const
TGeoMgrFromDdd(const edm::ParameterSet &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
double startPhi(void) const
std::vector< double > zVec(void) const
std::vector< double > zxVec(void) const
std::map< std::string, TGeoMaterial * > nameToMaterial_
double density() const
returns the density
double deltaPhi(void) const
std::map< std::string, TGeoVolume * > nameToVolume_
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double startPhi(void) const
angular start of the tube-section
TGeoManager * createManager(int level)
std::map< std::string, TGeoMedium * > nameToMedium_
std::pair< const N *, bool > def_type
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
alpha
zGenParticlesMatch = cms.InputTag(""),
static void fillDescriptions(edm::ConfigurationDescriptions &)
double x2(void) const
half length along x on +z
double rOut(void) const
outer radius
std::vector< double > zscaleVec(void) const
const std::string & name() const
Returns the name.
edm::ESGetToken< DDCompactView, IdealGeometryRecord > viewToken_
double x1(void) const
half length along x on -z
DDRotationMatrix & matrix()
double radius(void) const
radius of the cut-out (neg.) or rounding (pos.)