31 #include "TGeoManager.h" 32 #include "TGeoMatrix.h" 33 #include "TGeoCompositeShape.h" 37 #include "TGeoBoolNode.h" 43 #include "Math/GenVector/RotationX.h" 45 #include "CLHEP/Units/GlobalSystemOfUnits.h" 60 m_level (pset.getUntrackedParameter<
int> (
"level", 10)),
61 m_verbose (pset.getUntrackedParameter<
bool>(
"verbose",
false)),
84 printf(
"TGeoFromDddService::postBeginRun\n");
91 printf(
"TGeoFromDddService::postEndRun\n");
109 edm::LogError(
"TGeoFromDddService") <<
"getGeoManager() -- EventSetup not present.\n";
114 edm::LogError(
"TGeoFromDddService") <<
"getGeoManager() -- creation failed.\n";
133 iRot.GetComponents(elements);
135 r.SetMatrix(elements);
137 TGeoTranslation
t(iTrans.x()/cm,
141 return new TGeoCombiTrans(
t,r);
164 TGeoManager *geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
166 if (gGeoIdentity ==
nullptr)
168 gGeoIdentity =
new TGeoIdentity(
"Identity");
171 std::cout <<
"about to initialize the DDCompactView walker" << std::endl;
173 auto info = walker.current();
179 TGeoVolume *top =
createVolume(info.first.name().fullname(),
181 info.first.material());
188 geo_mgr->SetTopVolume(top);
190 top->SetVisibility(kFALSE);
191 top->SetLineColor(kBlue);
193 std::vector<TGeoVolume*> parentStack;
194 parentStack.push_back(top);
196 if( ! walker.firstChild() ) {
206 for(
unsigned int i=0;
i<parentStack.size();++
i) {
209 std::cout << info.first.name()<<
" "<<info.second->copyno()<<
" " 213 bool childAlreadyExists = (
nullptr !=
nameToVolume_[info.first.name().fullname()]);
216 info.first.material());
217 if (
nullptr!=child && info.second !=
nullptr)
219 parentStack.back()->AddNode(child,
220 info.second->copyno(),
221 createPlacement(info.second->rotation(),
222 info.second->translation()));
223 child->SetLineColor(kBlue);
227 if ( info.second ==
nullptr ) {
231 if (
nullptr == child || childAlreadyExists || level ==
int(parentStack.size()))
235 child->SetLineColor(kRed);
238 if ( ! walker.nextSibling())
240 while (walker.parent())
242 parentStack.pop_back();
243 if (walker.nextSibling()) {
251 if (walker.firstChild())
253 parentStack.push_back(child);
257 if ( ! walker.nextSibling())
259 while (walker.parent())
261 parentStack.pop_back();
262 if (walker.nextSibling()) {
269 }
while ( ! parentStack.empty());
271 geo_mgr->CloseGeometry();
273 geo_mgr->DefaultColors();
288 if (rSolid ==
nullptr)
290 const std::vector<double>& params = iSolid.
parameters();
292 switch(iSolid.
shape())
295 rSolid =
new TGeoBBox(
302 rSolid =
new TGeoConeSeg(
310 params[6]/deg+params[5]/deg
315 rSolid=
new TGeoTubeSeg(
321 params[3]/deg + params[4]/deg);
325 rSolid=
new TGeoCtub(
331 params[3]/deg + params[4]/deg,
332 params[5],params[6],params[7],
333 params[8],params[9],params[10]);
336 rSolid =
new TGeoTrap(
351 rSolid =
new TGeoPcon(
355 (params.size()-2)/3) ;
357 std::vector<double>
temp(params.size()+1);
358 temp.reserve(params.size()+1);
359 temp[0]=params[0]/deg;
360 temp[1]=params[1]/deg;
361 temp[2]=(params.size()-2)/3;
363 for(std::vector<double>::iterator it=
temp.begin()+3;
368 rSolid->SetDimensions(&(*(
temp.begin())));
372 rSolid =
new TGeoPgon(
376 static_cast<int>(params[0]),
377 (params.size()-3)/3);
379 std::vector<double>
temp(params.size()+1);
380 temp[0]=params[1]/deg;
381 temp[1]=params[2]/deg;
383 temp[3]=(params.size()-3)/3;
384 std::copy(params.begin()+3,params.end(),temp.begin()+4);
385 for(std::vector<double>::iterator it=temp.begin()+4;
390 rSolid->SetDimensions(&(*(temp.begin())));
396 std::vector<double>
x = extrPgon.
xVec();
397 std::transform(x.begin(), x.end(), x.begin(),[](
double d) {
return d/cm; });
398 std::vector<double>
y = extrPgon.
yVec();
399 std::transform(y.begin(), y.end(), y.begin(),[](
double d) {
return d/cm; });
400 std::vector<double>
z = extrPgon.
zVec();
401 std::vector<double> zx = extrPgon.
zxVec();
402 std::vector<double> zy = extrPgon.
zyVec();
403 std::vector<double> zscale = extrPgon.
zscaleVec();
405 TGeoXtru* mySolid =
new TGeoXtru(z.size());
406 mySolid->DefinePolygon(x.size(), &(*x.begin()), &(*y.begin()));
407 for(
size_t i = 0;
i < params[0]; ++
i )
409 mySolid->DefineSection(
i, z[
i]/cm, zx[
i]/cm, zy[
i]/cm, zscale[
i]);
428 double openingAngle = 2.0*asin(x/r);
429 double h=pt.
y1()<pt.
y2()? pt.
y2() :pt.
y1();
431 double displacement=0;
436 startPhi = 270.-openingAngle/deg/2.0;
439 startPhi = 90. - openingAngle/deg/2.;
441 std::unique_ptr<TGeoShape> trap(
new TGeoTrd2(pt.
name().
name().c_str(),
447 std::unique_ptr<TGeoShape> tubs(
new TGeoTubeSeg(pt.
name().
name().c_str(),
453 TGeoSubtraction* sub =
new TGeoSubtraction(trap.release(),
455 createPlacement(s_rot,
459 rSolid =
new TGeoCompositeShape(iName.c_str(),
469 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
476 if(
nullptr != left.get() &&
477 nullptr != right.get() ) {
478 TGeoSubtraction* sub =
new TGeoSubtraction(left.release(),right.release(),
483 rSolid =
new TGeoCompositeShape(iName.c_str(),
492 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
501 if(
nullptr != left.get() &&
502 nullptr != right.get() ) {
503 TGeoUnion* boolS =
new TGeoUnion(left.release(),right.release(),
508 rSolid =
new TGeoCompositeShape(iName.c_str(),
517 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
524 if(
nullptr != left.get() &&
525 nullptr != right.get() ) {
526 TGeoIntersection* boolS =
new TGeoIntersection(left.release(),
532 rSolid =
new TGeoCompositeShape(iName.c_str(),
542 if (rSolid ==
nullptr)
544 std::cerr <<
"COULD NOT MAKE "<<iName<<std::endl;
561 if (geo_med ==
nullptr)
564 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
569 v =
new TGeoVolume(iName.c_str(),
588 TGeoMixture *
mix =
new TGeoMixture(mat_name.c_str(),
600 mat =
new TGeoMaterial(mat_name.c_str(),
601 iMaterial.
a()*mole/
g, iMaterial.
z(),
void watchPostBeginRun(PostBeginRun::slot_type const &iSlot)
std::map< std::string, TGeoMaterial * > nameToMaterial_
double a() const
returns the atomic mass
TGeoManager * m_geoManager
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
double y2(void) const
half length along y on +z
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const edm::EventSetup * m_eventSetup
DDMaterial is used to define and access material information.
TGeoVolume * createVolume(const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
std::vector< double > yVec(void) const
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
std::map< std::string, TGeoVolume * > nameToVolume_
DDSolid solidB(void) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
std::vector< double > xVec(void) const
double z() const
retruns the atomic number
static const char *const name(DDSolidShape s)
DDRotation rotation(void) const
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 std::string fullname() const
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
DDSolidShape shape(void) const
The type of the solid.
std::map< std::string, TGeoMedium * > nameToMedium_
void postBeginRun(const edm::Run &, const edm::EventSetup &)
DDSolid solidA(void) const
TGeoFromDddService(const edm::ParameterSet &, edm::ActivityRegistry &)
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
std::vector< double > zVec(void) const
std::vector< double > zxVec(void) const
double density() const
returns the density
virtual ~TGeoFromDddService()
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
TGeoManager * createManager(int level)
std::map< std::string, TGeoShape * > nameToShape_
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
void watchPostEndRun(PostEndRun::slot_type const &iSlot)
double x2(void) const
half length along x on +z
std::vector< double > zscaleVec(void) const
value_type current() const
const std::string & name() const
Returns the name.
TGeoManager * getGeoManager()
void postEndRun(const edm::Run &, const edm::EventSetup &)
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
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.)