15#include <fairlogger/Logger.h>
16#include <TCollection.h>
18#include <TGeoMatrix.h>
20#include <TGeoPhysicalNode.h>
37std::mutex GeometryManager::sTGMutex;
43 if (!gGeoManager || !gGeoManager->IsClosed()) {
44 LOG(error) <<
"No active geometry or geometry not yet closed!";
48 std::lock_guard<std::mutex> guard(sTGMutex);
49 if (!gGeoManager->GetListOfPhysicalNodes()) {
50 LOG(warning) <<
"gGeoManager doesn't contain any aligned nodes!";
52 if (!gGeoManager->cd(symname)) {
53 LOG(error) <<
"Volume path " << symname <<
" not valid!";
56 m = *gGeoManager->GetCurrentMatrix();
61 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
62 const char*
path =
nullptr;
65 m = *pne->GetGlobalOrig();
68 LOG(warning) <<
"The symbolic volume name " << symname
69 <<
"does not correspond to a physical entry. Using it as a volume path!";
73 return getOriginalMatrixFromPath(
path,
m);
77Bool_t GeometryManager::getOriginalMatrixFromPath(
const char*
path, TGeoHMatrix&
m)
81 if (!gGeoManager || !gGeoManager->IsClosed()) {
82 LOG(error) <<
"Can't get the original global matrix! gGeoManager doesn't exist or it is still opened!";
85 std::lock_guard<std::mutex> guard(sTGMutex);
86 if (!gGeoManager->CheckPath(
path)) {
87 LOG(error) <<
"Volume path " <<
path <<
" not valid!";
91 TIter next(gGeoManager->GetListOfPhysicalNodes());
92 gGeoManager->cd(
path);
94 while (gGeoManager->GetLevel()) {
95 TGeoPhysicalNode* physNode =
nullptr;
97 TGeoNode* node = gGeoManager->GetCurrentNode();
99 while ((physNode = (TGeoPhysicalNode*)next())) {
100 if (physNode->GetNode() == node) {
105 TGeoMatrix* lm =
nullptr;
107 lm = physNode->GetOriginalMatrix();
109 lm = node->GetMatrix();
112 lm = node->GetMatrix();
128 if (!gGeoManager || !gGeoManager->IsClosed()) {
129 LOG(error) <<
"Can't get the global matrix! gGeoManager doesn't exist or it is still opened!";
134 TGeoPhysicalNode* pnode = pne->GetPhysicalNode();
136 return pnode->GetMatrix();
140 pne->SetPhysicalNode(
new TGeoPhysicalNode(pne->GetTitle()));
141 return pne->GetPhysicalNode()->GetMatrix();
150 if (!gGeoManager || !gGeoManager->IsClosed()) {
151 LOG(error) <<
"No active geometry or geometry not yet closed!";
155 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
170 TGeoPNEntry* pne = gGeoManager->GetAlignableEntryByUID(
id);
172 LOG(error) <<
"Failed to find alignable entry with index " <<
id <<
": Det" << detid <<
" Sens.Vol:" << sensid <<
") !";
175 return pne->GetName();
184 TGeoPNEntry* pne = gGeoManager->GetAlignableEntryByUID(
id);
186 LOG(error) <<
"The sens.vol " << sensid <<
" of det " << detid <<
" does not correspond to a physical entry!";
197 static TGeoHMatrix matTmp;
203 TGeoPhysicalNode* pnode = pne->GetPhysicalNode();
205 return pnode->GetMatrix();
208 const char*
path = pne->GetTitle();
209 gGeoManager->PushPath();
210 if (!gGeoManager->cd(
path)) {
211 gGeoManager->PopPath();
212 LOG(error) <<
"Volume path " <<
path <<
" not valid!";
215 matTmp = *gGeoManager->GetCurrentMatrix();
216 gGeoManager->PopPath();
240 for (
auto dv : algPars) {
252 int nvols = algPars.size();
253 std::vector<int> ord(
nvols);
254 std::iota(std::begin(ord), std::end(ord), 0);
255 std::sort(std::begin(ord), std::end(ord), [&algPars](
int a,
int b) {
return algPars[
a].getLevel() < algPars[
b].getLevel(); });
259 if (!algPars[ord[
i]].applyToGeometry()) {
261 LOG(error) <<
"Error applying alignment object for volume" << algPars[ord[
i]].getSymName();
272 double nrm = 1. / step;
285 bd.
meanRho = material->GetDensity();
286 bd.
meanX2X0 = material->GetRadLen();
287 bd.
meanA = material->GetA();
288 bd.
meanZ = material->GetZ();
289 if (material->IsMixture()) {
290 TGeoMixture* mixture = (TGeoMixture*)material;
293 for (Int_t iel = 0; iel < mixture->GetNelements(); iel++) {
294 norm += mixture->GetWmixt()[iel];
295 bd.
meanZ2A += mixture->GetZmixt()[iel] * mixture->GetWmixt()[iel] / mixture->GetAmixt()[iel];
323 throw std::runtime_error(
"meanMaterialBudgetExt requires geometry loaded");
326 double dir[3] = {
x1 -
x0,
y1 -
y0, z1 - z0};
327 if ((
length = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]) < TGeoShape::Tolerance() * TGeoShape::Tolerance()) {
331 double invlen = 1. /
length;
332 for (
int i = 3;
i--;) {
335 std::lock_guard<std::mutex> guard(sTGMutex);
337 TGeoNode* currentnode = gGeoManager->InitTrack(startD, dir);
339 LOG(error) <<
"start point out of geometry: " <<
x0 <<
':' <<
y0 <<
':' << z0;
344 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
349 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
350 Double_t stepTot = 0.0;
351 Double_t step = gGeoManager->GetStep();
353 if (!gGeoManager->IsOnBoundary()) {
359 while (
length > TGeoShape::Tolerance()) {
360 if (step < 2. * TGeoShape::Tolerance()) {
368 const double* curPos = gGeoManager->GetCurrentPoint();
369 LOG(warning) <<
"Cannot cross boundary at (" << curPos[0] <<
',' << curPos[1] <<
',' << curPos[2] <<
')';
386 currentnode = gGeoManager->GetCurrentNode();
391 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
392 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
393 step = gGeoManager->GetStep();
418 double dir[3] = {
x1 -
x0,
y1 -
y0, z1 - z0};
419 if ((
length = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]) < TGeoShape::Tolerance() * TGeoShape::Tolerance()) {
423 double invlen = 1. /
length;
424 for (
int i = 3;
i--;) {
427 std::lock_guard<std::mutex> guard(sTGMutex);
429 TGeoNode* currentnode = gGeoManager->InitTrack(startD, dir);
431 LOG(error) <<
"start point out of geometry: " <<
x0 <<
':' <<
y0 <<
':' << z0;
436 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
441 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
442 Double_t stepTot = 0.0;
443 Double_t step = gGeoManager->GetStep();
445 if (!gGeoManager->IsOnBoundary()) {
451 while (
length > TGeoShape::Tolerance()) {
452 if (step < 2. * TGeoShape::Tolerance()) {
460 const double* curPos = gGeoManager->GetCurrentPoint();
461 LOG(warning) <<
"Cannot cross boundary at (" << curPos[0] <<
',' << curPos[1] <<
',' << curPos[2] <<
')';
463 budTotal.
length = stepTot;
474 currentnode = gGeoManager->GetCurrentNode();
479 accountMaterial(currentnode->GetVolume()->GetMedium()->GetMaterial(), budStep);
480 gGeoManager->FindNextBoundaryAndStep(
length, kFALSE);
481 step = gGeoManager->GetStep();
484 budTotal.
length = stepTot;
493 LOG(fatal) <<
"geometry is not loaded";
495 if (applyMisalignment) {
497 aligner.applyAlignment();
504 auto loadGeom = [](
const std::string_view fname) {
505 LOG(info) <<
"Loading geometry from " << fname;
506 TFile flGeom(fname.data());
507 if (flGeom.IsZombie()) {
508 LOG(fatal) <<
"Failed to open file " << fname;
517 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 Aligner & 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"