FairShip
Loading...
Searching...
No Matches
shipgen Namespace Reference

Functions

double MeanMaterialBudget (std::span< const double, 3 > start, std::span< const double, 3 > end, std::span< double, 10 > mparam)
double NuclearCrossSection_mbarn (const TGeoMaterial &material)
constexpr double PythiaLengthToCm (double x)
 A Pythia8 position (mm) in FairShip units (cm).
constexpr double PythiaTimeToS (double t)
 A Pythia8 time (mm/c) in VMC units (s).

Variables

constexpr double kPythiaLengthPerCm = 10.
 Pythia8 lengths are in mm, FairShip lengths in cm.
constexpr double kCLightCmPerS = ShipUnit::c_light * ShipUnit::s
 Speed of light in cm/s, for VMC times in seconds.

Function Documentation

◆ MeanMaterialBudget()

double shipgen::MeanMaterialBudget ( std::span< const double, 3 > start,
std::span< const double, 3 > end,
std::span< double, 10 > mparam )

Definition at line 16 of file MeanMaterialBudget.cxx.

18 {
19 //
20 // Calculate mean material budget and material properties between
21 // the points "start" and "end".
22 //
23 // "mparam" - parameters used for the energy and multiple scattering
24 // corrections:
25 //
26 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
27 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [dimensionless]
28 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [dimensionless]
29 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [dimensionless]
30 // mparam[4] - length: sum(x_i) [cm]
31 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [dimensionless]
32 // mparam[6] - number of boundary crosses
33 // mparam[7] - maximum density encountered (g/cm^3)
34 // mparam[8] - equivalent interaction length fraction: sum(x_i/I0_i)
35 // [dimensionless] mparam[9] - maximum cross section encountered (mbarn)
36 //
37 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
38 //
39 // Original ALICE improvements by
40 // Andrea Dainese, Andrea.Dainese@lnl.infn.it
41 // Andrei Gheata, Andrei.Gheata@cern.ch
42 //
43 // SHiP enhancements:
44 // Thomas Ruf, Thomas.Ruf@cern.ch (interaction length support, Dec
45 // 2016) Anupama Reghunath, anupama.reghunath@cern.ch (error logging,
46 // Nov 2024)
47 //
48
49 mparam[0] = 0;
50 mparam[1] = 1;
51 mparam[2] = 0;
52 mparam[3] = 0;
53 mparam[4] = 0;
54 mparam[5] = 0;
55 mparam[6] = 0;
56 mparam[7] = 0;
57 mparam[8] = 0;
58 mparam[9] = 0;
59 //
60 double bparam[7]; // total parameters
61 double lparam[7]; // local parameters
62
63 for (Int_t i = 0; i < 7; i++) bparam[i] = 0;
64
65 if (!gGeoManager) {
66 return 0.;
67 }
68 //
69 double length;
70 double dir[3];
71 length = TMath::Sqrt((end[0] - start[0]) * (end[0] - start[0]) +
72 (end[1] - start[1]) * (end[1] - start[1]) +
73 (end[2] - start[2]) * (end[2] - start[2]));
74 mparam[4] = length;
75 if (length < TGeoShape::Tolerance()) return 0.0;
76 double invlen = 1. / length;
77 dir[0] = (end[0] - start[0]) * invlen;
78 dir[1] = (end[1] - start[1]) * invlen;
79 dir[2] = (end[2] - start[2]) * invlen;
80
81 // Initialise start point and direction
82 TGeoNode* currentnode = nullptr;
83 TGeoNode* startnode = gGeoManager->InitTrack(start.data(), dir);
84 if (!startnode) {
85 LOG(error) << "MeanMaterialBudget: start point out of geometry: x "
86 << start[0] << ", y " << start[1] << ", z " << start[2];
87 return 0.0;
88 }
89 TGeoMaterial* material = startnode->GetVolume()->GetMedium()->GetMaterial();
90 lparam[0] = material->GetDensity();
91 if (lparam[0] > mparam[7]) mparam[7] = lparam[0];
92 lparam[1] = material->GetRadLen();
93 lparam[2] = material->GetA();
94 lparam[3] = material->GetZ();
95 lparam[4] = length;
96 lparam[5] = lparam[3] / lparam[2];
97 lparam[6] = material->GetIntLen();
98 double sigma = NuclearCrossSection_mbarn(*material);
99 if (sigma > mparam[9]) mparam[9] = sigma;
100 if (material->IsMixture()) {
101 TGeoMixture* mixture = dynamic_cast<TGeoMixture*>(material);
102 lparam[5] = 0;
103 double sum = 0;
104 for (Int_t iel = 0; iel < mixture->GetNelements(); iel++) {
105 sum += mixture->GetWmixt()[iel];
106 lparam[5] += mixture->GetZmixt()[iel] * mixture->GetWmixt()[iel] /
107 mixture->GetAmixt()[iel];
108 }
109 lparam[5] /= sum;
110 }
111
112 // Locate next boundary within length without computing safety.
113 // Propagate either with length (if no boundary found) or just cross boundary
114 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
115 double step = 0.0; // Step made
116 double snext = gGeoManager->GetStep();
117 // If no boundary within proposed length, return current density
118 if (!gGeoManager->IsOnBoundary()) {
119 mparam[0] = lparam[0];
120 mparam[1] = lparam[4] / lparam[1];
121 mparam[2] = lparam[2];
122 mparam[3] = lparam[3];
123 mparam[4] = lparam[4];
124 mparam[8] = lparam[4] / lparam[6];
125 return lparam[0];
126 }
127 // Try to cross the boundary and see what is next
128 Int_t nzero = 0;
129 while (length > TGeoShape::Tolerance()) {
130 currentnode = gGeoManager->GetCurrentNode();
131 if (snext < 2. * TGeoShape::Tolerance())
132 nzero++;
133 else
134 nzero = 0;
135 if (nzero > 3) {
136 // This means navigation has problems on one boundary
137 // Try to cross by making a small step
138 mparam[0] = bparam[0] / step;
139 mparam[1] = bparam[1];
140 mparam[2] = bparam[2] / step;
141 mparam[3] = bparam[3] / step;
142 mparam[5] = bparam[5] / step;
143 mparam[8] = bparam[6];
144 mparam[4] = step;
145 mparam[0] = 0.; // if crash of navigation take mean density 0
146 mparam[1] = 1000000; // and infinite rad length
147 return bparam[0] / step;
148 }
149 mparam[6] += 1.;
150 step += snext;
151 bparam[1] += snext / lparam[1];
152 bparam[2] += snext * lparam[2];
153 bparam[3] += snext * lparam[3];
154 bparam[5] += snext * lparam[5];
155 bparam[6] += snext / lparam[6];
156 bparam[0] += snext * lparam[0];
157
158 if (snext >= length) break;
159 if (!currentnode) break;
160 length -= snext;
161 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
162 lparam[0] = material->GetDensity();
163 if (lparam[0] > mparam[7]) mparam[7] = lparam[0];
164 lparam[1] = material->GetRadLen();
165 lparam[2] = material->GetA();
166 lparam[3] = material->GetZ();
167 lparam[5] = lparam[3] / lparam[2];
168 lparam[6] = material->GetIntLen();
169 sigma = NuclearCrossSection_mbarn(*material);
170 if (sigma > mparam[9]) mparam[9] = sigma;
171 if (material->IsMixture()) {
172 TGeoMixture* mixture = dynamic_cast<TGeoMixture*>(material);
173 lparam[5] = 0;
174 double sum = 0;
175 for (Int_t iel = 0; iel < mixture->GetNelements(); iel++) {
176 sum += mixture->GetWmixt()[iel];
177 lparam[5] += mixture->GetZmixt()[iel] * mixture->GetWmixt()[iel] /
178 mixture->GetAmixt()[iel];
179 }
180 lparam[5] /= sum;
181 }
182 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
183 snext = gGeoManager->GetStep();
184 }
185 mparam[0] = bparam[0] / step;
186 mparam[1] = bparam[1];
187 mparam[2] = bparam[2] / step;
188 mparam[3] = bparam[3] / step;
189 mparam[5] = bparam[5] / step;
190 mparam[8] = bparam[6];
191 return bparam[0] / step;
192}
double NuclearCrossSection_mbarn(const TGeoMaterial &material)

