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);
227 const std::vector<double>& params = iSolid.
parameters();
229 switch(iSolid.
shape())
232 rSolid =
new TGeoBBox(
239 rSolid =
new TGeoConeSeg(
247 params[6]/deg+params[5]/deg
252 rSolid=
new TGeoTubeSeg(
258 params[3]/deg + params[4]/deg);
261 rSolid =
new TGeoTrap(
276 rSolid =
new TGeoPcon(
280 (params.size()-2)/3) ;
282 std::vector<double>
temp(params.size()+1);
283 temp.reserve(params.size()+1);
284 temp[0]=params[0]/deg;
285 temp[1]=params[1]/deg;
286 temp[2]=(params.size()-2)/3;
288 for(std::vector<double>::iterator it=
temp.begin()+3;
293 rSolid->SetDimensions(&(*(
temp.begin())));
297 rSolid =
new TGeoPgon(
301 static_cast<int>(params[0]),
302 (params.size()-3)/3);
304 std::vector<double>
temp(params.size()+1);
305 temp[0]=params[1]/deg;
306 temp[1]=params[2]/deg;
308 temp[3]=(params.size()-3)/3;
309 std::copy(params.begin()+3,params.end(),temp.begin()+4);
310 for(std::vector<double>::iterator it=temp.begin()+4;
315 rSolid->SetDimensions(&(*(temp.begin())));
328 bool intersec =
false;
338 double openingAngle = 2. * asin( x /
abs( r ))/deg;
339 double displacement = 0;
345 if( r < 0 &&
abs( r ) >= x )
348 h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
353 startPhi = 270. - openingAngle/2.;
358 startPhi = 90. - openingAngle/2.;
361 else if( r > 0 &&
abs( r ) >= x )
366 startPhi = 270. - openingAngle/2.;
372 startPhi = 90. - openingAngle/2.;
381 std::auto_ptr<TGeoShape> trap(
new TGeoTrd2( pt.
name().
name().c_str(),
388 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( pt.
name().
name().c_str(),
393 startPhi + openingAngle ));
396 TGeoSubtraction* sub =
new TGeoSubtraction( trap.release(),
399 createPlacement( s_rot,
403 rSolid =
new TGeoCompositeShape( iName.c_str(),
408 std::auto_ptr<TGeoShape> box(
new TGeoBBox( 1.1*x/cm, 1.1*h/cm,
sqrt(r*r-x*x)/cm ));
410 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
413 createPlacement( s_rot,
418 std::auto_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape( iName.c_str(), sub ));
420 TGeoUnion* boolS =
new TGeoUnion( trap.release(),
423 createPlacement( s_rot,
428 rSolid =
new TGeoCompositeShape( iName.c_str(),
437 rSolid =
new TGeoTorus( iName.c_str(),
449 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
456 if( 0 != left.get() &&
458 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
463 rSolid =
new TGeoCompositeShape(iName.c_str(),
473 throw cms::Exception(
"GeomConvert" ) <<
"conversion to DDTruncTubs failed";
475 double rIn( tt.
rIn());
476 double rOut( tt.
rOut());
477 double zHalf( tt.
zHalf());
486 if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 )
488 std::string
s =
"TruncTubs " + std::string( tt.
name().
fullname()) +
": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!";
493 std::string
s =
"TruncTubs " + std::string( tt.
name().
fullname()) +
": rIn<rOut violated!";
498 std::string
s=
"TruncTubs " + std::string( tt.
name().
fullname()) +
": startPhi != 0 not supported!";
503 double r( cutAtStart );
504 double R( cutAtDelta );
507 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi,
deltaPhi/deg ));
509 double boxX( rOut ), boxY( rOut );
512 double boxZ( 1.1 * zHalf );
517 double cos_alpha = cath / hypo;
518 double alpha = -acos( cos_alpha );
523 rot.RotateZ( alpha/deg );
529 xBox = r + boxX /
sin( fabs( alpha ));
533 xBox = - ( boxX /
sin( fabs( alpha )) -
r );
535 std::auto_ptr<TGeoShape> box(
new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm ));
537 TGeoTranslation trans( xBox/cm, 0., 0.);
539 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
541 0,
new TGeoCombiTrans( trans, rot ));
543 rSolid =
new TGeoCompositeShape( iName.c_str(),
551 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
560 if( 0 != left.get() &&
562 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
567 rSolid =
new TGeoCompositeShape(iName.c_str(),
576 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
583 if( 0 != left.get() &&
585 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
591 rSolid =
new TGeoCompositeShape(iName.c_str(),
603 std::cerr <<
"COULD NOT MAKE "<<iName<<
" of a shape "<<iSolid<<std::endl;
623 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
628 v =
new TGeoVolume(iName.c_str(),
647 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
659 mat =
new TGeoMaterial(mat_name.c_str(),
660 iMaterial.
a()*mole/
g, iMaterial.
z(),
const std::vector< double > & parameters() const
Don't use (only meant to be used by DDbox(), DDtub(), ...)
double a() const
returns the atomic mass
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
A truncated tube section.
double x2() const
half length along x on +z
double deltaPhi() const
angular span of the tube-section
double rIn() const
inner radius
DDSolidShape shape() const
The type of the solid.
DDMaterial is used to define and access material information.
double deltaPhi(float phi1, float phi2)
double startPhi() const
angular start of the tube-section
Sin< T >::type sin(const T &t)
An exception for DDD errors.
double zHalf() const
half of the z-Axis
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 cutAtStart() const
truncation at begin of the tube-section
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
double y1() const
half length along y on -z
double radius() const
radius of the cut-out (neg.) or rounding (pos.)
const DepRecordT & getRecord() const
double z() const
retruns the atomic number
graph< DDLogicalPart, DDPosData * >::value_type value_type
static const char * name(DDSolidShape s)
TGeoVolume * createVolume(const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
double halfZ() const
half of the z-Axis
double cutAtDelta() const
truncation at end of the tube-section
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
ReturnType produce(const DisplayGeomRecord &)
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
TGeoMgrFromDdd(const edm::ParameterSet &)
double x1() const
half length along x on -z
std::map< std::string, TGeoMaterial * > nameToMaterial_
double density() const
returns the density
bool cutInside() const
true, if truncation is on the inner side of the tube-section
std::map< std::string, TGeoVolume * > nameToVolume_
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
boost::shared_ptr< TGeoManager > ReturnType
std::map< std::string, TGeoMedium * > nameToMedium_
double rOut() const
outer radius
double y2() const
half length along y on +z
DDRotation rotation() const
virtual ~TGeoMgrFromDdd()
DDRotationMatrix * matrix()
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
DDTranslation translation() const
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
bool atMinusZ() const
true, if cut-out or rounding is on the -z side