Geant4  10.00.p02
G4INCLGlobals.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // INCL++ intra-nuclear cascade model
27 // Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28 // Davide Mancusi, CEA
29 // Alain Boudard, CEA
30 // Sylvie Leray, CEA
31 // Joseph Cugnon, University of Liege
32 //
33 #define INCLXX_IN_GEANT4_MODE 1
34 
35 #include "globals.hh"
36 
37 #include "G4INCLGlobals.hh"
38 #include "G4INCLParticle.hh"
39 
40 namespace G4INCL {
41  namespace Math {
42 
43  namespace {
44 
45  // constants for the Gaussian CDF approximation
46  const G4double gcdfa1 = 0.254829592;
47  const G4double gcdfa2 = -0.284496736;
48  const G4double gcdfa3 = 1.421413741;
49  const G4double gcdfa4 = -1.453152027;
50  const G4double gcdfa5 = 1.061405429;
51  const G4double gcdfp = 0.3275911;
52 
53  }
54 
56  {
57  // Save the sign of x
58  const G4double sgn = sign(x);
59  const G4double z = std::fabs(x) * oneOverSqrtTwo;
60 
61  // A&S formula 7.1.26
62  G4double t = 1.0/(1.0 + gcdfp*z);
63  G4double y = 1.0 - (((((gcdfa5*t + gcdfa4)*t) + gcdfa3)*t + gcdfa2)*t + gcdfa1)*t*std::exp(-z*z);
64 
65  return 0.5*(1.0 + sgn*y);
66  }
67 
68  G4double gaussianCDF(const G4double x, const G4double x0, const G4double sigma) {
69  return gaussianCDF((x-x0)/sigma);
70  }
71  }
72 
73  namespace ParticleConfig {
74  G4bool isPair(Particle const * const p1, Particle const * const p2, ParticleType t1, ParticleType t2) {
75  return ((p1->getType() == t1 && p2->getType() == t2) ||
76  (p1->getType() == t2 && p2->getType() == t1));
77  }
78  }
79 
80 #ifndef INCLXX_IN_GEANT4_MODE
81  namespace String {
82  void wrap(std::string &str, const size_t lineLength, const std::string &separators) {
83  const size_t len = str.size();
84  size_t startPos = 0;
85  while(len-startPos > lineLength) {
86  const size_t nextNewline = str.find('\n', startPos);
87  if(nextNewline!=std::string::npos && nextNewline-startPos<=lineLength)
88  startPos = nextNewline+1;
89  else {
90  size_t lastSeparator = str.find_last_of(separators, startPos+lineLength);
91  if(lastSeparator!=std::string::npos)
92  str[lastSeparator] = '\n';
93  startPos = lastSeparator+1;
94  }
95  }
96  }
97 
98  void replaceAll(std::string &str, const std::string &from, const std::string &to, const size_t maxPosition) {
99  if(from.empty())
100  return;
101  size_t start_pos = 0;
102  size_t cur_max_pos = maxPosition;
103  const size_t from_len = from.length();
104  const size_t to_len = to.length();
105  while((start_pos = str.find(from, start_pos)) != std::string::npos
106  && (cur_max_pos==std::string::npos || start_pos<cur_max_pos)) {
107  str.replace(start_pos, from_len, to);
108  start_pos += to_len; // In case 'to' contains 'from', like replacing 'x' with 'yx'
109  if(cur_max_pos!=std::string::npos)
110  cur_max_pos += to_len - from_len;
111  }
112  }
113  }
114 #endif // INCLXX_IN_GEANT4_MODE
115 
116 }
G4double z
Definition: TRTMaterials.hh:39
bool G4bool
Definition: G4Types.hh:79
G4INCL::ParticleType getType() const
Get the particle type.
void replaceAll(std::string &str, const std::string &from, const std::string &to, const size_t maxPosition=std::string::npos)
G4bool isPair(Particle const *const p1, Particle const *const p2, ParticleType t1, ParticleType t2)
double G4double
Definition: G4Types.hh:76
G4double gaussianCDF(const G4double x)
Cumulative distribution function for Gaussian.
G4int sign(const T t)
A simple sign function that allows us to port fortran code to c++ more easily.
const G4double oneOverSqrtTwo
void wrap(std::string &str, const size_t lineLength=78, const std::string &separators=" \t")