◆ NuclearCrossSection_mbarn()

double shipgen::NuclearCrossSection_mbarn ( const TGeoMaterial & material)

Definition at line 194 of file MeanMaterialBudget.cxx.

194 {
195 constexpr double mbarn = 1E-3 * 1E-24 * TMath::Na(); // cm^2 * Avogadro
196 const double n = material.GetDensity() / material.GetA();
197 return 1. / (n * material.GetIntLen()) / mbarn;
198}

◆ PythiaLengthToCm()

double shipgen::PythiaLengthToCm ( double x)
constexpr

A Pythia8 position (mm) in FairShip units (cm).

Definition at line 18 of file PythiaUnits.h.

18{ return x / kPythiaLengthPerCm; }
constexpr double kPythiaLengthPerCm
Pythia8 lengths are in mm, FairShip lengths in cm.
Definition PythiaUnits.h:13

◆ PythiaTimeToS()

double shipgen::PythiaTimeToS ( double t)
constexpr

A Pythia8 time (mm/c) in VMC units (s).

Definition at line 20 of file PythiaUnits.h.

20 {
22}
constexpr double kCLightCmPerS
Speed of light in cm/s, for VMC times in seconds.
Definition PythiaUnits.h:15

Variable Documentation

◆ kCLightCmPerS

double shipgen::kCLightCmPerS = ShipUnit::c_light * ShipUnit::s
constexpr

Speed of light in cm/s, for VMC times in seconds.

Definition at line 15 of file PythiaUnits.h.

◆ kPythiaLengthPerCm

double shipgen::kPythiaLengthPerCm = 10.
constexpr

Pythia8 lengths are in mm, FairShip lengths in cm.

Definition at line 13 of file PythiaUnits.h.