ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Geo2G4Builder Class Reference

Main builder to create/position all volumes described in a GeoModel Tree. More...

#include <Geo2G4Builder.h>

Inheritance diagram for Geo2G4Builder:
Collaboration diagram for Geo2G4Builder:

Public Member Functions

 Geo2G4Builder (const std::string &detectorName)
 
 ~Geo2G4Builder ()=default
 
G4LogicalVolume * BuildTree ()
 
void BuildOpticalSurfaces (const GeoBorderSurfaceContainer *surface_container, const OpticalVolumesMap *optical_volumes)
 
VolumeBuilderGetVolumeBuilder (std::string)
 
HepGeom::Transform3D GetDetectorTransform ()
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::string m_detectorName
 
GeoTrf::Transform3D m_motherTransform
 
std::vector< PVConstLink > m_treeTops
 
VolumeBuilderm_theBuilder
 
const GeoMaterial * m_matAir {nullptr}
 
ServiceHandle< StoreGateSvcm_pDetStore {"DetectorStore", "Geo2G4Builder"}
 
ServiceHandle< IGeo2G4Svcm_g2gSvc {"Geo2G4Svc", "Geo2G4Builder"}
 
GeoModelExperimentm_theExpt {nullptr}
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Main builder to create/position all volumes described in a GeoModel Tree.

Definition at line 33 of file Geo2G4Builder.h.

Constructor & Destructor Documentation

◆ Geo2G4Builder()

Geo2G4Builder::Geo2G4Builder ( const std::string &  detectorName)

Definition at line 32 of file Geo2G4Builder.cxx.

33  : AthMessaging("Geo2G4Builder")
34  , m_detectorName(detectorName)
35  , m_motherTransform(GeoTrf::Transform3D::Identity())
36 {
37  if (m_pDetStore.retrieve().isFailure()) {
38  THROW_EXCEPTION("ERROR: Geo2G4Builder for detector "<< detectorName << " could not access the detector store.");
39  }
40 
41  StatusCode sc = m_pDetStore->retrieve( m_theExpt, "ATLAS" );
42  if(sc.isFailure()){
43  THROW_EXCEPTION(detectorName<<" could not get GeoModelExperiment");
44  }
45  else {
46  const GeoVDetectorManager *theManager = m_theExpt->getManager(detectorName);
47  if (!theManager) {
48  THROW_EXCEPTION("Failed to retrieve manager "<<detectorName);
49  }
50  for(unsigned int i=0; i<theManager->getNumTreeTops(); ++i) {
51  m_treeTops.push_back(theManager->getTreeTop(i));
52  }
53 
54  ATH_MSG_INFO("Found detector: top volume(s)");
55  for(unsigned int i=0; i<m_treeTops.size();++i) {
56  ATH_MSG_INFO( " Tree Top " << i << " " << m_treeTops[i]->getLogVol()->getName() );
57  }
58 
59  if(m_treeTops.size()>1) {
60  // -------- -------- MATERIAL MANAGER -------- ----------
61  StoredMaterialManager* theMaterialManager = m_pDetStore->tryRetrieve<StoredMaterialManager>("MATERIALS");
62  if(theMaterialManager) {
63  m_matAir = theMaterialManager->getMaterial("std::Air");
64  }
65  else {
66  m_matAir = m_treeTops[0]->getLogVol()->getMaterial();
67  }
68  }
69 
70  if (m_g2gSvc.retrieve().isFailure()) {
71  THROW_EXCEPTION("Failed to retrieve manager Geo2G4Svc");
72  }
73 
74  m_theBuilder = m_g2gSvc->GetDefaultBuilder();
75  if(m_theBuilder)
76  ATH_MSG_INFO("Set volume builder ---> "<< m_theBuilder->GetKey());
77  else
78  ATH_MSG_WARNING("0 pointer to volume builder."
79  <<"\n Use 'DefaultBuilder' property of Geo2G4Svc or"
80  <<"\n 'GetVolumeBuilder' method of Geo2G4Builder");
81  }
82 }

◆ ~Geo2G4Builder()

Geo2G4Builder::~Geo2G4Builder ( )
default

Member Function Documentation

◆ BuildOpticalSurfaces()

void Geo2G4Builder::BuildOpticalSurfaces ( const GeoBorderSurfaceContainer surface_container,
const OpticalVolumesMap optical_volumes 
)

Definition at line 173 of file Geo2G4Builder.cxx.

