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#pragma once
10
11#include <vxd/dataobjects/VxdID.h>
12#include <vxd/geometry/SensorInfoBase.h>
13#include <vxd/geometry/GeoTools.h>
14#include <vector>
15#include <set>
16#include <map>
17#include <unordered_map>
18#include <memory>
19#include <framework/database/DBObjPtr.h>
20#include <alignment/dbobjects/VXDAlignment.h>
21
22class G4VPhysicalVolume;
23// forward declaring G4Transform3D is a pain
24namespace HepGeom { class Transform3D; }
25typedef HepGeom::Transform3D G4Transform3D;
26
27namespace Belle2 {
33 namespace VXD {
38 class GeoCache {
39 public:
41 ~GeoCache() { clear(); };
42
43
45 void clear();
46
61 void findVolumes(G4VPhysicalVolume* envelope);
62
69 void addSensor(SensorInfoBase* sensorinfo);
70
75 const std::set<Belle2::VxdID> getLayers(SensorInfoBase::SensorType sensortype = SensorInfoBase::VXD);
77 const std::set<Belle2::VxdID>& getLadders(Belle2::VxdID layer) const;
79 const std::set<Belle2::VxdID>& getSensors(Belle2::VxdID ladder) const;
80
85 bool validSensorID(Belle2::VxdID id) const;
86
91 const std::vector<VxdID> getListOfSensors() const;
92
94 /* If sensor not found, it returns a warning and the first sensor!*/
96
97 // ------------------ Alignment constants in reconstruction + hierarchy ------------------------------
98
101 const std::map<VxdID, TGeoHMatrix>& getHalfShellPlacements() const;
102
105 const std::vector<std::pair<VxdID, TGeoHMatrix>>& getLadderPlacements(VxdID halfShell) const;
106
109 const std::vector<std::pair<VxdID, TGeoHMatrix>>& getSensorPlacements(VxdID ladder) const;
110
112 void addHalfShellPlacement(VxdID halfShell, const G4Transform3D& placement);
113
115 void addLadderPlacement(VxdID halfShell, VxdID ladder, const G4Transform3D& placement);
116
118 void addSensorPlacement(VxdID ladder, VxdID sensor, const G4Transform3D& placement);
119
125
127 static TGeoHMatrix g4Transform3DToTGeo(const G4Transform3D& g4);
128
131 static TGeoHMatrix getTGeoFromRigidBodyParams(double dU, double dV, double dW, double dAlpha, double dBeta, double dGamma);
132
133 // --------------------------------------------------------------------------------------------------
134
136 static GeoCache& getInstance();
137
142 {
143 if (!m_geoToolsPtr)
144 m_geoToolsPtr = std::unique_ptr<GeoTools>(new GeoTools());
145 return m_geoToolsPtr.get();
146 }
147
148 private:
150 typedef std::unordered_map<VxdID::baseType, SensorInfoBase*> SensorInfoMap;
152 typedef std::map<Belle2::VxdID, std::set<Belle2::VxdID> > SensorHierachy;
153
155 GeoCache();
157 GeoCache(const GeoCache&) = delete;
159 GeoCache& operator=(const GeoCache&) = delete;
160
162 std::set<Belle2::VxdID> m_pxdLayers;
164 std::set<Belle2::VxdID> m_svdLayers;
166 std::set<Belle2::VxdID> m_telLayers;
171
173 std::map<VxdID, TGeoHMatrix> m_halfShellPlacements {};
175 std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_ladderPlacements {};
177 std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_sensorPlacements {};
180
182 std::unique_ptr<GeoTools> m_geoToolsPtr;
183
186 };
187 }
188
189} //Belle2 namespace
Class for accessing objects in the database.
Definition DBObjPtr.h:21
Class to facilitate easy access to sensor information of the VXD like coordinate transformations or p...
Definition GeoCache.h:38
GeoCache(const GeoCache &)=delete
Singleton class, hidden copy constructor.
DBObjPtr< VXDAlignment > m_vxdAlignments
DBObjPtr for the alignment.
Definition GeoCache.h:185
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:182
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 reference 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:41
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)
Convenient 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:150
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:162
const GeoTools * getGeoTools()
Return a raw pointer to a GeoTools object.
Definition GeoCache.h:141
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:175
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:166
SensorHierachy m_sensors
Map of all Sensor IDs belonging to a given Ladder ID.
Definition GeoCache.h:170
SensorInfoMap m_sensorInfo
Map to find the SensorInfo for a given Sensor ID.
Definition GeoCache.h:179
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:168
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:173
std::map< Belle2::VxdID, std::set< Belle2::VxdID > > SensorHierachy
Map to store a set of unique VxdIDs belonging to one VxdID.
Definition GeoCache.h:152
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:177
std::set< Belle2::VxdID > m_svdLayers
Set of all SVD layer IDs.
Definition GeoCache.h:164
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 specifying 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:32
Namespace to provide code needed by both Vertex Detectors, PXD and SVD, and also testbeam telescopes.
Definition GeoCache.h:33
Abstract base class for different kinds of events.