Belle II Software  release-08-01-10
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 
23 class G4VPhysicalVolume;
24 // forward declaring G4Transform3D is a pain
25 namespace HepGeom { class Transform3D; }
26 typedef HepGeom::Transform3D G4Transform3D;
27 
28 namespace 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 
139  static const SensorInfoBase& get(Belle2::VxdID id) { return getInstance().getSensorInfo(id); }
140 
142  static GeoCache& getInstance();
143 
148  {
149  if (!m_geoToolsPtr)
150  m_geoToolsPtr = std::unique_ptr<GeoTools>(new GeoTools());
151  return m_geoToolsPtr.get();
152  }
153 
154  private:
156  typedef std::unordered_map<VxdID::baseType, SensorInfoBase*> SensorInfoMap;
158  typedef std::map<Belle2::VxdID, std::set<Belle2::VxdID> > SensorHierachy;
159 
161  GeoCache();
163  GeoCache(const GeoCache&) = delete;
165  GeoCache& operator=(const GeoCache&) = delete;
166 
168  std::set<Belle2::VxdID> m_pxdLayers;
170  std::set<Belle2::VxdID> m_svdLayers;
172  std::set<Belle2::VxdID> m_telLayers;
177 
179  std::map<VxdID, TGeoHMatrix> m_halfShellPlacements {};
181  std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_ladderPlacements {};
183  std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_sensorPlacements {};
186 
188  std::unique_ptr<GeoTools> m_geoToolsPtr;
189 
192  };
193  }
195 } //Belle2 namespace
196 #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:191
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:188
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
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:156
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
const GeoTools * getGeoTools()
Return a raw pointer to a GeoTools object.
Definition: GeoCache.h:147
std::set< Belle2::VxdID > m_pxdLayers
Set of all PXD layer IDs.
Definition: GeoCache.h:168
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:181
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:172
SensorHierachy m_sensors
Map of all Sensor IDs belonging to a given Ladder ID.
Definition: GeoCache.h:176
SensorInfoMap m_sensorInfo
Map to find the SensorInfo for a given Sensor ID.
Definition: GeoCache.h:185
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getLadderPlacements(VxdID halfShell) const
Retrieve stored ladder placements into half-shell.
Definition: GeoCache.cc:250
GeoCache & operator=(const GeoCache &)=delete
Singleton class, hidden assignment operator.
SensorHierachy m_ladders
Map of all Ladder IDs belonging to a given Layer ID.
Definition: GeoCache.h:174
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:179
std::map< Belle2::VxdID, std::set< Belle2::VxdID > > SensorHierachy
Map to store a set of unique VxdIDs belonging to one VxdID.
Definition: GeoCache.h:158
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
Definition: GeoCache.h:139
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:183
std::set< Belle2::VxdID > m_svdLayers
Set of all SVD layer IDs.
Definition: GeoCache.h:170
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.