CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
TGeoMgrFromDdd Class Reference
Inheritance diagram for TGeoMgrFromDdd:
edm::ESProducer edm::ESProxyFactoryProducer edm::eventsetup::DataProxyProvider

Public Types

using ReturnType = std::unique_ptr< TGeoManager >
 

Public Member Functions

const TGeoMgrFromDddoperator= (const TGeoMgrFromDdd &)=delete
 
ReturnType produce (const DisplayGeomRecord &)
 
 TGeoMgrFromDdd (const edm::ParameterSet &)
 
 TGeoMgrFromDdd (const TGeoMgrFromDdd &)=delete
 
- Public Member Functions inherited from edm::ESProducer
 ESProducer ()
 
 ESProducer (const ESProducer &)=delete
 
ESProxyIndex const * getTokenIndices (unsigned int iIndex) const
 
ESRecordIndex const * getTokenRecordIndices (unsigned int iIndex) const
 
bool hasMayConsumes () const noexcept
 
size_t numberOfTokenIndices (unsigned int iIndex) const
 
ESProducer const & operator= (const ESProducer &)=delete
 
SerialTaskQueueChainqueue ()
 
template<typename Record >
std::optional< std::vector
< ESProxyIndex > > 
updateFromMayConsumes (unsigned int iIndex, const Record &iRecord) const
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &) final
 
 ~ESProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::ESProxyFactoryProducer
 ESProxyFactoryProducer ()
 
 ESProxyFactoryProducer (const ESProxyFactoryProducer &)=delete
 
const ESProxyFactoryProduceroperator= (const ESProxyFactoryProducer &)=delete
 
 ~ESProxyFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
