ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_Geant4
ISF_Geant4CommonServices
src
G4PolyconeGeoIDSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// class header include
6
#include "
G4PolyconeGeoIDSvc.h
"
7
8
// C includes
9
#include <math.h>
10
11
// framework includes
12
#include "GaudiKernel/Bootstrap.h"
13
#include "GaudiKernel/ISvcLocator.h"
14
15
// STL includes
16
#include <limits>
17
#include <iostream>
18
19
// ISF includes
20
#include "
ISF_Event/ISFParticle.h
"
21
22
// Geant4 includes
23
#include "geomdefs.hh"
24
#include "G4Polycone.hh"
25
#include "G4UnionSolid.hh"
26
27
28
// DetectorDescription
29
#include "
AtlasDetDescr/AtlasRegion.h
"
30
#include "
AtlasDetDescr/AtlasRegionHelper.h
"
31
33
ISF::G4PolyconeGeoIDSvc::G4PolyconeGeoIDSvc
(
const
std::string& name,ISvcLocator* svc) :
34
base_class(name,svc),
35
m_volume
(),
36
m_typeConverter
()
37
{
38
}
39
40
42
ISF::G4PolyconeGeoIDSvc::~G4PolyconeGeoIDSvc
()
43
{
44
}
45
46
47
// Athena algtool's Hooks
48
StatusCode
ISF::G4PolyconeGeoIDSvc::initialize
()
49
{
50
ATH_MSG_VERBOSE
(
"initialize()"
);
51
52
// retrieve envelope definition service
53
ATH_CHECK
(
m_envDefSvc
.retrieve() );
54
55
// create internal volume representations for the given dimensions
56
for
(
int
geoID=
AtlasDetDescr::fFirstAtlasRegion
; geoID<
AtlasDetDescr::fNumAtlasRegions
; ++geoID)
57
{
58
if
(
createVolume
(
AtlasDetDescr::AtlasRegion
(geoID)).isFailure())
59
{
60
ATH_MSG_ERROR
(
"Unable to create volume representation for geoID="
<<geoID);
61
}
62
}
63
64
// setup the converter for: G4 enum to ISF::InsideType
65
m_typeConverter
[kOutside] =
ISF::fOutside
;
66
m_typeConverter
[kSurface] =
ISF::fSurface
;
67
m_typeConverter
[kInside] =
ISF::fInside
;
68
69
return
StatusCode::SUCCESS;
70
}
71
72
73
ISF::InsideType
ISF::G4PolyconeGeoIDSvc::inside
(
const
Amg::Vector3D
&pos,
AtlasDetDescr::AtlasRegion
geoID)
const
74
{
75
// initialized with default return value
76
InsideType
where =
ISF::fOutside
;
77
78
// check for volume to be present
79
G4VSolid *curVol =
m_volume
[geoID];
80
if
(curVol)
81
{
82
G4ThreeVector posG4( pos.x(), pos.y(), pos.z() );
83
EInside g4Where = curVol->Inside( posG4 );
84
85
// use this trick to quickly convert G4 type to ISF::InsideType
86
where =
m_typeConverter
[g4Where];
87
}
88
89
// hand back the position information
90
return
where;
91
}
92
93
94
AtlasDetDescr::AtlasRegion
ISF::G4PolyconeGeoIDSvc::identifyGeoID
(
const
Amg::Vector3D
&pos)
const
95
{
96
// loop over geoIDs
97
for
(
unsigned
short
geoID=
AtlasDetDescr::fFirstAtlasRegion
; geoID<
AtlasDetDescr::fNumAtlasRegions
; ++geoID)
98
{
99
// point inside given geoID -> return geoID
100
if
(
inside
(pos,
AtlasDetDescr::AtlasRegion
(geoID))==
ISF::fInside
)
101
{
102
return
AtlasDetDescr::AtlasRegion
(geoID);
103
}
104
}
105
// point is not inside any of the registered geoIDs
106
return
AtlasDetDescr::fUndefinedAtlasRegion
;
107
}
108
109
110
AtlasDetDescr::AtlasRegion
ISF::G4PolyconeGeoIDSvc::identifyNextGeoID
(
const
Amg::Vector3D
&pos,
111
const
Amg::Vector3D
&dir)
const
112
{
113
114
// if position inside a volume -> return that volume as the next geoID
115
AtlasDetDescr::AtlasRegion
geoID =
identifyGeoID
(pos);
116
if
(
validAtlasRegion
(geoID))
117
{
118
return
geoID;
119
}
120
//not inside - make a step towards the p direction and check if inside again
121
const
Amg::Vector3D
&dirUnit = dir.unit();
122
const
Amg::Vector3D
&posStep = pos+dirUnit;
123
AtlasDetDescr::AtlasRegion
closestGeoID =
identifyGeoID
(posStep);
124
if
(
validAtlasRegion
(closestGeoID))
125
{
126
return
closestGeoID;
127
}
128
return
AtlasDetDescr::fUndefinedAtlasRegion
;
129
}
130
131
132
StatusCode
ISF::G4PolyconeGeoIDSvc::createVolume
(
AtlasDetDescr::AtlasRegion
geoID)
133
{
134
135
// ensure a proper numeric value for geoID
136
assert(
validAtlasRegion
(geoID));
137
138
ATH_MSG_INFO
(
"Building envelope volume for '"
<<
AtlasDetDescr::AtlasRegionHelper::getName
(geoID)
139
<<
"' (GeoID="
<< geoID <<
")."
);
140
141
// resetting volume for current geoID
142
m_volume
[geoID] = 0;
143
144
// volume definitions
145
const
double
phimin = 0.;
146
const
double
deltaphi = 360.*CLHEP::deg;
147
const
std::string volumeName(
AtlasDetDescr::AtlasRegionHelper::getName
(geoID));
148
149
{
150
// retrieve the vector of (r,z) values from the EnvelopeDefSvc
151
const
RZPairVector
&
rz
=
m_envDefSvc
->getRZBoundary( geoID );
152
153
// entries in the database table
154
size_t
curVolNumPoints =
rz
.size();
155
if
( !curVolNumPoints)
156
{
157
ATH_MSG_ERROR
(
"No entries for "
<<
AtlasDetDescr::AtlasRegionHelper::getName
(geoID) <<
" envelope in envelope definition service. Unable to build envelope."
);
158
// resources cleanup
159
return
StatusCode::FAILURE;
160
}
161
162
// arrays of (r,z) coordinates of the current envelope volume
163
double
*
z
=
new
double
[curVolNumPoints];
164
double
*
r
=
new
double
[curVolNumPoints];
165
166
// convert vector of pairs into two arrays
167
RZPairVector::const_iterator rzIt =
rz
.begin();
168
for
(
size_t
i=0; i<curVolNumPoints; ++i)
169
{
170
r
[i] = rzIt->first;
171
z
[i] = rzIt->second;
172
173
++rzIt;
174
}
175
176
// create a G4Polycone volume with the given dimensions
177
std::stringstream curName;
178
curName << volumeName;
179
// store it in the m_volume array
180
m_volume
[geoID] =
new
G4Polycone( curName.str(), phimin, deltaphi, curVolNumPoints,
r
,
z
);
181
// set the volume name
182
m_volume
[geoID]->SetName( volumeName);
183
184
// cleanup
185
delete
[]
r
;
186
delete
[]
z
;
187
}
188
189
return
StatusCode::SUCCESS;
190
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
AtlasRegionHelper.h
AtlasRegion.h
validAtlasRegion
bool validAtlasRegion(AtlasDetDescr::AtlasRegion region)
Check a given AtlasRegion for its validity.
Definition
AtlasRegion.h:40
G4PolyconeGeoIDSvc.h
ISFParticle.h
rz
static Double_t rz
Definition
LArPhysWaveHECTool.cxx:37
RZPairVector
std::vector< RZPair > RZPairVector
Definition
RZPair.h:18
z
#define z
AtlasDetDescr::AtlasRegionHelper::getName
static const char * getName(int region)
Definition
AtlasRegionHelper.cxx:13
ISF::G4PolyconeGeoIDSvc::m_typeConverter
ISF::InsideType m_typeConverter[ISF::fNumInsideTypes]
a quick way to convert G4 enum EInside to ISF::InsideType
Definition
G4PolyconeGeoIDSvc.h:80
ISF::G4PolyconeGeoIDSvc::identifyGeoID
AtlasDetDescr::AtlasRegion identifyGeoID(const Amg::Vector3D &pos) const
A static filter that returns the AtlasRegion of the given position.
Definition
G4PolyconeGeoIDSvc.cxx:94
ISF::G4PolyconeGeoIDSvc::inside
ISF::InsideType inside(const Amg::Vector3D &pos, AtlasDetDescr::AtlasRegion geoID) const
Checks if the given position (ISFParticle) is inside a given AtlasRegion.
Definition
G4PolyconeGeoIDSvc.cxx:73
ISF::G4PolyconeGeoIDSvc::m_envDefSvc
ServiceHandle< IEnvelopeDefSvc > m_envDefSvc
service providing the envelope dimensions for the different sub-detectors
Definition
G4PolyconeGeoIDSvc.h:74
ISF::G4PolyconeGeoIDSvc::m_volume
G4VSolid * m_volume[AtlasDetDescr::fNumAtlasRegions]
Definition
G4PolyconeGeoIDSvc.h:77
ISF::G4PolyconeGeoIDSvc::G4PolyconeGeoIDSvc
G4PolyconeGeoIDSvc(const std::string &name, ISvcLocator *svc)
Constructor with parameters.
Definition
G4PolyconeGeoIDSvc.cxx:33
ISF::G4PolyconeGeoIDSvc::initialize
StatusCode initialize()
Definition
G4PolyconeGeoIDSvc.cxx:48
ISF::G4PolyconeGeoIDSvc::~G4PolyconeGeoIDSvc
~G4PolyconeGeoIDSvc()
Destructor.
Definition
G4PolyconeGeoIDSvc.cxx:42
ISF::G4PolyconeGeoIDSvc::identifyNextGeoID
AtlasDetDescr::AtlasRegion identifyNextGeoID(const Amg::Vector3D &pos, const Amg::Vector3D &dir) const
Find the AtlasRegion that the particle will enter with its next infinitesimal step along the given di...
Definition
G4PolyconeGeoIDSvc.cxx:110
ISF::G4PolyconeGeoIDSvc::createVolume
StatusCode createVolume(AtlasDetDescr::AtlasRegion geoID)
Retrieve and fill in the dimensions for the different AtlasRegion.
Definition
G4PolyconeGeoIDSvc.cxx:132
r
int r
Definition
globals.cxx:22
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:47
AtlasDetDescr::AtlasRegion
AtlasRegion
A simple enum of ATLAS regions and sub-detectors.
Definition
AtlasRegion.h:21
AtlasDetDescr::fUndefinedAtlasRegion
@ fUndefinedAtlasRegion
Definition
AtlasRegion.h:23
AtlasDetDescr::fNumAtlasRegions
@ fNumAtlasRegions
Definition
AtlasRegion.h:33
AtlasDetDescr::fFirstAtlasRegion
@ fFirstAtlasRegion
Definition
AtlasRegion.h:25
ISF::InsideType
InsideType
Definition
IGeoIDSvc.h:22
ISF::fInside
@ fInside
Definition
IGeoIDSvc.h:25
ISF::fOutside
@ fOutside
Definition
IGeoIDSvc.h:23
ISF::fSurface
@ fSurface
Definition
IGeoIDSvc.h:24
Generated on
for ATLAS Offline Software by
1.17.0