Belle II Software development
GeoCache.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#ifndef VXD_GEOCACHE_H
10#define VXD_GEOCACHE_H
11
12#include <vxd/dataobjects/VxdID.h>
13#include <vxd/geometry/SensorInfoBase.h>
14#include <vxd/geometry/GeoTools.h>
15#include <vector>
16#include <set>
17#include <map>
18#include <unordered_map>
19#include <memory>
20#include <framework/database/DBObjPtr.h>
21#include <alignment/dbobjects/VXDAlignment.h>
22
23class G4VPhysicalVolume;
24// forward declaring G4Transform3D is a pain
25namespace HepGeom { class Transform3D; }
26typedef HepGeom::Transform3D G4Transform3D;
27
28namespace Belle2 {
34 namespace VXD {
39 class GeoCache {
40 public:
42 ~GeoCache() { clear(); };
43
44
46 void clear();
47
62 void findVolumes(G4VPhysicalVolume* envelope);
63
70 void addSensor(SensorInfoBase* sensorinfo);
71
76 const std::set<Belle2::VxdID> getLayers(SensorInfoBase::SensorType sensortype = SensorInfoBase::VXD);
78 const std::set<Belle2::VxdID>& getLadders(Belle2::VxdID layer) const;
80 const std::set<Belle2::VxdID>& getSensors(Belle2::VxdID ladder) const;
81
86 bool validSensorID(Belle2::VxdID id) const;
87
92 const std::vector<VxdID> getListOfSensors() const;
93
95 /* If sensor not found, it returns a warning and the first sensor!*/
97
98 // ------------------ Alignment constants in reconstruction + hierarchy ------------------------------
99
102 const std::map<VxdID, TGeoHMatrix>& getHalfShellPlacements() const;
103
106 const std::vector<std::pair<VxdID, TGeoHMatrix>>& getLadderPlacements(VxdID halfShell) const;
107
110 const std::vector<std::pair<VxdID, TGeoHMatrix>>& getSensorPlacements(VxdID ladder) const;
111
113 void addHalfShellPlacement(VxdID halfShell, const G4Transform3D& placement);
114
116 void addLadderPlacement(VxdID halfShell, VxdID ladder, const G4Transform3D& placement);
117
119 void addSensorPlacement(VxdID ladder, VxdID sensor, const G4Transform3D& placement);
120
126
128 static TGeoHMatrix g4Transform3DToTGeo(const G4Transform3D& g4);
129
132 static TGeoHMatrix getTGeoFromRigidBodyParams(double dU, double dV, double dW, double dAlpha, double dBeta, double dGamma);
133
134 // --------------------------------------------------------------------------------------------------
135
137 static GeoCache& getInstance();
138
143 {
144 if (!m_geoToolsPtr)
145 m_geoToolsPtr = std::unique_ptr<GeoTools>(new GeoTools());
146 return m_geoToolsPtr.get();
147 }
148
149 private:
151 typedef std::unordered_map<VxdID::baseType, SensorInfoBase*> SensorInfoMap;
153 typedef std::map<Belle2::VxdID, std::set<Belle2::VxdID> > SensorHierachy;
154
156 GeoCache();
158 GeoCache(const GeoCache&) = delete;
160 GeoCache& operator=(const GeoCache&) = delete;
161
163 std::set<Belle2::VxdID> m_pxdLayers;
165 std::set<Belle2::VxdID> m_svdLayers;
167 std::set<Belle2::VxdID> m_telLayers;
172
174 std::map<VxdID, TGeoHMatrix> m_halfShellPlacements {};
176 std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_ladderPlacements {};
178 std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_sensorPlacements {};
181
183 std::unique_ptr<GeoTools> m_geoToolsPtr;
184
187 };
188 }
190} //Belle2 namespace
191#endif
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
GeoCache(const GeoCache &)=delete
Singleton class, hidden copy constructor.
DBObjPtr< VXDAlignment > m_vxdAlignments
DBObjPtr for the alignment.
Definition: GeoCache.h:186
static TGeoHMatrix getTGeoFromRigidBodyParams(double dU, double dV, double dW, double dAlpha, double dBeta, double dGamma)
Convert 6 rigid body params (alignment corrections) to corresponding TGeoHMatrix Angles in radians,...
Definition: GeoCache.cc:372
std::unique_ptr< GeoTools > m_geoToolsPtr
Pointer to a GeoTools object.
Definition: GeoCache.h:183
const std::set< Belle2::VxdID > getLayers(SensorInfoBase::SensorType sensortype=SensorInfoBase::VXD)
Return a set of all known Layers.
Definition: GeoCache.cc:176
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
Definition: GeoCache.cc:59
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
void addSensorPlacement(VxdID ladder, VxdID sensor, const G4Transform3D &placement)
Remember how sensor is placed into ladder.
Definition: GeoCache.cc:220
const std::set< Belle2::VxdID > & getSensors(Belle2::VxdID ladder) const
Return a set of all sensor IDs belonging to a given ladder.
Definition: GeoCache.cc:204
~GeoCache()
destructor to clean up structures
Definition: GeoCache.h:42
GeoCache & operator=(const GeoCache &)=delete
Singleton class, hidden assignment operator.
void setupReconstructionTransformations()
Initialize from DB for reconstruction Updates all SensorInfo transformations for reconstruction from ...
Definition: GeoCache.cc:259
static TGeoHMatrix g4Transform3DToTGeo(const G4Transform3D &g4)
Covenient function to convert G4Transform3D to TGeoHMatrix.
Definition: GeoCache.cc:349
void findVolumes(G4VPhysicalVolume *envelope)
Search a given Geometry for Sensors.
Definition: GeoCache.cc:78
void addSensor(SensorInfoBase *sensorinfo)
Add a SensorInfo instance to the list of known sensors This method will manually add a SensorInfo ins...
Definition: GeoCache.cc:147
std::unordered_map< VxdID::baseType, SensorInfoBase * > SensorInfoMap
Hash map to store pointers to all existing SensorInfos with constant lookup complexity.
Definition: GeoCache.h:151
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getSensorPlacements(VxdID ladder) const
Retrieve stored sensor placements into ladders.
Definition: GeoCache.cc:241
std::set< Belle2::VxdID > m_pxdLayers
Set of all PXD layer IDs.
Definition: GeoCache.h:163
const GeoTools * getGeoTools()
Return a raw pointer to a GeoTools object.
Definition: GeoCache.h:142
void addHalfShellPlacement(VxdID halfShell, const G4Transform3D &placement)
Remember how half-shell is placed into world volume.
Definition: GeoCache.cc:232
GeoCache()
Singleton class, hidden constructor.
Definition: GeoCache.cc:32
std::map< VxdID, std::vector< std::pair< VxdID, TGeoHMatrix > > > m_ladderPlacements
Map of shell ids and their associated ladder ids and their placements.
Definition: GeoCache.h:176
const std::map< VxdID, TGeoHMatrix > & getHalfShellPlacements() const
Retrieve stored half-shell placements into world volume.
Definition: GeoCache.cc:239
std::set< Belle2::VxdID > m_telLayers
Set of all Tel layer IDs.
Definition: GeoCache.h:167
SensorHierachy m_sensors
Map of all Sensor IDs belonging to a given Ladder ID.
Definition: GeoCache.h:171
SensorInfoMap m_sensorInfo
Map to find the SensorInfo for a given Sensor ID.
Definition: GeoCache.h:180
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getLadderPlacements(VxdID halfShell) const
Retrieve stored ladder placements into half-shell.
Definition: GeoCache.cc:250
SensorHierachy m_ladders
Map of all Ladder IDs belonging to a given Layer ID.
Definition: GeoCache.h:169
void clear()
Clean up internal structures.
Definition: GeoCache.cc:38
std::map< VxdID, TGeoHMatrix > m_halfShellPlacements
Map of shell ids and their placements in top volume.
Definition: GeoCache.h:174
std::map< Belle2::VxdID, std::set< Belle2::VxdID > > SensorHierachy
Map to store a set of unique VxdIDs belonging to one VxdID.
Definition: GeoCache.h:153
bool validSensorID(Belle2::VxdID id) const
Check that id is a valid sensor number.
Definition: GeoCache.cc:52
void addLadderPlacement(VxdID halfShell, VxdID ladder, const G4Transform3D &placement)
Remember how ladder is placed into half-shell.
Definition: GeoCache.cc:225
const std::set< Belle2::VxdID > & getLadders(Belle2::VxdID layer) const
Return a set of all ladder IDs belonging to a given layer.
Definition: GeoCache.cc:193
std::map< VxdID, std::vector< std::pair< VxdID, TGeoHMatrix > > > m_sensorPlacements
Map of ladder ids and their associated sensor ids and their placements.
Definition: GeoCache.h:178
std::set< Belle2::VxdID > m_svdLayers
Set of all SVD layer IDs.
Definition: GeoCache.h:165
The class collects utility functions for numbering layers, sensors snd chips based on current VXD geo...
Definition: GeoTools.h:25
Base class to provide Sensor Information for PXD and SVD.
SensorType
Enum specifing the type of sensor the SensorInfo represents.
@ VXD
Any type of VXD Sensor.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.