void createKeyedProxies (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
 DataProxyProvider ()
 
 DataProxyProvider (const DataProxyProvider &)=delete
 
const ComponentDescriptiondescription () const
 
void fillRecordsNotAllowingConcurrentIOVs (std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
 
virtual void initConcurrentIOVs (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
bool isUsingRecord (const EventSetupRecordKey &key) const
 
KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
 
const DataProxyProvideroperator= (const DataProxyProvider &)=delete
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 

Private Member Functions

TGeoManager * createManager (int level)
 
TGeoMaterial * createMaterial (const DDMaterial &iMaterial)
 
TGeoShape * createShape (const std::string &iName, const DDSolid &iSolid)
 
TGeoVolume * createVolume (const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
 

Private Attributes

const bool m_fullname
 
const int m_level
 
std::string m_TGeoName
 
std::string m_TGeoTitle
 
const bool m_verbose
 
std::map< std::string,
TGeoMaterial * > 
nameToMaterial_
 
std::map< std::string,
TGeoMedium * > 
nameToMedium_
 
std::map< std::string,
TGeoShape * > 
nameToShape_
 
std::map< std::string,
TGeoVolume * > 
nameToVolume_
 
const edm::ESGetToken
< DDCompactView,
IdealGeometryRecord
viewToken_
 

Additional Inherited Members

- Protected Types inherited from edm::ESProxyFactoryProducer
using EventSetupRecordKey = eventsetup::EventSetupRecordKey
 
- Protected Types inherited from edm::eventsetup::DataProxyProvider
using KeyedProxiesVector = std::vector< std::pair< DataKey, std::shared_ptr< DataProxy >>>
 
- Protected Member Functions inherited from edm::ESProducer
template<typename T >
auto setWhatProduced (T *iThis, const es::Label &iLabel={})
 
template<typename T >
auto setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
auto setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
auto setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord >
auto setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord , typename TArg >
ESConsumesCollectorT< TRecord > setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
 
void usesResources (std::vector< std::string > const &)
 
- Protected Member Functions inherited from edm::ESProxyFactoryProducer
template<class TFactory >
void registerFactory (std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
 
virtual void registerFactoryWithKey (const EventSetupRecordKey &iRecord, std::unique_ptr< eventsetup::ProxyFactoryBase > iFactory, const std::string &iLabel=std::string())
 
KeyedProxiesVector registerProxies (const EventSetupRecordKey &, unsigned int iovIndex) override
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &key)
 

Detailed Description

Definition at line 49 of file TGeoMgrFromDdd.cc.

Member Typedef Documentation

using TGeoMgrFromDdd::ReturnType = std::unique_ptr<TGeoManager>

Definition at line 55 of file TGeoMgrFromDdd.cc.

Constructor & Destructor Documentation

TGeoMgrFromDdd::TGeoMgrFromDdd ( const edm::ParameterSet pset)

Definition at line 90 of file TGeoMgrFromDdd.cc.

91  : m_level(pset.getUntrackedParameter<int>("level")),
92  m_verbose(pset.getUntrackedParameter<bool>("verbose")),
93  m_fullname(pset.getUntrackedParameter<bool>("fullName")),
94  viewToken_(setWhatProduced(this).consumes()) {}
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
T getUntrackedParameter(std::string const &, T const &) const
const bool m_fullname
const edm::ESGetToken< DDCompactView, IdealGeometryRecord > viewToken_
const bool m_verbose
const int m_level
TGeoMgrFromDdd::TGeoMgrFromDdd ( const TGeoMgrFromDdd )
delete

Member Function Documentation

TGeoManager* TGeoMgrFromDdd::createManager ( int  level)
private
TGeoMaterial * TGeoMgrFromDdd::createMaterial ( const DDMaterial iMaterial)
private

Definition at line 611 of file TGeoMgrFromDdd.cc.

References DDMaterial::a(), DDMaterial::constituent(), DDMaterial::density(), DDName::fullname(), g, mps_fire::i, m_fullname, reco_application_tbsim_DetSim-Digi_cfg::mix, DDName::name(), DDBase< N, C >::name(), nameToMaterial_, DDMaterial::noOfConstituents(), AlCaHLTBitMon_QueryRunRegistry::string, and DDMaterial::z().

Referenced by createVolume().

611  {
612  std::string mat_name = m_fullname ? iMaterial.name().fullname() : iMaterial.name().name();
613  TGeoMaterial* mat = nameToMaterial_[mat_name];
614 
615  if (mat == nullptr) {
616  if (iMaterial.noOfConstituents() > 0) {
617  TGeoMixture* mix = new TGeoMixture(mat_name.c_str(), iMaterial.noOfConstituents(), iMaterial.density() * cm3 / g);
618  for (int i = 0; i < iMaterial.noOfConstituents(); ++i) {
619  mix->AddElement(createMaterial(iMaterial.constituent(i).first), iMaterial.constituent(i).second);
620  }
621  mat = mix;
622  } else {
623  mat = new TGeoMaterial(mat_name.c_str(), iMaterial.a() * mole / g, iMaterial.z(), iMaterial.density() * cm3 / g);
624  }
625  nameToMaterial_[mat_name] = mat;
626  }
627 
628  return mat;
629 }
double a() const
returns the atomic mass
Definition: DDMaterial.cc:76
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
const N & name() const
Definition: DDBase.h:59
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
Definition: Activities.doc:4
const bool m_fullname
double z() const
retruns the atomic number
Definition: DDMaterial.cc:78
const std::string fullname() const
Definition: DDName.h:43
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:74
std::map< std::string, TGeoMaterial * > nameToMaterial_
double density() const
returns the density
Definition: DDMaterial.cc:80
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:72
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
TGeoShape * TGeoMgrFromDdd::createShape ( const std::string &  iName,
const DDSolid iSolid 
)
private

Definition at line 236 of file TGeoMgrFromDdd.cc.

References funct::abs(), alpha, DDPseudoTrap::atMinusZ(), filterCSVwithJSON::copy, funct::cos(), dd4hep::createPlacement(), DDTruncTubs::cutAtDelta(), DDTruncTubs::cutAtStart(), DDTruncTubs::cutInside(), ztail::d, ddbox, ddcons, ddcuttubs, ddellipticaltube, ddextrudedpolygon, ddintersection, ddpolycone_rrz, ddpolyhedra_rrz, ddpseudotrap, ddsubtraction, ddtorus, ddtrap, ddtrunctubs, ddtubs, ddunion, CommonMethods::delta(), srCondWrite_cfg::deltaPhi, DDTruncTubs::deltaPhi(), DDTorus::deltaPhi(), Exception, DDName::fullname(), h, DDPseudoTrap::halfZ(), mps_fire::i, m_fullname, DDRotation::matrix(), DDName::name(), DDBase< N, C >::name(), mergeVDriftHistosByStation::name, nameToShape_, submitPVValidationJobs::params, DiDispStaMuonMonitor_cfi::pt, dttmaxenums::R, alignCSCRings::r, DDPseudoTrap::radius(), DDTruncTubs::rIn(), DDTorus::rMax(), DDTorus::rMin(), makeMuonMisalignmentScenario::rot, DDBooleanSolid::rotation(), DDTruncTubs::rOut(), DDTorus::rTorus(), alignCSCRings::s, funct::sin(), DDBooleanSolid::solidA(), DDBooleanSolid::solidB(), mathSSE::sqrt(), DDTruncTubs::startPhi(), DDTorus::startPhi(), AlCaHLTBitMon_QueryRunRegistry::string, groupFilesInBlocks::temp, HcalDetIdTransform::transform(), DDBooleanSolid::translation(), groupFilesInBlocks::tt, x, DDPseudoTrap::x1(), DDPseudoTrap::x2(), DDExtrudedPolygon::xVec(), y, DDPseudoTrap::y1(), DDPseudoTrap::y2(), DDExtrudedPolygon::yVec(), z, DDTruncTubs::zHalf(), DDExtrudedPolygon::zscaleVec(), DDExtrudedPolygon::zVec(), DDExtrudedPolygon::zxVec(), and DDExtrudedPolygon::zyVec().

Referenced by createVolume().

236  {
237  edm::LogVerbatim("TGeoMgrFromDdd") << "with name: " << iName << " and solid: " << iSolid;
238 
239  DDBase<DDName, DDI::Solid*>::def_type defined(iSolid.isDefined());
240  if (!defined.first)
241  throw cms::Exception("TGeoMgrFromDdd::createShape * solid " + iName + " is not declared * ");
242  if (!defined.second)
243  throw cms::Exception("TGeoMgrFromDdd::createShape * solid " + defined.first->name() + " is not defined *");
244 
245  TGeoShape* rSolid = nameToShape_[iName];
246  if (rSolid == nullptr) {
247  const std::vector<double>& params = iSolid.parameters();
248  switch (iSolid.shape()) {
249  case DDSolidShape::ddbox:
250  rSolid = new TGeoBBox(iName.c_str(), params[0] / cm, params[1] / cm, params[2] / cm);
251  break;
253  rSolid = new TGeoConeSeg(iName.c_str(),
254  params[0] / cm,
255  params[1] / cm,
256  params[2] / cm,
257  params[3] / cm,
258  params[4] / cm,
259  params[5] / deg,
260  params[6] / deg + params[5] / deg);
261  break;
263  //Order in params is zhalf,rIn,rOut,startPhi,deltaPhi
264  rSolid = new TGeoTubeSeg(iName.c_str(),
265  params[1] / cm,
266  params[2] / cm,
267  params[0] / cm,
268  params[3] / deg,
269  params[3] / deg + params[4] / deg);
270  break;
272  //Order in params is zhalf,rIn,rOut,startPhi,deltaPhi,lx,ly,lz,tx,ty,tz
273  rSolid = new TGeoCtub(iName.c_str(),
274  params[1] / cm,
275  params[2] / cm,
276  params[0] / cm,
277  params[3] / deg,
278  params[3] / deg + params[4] / deg,
279  params[5],
280  params[6],
281  params[7],
282  params[8],
283  params[9],
284  params[10]);
285  break;
287  rSolid = new TGeoTrap(iName.c_str(),
288  params[0] / cm, //dz
289  params[1] / deg, //theta
290  params[2] / deg, //phi
291  params[3] / cm, //dy1
292  params[4] / cm, //dx1
293  params[5] / cm, //dx2
294  params[6] / deg, //alpha1
295  params[7] / cm, //dy2
296  params[8] / cm, //dx3
297  params[9] / cm, //dx4
298  params[10] / deg); //alpha2
299  break;
301  rSolid = new TGeoPcon(iName.c_str(), params[0] / deg, params[1] / deg, (params.size() - 2) / 3);
302  {
303  std::vector<double> temp(params.size() + 1);
304  temp.reserve(params.size() + 1);
305  temp[0] = params[0] / deg;
306  temp[1] = params[1] / deg;
307  temp[2] = (params.size() - 2) / 3;
308  std::copy(params.begin() + 2, params.end(), temp.begin() + 3);
309  for (std::vector<double>::iterator it = temp.begin() + 3; it != temp.end(); ++it) {
310  *it /= cm;
311  }
312  rSolid->SetDimensions(&(*(temp.begin())));
313  }
314  break;
316  rSolid = new TGeoPgon(
317  iName.c_str(), params[1] / deg, params[2] / deg, static_cast<int>(params[0]), (params.size() - 3) / 3);
318  {
319  std::vector<double> temp(params.size() + 1);
320  temp[0] = params[1] / deg;
321  temp[1] = params[2] / deg;
322  temp[2] = params[0];
323  temp[3] = (params.size() - 3) / 3;
324  std::copy(params.begin() + 3, params.end(), temp.begin() + 4);
325  for (std::vector<double>::iterator it = temp.begin() + 4; it != temp.end(); ++it) {
326  *it /= cm;
327  }
328  rSolid->SetDimensions(&(*(temp.begin())));
329  }
330  break;
332  DDExtrudedPolygon extrPgon(iSolid);
333  std::vector<double> x = extrPgon.xVec();
334  std::transform(x.begin(), x.end(), x.begin(), [](double d) { return d / cm; });
335  std::vector<double> y = extrPgon.yVec();
336  std::transform(y.begin(), y.end(), y.begin(), [](double d) { return d / cm; });
337  std::vector<double> z = extrPgon.zVec();
338  std::vector<double> zx = extrPgon.zxVec();
339  std::vector<double> zy = extrPgon.zyVec();
340  std::vector<double> zscale = extrPgon.zscaleVec();
341 
342  TGeoXtru* mySolid = new TGeoXtru(z.size());
343  mySolid->DefinePolygon(x.size(), &(*x.begin()), &(*y.begin()));
344  for (size_t i = 0; i < params[0]; ++i) {
345  mySolid->DefineSection(i, z[i] / cm, zx[i] / cm, zy[i] / cm, zscale[i]);
346  }
347 
348  rSolid = mySolid;
349  } break;
351  //implementation taken from SimG4Core/Geometry/src/DDG4SolidConverter.cc
352  const static DDRotationMatrix s_rot(ROOT::Math::RotationX(90. * deg));
353  DDPseudoTrap pt(iSolid);
354 
355  double r = pt.radius();
356  bool atMinusZ = pt.atMinusZ();
357  double x = 0;
358  double h = 0;
359  bool intersec = false; // union or intersection solid
360 
361  if (atMinusZ) {
362  x = pt.x1(); // tubs radius
363  } else {
364  x = pt.x2(); // tubs radius
365  }
366  double halfOpeningAngle = asin(x / std::abs(r)) / deg;
367  double displacement = 0;
368  double startPhi = 0;
369  /* calculate the displacement of the tubs w.r.t. to the trap,
370  determine the opening angle of the tubs */
371  double delta = sqrt(r * r - x * x);
372  std::string name = m_fullname ? pt.name().fullname() : pt.name().name();
373 
374  if (r < 0 && std::abs(r) >= x) {
375  intersec = true; // intersection solid
376  h = pt.y1() < pt.y2() ? pt.y2() : pt.y1(); // tubs half height
377  h += h / 20.; // enlarge a bit - for subtraction solid
378  if (atMinusZ) {
379  displacement = -pt.halfZ() - delta;
380  startPhi = 90. - halfOpeningAngle;
381  } else {
382  displacement = pt.halfZ() + delta;
383  startPhi = -90. - halfOpeningAngle;
384  }
385  } else if (r > 0 && std::abs(r) >= x) {
386  if (atMinusZ) {
387  displacement = -pt.halfZ() + delta;
388  startPhi = 270. - halfOpeningAngle;
389  h = pt.y1();
390  } else {
391  displacement = pt.halfZ() - delta;
392  startPhi = 90. - halfOpeningAngle;
393  h = pt.y2();
394  }
395  } else {
396  throw cms::Exception("Check parameters of the PseudoTrap! name=" + name);
397  }
398 
399  std::unique_ptr<TGeoShape> trap(
400  new TGeoTrd2(name.c_str(), pt.x1() / cm, pt.x2() / cm, pt.y1() / cm, pt.y2() / cm, pt.halfZ() / cm));
401 
402  std::unique_ptr<TGeoShape> tubs(new TGeoTubeSeg(name.c_str(),
403  0.,
404  std::abs(r) / cm, // radius cannot be negative!!!
405  h / cm,
406  startPhi,
407  startPhi + halfOpeningAngle * 2.));
408  if (intersec) {
409  TGeoSubtraction* sub = new TGeoSubtraction(
410  trap.release(), tubs.release(), nullptr, createPlacement(s_rot, DDTranslation(0., 0., displacement)));
411  rSolid = new TGeoCompositeShape(iName.c_str(), sub);
412  } else {
413  std::unique_ptr<TGeoShape> box(new TGeoBBox(1.1 * x / cm, 1.1 * h / cm, sqrt(r * r - x * x) / cm));
414 
415  TGeoSubtraction* sub = new TGeoSubtraction(
416  tubs.release(), box.release(), nullptr, createPlacement(s_rot, DDTranslation(0., 0., 0.)));
417 
418  std::unique_ptr<TGeoShape> tubicCap(new TGeoCompositeShape(iName.c_str(), sub));
419 
420  TGeoUnion* boolS = new TGeoUnion(
421  trap.release(), tubicCap.release(), nullptr, createPlacement(s_rot, DDTranslation(0., 0., displacement)));
422 
423  rSolid = new TGeoCompositeShape(iName.c_str(), boolS);
424  }
425 
426  break;
427  }
428  case DDSolidShape::ddtorus: {
429  DDTorus solid(iSolid);
430  rSolid = new TGeoTorus(iName.c_str(),
431  solid.rTorus() / cm,
432  solid.rMin() / cm,
433  solid.rMax() / cm,
434  solid.startPhi() / deg,
435  solid.deltaPhi() / deg);
436  break;
437  }
439  DDBooleanSolid boolSolid(iSolid);
440  if (!boolSolid) {
441  throw cms::Exception("GeomConvert") << "conversion to DDBooleanSolid failed";
442  }
443 
444  std::string nameA = m_fullname ? boolSolid.solidA().name().fullname() : boolSolid.solidA().name().name();
445  std::string nameB = m_fullname ? boolSolid.solidB().name().fullname() : boolSolid.solidB().name().name();
446  std::unique_ptr<TGeoShape> left(createShape(nameA, boolSolid.solidA()));
447  std::unique_ptr<TGeoShape> right(createShape(nameB, boolSolid.solidB()));
448  if (nullptr != left.get() && nullptr != right.get()) {
449  TGeoSubtraction* sub =
450  new TGeoSubtraction(left.release(),
451  right.release(),
452  nullptr,
453  createPlacement(boolSolid.rotation().matrix(), boolSolid.translation()));
454  rSolid = new TGeoCompositeShape(iName.c_str(), sub);
455  }
456  break;
457  }
459  DDTruncTubs tt(iSolid);
460  if (!tt) {
461  throw cms::Exception("GeomConvert") << "conversion to DDTruncTubs failed";
462  }
463  double rIn(tt.rIn());
464  double rOut(tt.rOut());
465  double zHalf(tt.zHalf());
466  double startPhi(tt.startPhi());
467  double deltaPhi(tt.deltaPhi());
468  double cutAtStart(tt.cutAtStart());
469  double cutAtDelta(tt.cutAtDelta());
470  bool cutInside(bool(tt.cutInside()));
471  std::string name = m_fullname ? tt.name().fullname() : tt.name().name();
472 
473  // check the parameters
474  if (rIn <= 0 || rOut <= 0 || cutAtStart <= 0 || cutAtDelta <= 0) {
475  std::string s = "TruncTubs " + name + ": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!";
476  throw cms::Exception(s);
477  }
478  if (rIn >= rOut) {
479  std::string s = "TruncTubs " + name + ": rIn<rOut violated!";
480  throw cms::Exception(s);
481  }
482  if (startPhi != 0.) {
483  std::string s = "TruncTubs " + name + ": startPhi != 0 not supported!";
484  throw cms::Exception(s);
485  }
486 
487  startPhi = 0.;
488  double r(cutAtStart);
489  double R(cutAtDelta);
490 
491  // Note: startPhi is always 0.0
492  std::unique_ptr<TGeoShape> tubs(
493  new TGeoTubeSeg(name.c_str(), rIn / cm, rOut / cm, zHalf / cm, startPhi, deltaPhi / deg));
494 
495  double boxX(rOut), boxY(rOut); // exaggerate dimensions - does not matter, it's subtracted!
496 
497  // width of the box > width of the tubs
498  double boxZ(1.1 * zHalf);
499 
500  // angle of the box w.r.t. tubs
501  double cath = r - R * cos(deltaPhi);
502  double hypo = sqrt(r * r + R * R - 2. * r * R * cos(deltaPhi));
503  double cos_alpha = cath / hypo;
504  double alpha = -acos(cos_alpha);
505 
506  // rotationmatrix of box w.r.t. tubs
507  TGeoRotation rot;
508  rot.RotateX(90);
509  rot.RotateZ(alpha / deg);
510 
511  // center point of the box
512  double xBox;
513  if (!cutInside) {
514  xBox = r + boxX / sin(fabs(alpha));
515  } else {
516  xBox = -(boxX / sin(fabs(alpha)) - r);
517  }
518  std::unique_ptr<TGeoShape> box(new TGeoBBox(name.c_str(), boxX / cm, boxZ / cm, boxY / cm));
519 
520  TGeoTranslation trans(xBox / cm, 0., 0.);
521 
522  TGeoSubtraction* sub =
523  new TGeoSubtraction(tubs.release(), box.release(), nullptr, new TGeoCombiTrans(trans, rot));
524 
525  rSolid = new TGeoCompositeShape(iName.c_str(), sub);
526  break;
527  }
528  case DDSolidShape::ddunion: {
529  DDBooleanSolid boolSolid(iSolid);
530  if (!boolSolid) {
531  throw cms::Exception("GeomConvert") << "conversion to DDBooleanSolid failed";
532  }
533 
534  std::string nameA = m_fullname ? boolSolid.solidA().name().fullname() : boolSolid.solidA().name().name();
535  std::string nameB = m_fullname ? boolSolid.solidB().name().fullname() : boolSolid.solidB().name().name();
536  std::unique_ptr<TGeoShape> left(createShape(nameA, boolSolid.solidA()));
537  std::unique_ptr<TGeoShape> right(createShape(nameB, boolSolid.solidB()));
538  //DEBUGGING
539  //break;
540  if (nullptr != left.get() && nullptr != right.get()) {
541  TGeoUnion* boolS = new TGeoUnion(left.release(),
542  right.release(),
543  nullptr,
544  createPlacement(boolSolid.rotation().matrix(), boolSolid.translation()));
545  rSolid = new TGeoCompositeShape(iName.c_str(), boolS);
546  }
547  break;
548  }
550  DDBooleanSolid boolSolid(iSolid);
551  if (!boolSolid) {
552  throw cms::Exception("GeomConvert") << "conversion to DDBooleanSolid failed";
553  }
554 
555  std::string nameA = m_fullname ? boolSolid.solidA().name().fullname() : boolSolid.solidA().name().name();
556  std::string nameB = m_fullname ? boolSolid.solidB().name().fullname() : boolSolid.solidB().name().name();
557  std::unique_ptr<TGeoShape> left(createShape(nameA, boolSolid.solidA()));
558  std::unique_ptr<TGeoShape> right(createShape(nameB, boolSolid.solidB()));
559  if (nullptr != left.get() && nullptr != right.get()) {
560  TGeoIntersection* boolS =
561  new TGeoIntersection(left.release(),
562  right.release(),
563  nullptr,
564  createPlacement(boolSolid.rotation().matrix(), boolSolid.translation()));
565  rSolid = new TGeoCompositeShape(iName.c_str(), boolS);
566  }
567  break;
568  }
570  DDEllipticalTube eSolid(iSolid);
571  if (!eSolid) {
572  throw cms::Exception("GeomConvert") << "conversion to DDEllipticalTube failed";
573  }
574  rSolid = new TGeoEltu(iName.c_str(), params[0] / cm, params[1] / cm, params[2] / cm);
575  break;
576  }
577  default:
578  break;
579  }
580  nameToShape_[iName] = rSolid;
581  }
582  if (rSolid == nullptr) {
583  edm::LogError("TGeoMgrFromDdd") << "COULD NOT MAKE " << iName << " of a shape " << iSolid;
584  }
585 
586  edm::LogVerbatim("TGeoMgrFromDdd") << "solid " << iName << " has been created.";
587 
588  return rSolid;
589 }
Log< level::Info, true > LogVerbatim
float alpha
Definition: AMPTWrapper.h:105
A truncated tube section.
Definition: DDSolid.h:139
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Log< level::Error, false > LogError
TGeoCombiTrans * createPlacement(const Rotation3D &iRot, const Position &iTrans)
const bool m_fullname
tuple d
Definition: ztail.py:151
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::map< std::string, TGeoShape * > nameToShape_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
std::pair< const N *, bool > def_type
Definition: DDBase.h:51
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
unsigned transform(const HcalDetId &id, unsigned transformCode)
TGeoVolume * TGeoMgrFromDdd::createVolume ( const std::string &  iName,
const DDSolid iSolid,
const DDMaterial iMaterial 
)
private

