34 #define INCLXX_IN_GEANT4_MODE 1
51 const G4double gcdfa2 = -0.284496736;
53 const G4double gcdfa4 = -1.453152027;
68 return t - ((igcdfc3*t + igcdfc2)*t + igcdfc1) /
69 (((igcdfd3*t + igcdfd2)*t + igcdfd1)*t + 1.0);
82 G4double y = 1.0 - (((((gcdfa5*t + gcdfa4)*t) + gcdfa3)*t + gcdfa2)*t + gcdfa1)*t*std::exp(-z*z);
84 return 0.5*(1.0 + sgn*
y);
93 return -inverseGaussianCDFRational( std::sqrt(-2.0*std::log(x)) );
95 return inverseGaussianCDFRational( std::sqrt(-2.0*std::log(1.-x)) );
100 return ((x > 1.) ? 0. : ((x<-1.) ?
pi : std::asin(x)));
105 return ((x > 1.) ? 0. : ((x<-1.) ?
pi : std::acos(x)));
109 namespace ParticleConfig {
116 #ifndef INCLXX_IN_GEANT4_MODE
118 void wrap(std::string &str,
const size_t lineLength,
const std::string &separators) {
119 const size_t len = str.size();
121 while(len-startPos > lineLength) {
122 const size_t nextNewline = str.find(
'\n', startPos);
123 if(nextNewline!=std::string::npos && nextNewline-startPos<=lineLength)
124 startPos = nextNewline+1;
126 size_t lastSeparator = str.find_last_of(separators, startPos+lineLength);
127 if(lastSeparator!=std::string::npos)
128 str[lastSeparator] =
'\n';
129 startPos = lastSeparator+1;
134 void replaceAll(std::string &str,
const std::string &from,
const std::string &to,
const size_t maxPosition) {
137 size_t start_pos = 0;
138 size_t cur_max_pos = maxPosition;
139 const size_t from_len = from.length();
140 const size_t to_len = to.length();
141 while((start_pos = str.find(from, start_pos)) != std::string::npos
142 && (cur_max_pos==std::string::npos || start_pos<cur_max_pos)) {
143 str.replace(start_pos, from_len, to);
145 if(cur_max_pos!=std::string::npos)
146 cur_max_pos += to_len - from_len;
150 std::vector<std::string> tokenize(std::string
const &str,
const std::string &delimiters) {
151 size_t startPos = 0, endPos;
152 std::vector<std::string> tokens;
154 endPos = str.find_first_of(delimiters, startPos);
155 std::string token = str.substr(startPos, endPos-startPos);
156 tokens.push_back(token);
157 startPos = str.find_first_not_of(delimiters, endPos);
158 }
while(endPos!=std::string::npos);
163 G4bool isInteger(std::string
const &str) {
164 const size_t pos = str.find_first_not_of(
"0123456789");
165 return (pos==std::string::npos);
168 std::string expandPath(std::string
const &path) {
170 wordexp_t expansionResult;
172 G4int err = wordexp(path.c_str(), &expansionResult, WRDE_NOCMD);
176 result = expansionResult.we_wordv[0];
177 wordfree(&expansionResult);
186 #endif // INCLXX_IN_GEANT4_MODE