BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnGeoNavigator.cxx
Go to the documentation of this file.
1/** BmnTGeoNavigator.cxx
2 * \author Andrey Lebedev <andrey.lebedev@gsi.de> - Original author. First version of code for CBM experiment.
3 * \author Sergey Merts <Sergey.Merts@gmail.com> - Modification for BMN experiment.
4 * \date 2008-2014
5 **/
6
7#include "BmnGeoNavigator.h"
8
9#include "FairTrackParam.h"
10#include "TGeoManager.h"
11#include "TGeoMaterial.h"
12#include "TGeoNode.h"
13#include "TGeoVolume.h"
14#include "TMath.h"
15
16#include <cmath>
17#include <iostream>
18
19using namespace TMath;
20
22
24
25BmnStatus BmnGeoNavigator::FindIntersections(const FairTrackParam* par, Float_t zOut, vector<BmnMaterialInfo>& inter)
26{
27 Bool_t downstream = zOut <= par->GetZ();
28 // std::cout << "zOut=" << zOut << " Z=" << par->GetZ() << " downstream=" << downstream << std::endl;
29
30 InitTrack(par, downstream);
31 if (gGeoManager->IsOutside()) {
32 return kBMNERROR;
33 }
34
35 BmnMaterialInfo stepInfo;
36 Bool_t last = kFALSE;
37
38 cout.precision(7);
39
40 do {
41 gGeoManager->PushPoint();
42 stepInfo = MakeStep();
43 // std::cout << "stepInfo=" << stepInfo.ToString();
44 // Check if outside of the geometry
45 if (gGeoManager->IsOutside()) {
46 // std::cout << "Error! BmnTGeoNavigator::FindIntersections: Outside geometry.\n";
47 gGeoManager->PopDummy();
48 return kBMNERROR;
49 }
50 // Check for NaN values
51 if (IsNaN(gGeoManager->GetCurrentPoint()[0]) || IsNaN(gGeoManager->GetCurrentPoint()[1])
52 || IsNaN(gGeoManager->GetCurrentPoint()[2]))
53 {
54 // std::cout << "Error! BmnTGeoNavigator::FindIntersections: NaN values.\n";
55 gGeoManager->PopDummy();
56 return kBMNERROR;
57 }
58 // Check if we currently at the output position
59 Bool_t away = (!downstream) ? stepInfo.GetZpos() >= zOut : stepInfo.GetZpos() <= zOut;
60 if (away) { //|| gGeoManager->IsNullStep()){
61 gGeoManager->PopPoint();
62 Float_t l = CalcLength(zOut);
63 stepInfo.SetLength(l);
64 stepInfo.SetZpos(zOut);
65 last = kTRUE;
66 } else {
67 gGeoManager->PopDummy();
68 }
69 inter.push_back(stepInfo);
70 } while (!last);
71 return kBMNSUCCESS;
72}
73
74void BmnGeoNavigator::InitTrack(const FairTrackParam* par, Bool_t downstream) const
75{
76 Double_t nz = 1. / TMath::Sqrt(par->GetTx() * par->GetTx() + par->GetTy() * par->GetTy() + 1);
77
78 Double_t nx = par->GetTx() * nz;
79 Double_t ny = par->GetTy() * nz;
80
81 // Change track direction for upstream
82 if (downstream) {
83 nx = -nx;
84 ny = -ny;
85 nz = -nz;
86 }
87 gGeoManager->InitTrack(par->GetX(), par->GetY(), par->GetZ(), nx, ny, nz);
88}
89
91{
92 // fill current material information and then make a step
93 BmnMaterialInfo matInfo;
94 TGeoMaterial* mat = gGeoManager->GetCurrentNode()->GetMedium()->GetMaterial();
95 matInfo.SetRL(mat->GetRadLen());
96 matInfo.SetRho(mat->GetDensity());
97 matInfo.SetZ(mat->GetZ());
98 matInfo.SetA(mat->GetA());
99 matInfo.SetName(gGeoManager->GetCurrentNode()->GetName());
100
101 if (step == 0.) {
102 gGeoManager->FindNextBoundaryAndStep(25.);
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 Float_t nx = gGeoManager->GetCurrentDirection()[0];
118 Float_t ny = gGeoManager->GetCurrentDirection()[1];
119 Float_t nz = gGeoManager->GetCurrentDirection()[2];
120 Float_t z = gGeoManager->GetCurrentPoint()[2];
121
122 Float_t t0 = (zOut - z) / nz;
123
124 Float_t dx = nx * t0;
125 Float_t dy = ny * t0;
126 Float_t dz = (zOut - z); // nz * t0;
127
128 // calculate distance between two points
129 return std::sqrt(dx * dx + dy * dy + dz * dz);
130}
bool Bool_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
R__EXTERN TGeoManager * gGeoManager
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
virtual ~BmnGeoNavigator()
BmnStatus FindIntersections(const FairTrackParam *par, Float_t zOut, vector< BmnMaterialInfo > &inter)
void InitTrack(const FairTrackParam *par, Bool_t downstream) const
BmnMaterialInfo MakeStep(Float_t step=0.) const
Float_t CalcLength(Float_t zOut) const
void SetRho(Float_t rho)
void SetLength(Float_t length)
void SetName(const string &name)
Float_t GetZpos() const
void SetA(Float_t A)
void SetRL(Float_t rl)
void SetZpos(Float_t zpos)
void SetZ(Float_t Z)
virtual Double_t GetRadLen() const
virtual Double_t GetA() const
virtual Double_t GetDensity() const
virtual Double_t GetZ() const
Bool_t IsNaN(Double_t x)
Double_t Sqrt(Double_t x)