Definition at line 591 of file TGeoMgrFromDdd.cc.

References createMaterial(), createShape(), DDName::fullname(), m_fullname, DDName::name(), DDBase< N, C >::name(), nameToMedium_, nameToVolume_, AlCaHLTBitMon_QueryRunRegistry::string, and findQualityFiles::v.

Referenced by produce().

591  {
592  TGeoVolume* v = nameToVolume_[iName];
593  if (v == nullptr) {
594  TGeoShape* solid =
595  m_fullname ? createShape(iSolid.name().fullname(), iSolid) : createShape(iSolid.name().name(), iSolid);
596  std::string mat_name = m_fullname ? iMaterial.name().fullname() : iMaterial.name().name();
597  TGeoMedium* geo_med = nameToMedium_[mat_name];
598  if (geo_med == nullptr) {
599  TGeoMaterial* geo_mat = createMaterial(iMaterial);
600  geo_med = new TGeoMedium(mat_name.c_str(), 0, geo_mat);
601  nameToMedium_[mat_name] = geo_med;
602  }
603  if (solid) {
604  v = new TGeoVolume(iName.c_str(), solid, geo_med);
605  }
606  nameToVolume_[iName] = v;
607  }
608  return v;
609 }
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
const N & name() const
Definition: DDBase.h:59
const bool m_fullname
const std::string fullname() const
Definition: DDName.h:43
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
std::map< std::string, TGeoVolume * > nameToVolume_
std::map< std::string, TGeoMedium * > nameToMedium_
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
void TGeoMgrFromDdd::fillDescriptions ( edm::ConfigurationDescriptions conf)
static

