33 #define INCLXX_IN_GEANT4_MODE 1
54 std::pair<G4double,G4double> RootFinder::solution;
56 const G4double RootFinder::toleranceY = 1.e-4;
61 if( std::abs(y0) < toleranceY ) {
62 solution = std::make_pair(x0,y0);
67 std::pair<G4double,G4double> bracket = bracketRoot(f,x0);
74 if(std::abs(y_at_zero)<=toleranceY) {
76 solution = std::make_pair(0.,y_at_zero);
79 WARN(
"Root-finding algorithm could not bracket the root." << std::endl);
95 G4int lastUpdated = 0;
97 for(
G4int iterations=0; std::abs(y) > toleranceY; iterations++) {
99 if(iterations > maxIterations) {
100 WARN(
"Root-finding algorithm did not converge." << std::endl);
106 x = (y1*x2-y2*
x1)/(y1-y2);
115 if(lastUpdated==-1) y2 *= 0.5;
120 if(lastUpdated==1) y1 *= 0.5;
129 solution = std::make_pair(x,y);
134 std::pair<G4double,G4double> RootFinder::bracketRoot(
RootFunctor const *
const f,
G4double x0) {
147 return std::make_pair(x0,x1);
149 const G4double scaleFactorMinus1 = 1./scaleFactor;
153 if(iterations > maxIterations) {
154 DEBUG(
"Could not bracket the root." << std::endl);
162 x0 *= scaleFactorMinus1;
170 return std::make_pair(x0,oldx0);
172 return std::make_pair(oldx1,x1);