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 ))
71 iRot.GetComponents(elements);
73 r.SetMatrix(elements);
75 TGeoTranslation
t(iTrans.x()/cm,
79 return new TGeoCombiTrans(
t,r);
97 return std::unique_ptr<TGeoManager>();
100 TGeoManager *geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
102 if (gGeoIdentity ==
nullptr)
104 gGeoIdentity =
new TGeoIdentity(
"Identity");
107 std::cout <<
"about to initialize the DDCompactView walker" 108 <<
" with a root node " << viewH->
root() << std::endl;
110 auto walker = viewH->
walker();
111 auto info = walker.current();
116 if( ! walker.firstChild()) {
117 return std::unique_ptr<TGeoManager>();
122 info.first.material());
124 if (top ==
nullptr) {
125 return std::unique_ptr<TGeoManager>();
128 geo_mgr->SetTopVolume(top);
130 top->SetVisibility(kFALSE);
131 top->SetLineColor(kBlue);
133 std::vector<TGeoVolume*> parentStack;
134 parentStack.push_back(top);
138 auto info = walker.current();
142 for(
unsigned int i=0;
i<parentStack.size();++
i) {
149 bool childAlreadyExists = (
nullptr !=
nameToVolume_[
info.first.name().fullname()]);
152 info.first.material());
153 if (
nullptr!=child &&
info.second !=
nullptr)
155 parentStack.back()->AddNode(child,
156 info.second->copyno(),
157 createPlacement(
info.second->rotation(),
158 info.second->translation()));
159 child->SetLineColor(kBlue);
163 if (
info.second ==
nullptr ) {
167 if (
nullptr == child || childAlreadyExists ||
m_level ==
int(parentStack.size()))
171 child->SetLineColor(kRed);
174 if ( ! walker.nextSibling())
176 while (walker.parent())
178 parentStack.pop_back();
179 if (walker.nextSibling()) {
187 if (walker.firstChild())
189 parentStack.push_back(child);
193 if ( ! walker.nextSibling())
195 while (walker.parent())
197 parentStack.pop_back();
198 if (walker.nextSibling()) {
205 }
while ( ! parentStack.empty());
207 geo_mgr->CloseGeometry();
209 geo_mgr->DefaultColors();
216 return std::unique_ptr<TGeoManager>(geo_mgr);
228 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"with name: " << iName <<
" and solid: " << iSolid;
231 if( !defined.first )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + iName +
" is not declared * " );
232 if( !defined.second )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + defined.first->name() +
" is not defined *" );
235 if (rSolid ==
nullptr)
237 const std::vector<double>& params = iSolid.parameters();
238 switch(iSolid.shape())
241 rSolid =
new TGeoBBox(
248 rSolid =
new TGeoConeSeg(
256 params[6]/deg+params[5]/deg
261 rSolid=
new TGeoTubeSeg(
267 params[3]/deg + params[4]/deg);
271 rSolid=
new TGeoCtub(
277 params[3]/deg + params[4]/deg,
278 params[5],params[6],params[7],
279 params[8],params[9],params[10]);
282 rSolid =
new TGeoTrap(
297 rSolid =
new TGeoPcon(
301 (params.size()-2)/3) ;
303 std::vector<double>
temp(params.size()+1);
304 temp.reserve(params.size()+1);
305 temp[0]=params[0]/deg;
306 temp[1]=params[1]/deg;
307 temp[2]=(params.size()-2)/3;
309 for(std::vector<double>::iterator it=
temp.begin()+3;
314 rSolid->SetDimensions(&(*(
temp.begin())));
318 rSolid =
new TGeoPgon(
322 static_cast<int>(params[0]),
323 (params.size()-3)/3);
325 std::vector<double>
temp(params.size()+1);
326 temp[0]=params[1]/deg;
327 temp[1]=params[2]/deg;
329 temp[3]=(params.size()-3)/3;
330 std::copy(params.begin()+3,params.end(),temp.begin()+4);
331 for(std::vector<double>::iterator it=temp.begin()+4;
336 rSolid->SetDimensions(&(*(temp.begin())));
342 std::vector<double>
x = extrPgon.
xVec();
343 std::transform(x.begin(), x.end(), x.begin(),[](
double d) {
return d/cm; });
344 std::vector<double>
y = extrPgon.
yVec();
345 std::transform(y.begin(), y.end(), y.begin(),[](
double d) {
return d/cm; });
346 std::vector<double>
z = extrPgon.
zVec();
347 std::vector<double> zx = extrPgon.
zxVec();
348 std::vector<double> zy = extrPgon.
zyVec();
349 std::vector<double> zscale = extrPgon.
zscaleVec();
351 TGeoXtru* mySolid =
new TGeoXtru(z.size());
352 mySolid->DefinePolygon(x.size(), &(*x.begin()), &(*y.begin()));
353 for(
size_t i = 0;
i < params[0]; ++
i )
355 mySolid->DefineSection(
i, z[
i]/cm, zx[
i]/cm, zy[
i]/cm, zscale[
i]);
371 bool intersec =
false;
381 double halfOpeningAngle = asin( x /
std::abs( r ))/deg;
382 double displacement = 0;
391 h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
396 startPhi = 90. - halfOpeningAngle;
401 startPhi = -90.- halfOpeningAngle;
404 else if( r > 0 &&
std::abs( r ) >= x )
409 startPhi = 270.- halfOpeningAngle;
415 startPhi = 90. - halfOpeningAngle;
424 std::unique_ptr<TGeoShape> trap(
new TGeoTrd2( pt.
name().
name().c_str(),
431 std::unique_ptr<TGeoShape> tubs(
new TGeoTubeSeg( pt.
name().
name().c_str(),
436 startPhi + halfOpeningAngle * 2. ));
439 TGeoSubtraction* sub =
new TGeoSubtraction( trap.release(),
442 createPlacement( s_rot,
446 rSolid =
new TGeoCompositeShape( iName.c_str(),
451 std::unique_ptr<TGeoShape> box(
new TGeoBBox( 1.1*x/cm, 1.1*h/cm,
sqrt(r*r-x*x)/cm ));
453 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
456 createPlacement( s_rot,
461 std::unique_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape( iName.c_str(), sub ));
463 TGeoUnion* boolS =
new TGeoUnion( trap.release(),
466 createPlacement( s_rot,
471 rSolid =
new TGeoCompositeShape( iName.c_str(),
480 rSolid =
new TGeoTorus( iName.c_str(),
492 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
499 if(
nullptr != left.get() &&
500 nullptr != right.get() ) {
501 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
506 rSolid =
new TGeoCompositeShape(iName.c_str(),
516 throw cms::Exception(
"GeomConvert" ) <<
"conversion to DDTruncTubs failed";
518 double rIn( tt.
rIn());
519 double rOut( tt.
rOut());
520 double zHalf( tt.
zHalf());
529 if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 )
546 double r( cutAtStart );
547 double R( cutAtDelta );
550 std::unique_ptr<TGeoShape> tubs(
new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi,
deltaPhi/deg ));
552 double boxX( rOut ), boxY( rOut );
555 double boxZ( 1.1 * zHalf );
560 double cos_alpha = cath / hypo;
561 double alpha = -acos( cos_alpha );
566 rot.RotateZ( alpha/deg );
572 xBox = r + boxX /
sin( fabs( alpha ));
576 xBox = - ( boxX /
sin( fabs( alpha )) -
r );
578 std::unique_ptr<TGeoShape> box(
new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm ));
580 TGeoTranslation trans( xBox/cm, 0., 0.);
582 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
584 nullptr,
new TGeoCombiTrans( trans, rot ));
586 rSolid =
new TGeoCompositeShape( iName.c_str(),
594 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
603 if(
nullptr != left.get() &&
604 nullptr != right.get() ) {
605 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
610 rSolid =
new TGeoCompositeShape(iName.c_str(),
619 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
626 if(
nullptr != left.get() &&
627 nullptr != right.get() ) {
628 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
634 rSolid =
new TGeoCompositeShape(iName.c_str(),
643 throw cms::Exception(
"GeomConvert") <<
"conversion to DDEllipticalTube failed";
645 rSolid =
new TGeoEltu(iName.c_str(),
656 if (rSolid ==
nullptr)
658 std::cerr <<
"COULD NOT MAKE "<<iName<<
" of a shape "<<iSolid<<std::endl;
661 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
678 if (geo_med ==
nullptr)
681 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
686 v =
new TGeoVolume(iName.c_str(),
705 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
717 mat =
new TGeoMaterial(mat_name.c_str(),
718 iMaterial.
a()*mole/
g, iMaterial.
z(),
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
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
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
GraphWalker walker() const
double deltaPhi(void) const
angular span of the tube-section
DDMaterial is used to define and access material information.
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
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
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
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
const DepRecordT getRecord() const
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_
std::pair< const N *, bool > def_type
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
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.
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.)