28 std::string fname = filename;
29 if(fname.find(
".txt") == std::string::npos) {
33 std::string grsipath = getenv(
"GRSISYS");
34 std::ostringstream ostr;
35 ostr << grsipath <<
"/libraries/TAnalysis/SRIMData/";
37 ostr.str(std::string());
38 ostr << grsipath <<
"/SRIMData/";
41 std::cout << std::endl
42 <<
"Failed to find directory with SRIM data, tried \"" << grsipath <<
"/libraries/TAnalysis/SRIMData/\" and \"" << grsipath <<
"/SRIMData/\"!" << std::endl;
46 std::cout << std::endl
47 <<
"Searching for " << ostr.str() <<
"..." << std::endl;
50 infile.open(ostr.str().c_str());
52 std::cout <<
"{TSRIM} Warning : Couldn't find the file '" << filename <<
"' ..." << std::endl;
57 double density_scale = 0.;
60 std::vector<double> number_input;
61 std::vector<double> dEdX_temp;
62 std::vector<std::string> string_input;
64 while(!std::getline(infile, line).fail()) {
65 if(line.length() == 0u) {
68 std::istringstream linestream(line);
71 while(!(linestream >> word).fail()) {
72 std::istringstream str(word);
73 if(!(str >> temp).fail()) {
74 number_input.push_back(temp);
76 string_input.push_back(str.str());
80 if((string_input[0].compare(0, 3,
"keV") == 0) && (string_input[1].compare(0, 1,
"/") == 0) &&
81 (string_input[2].compare(0, 6,
"micron") == 0)) {
82 density_scale = number_input[0];
84 }
else if(number_input.size() != 6) {
88 if(string_input[0].compare(0, 3,
"eV") == 0 && string_input[1].compare(0, 1,
"/") != 0) {
90 }
else if(string_input[0].compare(0, 3,
"keV") == 0 && string_input[1].compare(0, 1,
"/") != 0) {
92 }
else if(string_input[0].compare(0, 3,
"MeV") == 0 && string_input[1].compare(0, 1,
"/") != 0) {
94 }
else if(string_input[0].compare(0, 3,
"GeV") == 0 && string_input[1].compare(0, 1,
"/") != 0) {
100 dEdX_temp.push_back((number_input[1] + number_input[2]));
103 if(!dEdX_temp.empty()) {
104 if(density_scale == 0.) {
105 std::cout <<
"WARNING: stopping power remains in original units, unable to find scale factor." << std::endl;
109 for(
double index : dEdX_temp) {
110 fdEdX.push_back(index * density_scale);
115 fEnergyLoss->GetYaxis()->SetTitle(
"dE/dx (keV/um)");
123 }
else if(emax > dataEmax || emax < dataEmin) {
124 std::cout << std::endl
125 <<
"{TSRIM} WARNING: specified emax is out of range. Setting emax to default value (" << dataEmax <<
")" << std::endl;
130 }
else if(emin < dataEmin || emin > dataEmax) {
131 std::cout << std::endl
132 <<
"{TSRIM} WARNING: specified emin is out of range. Setting emin to default value (" << dataEmin <<
")" << std::endl;
136 double emaxtemp = emax;
145 std::array<double, 4> k = {0, 0, 0, 0};
147 for(
int i = 0; i < 3; i++) {
156 while(
fE.back() > 0) {
166 etemp -= xstep * (55 / 24 * k[0] - 59 / 24 * k[1] + 37 / 24 * k[2] - 8 / 24 * k[3]);
169 fX.back() =
fX[
fX.size() - 2] + (
fX.back() -
fX[
fX.size() - 2]) * (emin -
fE[
fE.size() - 2]) / (
fE.back() -
fE[
fE.size() - 2]);
172 fEmin = TMath::MinElement(
static_cast<Long64_t
>(
fE.size()),
fE.data());
173 fEmax = TMath::MaxElement(
static_cast<Long64_t
>(
fE.size()),
fE.data());
174 fXmin = TMath::MinElement(
static_cast<Long64_t
>(
fX.size()),
fX.data());
175 fXmax = TMath::MaxElement(
static_cast<Long64_t
>(
fX.size()),
fX.data());
177 fXgetE =
new TGraph(
static_cast<Int_t
>(
fX.size()),
fX.data(),
fE.data());
179 fXgetE->SetTitle(filename);
180 fXgetE->GetXaxis()->SetTitle(
"Distance (um)");
181 fXgetE->GetYaxis()->SetTitle(
"Energy (keV)");
182 fsXgetE =
new TSpline3(Form(
"%s_Xspline", filename),
fXgetE);
183 fsXgetE->SetName(Form(
"%s_Xspline", filename));
185 fEgetX =
new TGraph(
static_cast<Int_t
>(
fE.size()));
186 for(
int x =
fE.size() - 1; x >= 0; x--) {
187 fEgetX->SetPoint(
fE.size() - x - 1,
fE.at(x),
fX.at(x));
190 fEgetX->SetTitle(filename);
191 fEgetX->GetYaxis()->SetTitle(
"Distance (um)");
192 fEgetX->GetXaxis()->SetTitle(
"Energy (keV)");
193 fsEgetX =
new TSpline3(Form(
"%s_Espline", filename),
fEgetX);
194 fsEgetX->SetName(Form(
"%s_Espline", filename));
198 std::cout << std::endl
199 <<
"\t" << fname <<
" file read in, " <<
fdEdX.size() <<
" entries found." << std::endl;
200 std::cout <<
"[Energy loss range = " <<
fEmax <<
" - " <<
fEmin <<
" keV & total range = " <<
fXmin <<
" - " <<
fXmax <<
" um ]" << std::endl;