Skip to content

Commit

Permalink
Merge pull request #1424 from VinzenzBildstein/main
Browse files Browse the repository at this point in the history
Some improvements to TNucleus and to the doxygen documentation
  • Loading branch information
VinzenzBildstein authored May 28, 2024
2 parents ebb18ad + b565324 commit 4c11dc0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 82 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ grsi_logon.C
*.pcm
*Data
.grsirc
documentation
wiki
doxygen
5 changes: 2 additions & 3 deletions doxygen/DoxygenLayout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<class>
<briefdescription visible="yes"/>
<detaileddescription title=""/>
<includes visible="$SHOW_HEADERFILE"/>
<inheritancegraph visible="$CLASS_GRAPH"/>
<collaborationgraph visible="yes"/>
<memberdecl>
<nestedclasses visible="yes" title=""/>
<publictypes title=""/>
Expand Down Expand Up @@ -84,6 +81,8 @@
<related title="" subtitle=""/>
<membergroups visible="yes"/>
</memberdecl>
<inheritancegraph visible="$CLASS_GRAPH"/>
<collaborationgraph visible="yes"/>
<memberdef>
<inlineclasses title=""/>
<typedefs title=""/>
Expand Down
3 changes: 3 additions & 0 deletions include/GCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ class GMarker : public TObject {
/// histograms on a new canvas, or (for 2D histograms) create new GH2D from
/// histogram and draw it on a new canvas (using "colz").
/// - control click: doesn't do anything right now, code for TCutG is commented out.
///
/// For TLevelSchemes we also have:
/// - mouse wheel to change zoom level
/// - mouse drag to zoom in
/// - u unzooms.
///
/// Also adds keyboard controls for 1D histograms:
/// - left/right arrow moves the range left/right by 50%.
/// - up/down arrow on GH1D histograms selects the next/previous histogram and draws it.
Expand Down Expand Up @@ -170,6 +172,7 @@ class GMarker : public TObject {
/// - R Bring up the dialogue box used to set the desired y-axis range.
/// - s Show peak values.
/// - S Remove peak values.
///
/// And for 2D histograms these keyboard controls are added:
/// - left/right arrow moves the range left/right by 50%.
/// - up/down arrow moves the range up/down by 50%.
Expand Down
5 changes: 4 additions & 1 deletion include/TNucleus.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class TNucleus : public TNamed {

~TNucleus() override;

static std::string SortName(const char* name);
static void ParseName(const char* input, std::string& symbol, int& number, std::string& element) { std::string tmp(input); return ParseName(tmp, symbol, number, element); }
static void ParseName(std::string input, std::string& symbol, int& number, std::string& element);
static std::string SortName(const char* input) { std::string tmp(input); return SortName(tmp); }
static std::string SortName(std::string input);
void SetZ(int); ///< Sets the Z (# of protons) of the nucleus
void SetN(int); ///< Sets the N (# of neutrons) of the nucleus
void SetMassExcess(double); ///< Sets the mass excess of the nucleus (in MeV)
Expand Down
9 changes: 9 additions & 0 deletions include/TUserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
/// where userSettings is of type TUserSettings* and filename is
/// either a std::string or char*.
///
/// The settings file is expected to have the format
/// parameter name: value
/// where parameter name is a string w/o whitespace and value is the value of the parameter
/// the type of the value (bool, int, double, std::string, or vectors of these types) will be determined automatically.
/// Vectors are comma separated values of one type.
/// The default type is std::string.
/// Any lines starting with '#' or '//' or without a colon will be ignored.
/// See "examples/AngularCorrelationSettings.par" for an example of a settings file.
///
/////////////////////////////////////////////////////////////

class TUserSettings : public TNamed {
Expand Down
127 changes: 51 additions & 76 deletions libraries/TAnalysis/TNucleus/TNucleus.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,20 @@ std::string& TNucleus::massfile()
TNucleus::TNucleus(const char* name)
{
// Creates a nucleus based on symbol (ex. 26Na OR Na26) and sets all parameters from mass.dat
std::string Name = name;
int Number = 0;
int number = 0;
std::string symbol;
std::string element;
int first_digit, first_letter;
int z, n;
std::string sym_name;
double mass;
bool found = false;
std::string line;
std::ifstream infile;
std::string MassFile;
Name.erase(std::remove_if(Name.begin(), Name.end(), (int (*)(int))std::isspace), Name.end());

if(Name.length() < 2) {
switch(Name[0]) {
case 'p':
Name.clear();
Name.assign("h1");
break;
case 'd':
Name.clear();
Name.assign("h2");
break;
case 't':
Name.clear();
Name.assign("h3");
break;
case 'a':
Name.clear();
Name.assign("he4");
break;
default:
std::cout<<"error, type numbersymbol, or symbolnumber, i.e. 30Mg oder Mg30"<<std::endl;
return;
};
}
std::string massFile;
ParseName(name, symbol, number, element);
try {
first_digit = Name.find_first_of("0123456789 \t\n\r");
first_letter = Name.find_first_not_of("0123456789 \t\n\r");

if(first_digit > first_letter) {
Number = atoi(Name.substr(first_digit).c_str());
symbol.append(Name.substr(first_letter, first_digit - first_letter));
} else {
Number = atoi(Name.substr(first_digit, first_letter - first_digit).c_str());
symbol.append(Name.substr(first_letter));
}
element.append(std::to_string(static_cast<long long>(Number)));
element.append(symbol);
MassFile = massfile();
infile.open(MassFile.c_str());
massFile = massfile();
infile.open(massFile.c_str());
while(!getline(infile, line).fail()) {
if(line.length() < 1) {
continue;
Expand All @@ -96,7 +58,7 @@ TNucleus::TNucleus(const char* name)
return;
}
if(!found) {
std::cout<<"Warning: Element "<<element<<" not found in the mass table "<<MassFile<<"."<<std::endl
std::cout<<"Warning: Element "<<element<<" not found in the mass table "<<massFile<<"."<<std::endl
<<"Nucleus not set!"<<std::endl;
return;
}
Expand Down Expand Up @@ -177,51 +139,64 @@ TNucleus::~TNucleus()
fTransitionListByEnergy.Delete();
}

std::string TNucleus::SortName(const char* name)
void TNucleus::ParseName(std::string name, std::string& symbol, int& number, std::string& element)
{
// Names a nucleus based on symbol (ex. 26Na OR Na26). This is to get a nice naming convention.
std::string Name = name;
int Number = 0;
std::string symbol;
std::string element;
Name.erase(std::remove_if(Name.begin(), Name.end(), (int (*)(int))std::isspace), Name.end());

if(Name.length() < 2) {
switch(Name[0]) {
/// Strips any non-alphanumeric character from input, parses rest as number and symbol.
/// E.g. turns "na26" into "Na" and 26 or " 152 EU... " into "Eu" and 152.
/// Only uses the first number and first letter, so "na26 eu152" would be turned into "Na" and 26,
/// but "na26 152eu" would be turned into "Na" and 26152, and "26na 152eu" would be turned into "Na152eu" and 26.
/// Special inputs are "p" for "H" and 1, "d" for "H" and 2, "t" for "H" and 3, and "a" for "He" and 4.
/// element simply is the combined string of number and element.

// remove any characters that aren't alphanumeric
name.erase(std::remove_if(name.begin(), name.end(), [](char c) { return !std::isalnum(c); }), name.end());

// special single letter cases
if(name.length() == 1) {
switch(name[0]) {
case 'p':
Name.clear();
Name.assign("h1");
break;
symbol.assign("H");
return ;
case 'd':
Name.clear();
Name.assign("h2");
break;
symbol.assign("H");
return;
case 't':
Name.clear();
Name.assign("h3");
break;
symbol.assign("H");
return;
case 'a':
Name.clear();
Name.assign("he4");
break;
symbol.assign("He");
return;
default:
std::cout<<"error, type numbersymbol, or symbolnumber, i.e. 30Mg oder Mg30"<<std::endl;
return "";
std::cout<<"error, type numbersymbol, or symbolnumber, i.e. 30Mg oder Mg30, not "<<name<<std::endl;
return;
};
}
int first_digit = Name.find_first_of("0123456789 \t\n\r");
int first_letter = Name.find_first_not_of("0123456789 \t\n\r");
if(first_digit > first_letter) {
Number = atoi(Name.substr(first_digit).c_str());
symbol.append(Name.substr(first_letter, first_digit - first_letter));

int firstDigit = name.find_first_of("0123456789");
int firstLetter = name.find_first_not_of("0123456789");
if(firstDigit > firstLetter) {
number = atoi(name.substr(firstDigit).c_str());
symbol.append(name.substr(firstLetter, firstDigit - firstLetter));
} else {
Number = atoi(Name.substr(first_digit, first_letter - first_digit).c_str());
symbol.append(Name.substr(first_letter));
number = atoi(name.substr(firstDigit, firstLetter - firstDigit).c_str());
symbol.append(name.substr(firstLetter));
}
// make certain the symbol starts with upper case and rest is lower case by first transforming everything to lower case and then the first character to upper case.
std::transform(symbol.begin(), symbol.end(), symbol.begin(), ::tolower);
symbol[0] = toupper(symbol[0]);
element.append(std::to_string(static_cast<long long>(Number)));
element.append(std::to_string(static_cast<long long>(number)));
element.append(symbol);
}

std::string TNucleus::SortName(std::string input)
{
/// Strips any non-alphanumeric character from input, parses rest as number and symbol.
/// E.g. turns "na26" into "26Na" or " 152 EU... " into "152Eu".
/// Special inputs are "p" for "1H", "d" for "2H", "t" for "2H", and "a" for "4He".
int number = 0;
std::string symbol;
std::string element;
ParseName(input, symbol, number, element);

return element;
}
Expand Down

0 comments on commit 4c11dc0

Please sign in to comment.