Definition at line 96 of file TGeoMgrFromDdd.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), and submitPVResolutionJobs::desc.

96  {
98  desc.addUntracked<int>("level", 10)->setComment("How deep into the geometry hierarchy should the conversion go.");
99  desc.addUntracked<bool>("verbose", false);
100  desc.addUntracked<bool>("fullName", true)->setComment("use fillname() instead of name() when generating node names");
101 
102  conf.add("TGeoMgrFromDdd", desc);
103 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const TGeoMgrFromDdd& TGeoMgrFromDdd::operator= ( const TGeoMgrFromDdd )
delete
TGeoMgrFromDdd::ReturnType TGeoMgrFromDdd::produce ( const DisplayGeomRecord iRecord)

Definition at line 126 of file TGeoMgrFromDdd.cc.

References gather_cfg::cout, dd4hep::createPlacement(), createVolume(), edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::getTransientHandle(), info(), m_fullname, m_level, m_verbose, DDSolidShapesName::name(), mergeVDriftHistosByStation::name, nameToMaterial_, nameToMedium_, nameToShape_, nameToVolume_, pileupDistInMC::num, AlCaHLTBitMon_QueryRunRegistry::string, and viewToken_.

126  {
127  using namespace edm;
128 
130 
131  if (!viewH.isValid()) {
132  return std::unique_ptr<TGeoManager>();
133  }
134 
135  TGeoManager* geo_mgr = new TGeoManager("cmsGeo", "CMS Detector");
136  // NOTE: the default constructor does not create the identity matrix
137  if (gGeoIdentity == nullptr) {
138  gGeoIdentity = new TGeoIdentity("Identity");
139  }
140 
141  std::cout << "about to initialize the DDCompactView walker"
142  << " with a root node " << viewH->root() << std::endl;
143 
144  auto walker = viewH->walker();
145  auto info = walker.current();
146 
147  // The top most item is actually the volume holding both the
148  // geometry AND the magnetic field volumes!
149  walker.firstChild();
150  if (!walker.firstChild()) {
151  return std::unique_ptr<TGeoManager>();
152  }
153 
154  TGeoVolume* top = (m_fullname ? createVolume(info.first.name().fullname(), info.first.solid(), info.first.material())
155  : createVolume(info.first.name().name(), info.first.solid(), info.first.material()));
156 
157  if (top == nullptr) {
158  return std::unique_ptr<TGeoManager>();
159  }
160 
161  geo_mgr->SetTopVolume(top);
162  // ROOT chokes unless colors are assigned
163  top->SetVisibility(kFALSE);
164  top->SetLineColor(kBlue);
165 
166  std::vector<TGeoVolume*> parentStack;
167  parentStack.push_back(top);
168 
169  do {
170  auto info = walker.current();
171 
172  if (m_verbose) {
173  std::cout << "parentStack of size " << parentStack.size() << std::endl;
174  auto num = (info.second != nullptr) ? info.second->copyno() : 0;
175  std::cout << info.first.name() << " " << num << " " << DDSolidShapesName::name(info.first.solid().shape())
176  << std::endl;
177  }
178 
179  std::string name = m_fullname ? info.first.name().fullname() : info.first.name().name();
180  bool childAlreadyExists = (nullptr != nameToVolume_[name]);
181  TGeoVolume* child = createVolume(name, info.first.solid(), info.first.material());
182  if (nullptr != child && info.second != nullptr) {
183  parentStack.back()->AddNode(
184  child, info.second->copyno(), createPlacement(info.second->rotation(), info.second->translation()));
185  child->SetLineColor(kBlue);
186  } else {
187  if (info.second == nullptr) {
188  break;
189  }
190  }
191  if (nullptr == child || childAlreadyExists || m_level == int(parentStack.size())) {
192  if (nullptr != child) {
193  child->SetLineColor(kRed);
194  }
195  //stop descending
196  if (!walker.nextSibling()) {
197  while (walker.parent()) {
198  parentStack.pop_back();
199  if (walker.nextSibling()) {
200  break;
201  }
202  }
203  }
204  } else {
205  if (walker.firstChild()) {
206  parentStack.push_back(child);
207  } else {
208  if (!walker.nextSibling()) {
209  while (walker.parent()) {
210  parentStack.pop_back();
211  if (walker.nextSibling()) {
212  break;
213  }
214  }
215  }
216  }
217  }
218  } while (!parentStack.empty());
219 
220  geo_mgr->CloseGeometry();
221 
222  geo_mgr->DefaultColors();
223 
224  nameToShape_.clear();
225  nameToVolume_.clear();
226  nameToMaterial_.clear();
227  nameToMedium_.clear();
228 
229  return std::unique_ptr<TGeoManager>(geo_mgr);
230 }
static const TGPicture * info(bool iBackgroundIsBlack)
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
TGeoCombiTrans * createPlacement(const Rotation3D &iRot, const Position &iTrans)
const bool m_fullname
const edm::ESGetToken< DDCompactView, IdealGeometryRecord > viewToken_
static const char *const name(DDSolidShape s)
Definition: DDSolidShapes.h:33
TGeoVolume * createVolume(const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
std::map< std::string, TGeoShape * > nameToShape_
std::map< std::string, TGeoMaterial * > nameToMaterial_
const bool m_verbose
std::map< std::string, TGeoVolume * > nameToVolume_
std::map< std::string, TGeoMedium * > nameToMedium_
tuple cout
Definition: gather_cfg.py:144
const int m_level

Member Data Documentation

const bool TGeoMgrFromDdd::m_fullname
private

Definition at line 78 of file TGeoMgrFromDdd.cc.

Referenced by createMaterial(), createShape(), createVolume(), and produce().

const int TGeoMgrFromDdd::m_level
private

Definition at line 76 of file TGeoMgrFromDdd.cc.

Referenced by produce().

std::string TGeoMgrFromDdd::m_TGeoName
private

Definition at line 79 of file TGeoMgrFromDdd.cc.

std::string TGeoMgrFromDdd::m_TGeoTitle
private

Definition at line 80 of file TGeoMgrFromDdd.cc.

const bool TGeoMgrFromDdd::m_verbose
private

Definition at line 77 of file TGeoMgrFromDdd.cc.

Referenced by produce().

std::map<std::string, TGeoMaterial*> TGeoMgrFromDdd::nameToMaterial_
private

Definition at line 84 of file TGeoMgrFromDdd.cc.

Referenced by createMaterial(), and produce().

std::map<std::string, TGeoMedium*> TGeoMgrFromDdd::nameToMedium_
private

Definition at line 85 of file TGeoMgrFromDdd.cc.

Referenced by createVolume(), and produce().

std::map<std::string, TGeoShape*> TGeoMgrFromDdd::nameToShape_
private

Definition at line 82 of file TGeoMgrFromDdd.cc.

Referenced by createShape(), and produce().

std::map<std::string, TGeoVolume*> TGeoMgrFromDdd::nameToVolume_
private

Definition at line 83 of file TGeoMgrFromDdd.cc.

Referenced by createVolume(), and produce().

const edm::ESGetToken<DDCompactView, IdealGeometryRecord> TGeoMgrFromDdd::viewToken_
private

Definition at line 87 of file TGeoMgrFromDdd.cc.

Referenced by produce().