ATLAS Offline Software
G4PolyconeGeoIDSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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
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 
43 {
44 }
45 
46 
47 // Athena algtool's Hooks
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
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 
74 {
75  // initialized with default return value
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 
95 {
96  // loop over geoIDs
97  for (unsigned short geoID=AtlasDetDescr::fFirstAtlasRegion; geoID<AtlasDetDescr::fNumAtlasRegions; ++geoID)
98  {
99  // point inside given geoID -> return geoID
101  {
102  return AtlasDetDescr::AtlasRegion(geoID);
103  }
104  }
105  // point is not inside any of the registered geoIDs
107 }
108 
109 
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  }
129 }
130 
131 
133 {
134 
135  // ensure a proper numeric value for geoID
136  assertAtlasRegion( 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 }
AtlasDetDescr::fNumAtlasRegions
@ fNumAtlasRegions
Definition: AtlasRegion.h:39
beamspotman.r
def r
Definition: beamspotman.py:676
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::~G4PolyconeGeoIDSvc
~G4PolyconeGeoIDSvc()
Destructor.
Definition: G4PolyconeGeoIDSvc.cxx:42
ISF::G4PolyconeGeoIDSvc::createVolume
StatusCode createVolume(AtlasDetDescr::AtlasRegion geoID)
Retrieve and fill in the dimensions for the different AtlasRegion.
Definition: G4PolyconeGeoIDSvc.cxx:132
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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
RZPairVector
std::vector< RZPair > RZPairVector
Definition: RZPair.h:18
AtlasRegion.h
AtlasDetDescr::AtlasRegion
AtlasRegion
Definition: AtlasRegion.h:27
ISF::G4PolyconeGeoIDSvc::G4PolyconeGeoIDSvc
G4PolyconeGeoIDSvc(const std::string &name, ISvcLocator *svc)
Constructor with parameters.
Definition: G4PolyconeGeoIDSvc.cxx:33
ISF::InsideType
InsideType
Definition: IGeoIDSvc.h:22
deg
#define deg
Definition: SbPolyhedron.cxx:17
AtlasDetDescr::fUndefinedAtlasRegion
@ fUndefinedAtlasRegion
Definition: AtlasRegion.h:29
ISF::fOutside
@ fOutside
Definition: IGeoIDSvc.h:23
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AtlasDetDescr::AtlasRegionHelper::getName
static const char * getName(int region)
Definition: AtlasRegionHelper.cxx:13
ISF::fSurface
@ fSurface
Definition: IGeoIDSvc.h:24
ISF::fInside
@ fInside
Definition: IGeoIDSvc.h:25
ISFParticle.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
G4PolyconeGeoIDSvc.h
python.Utils.unixtools.where
def where(filename, prepath=[])
"which" for python files -------------------------------------------------—
Definition: unixtools.py:53
AtlasRegionHelper.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
beamspotman.dir
string dir
Definition: beamspotman.py:623
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ISF::G4PolyconeGeoIDSvc::initialize
StatusCode initialize()
Definition: G4PolyconeGeoIDSvc.cxx:48
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::inside
@ inside
Definition: PropDirection.h:29
assertAtlasRegion
#define assertAtlasRegion(region)
Definition: AtlasRegion.h:16
validAtlasRegion
#define validAtlasRegion(region)
Definition: AtlasRegion.h:15
AtlasDetDescr::fFirstAtlasRegion
@ fFirstAtlasRegion
Definition: AtlasRegion.h:31