10#include <vxd/geometry/GeoCache.h>
11#include <vxd/simulation/SensitiveDetectorBase.h>
12#include <framework/gearbox/Unit.h>
13#include <framework/logging/Logger.h>
19#include <G4LogicalVolume.hh>
20#include <G4VPhysicalVolume.hh>
21#include <G4NavigationHistory.hh>
22#include <G4Transform3D.hh>
54 id.setSegmentNumber(0);
55 SensorInfoMap::const_iterator info =
m_sensorInfo.find(
id);
61 vector<VxdID> sensors;
63 sensors.push_back(entry.first);
69 id.setSegmentNumber(0);
70 SensorInfoMap::const_iterator info =
m_sensorInfo.find(
id);
72 B2WARNING(
"VXD Sensor " <<
id <<
" does not exist.");
75 return *(info->second);
83 G4NavigationHistory nav;
86 stack<G4VPhysicalVolume*> volumes;
87 volumes.push(envelope);
90 while (!volumes.empty()) {
91 G4VPhysicalVolume* physical = volumes.top();
103 nav.NewLevel(physical);
105 G4LogicalVolume* logical = physical->GetLogicalVolume();
112 if (!info) B2FATAL(
"No SensorInfo found for Volume " << logical->GetName());
115 const G4AffineTransform g4transform = nav.GetTopTransform().Inverse();
116 TGeoHMatrix transform;
117 double rotation[9] = {
118 g4transform[0], g4transform[4], g4transform[8],
119 g4transform[1], g4transform[5], g4transform[9],
120 g4transform[2], g4transform[6], g4transform[10]
122 transform.SetRotation(rotation);
123 transform.SetDx(g4transform[12]*
Unit::mm);
124 transform.SetDy(g4transform[13]*
Unit::mm);
125 transform.SetDz(g4transform[14]*
Unit::mm);
126 info->setTransformation(transform);
127 info->setTransformation(transform,
true);
132 int nDaughters = logical->GetNoDaughters();
137 for (
int i = nDaughters - 1; i >= 0; --i) {
138 G4VPhysicalVolume* daughter = logical->GetDaughter(i);
139 volumes.push(daughter);
152 VxdID ladderID = sensorID;
154 VxdID layerID = ladderID;
159 switch (sensorinfo->
getType()) {
170 B2FATAL(
"Cannot use anything else as SensorTypes PXD, SVD, or TEL when creating VXD Sensors");
196 layer.setLadderNumber(0);
197 layer.setSensorNumber(0);
198 layer.setSegmentNumber(0);
199 SensorHierachy::const_iterator info =
m_ladders.find(layer);
200 if (info ==
m_ladders.end()) B2FATAL(
"VXD Layer " << layer <<
"does not exist.");
207 ladder.setSensorNumber(0);
208 ladder.setSegmentNumber(0);
209 SensorHierachy::const_iterator info =
m_sensors.find(ladder);
210 if (info ==
m_sensors.end()) B2FATAL(
"VXD Ladder " << ladder <<
"does not exist.");
216 static unique_ptr<GeoCache> instance(
new GeoCache());
245 throw std::invalid_argument(
"Invalid ladder id " + (std::string) ladder);
247 return placements->second;
254 throw std::invalid_argument(
"Invalid half-shelve id " + (std::string) halfShell);
256 return placements->second;
262 B2WARNING(
"No VXD alignment data. Defaults (0's) will be used!");
268 std::vector<double> planarParameters = {
305 TGeoHMatrix trafoHalfShell = halfShellPlacement.second;
317 TGeoHMatrix trafoLadder = ladderPlacement.second;
329 TGeoHMatrix trafoSensor = sensorPlacement.second;
341 geometry.setTransformation(trafoHalfShell * trafoLadder * trafoSensor,
true);
353 TGeoTranslation translation;
355 TGeoRotation rotation;
358 trafo.SetDx(g4.getTranslation()[0] / 10.);
359 trafo.SetDy(g4.getTranslation()[1] / 10.);
360 trafo.SetDz(g4.getTranslation()[2] / 10.);
362 Double_t rotMatrix[9];
363 for (
int i = 0; i < 3; ++i) {
364 for (
int j = 0; j < 3; ++j) {
365 rotMatrix[i * 3 + j] = g4.getRotation()[i][j];
368 trafo.SetRotation(rotMatrix);
375 TGeoTranslation translation;
377 TGeoRotation rotation;
379 translation.SetTranslation(dU, dV, dW);
380 rotation.RotateX(- dAlpha * TMath::RadToDeg());
381 rotation.RotateY(- dBeta * TMath::RadToDeg());
382 rotation.RotateZ(- dGamma * TMath::RadToDeg());
385 TGeoCombiTrans combi(translation, rotation);
387 trafo = trafo * combi;
static const double mm
[millimeters]
static const baseType dAlpha
Sensor/layer/ladder alignment in local alpha.
static const baseType dGamma
Sensor/layer/ladder alignment in local gamma.
static const baseType dW
Sensor/layer/ladder alignment in local w.
static const baseType dBeta
Sensor/layer/ladder alignment in local beta.
static const baseType dU
Sensor/layer/ladder alignment in local u.
static const baseType dV
Sensor/layer/ladder alignment in local v.
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
DBObjPtr< VXDAlignment > m_vxdAlignments
DBObjPtr for the alignment.
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,...
const std::set< Belle2::VxdID > getLayers(SensorInfoBase::SensorType sensortype=SensorInfoBase::VXD)
Return a set of all known Layers.
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
void addSensorPlacement(VxdID ladder, VxdID sensor, const G4Transform3D &placement)
Remember how sensor is placed into ladder.
const std::set< Belle2::VxdID > & getSensors(Belle2::VxdID ladder) const
Return a set of all sensor IDs belonging to a given ladder.
void setupReconstructionTransformations()
Initialize from DB for reconstruction Updates all SensorInfo transformations for reconstruction from ...
static TGeoHMatrix g4Transform3DToTGeo(const G4Transform3D &g4)
Covenient function to convert G4Transform3D to TGeoHMatrix.
void findVolumes(G4VPhysicalVolume *envelope)
Search a given Geometry for Sensors.
void addSensor(SensorInfoBase *sensorinfo)
Add a SensorInfo instance to the list of known sensors This method will manually add a SensorInfo ins...
static GeoCache & getInstance()
Return a reference to the singleton instance.
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getSensorPlacements(VxdID ladder) const
Retrieve stored sensor placements into ladders.
std::set< Belle2::VxdID > m_pxdLayers
Set of all PXD layer IDs.
void addHalfShellPlacement(VxdID halfShell, const G4Transform3D &placement)
Remember how half-shell is placed into world volume.
GeoCache()
Singleton class, hidden constructor.
std::map< VxdID, std::vector< std::pair< VxdID, TGeoHMatrix > > > m_ladderPlacements
Map of shell ids and their associated ladder ids and their placements.
const std::map< VxdID, TGeoHMatrix > & getHalfShellPlacements() const
Retrieve stored half-shell placements into world volume.
std::set< Belle2::VxdID > m_telLayers
Set of all Tel layer IDs.
SensorHierachy m_sensors
Map of all Sensor IDs belonging to a given Ladder ID.
SensorInfoMap m_sensorInfo
Map to find the SensorInfo for a given Sensor ID.
const std::vector< std::pair< VxdID, TGeoHMatrix > > & getLadderPlacements(VxdID halfShell) const
Retrieve stored ladder placements into half-shell.
SensorHierachy m_ladders
Map of all Ladder IDs belonging to a given Layer ID.
void clear()
Clean up internal structures.
std::map< VxdID, TGeoHMatrix > m_halfShellPlacements
Map of shell ids and their placements in top volume.
bool validSensorID(Belle2::VxdID id) const
Check that id is a valid sensor number.
void addLadderPlacement(VxdID halfShell, VxdID ladder, const G4Transform3D &placement)
Remember how ladder is placed into half-shell.
const std::set< Belle2::VxdID > & getLadders(Belle2::VxdID layer) const
Return a set of all ladder IDs belonging to a given layer.
std::map< VxdID, std::vector< std::pair< VxdID, TGeoHMatrix > > > m_sensorPlacements
Map of ladder ids and their associated sensor ids and their placements.
std::set< Belle2::VxdID > m_svdLayers
Set of all SVD layer IDs.
Base class for Sensitive Detector implementation of PXD and SVD.
SensorInfoBase * getSensorInfo()
Return a pointer to the SensorInfo associated with this instance.
Base class to provide Sensor Information for PXD and SVD.
SensorType getType() const
Return the Type of the Sensor.
SensorType
Enum specifing the type of sensor the SensorInfo represents.
@ TEL
Testbeam telescope sensor.
VxdID getID() const
Return the ID of the Sensor.
void setSurfaceParameters(const std::vector< double > &planarParameters)
Fill parameters of planar deformation to vector.
Class to uniquely identify a any structure of the PXD and SVD.
void setSensorNumber(baseType sensor)
Set the sensor id.
void setLadderNumber(baseType ladder)
Set the ladder id.
Abstract base class for different kinds of events.