29 #include "TGeoManager.h"
30 #include "TGeoMatrix.h"
31 #include "TGeoCompositeShape.h"
35 #include "TGeoBoolNode.h"
39 #include "TGeoTorus.h"
42 #include "Math/GenVector/RotationX.h"
43 #include "Math/GenVector/RotationZ.h"
45 #include "CLHEP/Units/GlobalSystemOfUnits.h"
49 : m_level( pset.getUntrackedParameter<int> (
"level", 10 )),
50 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);
96 if ( ! viewH.isValid()) {
97 return std::shared_ptr<TGeoManager>();
100 TGeoManager *geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
102 if (gGeoIdentity == 0)
104 gGeoIdentity =
new TGeoIdentity(
"Identity");
107 std::cout <<
"about to initialize the DDCompactView walker" << std::endl;
114 if( ! walker.firstChild()) {
115 return std::shared_ptr<TGeoManager>();
120 info.first.material());
122 return std::shared_ptr<TGeoManager>();
125 geo_mgr->SetTopVolume(top);
127 top->SetVisibility(kFALSE);
128 top->SetLineColor(kBlue);
130 std::vector<TGeoVolume*> parentStack;
131 parentStack.push_back(top);
139 for(
unsigned int i=0;
i<parentStack.size();++
i) {
142 std::cout << info.first.name()<<
" "<<info.second->copyno_<<
" "
146 bool childAlreadyExists = (0 !=
nameToVolume_[info.first.name().fullname()]);
149 info.first.material());
150 if (0!=child && info.second != 0)
152 parentStack.back()->AddNode(child,
153 info.second->copyno_,
154 createPlacement(info.second->rotation(),
155 info.second->translation()));
156 child->SetLineColor(kBlue);
160 if ( info.second == 0 ) {
164 if (0 == child || childAlreadyExists ||
m_level ==
int(parentStack.size()))
168 child->SetLineColor(kRed);
171 if ( ! walker.nextSibling())
173 while (walker.parent())
175 parentStack.pop_back();
176 if (walker.nextSibling()) {
184 if (walker.firstChild())
186 parentStack.push_back(child);
190 if ( ! walker.nextSibling())
192 while (walker.parent())
194 parentStack.pop_back();
195 if (walker.nextSibling()) {
202 }
while ( ! parentStack.empty());
204 geo_mgr->CloseGeometry();
206 geo_mgr->DefaultColors();
213 return std::shared_ptr<TGeoManager>(geo_mgr);
225 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"with name: " << iName <<
" and solid: " << iSolid;
228 if( !defined.first )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + iName +
" is not declared * " );
229 if( !defined.second )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + defined.first->name() +
" is not defined *" );
234 const std::vector<double>& params = iSolid.parameters();
235 switch(iSolid.shape())
238 rSolid =
new TGeoBBox(
245 rSolid =
new TGeoConeSeg(
253 params[6]/deg+params[5]/deg
258 rSolid=
new TGeoTubeSeg(
264 params[3]/deg + params[4]/deg);
268 rSolid=
new TGeoCtub(
274 params[3]/deg + params[4]/deg,
275 params[5],params[6],params[7],
276 params[8],params[9],params[10]);
279 rSolid =
new TGeoTrap(
294 rSolid =
new TGeoPcon(
298 (params.size()-2)/3) ;
300 std::vector<double>
temp(params.size()+1);
301 temp.reserve(params.size()+1);
302 temp[0]=params[0]/deg;
303 temp[1]=params[1]/deg;
304 temp[2]=(params.size()-2)/3;
306 for(std::vector<double>::iterator it=
temp.begin()+3;
311 rSolid->SetDimensions(&(*(
temp.begin())));
315 rSolid =
new TGeoPgon(
319 static_cast<int>(params[0]),
320 (params.size()-3)/3);
322 std::vector<double>
temp(params.size()+1);
323 temp[0]=params[1]/deg;
324 temp[1]=params[2]/deg;
326 temp[3]=(params.size()-3)/3;
327 std::copy(params.begin()+3,params.end(),temp.begin()+4);
328 for(std::vector<double>::iterator it=temp.begin()+4;
333 rSolid->SetDimensions(&(*(temp.begin())));
346 bool intersec =
false;
356 double halfOpeningAngle = asin( x /
std::abs( r ))/deg;
357 double displacement = 0;
366 h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
371 startPhi = 90. - halfOpeningAngle;
376 startPhi = -90.- halfOpeningAngle;
379 else if( r > 0 &&
std::abs( r ) >= x )
384 startPhi = 270.- halfOpeningAngle;
390 startPhi = 90. - halfOpeningAngle;
399 std::auto_ptr<TGeoShape> trap(
new TGeoTrd2( pt.
name().
name().c_str(),
406 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( pt.
name().
name().c_str(),
411 startPhi + halfOpeningAngle * 2. ));
414 TGeoSubtraction* sub =
new TGeoSubtraction( trap.release(),
417 createPlacement( s_rot,
421 rSolid =
new TGeoCompositeShape( iName.c_str(),
426 std::auto_ptr<TGeoShape> box(
new TGeoBBox( 1.1*x/cm, 1.1*h/cm,
sqrt(r*r-x*x)/cm ));
428 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
431 createPlacement( s_rot,
436 std::auto_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape( iName.c_str(), sub ));
438 TGeoUnion* boolS =
new TGeoUnion( trap.release(),
441 createPlacement( s_rot,
446 rSolid =
new TGeoCompositeShape( iName.c_str(),
455 rSolid =
new TGeoTorus( iName.c_str(),
467 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
474 if( 0 != left.get() &&
476 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
481 rSolid =
new TGeoCompositeShape(iName.c_str(),
491 throw cms::Exception(
"GeomConvert" ) <<
"conversion to DDTruncTubs failed";
493 double rIn( tt.
rIn());
494 double rOut( tt.
rOut());
495 double zHalf( tt.
zHalf());
504 if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 )
521 double r( cutAtStart );
522 double R( cutAtDelta );
525 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi,
deltaPhi/deg ));
527 double boxX( rOut ), boxY( rOut );
530 double boxZ( 1.1 * zHalf );
535 double cos_alpha = cath / hypo;
536 double alpha = -acos( cos_alpha );
541 rot.RotateZ( alpha/deg );
547 xBox = r + boxX /
sin( fabs( alpha ));
551 xBox = - ( boxX /
sin( fabs( alpha )) -
r );
553 std::auto_ptr<TGeoShape> box(
new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm ));
555 TGeoTranslation trans( xBox/cm, 0., 0.);
557 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
559 0,
new TGeoCombiTrans( trans, rot ));
561 rSolid =
new TGeoCompositeShape( iName.c_str(),
569 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
578 if( 0 != left.get() &&
580 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
585 rSolid =
new TGeoCompositeShape(iName.c_str(),
594 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
601 if( 0 != left.get() &&
603 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
609 rSolid =
new TGeoCompositeShape(iName.c_str(),
618 throw cms::Exception(
"GeomConvert") <<
"conversion to DDEllipticalTube failed";
620 rSolid =
new TGeoEltu(iName.c_str(),
633 std::cerr <<
"COULD NOT MAKE "<<iName<<
" of a shape "<<iSolid<<std::endl;
636 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
656 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
661 v =
new TGeoVolume(iName.c_str(),
680 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
692 mat =
new TGeoMaterial(mat_name.c_str(),
693 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
double y2(void) const
half length along y on +z
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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
double cutAtDelta(void) const
truncation at end of the tube-section
double rIn(void) const
inner radius
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
const DepRecordT & getRecord() const
double z() const
retruns the atomic number
static const char *const name(DDSolidShape s)
DDRotation rotation(void) const
graph< DDLogicalPart, DDPosData * >::value_type value_type
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::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_
virtual ~TGeoMgrFromDdd()
volatile std::atomic< bool > shutdown_flag false
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.
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.)