34 #define INCLXX_IN_GEANT4_MODE 1
55 namespace RootFinder {
63 const G4int maxIterations=50;
75 std::pair<G4double,G4double> bracketRoot(RootFunctor
const *
const f,
G4double x0) {
88 return std::make_pair(x0,x1);
90 const G4double scaleFactorMinus1 = 1./scaleFactor;
94 if(iterations > maxIterations) {
95 INCL_DEBUG(
"Could not bracket the root." <<
'\n');
103 x0 *= scaleFactorMinus1;
111 return std::make_pair(x0,oldx0);
113 return std::make_pair(oldx1,x1);
121 if( std::abs(y0) < toleranceY ) {
126 std::pair<G4double,G4double> bracket = bracketRoot(f,x0);
133 if(std::abs(y_at_zero)<=toleranceY) {
137 INCL_DEBUG(
"Root-finding algorithm could not bracket the root." <<
'\n');
153 G4int lastUpdated = 0;
155 for(
G4int iterations=0; std::abs(y) > toleranceY; iterations++) {
157 if(iterations > maxIterations) {
158 INCL_DEBUG(
"Root-finding algorithm did not converge." <<
'\n');
164 x = (y1*x2-y2*
x1)/(y1-y2);
173 if(lastUpdated==-1) y2 *= 0.5;
178 if(lastUpdated==1) y1 *= 0.5;
virtual void cleanUp(const G4bool success) const =0
Static root-finder algorithm.
Float_t y1[n_points_granero]
Float_t x1[n_points_granero]
Float_t y2[n_points_geant4]
Solution solve(RootFunctor const *const f, const G4double x0)
Numerically solve a one-dimensional equation.
Float_t x2[n_points_geant4]