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