175 {
176  Geo2G4OpticalSurfaceFactory surfaceFactory;
177 
178  for (const GeoBorderSurface& border_surface : *surface_container)
179  {
180  // Build Optical Surface
181  G4OpticalSurface* g4OptSurface = surfaceFactory.Build(border_surface.getOptSurface());
182 
183  G4VPhysicalVolume* g4PV1 = 0;
184  G4VPhysicalVolume* g4PV2 = 0;
185  OpticalVolumesMap::const_iterator volIt;
186 
187  // First physical volume
188  volIt = optical_volumes->find(border_surface.getPV1());
189  if(volIt == optical_volumes->end())
190  {
191  ATH_MSG_WARNING("Unable to find " << border_surface.getPV1()->getLogVol()->getName() << " in Optical Volumes map");
192  continue;
193  }
194  g4PV1 = volIt.operator->()->second;
195 
196  // Second physical volume
197  volIt = optical_volumes->find(border_surface.getPV2());
198  if(volIt == optical_volumes->end())
199  {
200  ATH_MSG_WARNING("Unable to find " << border_surface.getPV2()->getLogVol()->getName() << " in Optical Volumes map");
201  continue;
202  }
203  g4PV2 = volIt.operator->()->second;
204 
205  // G4LogicalBorderSurface
206  G4LogicalBorderSurface* g4BorderSurface __attribute__((unused)) = new G4LogicalBorderSurface(border_surface.getName(),g4PV1,g4PV2,g4OptSurface);
207  }
208 }

◆ BuildTree()

G4LogicalVolume * Geo2G4Builder::BuildTree ( )

Definition at line 84 of file Geo2G4Builder.cxx.

85 {
86  ATH_MSG_DEBUG("Entering Geo2G4Builder::BuildTree()...");
87  G4LogicalVolume* result = nullptr;
88  OpticalVolumesMap* optical_volumes = nullptr;
89  const GeoBorderSurfaceContainer* surface_container = nullptr;
90 
91  // Check whether we have to deal with optical surfaces
93  StatusCode sc = m_pDetStore->retrieve(surface_container,m_detectorName);
94  if(sc.isSuccess() && surface_container->size()>0) {
95  optical_volumes = new OpticalVolumesMap();
96  }
97  }
98 
99  if(m_theBuilder) {
100  if(m_treeTops.size()==1) {
101  m_motherTransform = m_treeTops[0]->getX();
102  result = m_theBuilder->Build(m_treeTops[0],optical_volumes);
103  }
104  else {
105  // Create temporary GeoModel physical volume
106  // The shape is composed by TreeTop shapes + their transforms
107  const GeoShape& shFirst = (*(m_treeTops[0]->getLogVol()->getShape()))<<(m_treeTops[0]->getX());
108  const GeoShape* shResult = &shFirst;
109 
110  for(unsigned int i=1; i<m_treeTops.size(); i++) {
111  shResult = & shResult->add((*(m_treeTops[i]->getLogVol()->getShape()))<<(m_treeTops[i]->getX()));
112  }
113 
114  GeoLogVol* lvEnvelope = new GeoLogVol(m_detectorName,shResult,m_matAir);
115  GeoPhysVol* pvEnvelope = new GeoPhysVol(lvEnvelope);
116  m_theExpt->addTmpVolume(pvEnvelope);
117  result = m_theBuilder->Build(pvEnvelope);
118 
119  // Get pointer to the World
120  PVConstLink world = m_treeTops[0]->getParent();
121 
122  // Add all tree tops to the result
123  for(unsigned int i=0; i<m_treeTops.size(); i++) {
124  // Current Tree Top and its index
125  PVConstLink pv = m_treeTops[i];
126  Query<unsigned int> childIndx = world->indexOf(pv);
127 
128  // Tree Top transformation
129  G4Transform3D theG4Position(Amg::EigenTransformToCLHEP(world->getXToChildVol(childIndx)));
130 
131  // Copy number
132  int id = 16969;
133  Query<int> Qint = world->getIdOfChildVol(childIndx);
134  if(Qint.isValid()) id = Qint;
135 
136  // PV Tree Top name
137  std::string nameTT = world->getNameOfChildVol(childIndx);
138  if (nameTT == "ANON") nameTT = pv->getLogVol()->getName();
139 
140 
141  G4LogicalVolume* g4LV = m_theBuilder->Build(pv,optical_volumes);
142  G4ReflectionFactory::Instance()->Place(theG4Position,
143  nameTT,
144  g4LV,
145  result,
146  false,
147  id);
148  }
149  }
150  }
151 
152  // build optical surfaces if necessary
153  if(optical_volumes) {
154  if(optical_volumes->size()>0) {
155  BuildOpticalSurfaces(surface_container,optical_volumes);
156  }
157  else {
158  ATH_MSG_WARNING("Optical volumes apparently requested, but none found! Deleting temps");
159  }
160  delete optical_volumes;
161  }
162 
163  return result;
164 }

◆ GetDetectorTransform()

HepGeom::Transform3D Geo2G4Builder::GetDetectorTransform ( )
inline

Definition at line 51 of file Geo2G4Builder.h.

◆ GetVolumeBuilder()

VolumeBuilder * Geo2G4Builder::GetVolumeBuilder ( std::string  bname)

Definition at line 167 of file Geo2G4Builder.cxx.

168 {
169  m_theBuilder = m_g2gSvc->GetVolumeBuilder(std::move(bname));
170  return m_theBuilder;
171 }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_detectorName

std::string Geo2G4Builder::m_detectorName
private

Definition at line 56 of file Geo2G4Builder.h.

