BmnRoot
Loading...
Searching...
No Matches
BmnGeoNavigator.cxx
Go to the documentation of this file.
1
7#include "BmnGeoNavigator.h"
8#include "TMath.h"
9#include "FairTrackParam.h"
10
11#include "TGeoManager.h"
12#include "TGeoNode.h"
13#include "TGeoMaterial.h"
14#include "TGeoVolume.h"
15
16#include <iostream>
17#include <cmath>
18
19using namespace TMath;
20
23
26
27BmnStatus BmnGeoNavigator::FindIntersections(const FairTrackParam* par, Float_t zOut, vector<BmnMaterialInfo>& inter) {
28 Bool_t downstream = zOut <= par->GetZ();
29// std::cout << "zOut=" << zOut << " Z=" << par->GetZ() << " downstream=" << downstream << std::endl;
30
31 InitTrack(par, downstream);
32 if (gGeoManager->IsOutside()) {
33 return kBMNERROR;
34 }
35
36 BmnMaterialInfo stepInfo;
37 Bool_t last = kFALSE;
38
39 cout.precision(7);
40
41 do {
42 gGeoManager->PushPoint();
43 stepInfo = MakeStep();
44 // std::cout << "stepInfo=" << stepInfo.ToString();
45 // Check if outside of the geometry
46 if (gGeoManager->IsOutside()) {
47 // std::cout << "Error! BmnTGeoNavigator::FindIntersections: Outside geometry.\n";
48 gGeoManager->PopDummy();
49 return kBMNERROR;
50 }
51 // Check for NaN values
52 if (IsNaN(gGeoManager->GetCurrentPoint()[0]) ||
53 IsNaN(gGeoManager->GetCurrentPoint()[1]) ||
54 IsNaN(gGeoManager->GetCurrentPoint()[2])) {
55 // std::cout << "Error! BmnTGeoNavigator::FindIntersections: NaN values.\n";
56 gGeoManager->PopDummy();
57 return kBMNERROR;
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 Float_t l = CalcLength(zOut);
64 stepInfo.SetLength(l);
65 stepInfo.SetZpos(zOut);
66 last = kTRUE;
67 } else {
68 gGeoManager->PopDummy();
69 }
70 inter.push_back(stepInfo);
71 } while (!last);
72 return kBMNSUCCESS;
73}
74
75void BmnGeoNavigator::InitTrack(const FairTrackParam* par, Bool_t downstream) const {
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
90BmnMaterialInfo BmnGeoNavigator::MakeStep(Float_t step) const {
91 // fill current material information and then make a step
92 BmnMaterialInfo 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(25.);
102 } else {
103 gGeoManager->SetStep(step);
104 gGeoManager->Step(kFALSE);
105 }
106
107 matInfo.SetLength(gGeoManager->GetStep());
108 matInfo.SetZpos(gGeoManager->GetCurrentPoint()[2]);
109
110 return matInfo;
111}
112
113Float_t BmnGeoNavigator::CalcLength(Float_t zOut) const {
114 //find intersection point of straight line with plane
115 Float_t nx = gGeoManager->GetCurrentDirection()[0];
116 Float_t ny = gGeoManager->GetCurrentDirection()[1];
117 Float_t nz = gGeoManager->GetCurrentDirection()[2];
118 Float_t z = gGeoManager->GetCurrentPoint()[2];
119
120 Float_t t0 = (zOut - z) / nz;
121
122 Float_t dx = nx * t0;
123 Float_t dy = ny * t0;
124 Float_t dz = (zOut - z); //nz * t0;
125
126 //calculate distance between two points
127 return std::sqrt(dx * dx + dy * dy + dz * dz);
128}
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
virtual ~BmnGeoNavigator()
BmnStatus FindIntersections(const FairTrackParam *par, Float_t zOut, vector< BmnMaterialInfo > &inter)
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)