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" 50 : m_level( pset.getUntrackedParameter<
int> (
"level", 10 )),
51 m_verbose( pset.getUntrackedParameter<
bool>(
"verbose",
false ))
72 iRot.GetComponents(elements);
74 r.SetMatrix(elements);
76 TGeoTranslation
t(iTrans.x()/cm,
80 return new TGeoCombiTrans(
t,r);
98 return std::shared_ptr<TGeoManager>();
101 TGeoManager *geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
103 if (gGeoIdentity ==
nullptr)
105 gGeoIdentity =
new TGeoIdentity(
"Identity");
108 std::cout <<
"about to initialize the DDCompactView walker" << std::endl;
115 if( ! walker.firstChild()) {
116 return std::shared_ptr<TGeoManager>();
119 TGeoVolume *top =
createVolume(info.first.name().fullname(),
121 info.first.material());
122 if (top ==
nullptr) {
123 return std::shared_ptr<TGeoManager>();
126 geo_mgr->SetTopVolume(top);
128 top->SetVisibility(kFALSE);
129 top->SetLineColor(kBlue);
131 std::vector<TGeoVolume*> parentStack;
132 parentStack.push_back(top);
140 for(
unsigned int i=0;
i<parentStack.size();++
i) {
143 std::cout << info.first.name()<<
" "<<info.second->copyno()<<
" " 147 bool childAlreadyExists = (
nullptr !=
nameToVolume_[info.first.name().fullname()]);
150 info.first.material());
151 if (
nullptr!=child && info.second !=
nullptr)
153 parentStack.back()->AddNode(child,
154 info.second->copyno(),
155 createPlacement(info.second->rotation(),
156 info.second->translation()));
157 child->SetLineColor(kBlue);
161 if ( info.second ==
nullptr ) {
165 if (
nullptr == child || childAlreadyExists ||
m_level ==
int(parentStack.size()))
169 child->SetLineColor(kRed);
172 if ( ! walker.nextSibling())
174 while (walker.parent())
176 parentStack.pop_back();
177 if (walker.nextSibling()) {
185 if (walker.firstChild())
187 parentStack.push_back(child);
191 if ( ! walker.nextSibling())
193 while (walker.parent())
195 parentStack.pop_back();
196 if (walker.nextSibling()) {
203 }
while ( ! parentStack.empty());
205 geo_mgr->CloseGeometry();
207 geo_mgr->DefaultColors();
214 return std::shared_ptr<TGeoManager>(geo_mgr);
226 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"with name: " << iName <<
" and solid: " << iSolid;
229 if( !defined.first )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + iName +
" is not declared * " );
230 if( !defined.second )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + defined.first->name() +
" is not defined *" );
233 if (rSolid ==
nullptr)
235 const std::vector<double>& params = iSolid.parameters();
236 switch(iSolid.shape())
239 rSolid =
new TGeoBBox(
246 rSolid =
new TGeoConeSeg(
254 params[6]/deg+params[5]/deg
259 rSolid=
new TGeoTubeSeg(
265 params[3]/deg + params[4]/deg);
269 rSolid=
new TGeoCtub(
275 params[3]/deg + params[4]/deg,
276 params[5],params[6],params[7],
277 params[8],params[9],params[10]);
280 rSolid =
new TGeoTrap(
295 rSolid =
new TGeoPcon(
299 (params.size()-2)/3) ;
301 std::vector<double>
temp(params.size()+1);
302 temp.reserve(params.size()+1);
303 temp[0]=params[0]/deg;
304 temp[1]=params[1]/deg;
305 temp[2]=(params.size()-2)/3;
307 for(std::vector<double>::iterator it=
temp.begin()+3;
312 rSolid->SetDimensions(&(*(
temp.begin())));
316 rSolid =
new TGeoPgon(
320 static_cast<int>(params[0]),
321 (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;
334 rSolid->SetDimensions(&(*(temp.begin())));
340 std::vector<double>
x = extrPgon.
xVec();
341 std::transform(x.begin(), x.end(), x.begin(),[](
double d) {
return d/cm; });
342 std::vector<double>
y = extrPgon.
yVec();
343 std::transform(y.begin(), y.end(), y.begin(),[](
double d) {
return d/cm; });
344 std::vector<double>
z = extrPgon.
zVec();
345 std::vector<double> zx = extrPgon.
zxVec();
346 std::vector<double> zy = extrPgon.
zyVec();
347 std::vector<double> zscale = extrPgon.
zscaleVec();
349 TGeoXtru* mySolid =
new TGeoXtru(z.size());
350 mySolid->DefinePolygon(x.size(), &(*x.begin()), &(*y.begin()));
351 for(
size_t i = 0;
i < params[0]; ++
i )
353 mySolid->DefineSection(
i, z[
i]/cm, zx[
i]/cm, zy[
i]/cm, zscale[
i]);
369 bool intersec =
false;
379 double halfOpeningAngle = asin( x /
std::abs( r ))/deg;
380 double displacement = 0;
389 h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
394 startPhi = 90. - halfOpeningAngle;
399 startPhi = -90.- halfOpeningAngle;
402 else if( r > 0 &&
std::abs( r ) >= x )
407 startPhi = 270.- halfOpeningAngle;
413 startPhi = 90. - halfOpeningAngle;
422 std::auto_ptr<TGeoShape> trap(
new TGeoTrd2( pt.
name().
name().c_str(),
429 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( pt.
name().
name().c_str(),
434 startPhi + halfOpeningAngle * 2. ));
437 TGeoSubtraction* sub =
new TGeoSubtraction( trap.release(),
440 createPlacement( s_rot,
444 rSolid =
new TGeoCompositeShape( iName.c_str(),
449 std::auto_ptr<TGeoShape> box(
new TGeoBBox( 1.1*x/cm, 1.1*h/cm,
sqrt(r*r-x*x)/cm ));
451 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
454 createPlacement( s_rot,
459 std::auto_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape( iName.c_str(), sub ));
461 TGeoUnion* boolS =
new TGeoUnion( trap.release(),
464 createPlacement( s_rot,
469 rSolid =
new TGeoCompositeShape( iName.c_str(),
478 rSolid =
new TGeoTorus( iName.c_str(),
490 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
497 if(
nullptr != left.get() &&
498 nullptr != right.get() ) {
499 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
504 rSolid =
new TGeoCompositeShape(iName.c_str(),
514 throw cms::Exception(
"GeomConvert" ) <<
"conversion to DDTruncTubs failed";
516 double rIn( tt.
rIn());
517 double rOut( tt.
rOut());
518 double zHalf( tt.
zHalf());
527 if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 )
544 double r( cutAtStart );
545 double R( cutAtDelta );
548 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi,
deltaPhi/deg ));
550 double boxX( rOut ), boxY( rOut );
553 double boxZ( 1.1 * zHalf );
558 double cos_alpha = cath / hypo;
559 double alpha = -acos( cos_alpha );
564 rot.RotateZ( alpha/deg );
570 xBox = r + boxX /
sin( fabs( alpha ));
574 xBox = - ( boxX /
sin( fabs( alpha )) -
r );
576 std::auto_ptr<TGeoShape> box(
new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm ));
578 TGeoTranslation trans( xBox/cm, 0., 0.);
580 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
582 nullptr,
new TGeoCombiTrans( trans, rot ));
584 rSolid =
new TGeoCompositeShape( iName.c_str(),
592 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
601 if(
nullptr != left.get() &&
602 nullptr != right.get() ) {
603 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
608 rSolid =
new TGeoCompositeShape(iName.c_str(),
617 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
624 if(
nullptr != left.get() &&
625 nullptr != right.get() ) {
626 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
632 rSolid =
new TGeoCompositeShape(iName.c_str(),
641 throw cms::Exception(
"GeomConvert") <<
"conversion to DDEllipticalTube failed";
643 rSolid =
new TGeoEltu(iName.c_str(),
654 if (rSolid ==
nullptr)
656 std::cerr <<
"COULD NOT MAKE "<<iName<<
" of a shape "<<iSolid<<std::endl;
659 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
676 if (geo_med ==
nullptr)
679 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
684 v =
new TGeoVolume(iName.c_str(),
703 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
715 mat =
new TGeoMaterial(mat_name.c_str(),
716 iMaterial.
a()*mole/
g, iMaterial.
z(),
double a() const
returns the atomic mass
double cutAtStart(void) const
truncation at begin of the tube-section
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
typename math::Graph< DDLogicalPart, DDPosData * >::value_type value_type
double y2(void) const
half length along y on +z
double deltaPhi(void) const
angular span of the tube-section
DDMaterial is used to define and access material information.
Sin< T >::type sin(const T &t)
double rTorus(void) const
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
double cutAtDelta(void) const
truncation at end of the tube-section
std::vector< double > yVec(void) const
double rIn(void) const
inner radius
std::vector< double > zyVec(void) const
DDTranslation translation(void) const
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
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
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
~TGeoMgrFromDdd() override
std::vector< double > xVec(void) const
const DepRecordT & getRecord() 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 &)
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
double startPhi(void) const
angular start of the tube-section
std::map< std::string, TGeoMedium * > nameToMedium_
DDRotationMatrix * matrix()
double x2(void) const
half length along x on +z
double rOut(void) const
outer radius
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
std::vector< double > zscaleVec(void) const
const std::string & name() const
Returns the name.
double x1(void) const
half length along x on -z
std::shared_ptr< TGeoManager > ReturnType
double radius(void) const
radius of the cut-out (neg.) or rounding (pos.)