15#include <fairlogger/Logger.h>
16#include <TCollection.h>
18#include <TGeoMatrix.h>
20#include <TGeoPhysicalNode.h>
38std::mutex GeometryManager::sTGMutex;
44 if (!gGeoManager || !gGeoManager->IsClosed()) {
45 LOG(error) <<
"No active geometry or geometry not yet closed!";
49 std::lock_guard<std::mutex> guard(sTGMutex);
50 if (!gGeoManager->GetListOfPhysicalNodes()) {
51 LOG(warning) <<
"gGeoManager doesn't contain any aligned nodes!";
53 if (!gGeoManager->cd(symname)) {
54 LOG(error) <<
"Volume path " << symname <<
" not valid!";
57 m = *gGeoManager->GetCurrentMatrix();
62 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
63 const char*
path =
nullptr;
66 m = *pne->GetGlobalOrig();
69 LOG(warning) <<
"The symbolic volume name " << symname
70 <<
"does not correspond to a physical entry. Using it as a volume path!";
74 return getOriginalMatrixFromPath(
path,
m);
78Bool_t GeometryManager::getOriginalMatrixFromPath(
const char*
path, TGeoHMatrix&
m)
82 if (!gGeoManager || !gGeoManager->IsClosed()) {
83 LOG(error) <<
"Can't get the original global matrix! gGeoManager doesn't exist or it is still opened!";
86 std::lock_guard<std::mutex> guard(sTGMutex);
87 if (!gGeoManager->CheckPath(
path)) {
88 LOG(error) <<
"Volume path " <<
path <<
" not valid!";
92 TIter next(gGeoManager->GetListOfPhysicalNodes());
93 gGeoManager->cd(
path);
95 while (gGeoManager->GetLevel()) {
96 TGeoPhysicalNode* physNode =
nullptr;
98 TGeoNode* node = gGeoManager->GetCurrentNode();
100 while ((physNode = (TGeoPhysicalNode*)next())) {
101 if (physNode->GetNode() == node) {
106 TGeoMatrix* lm =
nullptr;
108 lm = physNode->GetOriginalMatrix();
110 lm = node->GetMatrix();
113 lm = node->GetMatrix();
129 if (!gGeoManager || !gGeoManager->IsClosed()) {
130 LOG(error) <<
"Can't get the global matrix! gGeoManager doesn't exist or it is still opened!";
135 TGeoPhysicalNode* pnode = pne->GetPhysicalNode();
137 return pnode->GetMatrix();
141 pne->SetPhysicalNode(
new TGeoPhysicalNode(pne->GetTitle()));
142 return pne->GetPhysicalNode()->GetMatrix();
151 if (!gGeoManager || !gGeoManager->IsClosed()) {
152 LOG(error) <<
"No active geometry or geometry not yet closed!";
156 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
171 TGeoPNEntry* pne = gGeoManager->GetAlignableEntryByUID(
id);
173 LOG(error) <<
"Failed to find alignable entry with index " <<
id <<
": Det" << detid <<
" Sens.Vol:" << sensid <<
") !";
176 return pne->GetName();
185 TGeoPNEntry* pne = gGeoManager->GetAlignableEntryByUID(
id);
187 LOG(error) <<
"The sens.vol " << sensid <<
" of det " << detid <<
" does not correspond to a physical entry!";
198 static TGeoHMatrix matTmp;
204 TGeoPhysicalNode* pnode = pne->GetPhysicalNode();
206 return pnode->GetMatrix();
209 const char*
path = pne->GetTitle();
210 gGeoManager->PushPath();
211 if (!gGeoManager->cd(
path)) {
212 gGeoManager->PopPath();
213 LOG(error) <<
"Volume path " <<
path <<
" not valid!";
216 matTmp = *gGeoManager->GetCurrentMatrix();
217 gGeoManager->PopPath();
241 for (
auto dv : algPars) {
253 int nvols = algPars.size();
254 std::vector<int> ord(
nvols);
255 std::iota(std::begin(ord), std::end(ord), 0);
256 std::sort(std::begin(ord), std::end(ord), [&algPars](
int a,
int b) {
return algPars[
a].getLevel() < algPars[
b].getLevel(); });
262 LOG(error) <<
"Error applying alignment object for volume" << algPars[ord[
i]].getSymName();
273 double nrm = 1. / step;
286 bd.
meanRho = material->GetDensity();
287 bd.
meanX2X0 = material->GetRadLen();
288 bd.
meanA = material->GetA();
289 bd.
meanZ = material->GetZ();
290 if (material->IsMixture()) {
291 TGeoMixture* mixture = (TGeoMixture*)material;
294 for (Int_t iel = 0; iel < mixture->GetNelements(); iel++) {
295 norm += mixture->GetWmixt()[iel];
296 bd.
meanZ2A += mixture->GetZmixt()[iel] * mixture->GetWmixt()[iel] / mixture->GetAmixt()[iel];
324 throw std::runtime_error(
"meanMaterialBudgetExt requires geometry loaded");
327 double dir[3] = {
x1 -
x0,
y1 -
y0, z1 - z0};
328 if ((
length = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]) < TGeoShape::Tolerance() * TGeoShape::Tolerance()) {
332 double invlen = 1. /
length;
333 for (
int i = 3;
i--;) {
336 std::lock_guard<std::mutex> guard(sTGMutex);
338 TGeoNode* currentnode = gGeoManager->InitTrack(startD, dir);
340 LOG(error) <<
"start point out of geometry: " <<
x0 <<
':' <<
y0 <<
':' << z0;
345 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
350 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
351 Double_t stepTot = 0.0;
352 Double_t step = gGeoManager->GetStep();
354 if (!gGeoManager->IsOnBoundary()) {
360 while (
length > TGeoShape::Tolerance()) {
361 if (step < 2. * TGeoShape::Tolerance()) {
369 const double* curPos = gGeoManager->GetCurrentPoint();
370 LOG(warning) <<
"Cannot cross boundary at (" << curPos[0] <<
',' << curPos[1] <<
',' << curPos[2] <<
')';
387 currentnode = gGeoManager->GetCurrentNode();
392 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
393 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
394 step = gGeoManager->GetStep();
419 double dir[3] = {
x1 -
x0,
y1 -
y0, z1 - z0};
420 if ((
length = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]) < TGeoShape::Tolerance() * TGeoShape::Tolerance()) {
424 double invlen = 1. /
length;
425 for (
int i = 3;
i--;) {
428 std::lock_guard<std::mutex> guard(sTGMutex);
430 TGeoNode* currentnode = gGeoManager->InitTrack(startD, dir);
432 LOG(error) <<
"start point out of geometry: " <<
x0 <<
':' <<
y0 <<
':' << z0;
437 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
442 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
443 Double_t stepTot = 0.0;
444 Double_t step = gGeoManager->GetStep();
446 if (!gGeoManager->IsOnBoundary()) {
452 while (
length > TGeoShape::Tolerance()) {
453 if (step < 2. * TGeoShape::Tolerance()) {
461 const double* curPos = gGeoManager->GetCurrentPoint();
462 LOG(warning) <<
"Cannot cross boundary at (" << curPos[0] <<
',' << curPos[1] <<
',' << curPos[2] <<
')';
464 budTotal.
length = stepTot;
475 currentnode = gGeoManager->GetCurrentNode();
480 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
481 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
482 step = gGeoManager->GetStep();
485 budTotal.
length = stepTot;
494 LOG(fatal) <<
"geometry is not loaded";
496 if (applyMisalignment) {
498 aligner.applyAlignment();
505 auto loadGeom = [](
const std::string_view fname) {
506 LOG(info) <<
"Loading geometry from " << fname;
507 TFile flGeom(fname.data());
508 if (flGeom.IsZombie()) {
509 LOG(fatal) <<
"Failed to open file " << fname;
518 if (preferAlignedFile) {
Definition of the base alignment parameters class.
Definition of the GeometryManager class.
Definition of the Names Generator class.
static bool isGeometryLoaded()
static const char * getSymbolicName(o2::detectors::DetID detid, int sensid)
static o2::base::MatBudget meanMaterialBudget(float x0, float y0, float z0, float x1, float y1, float z1)
static Bool_t getOriginalMatrix(o2::detectors::DetID detid, int sensid, TGeoHMatrix &m)
static void loadGeometry(std::string_view geomFilePath="", bool applyMisalignment=false, bool preferAlignedFile=true)
static bool applyAlignment(const std::vector< o2::detectors::AlignParam > &algPars)
misalign geometry with alignment objects from the array, optionaly check overlaps
static MatBudgetExt meanMaterialBudgetExt(float x0, float y0, float z0, float x1, float y1, float z1)
static int getSensID(o2::detectors::DetID detid, int sensid)
static TGeoHMatrix * getMatrix(const char *symname)
static TGeoPNEntry * getPNEntry(o2::detectors::DetID detid, Int_t sensid)
static void applyMisalignent(bool applyMisalignment=true)
static std::string getAlignedGeomFileName(const std::string_view prefix="")
static std::string getGeomFileName(const std::string_view prefix="")
static constexpr std::string_view CCDBOBJECT
static constexpr std::string_view GEOMOBJECTNAME_FAIR
static const GeometryManagerParam & Instance()
Static class with identifiers, bitmasks and names for ALICE detectors.
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLfloat GLfloat GLfloat x1
GLboolean GLboolean GLboolean b
GLuint GLsizei GLsizei * length
GLsizei const GLchar *const * path
GLboolean GLboolean GLboolean GLboolean a
GLuint GLfloat GLfloat y0
void normalize(double nrm)
float length
length in material
float meanRho
mean density, g/cm^3
float meanX2X0
fraction of radiaton lenght
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"