29 #include "TGeoManager.h"
30 #include "TGeoMatrix.h"
31 #include "TGeoCompositeShape.h"
35 #include "TGeoBoolNode.h"
39 #include "TGeoTorus.h"
41 #include "Math/GenVector/RotationX.h"
42 #include "Math/GenVector/RotationZ.h"
44 #include "CLHEP/Units/GlobalSystemOfUnits.h"
48 : m_level( pset.getUntrackedParameter<int> (
"level", 10 )),
49 m_verbose( pset.getUntrackedParameter<bool>(
"verbose",
false ))
70 iRot.GetComponents(elements);
72 r.SetMatrix(elements);
74 TGeoTranslation
t(iTrans.x()/cm,
78 return new TGeoCombiTrans(
t,r);
95 if ( ! viewH.isValid()) {
96 return boost::shared_ptr<TGeoManager>();
99 TGeoManager *geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
101 if (gGeoIdentity == 0)
103 gGeoIdentity =
new TGeoIdentity(
"Identity");
106 std::cout <<
"about to initialize the DDCompactView walker" << std::endl;
113 if( ! walker.firstChild()) {
114 return boost::shared_ptr<TGeoManager>();
119 info.first.material());
121 return boost::shared_ptr<TGeoManager>();
124 geo_mgr->SetTopVolume(top);
126 top->SetVisibility(kFALSE);
127 top->SetLineColor(kBlue);
129 std::vector<TGeoVolume*> parentStack;
130 parentStack.push_back(top);
138 for(
unsigned int i=0;
i<parentStack.size();++
i) {
141 std::cout << info.first.name()<<
" "<<info.second->copyno_<<
" "
145 bool childAlreadyExists = (0 !=
nameToVolume_[info.first.name().fullname()]);
148 info.first.material());
149 if (0!=child && info.second != 0)
151 parentStack.back()->AddNode(child,
152 info.second->copyno_,
153 createPlacement(info.second->rotation(),
154 info.second->translation()));
155 child->SetLineColor(kBlue);
159 if ( info.second == 0 ) {
163 if (0 == child || childAlreadyExists ||
m_level ==
int(parentStack.size()))
167 child->SetLineColor(kRed);
170 if ( ! walker.nextSibling())
172 while (walker.parent())
174 parentStack.pop_back();
175 if (walker.nextSibling()) {
183 if (walker.firstChild())
185 parentStack.push_back(child);
189 if ( ! walker.nextSibling())
191 while (walker.parent())
193 parentStack.pop_back();
194 if (walker.nextSibling()) {
201 }
while ( ! parentStack.empty());
203 geo_mgr->CloseGeometry();
205 geo_mgr->DefaultColors();
212 return boost::shared_ptr<TGeoManager>(geo_mgr);
224 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"with name: " << iName <<
" and solid: " << iSolid;
227 if( !defined.first )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + iName +
" is not declared * " );
228 if( !defined.second )
throw cms::Exception(
"TGeoMgrFromDdd::createShape * solid " + defined.first->name() +
" is not defined *" );
233 const std::vector<double>& params = iSolid.parameters();
234 switch(iSolid.shape())
237 rSolid =
new TGeoBBox(
244 rSolid =
new TGeoConeSeg(
252 params[6]/deg+params[5]/deg
257 rSolid=
new TGeoTubeSeg(
263 params[3]/deg + params[4]/deg);
266 rSolid =
new TGeoTrap(
281 rSolid =
new TGeoPcon(
285 (params.size()-2)/3) ;
287 std::vector<double>
temp(params.size()+1);
288 temp.reserve(params.size()+1);
289 temp[0]=params[0]/deg;
290 temp[1]=params[1]/deg;
291 temp[2]=(params.size()-2)/3;
293 for(std::vector<double>::iterator it=
temp.begin()+3;
298 rSolid->SetDimensions(&(*(
temp.begin())));
302 rSolid =
new TGeoPgon(
306 static_cast<int>(params[0]),
307 (params.size()-3)/3);
309 std::vector<double>
temp(params.size()+1);
310 temp[0]=params[1]/deg;
311 temp[1]=params[2]/deg;
313 temp[3]=(params.size()-3)/3;
314 std::copy(params.begin()+3,params.end(),temp.begin()+4);
315 for(std::vector<double>::iterator it=temp.begin()+4;
320 rSolid->SetDimensions(&(*(temp.begin())));
333 bool intersec =
false;
343 double halfOpeningAngle = asin( x /
abs( r ))/deg;
344 double displacement = 0;
350 if( r < 0 &&
abs( r ) >= x )
353 h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
358 startPhi = 90. - halfOpeningAngle;
363 startPhi = -90.- halfOpeningAngle;
366 else if( r > 0 &&
abs( r ) >= x )
371 startPhi = 270.- halfOpeningAngle;
377 startPhi = 90. - halfOpeningAngle;
386 std::auto_ptr<TGeoShape> trap(
new TGeoTrd2( pt.
name().
name().c_str(),
393 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( pt.
name().
name().c_str(),
398 startPhi + halfOpeningAngle * 2. ));
401 TGeoSubtraction* sub =
new TGeoSubtraction( trap.release(),
404 createPlacement( s_rot,
408 rSolid =
new TGeoCompositeShape( iName.c_str(),
413 std::auto_ptr<TGeoShape> box(
new TGeoBBox( 1.1*x/cm, 1.1*h/cm,
sqrt(r*r-x*x)/cm ));
415 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
418 createPlacement( s_rot,
423 std::auto_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape( iName.c_str(), sub ));
425 TGeoUnion* boolS =
new TGeoUnion( trap.release(),
428 createPlacement( s_rot,
433 rSolid =
new TGeoCompositeShape( iName.c_str(),
442 rSolid =
new TGeoTorus( iName.c_str(),
454 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
461 if( 0 != left.get() &&
463 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
468 rSolid =
new TGeoCompositeShape(iName.c_str(),
478 throw cms::Exception(
"GeomConvert" ) <<
"conversion to DDTruncTubs failed";
480 double rIn( tt.
rIn());
481 double rOut( tt.
rOut());
482 double zHalf( tt.
zHalf());
491 if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 )
508 double r( cutAtStart );
509 double R( cutAtDelta );
512 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi,
deltaPhi/deg ));
514 double boxX( rOut ), boxY( rOut );
517 double boxZ( 1.1 * zHalf );
522 double cos_alpha = cath / hypo;
523 double alpha = -acos( cos_alpha );
528 rot.RotateZ( alpha/deg );
534 xBox = r + boxX /
sin( fabs( alpha ));
538 xBox = - ( boxX /
sin( fabs( alpha )) -
r );
540 std::auto_ptr<TGeoShape> box(
new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm ));
542 TGeoTranslation
trans( xBox/cm, 0., 0.);
544 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
546 0,
new TGeoCombiTrans( trans, rot ));
548 rSolid =
new TGeoCompositeShape( iName.c_str(),
556 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
565 if( 0 != left.get() &&
567 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
572 rSolid =
new TGeoCompositeShape(iName.c_str(),
581 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
588 if( 0 != left.get() &&
590 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
596 rSolid =
new TGeoCompositeShape(iName.c_str(),
608 std::cerr <<
"COULD NOT MAKE "<<iName<<
" of a shape "<<iSolid<<std::endl;
611 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
631 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
636 v =
new TGeoVolume(iName.c_str(),
655 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
667 mat =
new TGeoMaterial(mat_name.c_str(),
668 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
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)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
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
boost::shared_ptr< TGeoManager > ReturnType
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
double radius(void) const
radius of the cut-out (neg.) or rounding (pos.)