◆ m_g2gSvc

ServiceHandle<IGeo2G4Svc> Geo2G4Builder::m_g2gSvc {"Geo2G4Svc", "Geo2G4Builder"}
private

Definition at line 64 of file Geo2G4Builder.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_matAir

const GeoMaterial* Geo2G4Builder::m_matAir {nullptr}
private

Definition at line 62 of file Geo2G4Builder.h.

◆ m_motherTransform

GeoTrf::Transform3D Geo2G4Builder::m_motherTransform
private

Definition at line 57 of file Geo2G4Builder.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_pDetStore

ServiceHandle<StoreGateSvc> Geo2G4Builder::m_pDetStore {"DetectorStore", "Geo2G4Builder"}
private

Definition at line 63 of file Geo2G4Builder.h.

◆ m_theBuilder

VolumeBuilder* Geo2G4Builder::m_theBuilder
private

Definition at line 59 of file Geo2G4Builder.h.

◆ m_theExpt

GeoModelExperiment* Geo2G4Builder::m_theExpt {nullptr}
private

Definition at line 65 of file Geo2G4Builder.h.

◆ m_treeTops

std::vector<PVConstLink> Geo2G4Builder::m_treeTops
private

Definition at line 58 of file Geo2G4Builder.h.


The documentation for this class was generated from the following files:
Geo2G4Builder::m_treeTops
std::vector< PVConstLink > m_treeTops
Definition: Geo2G4Builder.h:58
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
Geo2G4Builder::m_matAir
const GeoMaterial * m_matAir
Definition: Geo2G4Builder.h:62
get_generator_info.result
result
Definition: get_generator_info.py:21
VolumeBuilder::GetKey
const std::string & GetKey() const
Definition: Simulation/G4Utilities/Geo2G4/src/VolumeBuilder.h:28
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
VolumeBuilder::Build
virtual G4LogicalVolume * Build(PVConstLink pv, OpticalVolumesMap *optical_volumes=0)=0
Geo2G4Builder::m_g2gSvc
ServiceHandle< IGeo2G4Svc > m_g2gSvc
Definition: Geo2G4Builder.h:64
OpticalVolumesMap
std::map< const GeoOpticalPhysVol *, G4VPhysicalVolume *, std::less< const GeoOpticalPhysVol * > > OpticalVolumesMap
Definition: Simulation/G4Utilities/Geo2G4/src/VolumeBuilder.h:17
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
Geo2G4Builder::BuildOpticalSurfaces
void BuildOpticalSurfaces(const GeoBorderSurfaceContainer *surface_container, const OpticalVolumesMap *optical_volumes)
Definition: Geo2G4Builder.cxx:173
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
Geo2G4Builder::m_motherTransform
GeoTrf::Transform3D m_motherTransform
Definition: Geo2G4Builder.h:57
GeoModelExperiment::addTmpVolume
void addTmpVolume(PVConstLink volume)
Definition: GeoModelExperiment.cxx:84
dumpTruth.getName
getName
Definition: dumpTruth.py:34
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
lumiFormat.i
int i
Definition: lumiFormat.py:85
GeoBorderSurface
Definition: GeoBorderSurface.h:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
GeoModelExperiment::getManager
const GeoVDetectorManager * getManager(const std::string &name) const
Definition: GeoModelExperiment.cxx:52
Geo2G4OpticalSurfaceFactory
Definition: Geo2G4OpticalSurfaceFactory.h:16
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
Geo2G4Builder::m_pDetStore
ServiceHandle< StoreGateSvc > m_pDetStore
Definition: Geo2G4Builder.h:63
unused
void unused(Args &&...)
Definition: VP1ExpertSettings.cxx:39
__attribute__
__attribute__((always_inline)) inline uint16_t TileCalibDrawerBase
Definition: TileCalibDrawerBase.h:190
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
GeoBorderSurfaceContainer
std::vector< GeoBorderSurface > GeoBorderSurfaceContainer
Definition: GeoBorderSurfaceContainer.h:12
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
Amg::EigenTransformToCLHEP
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
Definition: CLHEPtoEigenConverter.h:120
python.changerun.pv
pv
Definition: changerun.py:81
StoredMaterialManager::getMaterial
virtual const GeoMaterial * getMaterial(const std::string &name)=0
StoredMaterialManager
This class holds one or more material managers and makes them storeable, under StoreGate.
Definition: StoredMaterialManager.h:28
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
Geo2G4Builder::m_theExpt
GeoModelExperiment * m_theExpt
Definition: Geo2G4Builder.h:65
Geo2G4Builder::m_theBuilder
VolumeBuilder * m_theBuilder
Definition: Geo2G4Builder.h:59
Geo2G4OpticalSurfaceFactory::Build
G4OpticalSurface * Build(const GeoOpticalSurface *)
Definition: Geo2G4OpticalSurfaceFactory.cxx:16
Geo2G4Builder::m_detectorName
std::string m_detectorName
Definition: Geo2G4Builder.h:56