-
Notifications
You must be signed in to change notification settings - Fork 443
/
GeometryManager.h
147 lines (130 loc) · 6.56 KB
/
GeometryManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GeometryManager.h
/// \brief Definition of the GeometryManager class
#ifndef ALICEO2_BASE_GEOMETRYMANAGER_H_
#define ALICEO2_BASE_GEOMETRYMANAGER_H_
#include <TGeoManager.h> // for TGeoManager
#include <TGeoMaterial.h>
#include <TGeoPhysicalNode.h> // for TGeoPNEntry
#include <TGeoShape.h>
#include <TMath.h>
#include <TObject.h> // for TObject
#include <string_view>
#include "DetectorsCommonDataFormats/DetID.h"
#include "GPUCommonLogger.h" // for LOG
#include "MathUtils/Cartesian.h"
#include "DetectorsBase/MatCell.h"
#include <mutex>
class TGeoHMatrix; // lines 11-11
class TGeoManager; // lines 9-9
namespace o2
{
namespace detectors
{
class AlignParam;
}
namespace base
{
/// Class for interfacing to the geometry; it also builds and manages the look-up tables for fast
/// access to geometry and alignment information for sensitive alignable volumes:
/// 1) the look-up table mapping unique volume ids to TGeoPNEntries. This allows to access
/// directly by means of the unique index the associated symbolic name and original global matrix
/// in addition to the functionality of the physical node associated to a given alignable volume
/// 2) the look-up table of the alignment objects associated to the indexed alignable volumes
class GeometryManager : public TObject
{
public:
///< load geometry from file
///< When applyMisalignedment == false --> read from unaligned file
///< When preferAlignedFile == true and applyMisalignment == true : Prefer reading from existing aligned file
static void loadGeometry(std::string_view geomFilePath = "", bool applyMisalignment = false, bool preferAlignedFile = true);
static bool isGeometryLoaded() { return gGeoManager != nullptr; }
static void applyMisalignent(bool applyMisalignment = true);
///< Get the global transformation matrix (ideal geometry) for a given alignable volume
///< The alignable volume is identified by 'symname' which has to be either a valid symbolic
///< name, the query being performed after alignment, or a valid volume path if the query is
///< performed before alignment.
static Bool_t getOriginalMatrix(o2::detectors::DetID detid, int sensid, TGeoHMatrix& m);
static Bool_t getOriginalMatrix(const char* symname, TGeoHMatrix& m);
static TGeoHMatrix* getMatrix(const char* symname);
static const char* getSymbolicName(o2::detectors::DetID detid, int sensid);
static TGeoPNEntry* getPNEntry(o2::detectors::DetID detid, Int_t sensid);
static TGeoHMatrix* getMatrix(o2::detectors::DetID detid, Int_t sensid);
static int getSensID(o2::detectors::DetID detid, int sensid)
{
/// compose combined detector+sensor ID for sensitive volumes
return (detid << sDetOffset) | (sensid & sSensorMask);
}
/// Default destructor
~GeometryManager() override = default;
/// misalign geometry with alignment objects from the array, optionaly check overlaps
static bool applyAlignment(const std::vector<o2::detectors::AlignParam>& algPars);
static bool applyAlignment(const std::vector<const std::vector<o2::detectors::AlignParam>*> algPars);
struct MatBudgetExt {
double meanRho = 0.; // mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
double meanX2X0 = 0.; // equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
double meanA = 0.; // mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
double meanZ = 0.; // mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
double meanZ2A = 0.; // Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
double length = -1.; // length: sum(x_i) [cm]
int nCross = 0;
; // number of boundary crosses
MatBudgetExt() = default;
~MatBudgetExt() = default;
MatBudgetExt(const MatBudgetExt& src) = default;
MatBudgetExt& operator=(const MatBudgetExt& src) = default;
void normalize(double nrm);
ClassDefNV(MatBudgetExt, 1);
};
static o2::base::MatBudget meanMaterialBudget(float x0, float y0, float z0, float x1, float y1, float z1);
static o2::base::MatBudget meanMaterialBudget(const math_utils::Point3D<float>& start, const math_utils::Point3D<float>& end)
{
return meanMaterialBudget(start.X(), start.Y(), start.Z(), end.X(), end.Y(), end.Z());
}
static o2::base::MatBudget meanMaterialBudget(const math_utils::Point3D<double>& start, const math_utils::Point3D<double>& end)
{
return meanMaterialBudget(start.X(), start.Y(), start.Z(), end.X(), end.Y(), end.Z());
}
static MatBudgetExt meanMaterialBudgetExt(float x0, float y0, float z0, float x1, float y1, float z1);
static MatBudgetExt meanMaterialBudgetExt(const math_utils::Point3D<float>& start, const math_utils::Point3D<float>& end)
{
return meanMaterialBudgetExt(start.X(), start.Y(), start.Z(), end.X(), end.Y(), end.Z());
}
static MatBudgetExt meanMaterialBudgetExt(const math_utils::Point3D<double>& start, const math_utils::Point3D<double>& end)
{
return meanMaterialBudgetExt(start.X(), start.Y(), start.Z(), end.X(), end.Y(), end.Z());
}
private:
/// Default constructor
GeometryManager() = default;
static TGeoHMatrix* getMatrix(TGeoPNEntry* pne);
static void accountMaterial(const TGeoMaterial* material, MatBudgetExt& bd);
static void accountMaterial(const TGeoMaterial* material, o2::base::MatBudget& bd)
{
bd.meanRho = material->GetDensity();
bd.meanX2X0 = material->GetRadLen();
}
/// The method returns the global matrix for the volume identified by 'path' in the ideal
/// detector geometry. The output global matrix is stored in 'm'.
/// Returns kFALSE in case TGeo has not been initialized or the volume path is not valid.
static Bool_t getOriginalMatrixFromPath(const char* path, TGeoHMatrix& m);
private:
/// sensitive volume identifier composed from (det_ID<<sDetOffset)|(sensid&sSensorMask)
static constexpr UInt_t sDetOffset = 15; /// detector identifier will start from this bit
static constexpr UInt_t sSensorMask =
(0x1 << sDetOffset) - 1; /// mask=max sensitive volumes allowed per detector (0xffff)
static std::mutex sTGMutex;
ClassDefOverride(GeometryManager, 0); // Manager of geometry information for alignment
};
} // namespace base
} // namespace o2
#endif