KaliVeda
Toolkit for HIC analysis
KVIonRangeTable.cpp
1 //Created by KVClassFactory on Thu Feb 3 10:04:41 2011
2 //Author: frankland,,,,
3 
4 #include "KVIonRangeTable.h"
5 #include "KVIonRangeTableMaterial.h"
6 #include <TPluginManager.h>
7 #include <TError.h>
8 #include "TGeoManager.h"
9 #include "tknucleus.h"
10 
11 
13 
14 #define FIND_MAT_AND_EXEC(method,defval) \
15  KVIonRangeTableMaterial* M = GetMaterial(mat); \
16  if(M) return M->method; \
17  return defval
18 #define FIND_MAT_AND_SET(method,newval) \
19  KVIonRangeTableMaterial* M = GetMaterial(mat); \
20  if(M) M->method(newval)
21 #define CHECK_ION_FIND_MAT_AND_EXEC(method,defval) \
22  if(!CheckIon(Z,A)){ \
23  if(Z) Warning(#method , "Ion Z=%d out of range table limits", Z); \
24  return defval; \
25  } \
26 
27  KVIonRangeTableMaterial* M = GetMaterial(mat); \
28  if(M) return M->method; \
29  return defval
30 
32 
33 
34 
37 KVIonRangeTable::KVIonRangeTable(const Char_t* name, const Char_t* title)
38  : KVBase(name, title)
39 {
40  // Default constructor
41 }
42 
43 
44 
47 
49 {
50  // Destructor
51 }
52 
53 
54 
57 
59 {
60  // Generates an instance of the KVIonRangeTable plugin class corresponding to given name.
61 
62  TPluginHandler* ph;
63  //check and load plugin library
64  if (!(ph = LoadPlugin("KVIonRangeTable", name))) {
65  ::Error("KVIonRangeTable::GetRangeTable", "No plugin for KVIonRangeTable with name=%s found in .kvrootrc", name);
66  return 0;
67  }
69  return irt;
70 }
71 
72 
73 
74 
79 
81 {
82  // Return atomic mass of a material in the range table.
83  // "material" can be either the type or the name of the material.
84  // Prints a warning and returns 0 if material is unknown.
85 
86  KVIonRangeTableMaterial* M = GetMaterial(material);
87  if (!M) {
88  KVError::Warning(this, "GetAtomicMass", "Material %s is unknown. Returned mass = 0.", material);
89  return 0.0;
90  }
91  return M->GetMass();
92 }
93 
94 
95 
97 
99 {
100  return GetMaterialWithNameOrType(material);
101 }
102 
103 
104 
106 
108 {
109  return GetMaterialWithPointer(mat);
110 }
111 
112 
113 
117 
118 KVIonRangeTableMaterial* KVIonRangeTable::GetMaterialWithPointer(TGeoMaterial* material) const
119 {
120  // Returns pointer to material for given TGeoMaterial
121  // We try both the name and the title of the TGeoMaterial
122  KVIonRangeTableMaterial* mat = GetMaterial(material->GetTitle());
123  if (!mat) mat = GetMaterial(material->GetName());
124  return mat;
125 }
126 
127 
128 
131 
132 std::optional<double> KVIonRangeTable::get_element_density(int z) const
133 {
134  // \return density of element in [g/cm3] if known
135 
136  if (z > 0)
137  {
138  tkn::tknucleus nuc(z);
139  if(nuc.has_property("density"))
140  return nuc.get("density")->get_value(); // assumed to be in g/cm3: TkN does not provide density units!
141  KVError::Warning(this, "get_element_density",
142  "No element found in density table with Z=%d, density unknown", z);
143  return {};
144  }
145  KVError::Warning(this, "get_element_density",
146  "Called with Z=%d !", z);
147  return {};
148 }
149 
150 
151 
154 
155 bool KVIonRangeTable::is_gas(int z) const
156 {
157  // \returns true if TkN identifies the element as a gas at STP
158 
159  if (z <= 0) return false;
160  tkn::tknucleus nuc(z);
161  return nuc.is_gas();
162 }
163 
164 
165 
168 
169 std::string KVIonRangeTable::get_element_symbol(int z) const
170 {
171  // \return symbol for element z
172 
173  return tkn::tknucleus(z).get_element_symbol();
174 }
175 
176 
177 
180 
181 std::string KVIonRangeTable::get_element_name(int z) const
182 {
183  // \return name for element z
184 
185  return tkn::tknucleus(z).get_element_name();
186 }
187 
188 
189 
190 
195 
197 {
198  // Return atomic number of a material in the range table.
199  // "material" can be either the type or the name of the material.
200  // Prints a warning and returns 0 if material is unknown.
201 
202  KVIonRangeTableMaterial* M = GetMaterial(material);
203  if (!M) {
204  KVError::Warning(this, "GetZ", "Material %s is unknown. Returned Z = 0.", material);
205  return 0.0;
206  }
207  return M->GetZ();
208 }
209 
210 
211 
212 
215 
217 {
218  // Returns kTRUE if material of given name or type is in range table.
219  KVIonRangeTableMaterial* M = GetMaterial(material);
220  return (M != 0x0);
221 }
222 
223 
224 
227 
229 {
230  // Returns kTRUE if material corresponding to TGeoMaterial name or type is in range table.
231  KVIonRangeTableMaterial* M = GetMaterial(material);
232  return (M != 0x0);
233 }
234 
235 
236 
237 
240 
242 {
243  // Returns kTRUE if material of given name or type is gaseous.
244  FIND_MAT_AND_EXEC(IsGas(), kFALSE);
245 }
246 
247 
248 
249 
252 
254 {
255  // Return name of material of given type or name if it is in range tables
256  FIND_MAT_AND_EXEC(GetName(), "");
257 }
258 
259 
260 
261 
264 
266 {
267  // Return type of material of given type or name if it is in range tables
268  FIND_MAT_AND_EXEC(GetType(), "");
269 }
270 
271 
272 
273 
276 
278 {
279  // Return density of material (g/cm**3) of given type or name if it is in range tables
280  FIND_MAT_AND_EXEC(GetDensity(), 0.0);
281 }
282 
283 
284 
285 
288 
290 {
291  // Changes the density (g/cm**3) of a material of given type or name if it is in the range tables
292  FIND_MAT_AND_SET(SetDensity, dens);
293 }
294 
295 
296 
297 
302 
303 void KVIonRangeTable::SetTemperatureAndPressure(const Char_t* material, Double_t temperature, Double_t pressure)
304 {
305  // Set temperature (in degrees celsius) and pressure (in torr) for a given
306  // material. This has no effect except for gaseous materials, for which T & P
307  // determine the density (in g/cm**3).
308 
309  KVIonRangeTableMaterial* M = GetMaterial(material);
310  if (M) M->SetTemperatureAndPressure(temperature, pressure);
311 }
312 
313 
314 
315 
320 
322  Double_t Amat, Double_t, Double_t)
323 {
324  // Returns range (in g/cm**2) of ion (Z,A) with energy E (MeV) in material.
325  // Give Amat to change default (isotopic) mass of material,
326  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
327 
328  CHECK_ION_FIND_MAT_AND_EXEC(GetRangeOfIon(Z, A, E, Amat), 0.0);
329 }
330 
331 
332 
337 
339  Double_t Amat, Double_t T, Double_t P)
340 {
341  // Returns linear range (in cm) of ion (Z,A) with energy E (MeV) in material.
342  // Give Amat to change default (isotopic) mass of material,
343  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
344 
345  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearRangeOfIon(Z, A, E, Amat, T, P), 0.0);
346 }
347 
348 
349 
354 
356  Double_t Amat, Double_t, Double_t)
357 {
358  // Returns energy lost (in MeV) by ion (Z,A) with energy E (MeV) after thickness r (in g/cm**2).
359  // Give Amat to change default (isotopic) mass of material,
360  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
361 
362  CHECK_ION_FIND_MAT_AND_EXEC(GetDeltaEOfIon(Z, A, E, r, Amat), 0.0);
363 }
364 
365 
366 
371 
373  Double_t Amat, Double_t T, Double_t P)
374 {
375  // Returns energy lost (in MeV) by ion (Z,A) with energy E (MeV) after thickness d (in cm).
376  // Give Amat to change default (isotopic) mass of material,
377  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
378 
379  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearDeltaEOfIon(Z, A, E, d, Amat, T, P), 0.0);
380 }
381 
382 
383 
388 
390  Double_t Amat, Double_t, Double_t)
391 {
392  // Returns residual energy (in MeV) of ion (Z,A) with incident energy E (MeV) after thickness r (in g/cm**2).
393  // Give Amat to change default (isotopic) mass of material,
394  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
395 
396  CHECK_ION_FIND_MAT_AND_EXEC(GetEResOfIon(Z, A, E, r, Amat), 0.0);
397 }
398 
399 
400 
405 
407  Double_t Amat, Double_t T, Double_t P)
408 {
409  // Returns residual energy (in MeV) of ion (Z,A) with incident energy E (MeV) after thickness d (in cm).
410  // Give Amat to change default (isotopic) mass of material,
411  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
412 
413  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearEResOfIon(Z, A, E, d, Amat, T, P), 0.0);
414 }
415 
416 
417 
421 
423 {
424  // Calculates incident energy (in MeV) of an ion (Z,A) with residual energy Eres (MeV) after thickness e (in g/cm**2).
425  // Give Amat to change default (isotopic) mass of material,
426  CHECK_ION_FIND_MAT_AND_EXEC(GetEIncFromEResOfIon(Z, A, Eres, e, isoAmat), 0.0);
427 }
428 
429 
430 
435 
437  Double_t isoAmat, Double_t T, Double_t P)
438 {
439  // Calculates incident energy (in MeV) of an ion (Z,A) with residual energy Eres (MeV) after thickness e (in cm).
440  // Give Amat to change default (isotopic) mass of material,
441  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
442  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearEIncFromEResOfIon(Z, A, Eres, e, isoAmat, T, P), 0.0);
443 }
444 
445 
446 
450 
452 {
453  // Calculates incident energy (in MeV) of an ion (Z,A) from energy loss DeltaE (MeV) in thickness e (in g/cm**2).
454  // Give Amat to change default (isotopic) mass of material,
455  CHECK_ION_FIND_MAT_AND_EXEC(GetEIncFromDeltaEOfIon(Z, A, DeltaE, e, type, isoAmat), 0.0);
456 }
457 
458 
459 
464 
466  Double_t isoAmat, Double_t T, Double_t P)
467 {
468  // Calculates incident energy (in MeV) of an ion (Z,A) from energy loss DeltaE (MeV) in thickness e (in cm).
469  // Give Amat to change default (isotopic) mass of material,
470  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
471  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearEIncFromDeltaEOfIon(Z, A, deltaE, e, type, isoAmat, T, P), 0.0);
472 }
473 
474 
475 
479 
481 {
482  // Calculates incident energy (in MeV) of an ion (Z,A) from energy loss DeltaE (MeV) in thickness e (in g/cm**2).
483  // Give Amat to change default (isotopic) mass of material,
484  CHECK_ION_FIND_MAT_AND_EXEC(GetDeltaEFromEResOfIon(Z, A, Eres, e, isoAmat), 0.0);
485 }
486 
487 
488 
493 
495 {
496  // Calculates incident energy (in MeV) of an ion (Z,A) from energy loss DeltaE (MeV) in thickness e (in cm).
497  // Give Amat to change default (isotopic) mass of material,
498  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
499  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearDeltaEFromEResOfIon(Z, A, Eres, e, isoAmat, T, P), 0.0);
500 }
501 
502 
503 
510 
512 {
513  // Calculate incident energy (in MeV) for ion (Z,A) for which the range is equal to the
514  // given thickness e (in g/cm**2). At this energy the residual energy of the ion is (just) zero,
515  // for all energies above this energy the residual energy is > 0.
516  // Give Amat to change default (isotopic) mass of material.
517  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
518  CHECK_ION_FIND_MAT_AND_EXEC(GetPunchThroughEnergy(Z, A, e, isoAmat), 0.0);
519 }
520 
521 
522 
529 
531 {
532  // Calculate incident energy (in MeV) for ion (Z,A) for which the range is equal to the
533  // given thickness e (in cm). At this energy the residual energy of the ion is (just) zero,
534  // for all energies above this energy the residual energy is > 0.
535  // Give Amat to change default (isotopic) mass of material.
536  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
537  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearPunchThroughEnergy(Z, A, e, isoAmat, T, P), 0.0);
538 }
539 
540 
541 
545 
547 {
548  // Calculate maximum energy loss (in MeV) of ion (Z,A) in given thickness e (in g/cm**2).
549  // Give Amat to change default (isotopic) mass of material.
550  CHECK_ION_FIND_MAT_AND_EXEC(GetMaxDeltaEOfIon(Z, A, e, isoAmat), 0.0);
551 }
552 
553 
554 
559 
561 {
562  // Calculate incident energy (in MeV) corresponding to maximum energy loss of ion (Z,A)
563  // in given thickness e (in g/cm**2).
564  // Give Amat to change default (isotopic) mass of material.
565 
566  CHECK_ION_FIND_MAT_AND_EXEC(GetEIncOfMaxDeltaEOfIon(Z, A, e, isoAmat), 0.0);
567 }
568 
569 
570 
575 
577 {
578  // Calculate maximum energy loss (in MeV) of ion (Z,A) in given thickness e (in cm).
579  // Give Amat to change default (isotopic) mass of material.
580  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
581 
582  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearMaxDeltaEOfIon(Z, A, e, isoAmat, T, P), 0.0);
583 }
584 
585 
586 
592 
594 {
595  // Calculate incident energy (in MeV) corresponding to maximum energy loss of ion (Z,A)
596  // in given thickness e (in cm).
597  // Give Amat to change default (isotopic) mass of material.
598  // give temperature (degrees C) & pressure (torr) (T,P) for gaseous materials.
599 
600  CHECK_ION_FIND_MAT_AND_EXEC(GetLinearEIncOfMaxDeltaEOfIon(Z, A, e, isoAmat, T, P), 0.0);
601 }
602 
603 
604 
608 
610 {
611  // Returns maximum energy (in MeV) for which range table is valid
612  // for given material and incident ion (Z,A)
613 
614  CHECK_ION_FIND_MAT_AND_EXEC(GetEmaxValid(Z, A), 0.0);
615 }
616 
617 
618 
619 
623 
625 {
626  // Return pointer to TGeoMaterial corresponding to this material,
627  // for use in ROOT geometries, VMC, etc.
628 
629  FIND_MAT_AND_EXEC(GetTGeoMaterial(), 0x0);
630 }
631 
632 
633 
635 
637 {
638  printf("%s::%s\n%s\n", ClassName(), GetName(), GetTitle());
639 }
640 
641 
int Int_t
ROOT::R::TRInterface & r
#define d(i)
#define e(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Base class for KaliVeda framework.
Definition: KVBase.h:140
virtual const Char_t * GetType() const
Definition: KVBase.h:177
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:795
Material for use in energy loss & range calculations.
void SetTemperatureAndPressure(Double_t T, Double_t P)
Abstract base class for calculation of range & energy loss of charged particles in matter.
KVIonRangeTableMaterial * GetMaterial(const Char_t *material) const
Returns pointer to material of given name or type.
virtual Bool_t IsMaterialGas(const Char_t *)
Return kTRUE if material is gaseous.
virtual Double_t GetLinearEIncFromDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t DeltaE, Double_t e, enum SolType type=kEmax, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetEIncFromEResOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t Eres, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
void Print(Option_t *="") const override
std::string get_element_name(int z) const
const Char_t * GetMaterialName(const Char_t *)
Return name of material of given type or name if it is in range tables.
bool is_gas(int z) const
virtual Double_t GetAtomicMass(const Char_t *)
Returns atomic mass of a material in the range tables.
const Char_t * GetMaterialType(const Char_t *)
Return type of material of given type or name if it is in range tables.
std::string get_element_symbol(int z) const
virtual Double_t GetLinearMaxDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
std::optional< double > get_element_density(int z) const
virtual Double_t GetRangeOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t E, Double_t Amat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetEResOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t E, Double_t r, Double_t Amat=0., Double_t T=-1., Double_t P=-1.)
static KVIonRangeTable * GetRangeTable(const Char_t *name)
Generates an instance of the KVIonRangeTable plugin class corresponding to given name.
virtual Double_t GetMaxDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetLinearEIncFromEResOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t Eres, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual TGeoMaterial * GetTGeoMaterial(const Char_t *material)
Create and return pointer to TGeoMaterial/Mixture corresponding to material.
virtual Double_t GetZ(const Char_t *)
Returns atomic number of a material in the range tables.
virtual Double_t GetLinearEResOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t E, Double_t d, Double_t Amat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetEIncFromDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t DeltaE, Double_t e, enum SolType type=kEmax, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual void SetDensity(const Char_t *, Double_t)
Changes the density (g/cm**3) of a material in the range tables.
virtual Double_t GetPunchThroughEnergy(const Char_t *mat, Int_t Z, Int_t A, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetEmaxValid(const Char_t *material, Int_t Z, Int_t A)
virtual Double_t GetLinearEIncOfMaxDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetLinearPunchThroughEnergy(const Char_t *mat, Int_t Z, Int_t A, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetLinearDeltaEFromEResOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t ERes, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Bool_t IsMaterialKnown(const Char_t *)
Return kTRUE if material is in range tables.
virtual Double_t GetLinearDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t E, Double_t d, Double_t Amat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetDeltaEFromEResOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t ERes, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual ~KVIonRangeTable()
Destructor.
virtual Double_t GetEIncOfMaxDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t e, Double_t isoAmat=0., Double_t T=-1., Double_t P=-1.)
virtual Double_t GetDeltaEOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t E, Double_t r, Double_t Amat=0., Double_t T=-1., Double_t P=-1.)
virtual void SetTemperatureAndPressure(const Char_t *, Double_t temperature, Double_t pressure)
virtual Double_t GetDensity(const Char_t *)
Returns density (g/cm**3) of a material in the range tables.
virtual Double_t GetLinearRangeOfIon(const Char_t *mat, Int_t Z, Int_t A, Double_t E, Double_t Amat=0., Double_t T=-1., Double_t P=-1.)
const char * GetName() const override
const char * GetTitle() const override
virtual const char * ClassName() const
virtual void Error(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
void Warning(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:125
double T(double x)
constexpr Double_t E()
ClassImp(TPyArg)