CMS 3D CMS Logo

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::ESProductResolverFactoryProducer edm::eventsetup::ESProductResolverProvider

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
 
 ESProducer (ESProducer &&)=delete
 
ESResolverIndex const * getTokenIndices (unsigned int iIndex) const
 
ESRecordIndex const * getTokenRecordIndices (unsigned int iIndex) const
 
bool hasMayConsumes () const noexcept
 
size_t numberOfTokenIndices (unsigned int iIndex) const
 
ESProduceroperator= (const ESProducer &)=delete
 
ESProduceroperator= (ESProducer &&)=delete
 
SerialTaskQueueChainqueue ()
 
template<typename Record >
std::optional< std::vector< ESResolverIndex > > updateFromMayConsumes (unsigned int iIndex, const Record &iRecord) const
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &) final
 
 ~ESProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::ESProductResolverFactoryProducer
 ESProductResolverFactoryProducer ()
 
 ESProductResolverFactoryProducer (const ESProductResolverFactoryProducer &)=delete
 
const ESProductResolverFactoryProduceroperator= (const ESProductResolverFactoryProducer &)=delete
 
 ~ESProductResolverFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::ESProductResolverProvider
void createKeyedResolvers (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
const ComponentDescriptiondescription () const
 
 ESProductResolverProvider ()
 
 ESProductResolverProvider (const ESProductResolverProvider &)=delete
 
void fillRecordsNotAllowingConcurrentIOVs (std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
 
virtual void initConcurrentIOVs (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
bool isUsingRecord (const EventSetupRecordKey &key) const
 
KeyedResolverskeyedResolvers (const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
 
const ESProductResolverProvideroperator= (const ESProductResolverProvider &)=delete
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~ESProductResolverProvider () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
- Static Public Member Functions inherited from edm::eventsetup::ESProductResolverProvider
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, IdealGeometryRecordviewToken_
 

Additional Inherited Members

- Protected Types inherited from edm::ESProductResolverFactoryProducer
using EventSetupRecordKey = eventsetup::EventSetupRecordKey
 
- Protected Types inherited from edm::eventsetup::ESProductResolverProvider
using KeyedResolversVector = std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >>
 
- Protected Member Functions inherited from edm::ESProducer
ESConsumesInfoconsumesInfoPushBackNew ()
 
unsigned int consumesInfoSize () const
 
template<typename CallbackT , typename TList , typename TRecord >
void registerProducts (std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
 
template<typename CallbackT , typename TRecord >
void registerProducts (std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>>, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
 
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 TDecorator >
auto setWhatProduced (T *iThis, TReturn(T ::*iMethod)(const TRecord &), const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename TFunc >
auto setWhatProduced (TFunc &&func, const es::Label &iLabel={})
 
template<typename TReturn , typename TRecord , typename TFunc , typename TDecorator >
ESConsumesCollectorT< TRecord > setWhatProduced (TFunc &&func, TDecorator &&iDec, const es::Label &iLabel={})
 
void usesResources (std::vector< std::string > const &)
 
- Protected Member Functions inherited from edm::ESProductResolverFactoryProducer
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::ESProductResolverFactoryBase > iFactory, const std::string &iLabel=std::string())
 
KeyedResolversVector registerResolvers (const EventSetupRecordKey &, unsigned int iovIndex) override
 
- Protected Member Functions inherited from edm::eventsetup::ESProductResolverProvider
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &key)
 

Detailed Description

Definition at line 52 of file TGeoMgrFromDdd.cc.

Member Typedef Documentation

◆ ReturnType

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

Definition at line 58 of file TGeoMgrFromDdd.cc.

Constructor & Destructor Documentation

◆ TGeoMgrFromDdd() [1/2]

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

Definition at line 93 of file TGeoMgrFromDdd.cc.

94  : m_level(pset.getUntrackedParameter<int>("level")),
95  m_verbose(pset.getUntrackedParameter<bool>("verbose")),
96  m_fullname(pset.getUntrackedParameter<bool>("fullName")),
97  viewToken_(setWhatProduced(this).consumes()) {}
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
const bool m_fullname
const edm::ESGetToken< DDCompactView, IdealGeometryRecord > viewToken_
const bool m_verbose
const int m_level

◆ TGeoMgrFromDdd() [2/2]

TGeoMgrFromDdd::TGeoMgrFromDdd ( const TGeoMgrFromDdd )
delete

Member Function Documentation

◆ createManager()

TGeoManager* TGeoMgrFromDdd::createManager ( int  level)
private

◆ createMaterial()

TGeoMaterial * TGeoMgrFromDdd::createMaterial ( const DDMaterial iMaterial)
private

Definition at line 618 of file TGeoMgrFromDdd.cc.

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

Referenced by createVolume().

618  {
619  std::string mat_name = m_fullname ? iMaterial.name().fullname() : iMaterial.name().name();
620  edm::LogVerbatim("TGeoMgrFromDdd") << "createMaterial with name: " << mat_name;
621  TGeoMaterial* mat = nameToMaterial_[mat_name];
622 
623  if (mat == nullptr) {
624  if (iMaterial.noOfConstituents() > 0) {
625  TGeoMixture* mix =
626  new TGeoMixture(mat_name.c_str(), iMaterial.noOfConstituents(), iMaterial.density() * CLHEP::cm3 / CLHEP::g);
627  for (int i = 0; i < iMaterial.noOfConstituents(); ++i) {
628  mix->AddElement(createMaterial(iMaterial.constituent(i).first), iMaterial.constituent(i).second);
629  }
630  mat = mix;
631  } else {
632  mat = new TGeoMaterial(mat_name.c_str(),
633  iMaterial.a() * CLHEP::mole / CLHEP::g,
634  iMaterial.z(),
635  iMaterial.density() * CLHEP::cm3 / CLHEP::g);
636  }
637  nameToMaterial_[mat_name] = mat;
638  }
639 
640  return mat;
641 }
Log< level::Info, true > LogVerbatim
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
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
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
double density() const
returns the density
Definition: DDMaterial.cc:80
double z() const
retruns the atomic number
Definition: DDMaterial.cc:78
const N & name() const
Definition: DDBase.h:59
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_
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:72
const std::string fullname() const
Definition: DDName.h:43
double a() const
returns the atomic mass
Definition: DDMaterial.cc:76

◆ createShape()

TGeoShape * TGeoMgrFromDdd::createShape ( const std::string &  iName,
const DDSolid iSolid 
)
private

Definition at line 239 of file TGeoMgrFromDdd.cc.

References funct::abs(), simBeamSpotPI::alpha, filterCSVwithJSON::copy, funct::cos(), dd4hep::createPlacement(), ztail::d, ddbox, ddcons, ddcuttubs, ddellipticaltube, ddextrudedpolygon, ddintersection, ddpolycone_rrz, ddpolyhedra_rrz, ddpseudotrap, ddsubtraction, ddtorus, ddtrap, ddtrunctubs, ddtubs, ddunion, dumpMFGeometry_cfg::delta, SiPixelRawToDigiRegional_cfi::deltaPhi, DDTorus::deltaPhi(), Exception, DDName::fullname(), h, mps_fire::i, DDBase< N, C >::isDefined(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, m_fullname, DDRotation::matrix(), Skims_PA_cff::name, DDName::name(), DDBase< N, C >::name(), nameToShape_, DDSolid::parameters(), submitPVValidationJobs::params, DiDispStaMuonMonitor_cfi::pt, dttmaxenums::R, alignCSCRings::r, DDTorus::rMax(), DDTorus::rMin(), makeMuonMisalignmentScenario::rot, DDBooleanSolid::rotation(), DDTorus::rTorus(), alignCSCRings::s, DDSolid::shape(), funct::sin(), DDBooleanSolid::solidA(), DDBooleanSolid::solidB(), mathSSE::sqrt(), DDTorus::startPhi(), AlCaHLTBitMon_QueryRunRegistry::string, groupFilesInBlocks::temp, HcalDetIdTransform::transform(), DDBooleanSolid::translation(), groupFilesInBlocks::tt, x, DDExtrudedPolygon::xVec(), y, DDExtrudedPolygon::yVec(), z, DDExtrudedPolygon::zscaleVec(), DDExtrudedPolygon::zVec(), DDExtrudedPolygon::zxVec(), and DDExtrudedPolygon::zyVec().

Referenced by createVolume().

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

◆ createVolume()

TGeoVolume * TGeoMgrFromDdd::createVolume ( const std::string &  iName,
const DDSolid iSolid,
const DDMaterial iMaterial 
)
private

Definition at line 595 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().

595  {
596  edm::LogVerbatim("TGeoMgrFromDdd") << "createVolume with name: " << iName
597  << " and solid: " << iSolid.name().fullname() << " and material "
598  << iMaterial.name().fullname();
599  TGeoVolume* v = nameToVolume_[iName];
600  if (v == nullptr) {
601  TGeoShape* solid =
602  m_fullname ? createShape(iSolid.name().fullname(), iSolid) : createShape(iSolid.name().name(), iSolid);
603  std::string mat_name = m_fullname ? iMaterial.name().fullname() : iMaterial.name().name();
604  TGeoMedium* geo_med = nameToMedium_[mat_name];
605  if (geo_med == nullptr) {
606  TGeoMaterial* geo_mat = createMaterial(iMaterial);
607  geo_med = new TGeoMedium(mat_name.c_str(), 0, geo_mat);
608  nameToMedium_[mat_name] = geo_med;
609  }
610  if (solid) {
611  v = new TGeoVolume(iName.c_str(), solid, geo_med);
612  }
613  nameToVolume_[iName] = v;
614  }
615  return v;
616 }
Log< level::Info, true > LogVerbatim
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
const bool m_fullname
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
const N & name() const
Definition: DDBase.h:59
std::map< std::string, TGeoVolume * > nameToVolume_
const std::string fullname() const
Definition: DDName.h:43
std::map< std::string, TGeoMedium * > nameToMedium_

◆ fillDescriptions()

void TGeoMgrFromDdd::fillDescriptions ( edm::ConfigurationDescriptions conf)
static

Definition at line 99 of file TGeoMgrFromDdd.cc.

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

99  {
101  desc.addUntracked<int>("level", 10)->setComment("How deep into the geometry hierarchy should the conversion go.");
102  desc.addUntracked<bool>("verbose", false);
103  desc.addUntracked<bool>("fullName", true)->setComment("use fillname() instead of name() when generating node names");
104 
105  conf.add("TGeoMgrFromDdd", desc);
106 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ operator=()

const TGeoMgrFromDdd& TGeoMgrFromDdd::operator= ( const TGeoMgrFromDdd )
delete

◆ produce()

TGeoMgrFromDdd::ReturnType TGeoMgrFromDdd::produce ( const DisplayGeomRecord iRecord)

Definition at line 129 of file TGeoMgrFromDdd.cc.

References dd4hep::createPlacement(), createVolume(), edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::getTransientHandle(), info(), edm::ESHandleBase::isValid(), m_fullname, m_level, m_verbose, Skims_PA_cff::name, DDSolidShapesName::name(), nameToMaterial_, nameToMedium_, nameToShape_, nameToVolume_, EgammaValidation_cff::num, DDCompactView::root(), AlCaHLTBitMon_QueryRunRegistry::string, viewToken_, and DDCompactView::walker().

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

Member Data Documentation

◆ m_fullname

const bool TGeoMgrFromDdd::m_fullname
private

Definition at line 81 of file TGeoMgrFromDdd.cc.

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

◆ m_level

const int TGeoMgrFromDdd::m_level
private

Definition at line 79 of file TGeoMgrFromDdd.cc.

Referenced by produce().

◆ m_TGeoName

std::string TGeoMgrFromDdd::m_TGeoName
private

Definition at line 82 of file TGeoMgrFromDdd.cc.

◆ m_TGeoTitle

std::string TGeoMgrFromDdd::m_TGeoTitle
private

Definition at line 83 of file TGeoMgrFromDdd.cc.

◆ m_verbose

const bool TGeoMgrFromDdd::m_verbose
private

Definition at line 80 of file TGeoMgrFromDdd.cc.

Referenced by produce().

◆ nameToMaterial_

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

Definition at line 87 of file TGeoMgrFromDdd.cc.

Referenced by createMaterial(), and produce().

◆ nameToMedium_

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

Definition at line 88 of file TGeoMgrFromDdd.cc.

Referenced by createVolume(), and produce().

◆ nameToShape_

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

Definition at line 85 of file TGeoMgrFromDdd.cc.

Referenced by createShape(), and produce().

◆ nameToVolume_

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

Definition at line 86 of file TGeoMgrFromDdd.cc.

Referenced by createVolume(), and produce().

◆ viewToken_

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

Definition at line 90 of file TGeoMgrFromDdd.cc.

Referenced by produce().