4 #include "KVRangeYanez.h"
5 #include "KVRangeYanezMaterial.h"
8 #include "KVNumberList.h"
9 #include <KVSystemDirectory.h>
10 #include <KVSystemFile.h>
11 #include <Riostream.h>
40 "Interface to Range dE/dx and range library (Ricardo Yanez)")
60 KVString DataFilePaths = gEnv->GetValue(
"RANGE.PredefMaterials",
"");
61 DataFilePaths.
Begin(
" ");
64 while (!DataFilePaths.
End()) {
65 nextPath = DataFilePaths.
Next();
66 if (nextPath == lastPath)
break;
73 if (!gSystem->AccessPathName(fLocalMaterialsDirectory)) {
82 fDoNotSaveMaterials = kFALSE;
104 CastedObj.fLocalMaterialsDirectory = fLocalMaterialsDirectory;
105 CastedObj.fDoNotSaveMaterials = fDoNotSaveMaterials;
121 CheckMaterialsList();
135 printf(
"KVRangeYanez::%s\n%s\n", GetName(), GetTitle());
136 Int_t n = (fMaterials ? fMaterials->GetEntries() : 0);
138 printf(
"\nEnergy loss & range tables loaded for %d materials:\n\n", fMaterials->GetEntries());
142 printf(
"\nEnergy loss & range tables loaded for 0 materials.\n");
162 TObjArray* list =
new TObjArray(fMaterials->GetEntries());
163 list->SetOwner(kTRUE);
164 TIter next(fMaterials);
167 list->Add(
new TNamed(mat->GetName(), mat->
GetType()));
175 void KVRangeYanez::CheckMaterialsList()
const
179 fMaterials->SetName(
"RANGE materials list");
220 TString state =
"solid";
221 if (
is_gas(z)) state =
"gas";
224 state, d ? *d : 0., z, a);
227 CheckMaterialsList();
228 fMaterials->
Add(mat);
229 if (!fDoNotSaveMaterials) SaveMaterial(mat);
252 const std::vector<CompoundFormulaElement>& elements, Double_t density)
const
269 TString state =
"gas";
270 if (density > 0) state =
"solid";
273 for (
auto& el : elements) {
277 CheckMaterialsList();
278 fMaterials->
Add(mat);
279 if (!fDoNotSaveMaterials) SaveMaterial(mat);
300 const std::vector<MixtureFormulaElement>& elements, Double_t density)
const
315 TString state =
"gas";
316 if (density > 0) state =
"solid";
319 for (
auto& el : elements) {
323 CheckMaterialsList();
324 fMaterials->
Add(mat);
325 if (!fDoNotSaveMaterials) SaveMaterial(mat);
355 while (!isotopes.
End()) {
363 TString state =
"solid";
364 if (
is_gas(z)) state =
"gas";
370 while (!isotopes.
End()) {
388 TString DataFilePath = filename;
392 KVError::Error(
this,
"ReadPredefinedMaterials",
"Cannot open %s for reading", DataFilePath.Data());
395 Info(
"ReadPredefinedMaterials",
"Reading materials in file : %s", filename);
397 fDoNotSaveMaterials = kTRUE;
399 Bool_t compound, mixture;
400 compound = mixture = kFALSE;
403 while (filestream.good()) {
404 line.ReadLine(filestream);
405 if (filestream.good()) {
406 if (line.BeginsWith(
"//"))
continue;
407 if (line.BeginsWith(
"COMPOUND")) {
411 else if (line.BeginsWith(
"MIXTURE")) {
415 else if (line.BeginsWith(
"ELEMENT")) {
416 compound = mixture = kFALSE;
418 if (compound || mixture) {
421 Double_t density = -1;
423 std::vector<CompoundFormulaElement> compound_elements;
424 std::vector<MixtureFormulaElement> mixture_elements;
426 line.ReadLine(filestream);
427 while (filestream.good() && !line.IsWhitespace() && line !=
"\n") {
430 if (next ==
"name") name = line.
Next();
431 else if (next ==
"symbol") symbol = line.
Next();
432 else if (next ==
"state") state = line.
Next();
433 else if (next ==
"density") density = line.
Next().Atof();
434 else if (next ==
"nelem") {
435 nelem = line.
Next().Atoi();
436 for (
int i = 0; i < nelem; i++) {
437 line.ReadLine(filestream);
439 element = line.
Next();
444 auto natoms = line.
Next().Atoi();
446 auto proportion = line.
Next().Atof();
447 mixture_elements.push_back({z, a, natoms, proportion});
450 compound_elements.push_back({z, a, natoms});
454 line.ReadLine(filestream, kFALSE);
457 else if (mixture)
AddMixedMaterial(name, symbol, mixture_elements, density);
458 compound = mixture = kFALSE;
463 line.ReadLine(filestream);
464 while (filestream.good() && !line.IsWhitespace() && line !=
"\n") {
467 if (next ==
"name") name = line.
Next();
468 else if (next ==
"symbol") symbol = line.
Next();
469 else if (next ==
"state") state = line.
Next();
470 line.ReadLine(filestream, kFALSE);
477 fDoNotSaveMaterials = kFALSE;
500 if (gSystem->AccessPathName(fLocalMaterialsDirectory)) {
501 gSystem->mkdir(fLocalMaterialsDirectory,
true);
502 gSystem->Chmod(fLocalMaterialsDirectory, 0755);
504 TString matfilename(mat->GetName());
505 matfilename.ReplaceAll(
" ",
"_");
506 matfilename +=
".dat";
virtual const Char_t * GetType() const
static const Char_t * GetWORKDIRFilePath(const Char_t *namefile="")
void Copy(TObject &) const override
Make a copy of this object.
static Bool_t SearchAndOpenKVFile(const Char_t *name, KVSQLite::database &dbfile, const Char_t *kvsubdir="")
Extended version of ROOT THashList.
Material for use in energy loss & range calculations.
void AddCompoundElement(Int_t Z, Int_t A, Int_t Natoms)
void AddMixtureElement(Int_t Z, Int_t A, Int_t Natoms, Double_t Proportion)
virtual void Initialize()
Abstract base class for calculation of range & energy loss of charged particles in matter.
std::string get_element_name(int z) const
std::string get_element_symbol(int z) const
std::optional< double > get_element_density(int z) const
Description of properties and kinematics of atomic nuclei.
std::optional< double > GetAbundance(std::optional< int > z={}, std::optional< int > a={}) const
static Int_t IsMassGiven(const Char_t *)
Double_t GetNaturalA(std::optional< int > z={}) const
KVNumberList GetKnownARange(std::optional< int > z={}, std::optional< double > tmin={}) const
Int_t GetZ() const
Return the number of proton / atomic number.
Strings used to represent a set of ranges of values.
Description of absorber for the Range dE/dx and range library.
void Initialize() override
Interface to Range dE/dx and range library.
void Copy(TObject &) const override
Bool_t ReadMaterials(const Char_t *filename) const override
Read materials from file whose name is given.
void Print(Option_t *="") const override
TObjArray * GetListOfMaterials() override
KVIonRangeTableMaterial * AddElementalMaterial(Int_t z, Int_t a=0) const override
virtual KVIonRangeTableMaterial * AddMixedMaterial(const Char_t *name, const Char_t *symbol, const std::vector< MixtureFormulaElement > &elements, Double_t density=-1.0) const override
virtual KVIonRangeTableMaterial * AddCompoundMaterial(const Char_t *name, const Char_t *symbol, const std::vector< CompoundFormulaElement > &elements, Double_t density=-1.0) const override
KVIonRangeTableMaterial * MakeNaturallyOccuringElementMixture(Int_t z, Int_t &a) const
void Add(TObject *obj) override
TObject * FindObject(const char *name) const override
void SetOwner(Bool_t enable=kTRUE) override
virtual TObject * FindObjectByType(const Char_t *) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
Extension of ROOT TSystemDirectory class, handling browsing directories on disk.
TList * GetListOfFiles() const override
Extended ROOT TSystemFile with added info on file size etc.
const Char_t * GetFullPath() const
void Error(UserClass p, const char *location, const char *va_(fmt),...)