ATLAS Offline Software
Loading...
Searching...
No Matches
DetectorGeometryBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Base class
7
8// Geant4 includes used in functions
9#include "G4PVPlacement.hh"
10#include "G4RotationMatrix.hh"
11#include "G4LogicalVolumeStore.hh"
12
13DetectorGeometryBase::DetectorGeometryBase(const std::string& type, const std::string& name, const IInterface* parent)
14 : base_class(type,name,parent)
15{
16}
17
18// Athena method, called at initialization time
20{
21 ATH_MSG_VERBOSE( name() << "::initialize(): starting." );
22 if(m_detectorName.empty())
23 {
24 m_detectorName = this->name();
25 // re-initialize m_detectorName in order to take the real detector name rather than the path to it
26 size_t ipos=m_detectorName.value().find_last_of('.');
27 size_t length=m_detectorName.value().size();
28 if (ipos<length)
29 {
30 ATH_MSG_VERBOSE( "m_detectorName: " << m_detectorName.value() << " needs to be reset.");
31 m_detectorName=m_detectorName.value().substr(ipos+1,length-ipos-1);
32 ATH_MSG_VERBOSE( "m_detectorName default value reset to " << m_detectorName.value());
33 }
34 }
35 ATH_MSG_DEBUG( name() << "::initialize() (Base class method): Detector name = " << m_detectorName.value() );
36 CHECK(m_notifierSvc.retrieve());
37
38 // This fires initialize() for each of those tools
39 if (m_subDetTools.size())
40 {
41 ATH_MSG_DEBUG( name() << "::initialize(): Initializing list of " << m_subDetTools.size() << " detectors." );
42 CHECK( m_subDetTools.retrieve() );
43 }
44 else
45 {
46 ATH_MSG_DEBUG( name() << "::initialize(): no sub-detectors to initialize." );
47 }
48
49 ATH_MSG_VERBOSE( name() << "::initialize(): finished." );
50 return StatusCode::SUCCESS;
51}
52
54{
55 ATH_MSG_VERBOSE( name() << "::Build() (Base class method): Starting. Number of registered volumes "<<G4LogicalVolumeStore::GetInstance()->size() );
56
58 ATH_MSG_VERBOSE( name() << "::Build() - Envelope set. Number of registered volumes "<<G4LogicalVolumeStore::GetInstance()->size() );
59
60 m_notifierSvc->SetCurrentDetectorName(m_detectorName.value());
62 ATH_MSG_VERBOSE( name() << "::Build() - Geometry built. Number of registered volumes "<<G4LogicalVolumeStore::GetInstance()->size() );
63
65 ATH_MSG_VERBOSE( name() << "::Build() - Volume moved around. Number of registered volumes "<<G4LogicalVolumeStore::GetInstance()->size() );
66
68 ATH_MSG_VERBOSE( name() << "::Build() - Connected with parent. Number of registered volumes "<<G4LogicalVolumeStore::GetInstance()->size() );
69
71 ATH_MSG_VERBOSE( name() << "::Build() (Base class method): Finished. Number of registered volumes "<<G4LogicalVolumeStore::GetInstance()->size() );
72 return;
73}
74
76{
77 ATH_MSG_VERBOSE( "DetectorGeometryBase::BuildGeometry(): Using base-class method. Anything going wrong?");
78}
79
81{
82 ATH_MSG_VERBOSE( name() << "::SetRotationAndOffset() (Base class method)");
83 // Firstly do the rotation
84 if (!m_envelope.theRotation)
85 {
86 // m_envelope.theRotation is null, so create an identity
87 // rotation first.
88 // FIXME probably a neater way to do this part.
89 m_envelope.theRotation=new G4RotationMatrix;
90 // add the extra rotations.
91 m_envelope.theRotation->rotateX(m_rotateX);
92 m_envelope.theRotation->rotateY(m_rotateY);
93 m_envelope.theRotation->rotateZ(m_rotateZ);
94 if (m_envelope.thePositionedVolume)
95 {
96 // Override the rotation for m_envelope.thePositionedVolume.
97 m_envelope.thePositionedVolume->SetRotation(m_envelope.theRotation);
98 }
99 }
100 else
101 {
102 // m_envelope.theRotation already exists, so just add the
103 // extra rotations.
104 m_envelope.theRotation->rotateX(m_rotateX);
105 m_envelope.theRotation->rotateY(m_rotateY);
106 m_envelope.theRotation->rotateZ(m_rotateZ);
107 }
108 // Secondly add the additional position offset to the existing
109 // m_envelope.thePosition vector.
110 m_envelope.thePosition+=G4ThreeVector(m_offsetX,m_offsetY,m_offsetZ);
111 if (m_envelope.thePositionedVolume)
112 {
113 // Override the translation for m_envelope.thePositionedVolume.
114 m_envelope.thePositionedVolume->SetTranslation(m_envelope.thePosition);
115 }
116
117 ATH_MSG_VERBOSE( name() << "::SetRotationAndOffset() (Base class method): Finished" );
118 return;
119}
121{
122 ATH_MSG_VERBOSE( name() << "::PositionInParent() (Base class method)");
123 if (m_isWorld)
124 {
125 // check that the detector is built
126 if (m_envelope.IsBuilt())
127 {
128 G4VPhysicalVolume* physWorld= new G4PVPlacement(0,G4ThreeVector(),
129 m_envelope.theEnvelope,m_envelope.theEnvelope->GetName(),0,false,0,false);
130 m_envelope.thePositionedVolume=physWorld;
131 }
132 }
133 else
134 {
135 // check that there is a parent
136 if (!m_theParent)
137 {
138 ATH_MSG_ERROR("Parent not set for "<<m_detectorName.value()<<"!!!!!!!!!!");
139 }
140 else
141 {
142 if (m_theParent->GetEnvelope().IsBuilt())
143 {
144 // G4VPhysicalVolume *physVol = new G4PVPlacement(0,G4ThreeVector(),
145 // m_envelope.theEnvelope,m_envelope.theEnvelope->GetName(),m_theParent->GetEnvelope().theEnvelope,false,0,false);
146 // TODO: implement a possible rotation/displacement - something like this based on the old code?
147 G4VPhysicalVolume *physVol = new G4PVPlacement(m_envelope.theRotation,m_envelope.thePosition,
148 m_envelope.theEnvelope,m_envelope.theEnvelope->GetName(),m_theParent->GetEnvelope().theEnvelope,false,0);
149 m_envelope.thePositionedVolume=physVol;
150 }
151 }
152 }
153}
154
156{
157 ATH_MSG_VERBOSE( name() << "::BuildSubDetectors() (Base class method): Starting");
158 for (auto& subDetTool: m_subDetTools)
159 {
160 ATH_MSG_VERBOSE(name() << "::BuildSubDetectors() (Base class method): Positioning "<<subDetTool->GetDetectorName()<<" within "<<m_detectorName.value());
161 subDetTool->SetParent(this);
162 subDetTool->Build();
163 }
164 ATH_MSG_VERBOSE( name() << "::BuildSubDetectors() (Base class method): Finished");
165}
166
170
174
176{
178}
179
181{
182 return m_detectorName.value();
183}
184
189
194
199
201{
202 if (m_isWorld)
203 return m_envelope.thePositionedVolume;
204 else
205 {
206 ATH_MSG_ERROR("trying to get World from a DetectorTool which World is not!");
207 return 0;
208 }
209}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
double length(const pvec &v)
G4VPhysicalVolume * GetWorldVolume() override final
virtual void BuildGeometry() override
void SetParent(IDetectorGeometryTool *) override
Gaudi::Property< double > m_rotateY
DetectorGeometryBase(const std::string &type, const std::string &name, const IInterface *parent)
virtual void SetAsWorld() override
virtual void SetEnvelope() override
virtual void SetRotationAndOffset()
IDetectorGeometryTool * m_theParent
Gaudi::Property< double > m_rotateX
StatusCode initialize() override
Athena method.
Envelope & GetEnvelope() override final
Gaudi::Property< std::string > m_detectorName
Gaudi::Property< double > m_offsetX
virtual void ResetEnvelope() override
std::string GetDetectorName() const override
ServiceHandle< IG4GeometryNotifierSvc > m_notifierSvc
virtual void PositionInParent() override
Gaudi::Property< double > m_offsetY
void SetDetectorName(const std::string &) override
virtual void Build() override
purely virtual methods being implemented here
Gaudi::Property< double > m_rotateZ
Gaudi::Property< double > m_offsetZ
virtual void BuildSubDetectors() override
ToolHandleArray< IDetectorGeometryTool > m_subDetTools
Abstract interface to service for Geant4 detector geometry classes.