30 #include "TGeoManager.h"
31 #include "TGeoMatrix.h"
32 #include "TGeoCompositeShape.h"
36 #include "TGeoBoolNode.h"
40 #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 boost::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 boost::shared_ptr<TGeoManager>();
120 info.first.material());
122 return boost::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 boost::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);
267 rSolid =
new TGeoTrap(
282 rSolid =
new TGeoPcon(
286 (params.size()-2)/3) ;
288 std::vector<double>
temp(params.size()+1);
289 temp.reserve(params.size()+1);
290 temp[0]=params[0]/deg;
291 temp[1]=params[1]/deg;
292 temp[2]=(params.size()-2)/3;
294 for(std::vector<double>::iterator it=
temp.begin()+3;
299 rSolid->SetDimensions(&(*(
temp.begin())));
303 rSolid =
new TGeoPgon(
307 static_cast<int>(params[0]),
308 (params.size()-3)/3);
310 std::vector<double>
temp(params.size()+1);
311 temp[0]=params[1]/deg;
312 temp[1]=params[2]/deg;
314 temp[3]=(params.size()-3)/3;
315 std::copy(params.begin()+3,params.end(),temp.begin()+4);
316 for(std::vector<double>::iterator it=temp.begin()+4;
321 rSolid->SetDimensions(&(*(temp.begin())));
334 bool intersec =
false;
344 double halfOpeningAngle = asin( x /
abs( r ))/deg;
345 double displacement = 0;
351 if( r < 0 &&
abs( r ) >= x )
354 h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
359 startPhi = 90. - halfOpeningAngle;
364 startPhi = -90.- halfOpeningAngle;
367 else if( r > 0 &&
abs( r ) >= x )
372 startPhi = 270.- halfOpeningAngle;
378 startPhi = 90. - halfOpeningAngle;
387 std::auto_ptr<TGeoShape> trap(
new TGeoTrd2( pt.
name().
name().c_str(),
394 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( pt.
name().
name().c_str(),
399 startPhi + halfOpeningAngle * 2. ));
402 TGeoSubtraction* sub =
new TGeoSubtraction( trap.release(),
405 createPlacement( s_rot,
409 rSolid =
new TGeoCompositeShape( iName.c_str(),
414 std::auto_ptr<TGeoShape> box(
new TGeoBBox( 1.1*x/cm, 1.1*h/cm,
sqrt(r*r-x*x)/cm ));
416 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
419 createPlacement( s_rot,
424 std::auto_ptr<TGeoShape> tubicCap(
new TGeoCompositeShape( iName.c_str(), sub ));
426 TGeoUnion* boolS =
new TGeoUnion( trap.release(),
429 createPlacement( s_rot,
434 rSolid =
new TGeoCompositeShape( iName.c_str(),
443 rSolid =
new TGeoTorus( iName.c_str(),
455 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
462 if( 0 != left.get() &&
464 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
469 rSolid =
new TGeoCompositeShape(iName.c_str(),
479 throw cms::Exception(
"GeomConvert" ) <<
"conversion to DDTruncTubs failed";
481 double rIn( tt.
rIn());
482 double rOut( tt.
rOut());
483 double zHalf( tt.
zHalf());
492 if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 )
494 std::string
s =
"TruncTubs " + std::string( tt.
name().
fullname()) +
": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!";
499 std::string
s =
"TruncTubs " + std::string( tt.
name().
fullname()) +
": rIn<rOut violated!";
504 std::string
s=
"TruncTubs " + std::string( tt.
name().
fullname()) +
": startPhi != 0 not supported!";
509 double r( cutAtStart );
510 double R( cutAtDelta );
513 std::auto_ptr<TGeoShape> tubs(
new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi,
deltaPhi/deg ));
515 double boxX( rOut ), boxY( rOut );
518 double boxZ( 1.1 * zHalf );
523 double cos_alpha = cath / hypo;
524 double alpha = -acos( cos_alpha );
529 rot.RotateZ( alpha/deg );
535 xBox = r + boxX /
sin( fabs( alpha ));
539 xBox = - ( boxX /
sin( fabs( alpha )) -
r );
541 std::auto_ptr<TGeoShape> box(
new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm ));
543 TGeoTranslation trans( xBox/cm, 0., 0.);
545 TGeoSubtraction* sub =
new TGeoSubtraction( tubs.release(),
547 0,
new TGeoCombiTrans( trans, rot ));
549 rSolid =
new TGeoCompositeShape( iName.c_str(),
557 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
566 if( 0 != left.get() &&
568 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
573 rSolid =
new TGeoCompositeShape(iName.c_str(),
582 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
589 if( 0 != left.get() &&
591 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
597 rSolid =
new TGeoCompositeShape(iName.c_str(),
609 std::cerr <<
"COULD NOT MAKE "<<iName<<
" of a shape "<<iSolid<<std::endl;
612 LogDebug(
"TGeoMgrFromDdd::createShape") <<
"solid " << iName <<
" has been created.";
632 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
637 v =
new TGeoVolume(iName.c_str(),
656 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
668 mat =
new TGeoMaterial(mat_name.c_str(),
669 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
DDRotation rotation(void) const
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)
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
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
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
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()
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.)