Belle II Software  release-05-02-19
GeoCache.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef VXD_GEOCACHE_H
12 #define VXD_GEOCACHE_H
13 
14 #include <vxd/dataobjects/VxdID.h>
15 #include <vxd/geometry/SensorInfoBase.h>
16 #include <vxd/geometry/GeoTools.h>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #include <unordered_map>
21 #include <memory>
22 #include <framework/database/DBObjPtr.h>
23 #include <alignment/dbobjects/VXDAlignment.h>
24 
25 class G4VPhysicalVolume;
26 // forward declaring G4Transform3D is a pain
27 namespace HepGeom { class Transform3D; }
28 typedef HepGeom::Transform3D G4Transform3D;
29 
30 namespace Belle2 {
36  namespace VXD {
41  class GeoCache {
42  public:
44  ~GeoCache() { clear(); };
45 
46 
48  void clear();
49 
64  void findVolumes(G4VPhysicalVolume* envelope);
65 
72  void addSensor(SensorInfoBase* sensorinfo);
73 
78  const std::set<Belle2::VxdID> getLayers(SensorInfoBase::SensorType sensortype = SensorInfoBase::VXD);
80  const std::set<Belle2::VxdID>& getLadders(Belle2::VxdID layer) const;
82  const std::set<Belle2::VxdID>& getSensors(Belle2::VxdID ladder) const;
83 
88  bool validSensorID(Belle2::VxdID id) const;
89 
94  const std::vector<VxdID> getListOfSensors() const;
95 
97  /* If sensor not found, it returns a warning and the first sensor!*/
99 
100  // ------------------ Alignment constants in reconstruction + hierarchy ------------------------------
101 
104  const std::map<VxdID, TGeoHMatrix>& getHalfShellPlacements() const;
105 
108  const std::vector<std::pair<VxdID, TGeoHMatrix>>& getLadderPlacements(VxdID halfShell) const;
109 
112  const std::vector<std::pair<VxdID, TGeoHMatrix>>& getSensorPlacements(VxdID ladder) const;
113 
115  void addHalfShellPlacement(VxdID halfShell, const G4Transform3D& placement);
116 
118  void addLadderPlacement(VxdID halfShell, VxdID ladder, const G4Transform3D& placement);
119 
121  void addSensorPlacement(VxdID ladder, VxdID sensor, const G4Transform3D& placement);
122 
128 
130  static TGeoHMatrix g4Transform3DToTGeo(const G4Transform3D& g4);
131 
134  static TGeoHMatrix getTGeoFromRigidBodyParams(double dU, double dV, double dW, double dAlpha, double dBeta, double dGamma);
135 
136  // --------------------------------------------------------------------------------------------------
137 
141  static const SensorInfoBase& get(Belle2::VxdID id) { return getInstance().getSensorInfo(id); }
142 
144  static GeoCache& getInstance();
145 
150  {
151  if (!m_geoToolsPtr)
152  m_geoToolsPtr = std::unique_ptr<GeoTools>(new GeoTools());
153  return m_geoToolsPtr.get();
154  }
155 
156  private:
158  typedef std::unordered_map<VxdID::baseType, SensorInfoBase*> SensorInfoMap;
160  typedef std::map<Belle2::VxdID, std::set<Belle2::VxdID> > SensorHierachy;
161 
163  GeoCache();
165  GeoCache(const GeoCache&) = delete;
167  GeoCache& operator=(const GeoCache&) = delete;
168 
170  std::set<Belle2::VxdID> m_pxdLayers;
172  std::set<Belle2::VxdID> m_svdLayers;
174  std::set<Belle2::VxdID> m_telLayers;
179 
181  std::map<VxdID, TGeoHMatrix> m_halfShellPlacements {};
183  std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_ladderPlacements {};
185  std::map<VxdID, std::vector<std::pair<VxdID, TGeoHMatrix>>> m_sensorPlacements {};
188 
190  std::unique_ptr<GeoTools> m_geoToolsPtr;
191 
194  };
195  }
197 } //Belle2 namespace
198 #endif
Belle2::VXD::GeoCache::clear
void clear()
Clean up internal structures.
Definition: GeoCache.cc:39
Belle2::VXD::GeoCache::SensorInfoMap
std::unordered_map< VxdID::baseType, SensorInfoBase * > SensorInfoMap
Hash map to store pointers to all existing SensorInfos with constant lookup complexity.
Definition: GeoCache.h:158
Belle2::VXD::GeoCache::~GeoCache
~GeoCache()
destructor to clean up structures
Definition: GeoCache.h:44
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VXD::SensorInfoBase::SensorType
SensorType
Enum specifing the type of sensor the SensorInfo represents.
Definition: SensorInfoBase.h:43
Belle2::VXD::GeoCache::m_sensors
SensorHierachy m_sensors
Map of all Sensor IDs belonging to a given Ladder ID.
Definition: GeoCache.h:178
Belle2::VXD::GeoCache::get
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
Definition: GeoCache.h:141
Belle2::VXD::GeoCache::m_ladderPlacements
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:183
Belle2::VXD::SensorInfoBase::VXD
@ VXD
Any type of VXD Sensor.
Definition: SensorInfoBase.h:47
Belle2::VXD::GeoCache::m_svdLayers
std::set< Belle2::VxdID > m_svdLayers
Set of all SVD layer IDs.
Definition: GeoCache.h:172
Belle2::VXD::GeoCache::addSensorPlacement
void addSensorPlacement(VxdID ladder, VxdID sensor, const G4Transform3D &placement)
Remember how sensor is placed into ladder.
Definition: GeoCache.cc:221
Belle2::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::VXD::GeoCache::m_pxdLayers
std::set< Belle2::VxdID > m_pxdLayers
Set of all PXD layer IDs.
Definition: GeoCache.h:170
Belle2::VXD::GeoTools
The class collects utility functions for numbering layers, sensors snd chips based on current VXD geo...
Definition: GeoTools.h:35
Belle2::VXD::GeoCache::getLayers
const std::set< Belle2::VxdID > getLayers(SensorInfoBase::SensorType sensortype=SensorInfoBase::VXD)
Return a set of all known Layers.
Definition: GeoCache.cc:177
Belle2::VXD::GeoCache::setupReconstructionTransformations
void setupReconstructionTransformations()
Initialize from DB for reconstruction Updates all SensorInfo transformations for reconstruction from ...
Definition: GeoCache.cc:260
Belle2::VXD::GeoCache::getListOfSensors
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
Definition: GeoCache.cc:60
Belle2::VXD::GeoCache::addLadderPlacement
void addLadderPlacement(VxdID halfShell, VxdID ladder, const G4Transform3D &placement)
Remember how ladder is placed into half-shell.
Definition: GeoCache.cc:226
Belle2::VXD::GeoCache::findVolumes
void findVolumes(G4VPhysicalVolume *envelope)
Search a given Geometry for Sensors.
Definition: GeoCache.cc:79
Belle2::VXD::GeoCache::m_telLayers
std::set< Belle2::VxdID > m_telLayers
Set of all Tel layer IDs.
Definition: GeoCache.h:174
Belle2::VXD::GeoCache::validSensorID
bool validSensorID(Belle2::VxdID id) const
Check that id is a valid sensor number.
Definition: GeoCache.cc:53
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::VXD::GeoCache::getSensors
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:205
Belle2::VXD::GeoCache::getLadderPlacements
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getLadderPlacements(VxdID halfShell) const
Retrieve stored ladder placements into half-shell.
Definition: GeoCache.cc:251
Belle2::VXD::GeoCache::m_sensorPlacements
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:185
Belle2::VXD::GeoCache::addHalfShellPlacement
void addHalfShellPlacement(VxdID halfShell, const G4Transform3D &placement)
Remember how half-shell is placed into world volume.
Definition: GeoCache.cc:233
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXD::GeoCache::m_vxdAlignments
DBObjPtr< VXDAlignment > m_vxdAlignments
DBObjPtr for the alignment.
Definition: GeoCache.h:193
Belle2::VXD::GeoCache::getGeoTools
const GeoTools * getGeoTools()
Return a raw pointer to a GeoTools object.
Definition: GeoCache.h:149
Belle2::VXD::GeoCache::getSensorPlacements
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getSensorPlacements(VxdID ladder) const
Retrieve stored sensor placements into ladders.
Definition: GeoCache.cc:242
Belle2::VXD::GeoCache::m_geoToolsPtr
std::unique_ptr< GeoTools > m_geoToolsPtr
Pointer to a GeoTools object.
Definition: GeoCache.h:190
Belle2::VXD::GeoCache::SensorHierachy
std::map< Belle2::VxdID, std::set< Belle2::VxdID > > SensorHierachy
Map to store a set of unique VxdIDs belonging to one VxdID.
Definition: GeoCache.h:160
Belle2::VXD::GeoCache::addSensor
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:148
Belle2::VXD::GeoCache::m_sensorInfo
SensorInfoMap m_sensorInfo
Map to find the SensorInfo for a given Sensor ID.
Definition: GeoCache.h:187
Belle2::VXD::GeoCache::getHalfShellPlacements
const std::map< VxdID, TGeoHMatrix > & getHalfShellPlacements() const
Retrieve stored half-shell placements into world volume.
Definition: GeoCache.cc:240
Belle2::VXD::GeoCache
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:41
Belle2::VXD::GeoCache::m_halfShellPlacements
std::map< VxdID, TGeoHMatrix > m_halfShellPlacements
Map of shell ids and their placements in top volume.
Definition: GeoCache.h:181
Belle2::VXD::GeoCache::getSensorInfo
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:68
Belle2::VXD::GeoCache::GeoCache
GeoCache()
Singleton class, hidden constructor.
Definition: GeoCache.cc:33
Belle2::VXD::GeoCache::getTGeoFromRigidBodyParams
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:373
Belle2::VXD::GeoCache::getLadders
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:194
Belle2::VXD::GeoCache::operator=
GeoCache & operator=(const GeoCache &)=delete
Singleton class, hidden assignment operator.
Belle2::VXD::GeoCache::g4Transform3DToTGeo
static TGeoHMatrix g4Transform3DToTGeo(const G4Transform3D &g4)
Covenient function to convert G4Transform3D to TGeoHMatrix.
Definition: GeoCache.cc:350
Belle2::VXD::GeoCache::m_ladders
SensorHierachy m_ladders
Map of all Ladder IDs belonging to a given Layer ID.
Definition: GeoCache.h:176