CbmRoot
Loading...
Searching...
No Matches
CbmLitTGeoNavigator.cxx
Go to the documentation of this file.
1/* Copyright (C) 2008-2012 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
11
12#include "TGeoManager.h"
13#include "TGeoMaterial.h"
14#include "TGeoNode.h"
15#include "TGeoVolume.h"
18
19#include <cmath>
20#include <iostream>
21
23
25
27 std::vector<CbmLitMaterialInfo>& inter)
28{
29 Bool_t downstream = zOut >= par->GetZ();
30 // std::cout << "zOut=" << zOut << " Z=" << par->GetZ() << " downstream=" << downstream << std::endl;
31
32 InitTrack(par, downstream);
33 if (gGeoManager->IsOutside()) {
34 return kLITERROR;
35 }
36
37 CbmLitMaterialInfo stepInfo;
38 bool last = false;
39
40 std::cout.precision(7);
41
42 do {
43 gGeoManager->PushPoint();
44 stepInfo = MakeStep();
45 // std::cout << "stepInfo=" << stepInfo.ToString();
46 // Check if outside of the geometry
47 if (gGeoManager->IsOutside()) {
48 // std::cout << "Error! CbmLitTGeoNavigator::FindIntersections: Outside geometry.\n";
49 gGeoManager->PopDummy();
50 return kLITERROR;
51 }
52 // Check for NaN values
53 if (std::isnan(gGeoManager->GetCurrentPoint()[0]) || std::isnan(gGeoManager->GetCurrentPoint()[1])
54 || std::isnan(gGeoManager->GetCurrentPoint()[2])) {
55 // std::cout << "Error! CbmLitTGeoNavigator::FindIntersections: NaN values.\n";
56 gGeoManager->PopDummy();
57 return kLITERROR;
58 }
59 // Check if we currently at the output position
60 Bool_t away = (downstream) ? stepInfo.GetZpos() >= zOut : stepInfo.GetZpos() <= zOut;
61 if (away) { //|| gGeoManager->IsNullStep()){
62 gGeoManager->PopPoint();
63 litfloat l = CalcLength(zOut);
64 stepInfo.SetLength(l);
65 stepInfo.SetZpos(zOut);
66 last = true;
67 }
68 else {
69 gGeoManager->PopDummy();
70 }
71 inter.push_back(stepInfo);
72 } while (!last);
73 return kLITSUCCESS;
74}
75
76void CbmLitTGeoNavigator::InitTrack(const CbmLitTrackParam* par, Bool_t downstream) const
77{
78 litfloat nx, ny, nz;
79 par->GetDirCos(nx, ny, nz);
80 // Change track direction for upstream
81 if (!downstream) {
82 nx = -nx;
83 ny = -ny;
84 nz = -nz;
85 }
86 gGeoManager->InitTrack(par->GetX(), par->GetY(), par->GetZ(), nx, ny, nz);
87}
88
90{
91 // fill current material information and then make a step
92 CbmLitMaterialInfo matInfo;
93 TGeoMaterial* mat = gGeoManager->GetCurrentNode()->GetMedium()->GetMaterial();
94 matInfo.SetRL(mat->GetRadLen());
95 matInfo.SetRho(mat->GetDensity());
96 matInfo.SetZ(mat->GetZ());
97 matInfo.SetA(mat->GetA());
98 matInfo.SetName(gGeoManager->GetCurrentNode()->GetName());
99
100 if (step == 0.) {
101 gGeoManager->FindNextBoundaryAndStep(lit::CbmLitDefaultSettings::MAXIMUM_TGEO_NAVIGATION_DISTANCE);
102 }
103 else {
104 gGeoManager->SetStep(step);
105 gGeoManager->Step(kFALSE);
106 }
107
108 matInfo.SetLength(gGeoManager->GetStep());
109 matInfo.SetZpos(gGeoManager->GetCurrentPoint()[2]);
110
111 return matInfo;
112}
113
115{
116 //find intersection point of straight line with plane
117 litfloat nx = gGeoManager->GetCurrentDirection()[0];
118 litfloat ny = gGeoManager->GetCurrentDirection()[1];
119 litfloat nz = gGeoManager->GetCurrentDirection()[2];
120 litfloat z = gGeoManager->GetCurrentPoint()[2];
121
122 litfloat t0 = (zOut - z) / nz;
123
124 litfloat dx = nx * t0;
125 litfloat dy = ny * t0;
126 litfloat dz = (zOut - z); //nz * t0;
127
128 //calculate distance between two points
129 return std::sqrt(dx * dx + dy * dy + dz * dz);
130}
LitStatus
Definition CbmLitEnums.h:29
@ kLITERROR
Definition CbmLitEnums.h:31
@ kLITSUCCESS
Definition CbmLitEnums.h:30
double litfloat
Definition CbmLitFloat.h:19
Data class for track parameters.
void SetA(litfloat A)
void SetRL(litfloat rl)
void SetRho(litfloat rho)
void SetName(const string &name)
void SetLength(litfloat length)
void SetZ(litfloat Z)
void SetZpos(litfloat zpos)
litfloat GetZpos() const
LitStatus FindIntersections(const CbmLitTrackParam *par, litfloat zOut, std::vector< CbmLitMaterialInfo > &inter)
litfloat CalcLength(litfloat zOut) const
CbmLitMaterialInfo MakeStep(litfloat step=0.) const
void InitTrack(const CbmLitTrackParam *par, Bool_t downstream) const
Data class for track parameters.
litfloat GetZ() const
void GetDirCos(litfloat &nx, litfloat &ny, litfloat &nz) const
Return direction cosines.
litfloat GetX() const
litfloat GetY() const
static const litfloat MAXIMUM_TGEO_NAVIGATION_DISTANCE