]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TUHKMgen/UHKM/EquationSolver.h
New binning for Mass e+e- histos
[u/mrichter/AliRoot.git] / TUHKMgen / UHKM / EquationSolver.h
1 //////////////////////////////////////////////////////////////////////////////////       
2 //                                                                              //
3 //        Nikolai Amelin, Ludmila Malinina, Timur Pocheptsov (C) JINR/Dubna     //
4 //      amelin@sunhe.jinr.ru, malinina@sunhe.jinr.ru, pocheptsov@sunhe.jinr.ru  //
5 //                           November. 2, 2005                                  //
6 //                                                                              //
7 //           This equation solver class is taken from GEANT4 and modified!!     //
8 //////////////////////////////////////////////////////////////////////////////////
9 #ifndef EQUATIONSOLVER_H
10 #define EQUATIONSOLVER_H
11 #include <Rtypes.h>
12
13 #define DefaultTolerance 5.0e-14
14
15 template <class Function> 
16 class EquationSolver {
17
18  public:
19   enum {kDefaultMaxIter = 100};  
20   // default constructor
21   EquationSolver() : fMaxIter(kDefaultMaxIter), fTolerance(DefaultTolerance),
22     fA(0.0), fB(0.0), fRoot(0.0) {};
23         
24   EquationSolver(const Int_t iterations, const Double_t tol) :
25     fMaxIter(iterations), fTolerance(tol),
26     fA(0.0), fB(0.0), fRoot(0.0) {};
27
28   // copy constructor   
29   EquationSolver(const EquationSolver & right);
30
31   // destructor
32   ~EquationSolver() {};
33         
34   // operators
35   EquationSolver & operator=(const EquationSolver & right);
36   Bool_t operator==(const EquationSolver & right) const;
37   Bool_t operator!=(const EquationSolver & right) const;
38                 
39   Int_t GetMaxIterations(void) const {return fMaxIter;}
40   void SetMaxIterations(const Int_t iterations) {fMaxIter=iterations;}
41         
42   Double_t GetTolerance(void) const {return fTolerance;}
43   void SetTolerance(const Double_t epsilon) {fTolerance = epsilon;}
44   
45   Double_t GetIntervalLowerLimit(void) const {return fA;}
46   Double_t GetIntervalUpperLimit(void) const {return fB;}
47         
48   void SetIntervalLimits(const Double_t Limit1, const Double_t Limit2);
49
50   Double_t GetRoot(void) const {return fRoot;}  
51         
52   // Calculates the root by the Brent's method
53   Bool_t Brent(Function& theFunction);
54
55  private:
56   Int_t fMaxIter;         // Maximum number of iterations
57   Double_t fTolerance;    // tolerance (precision)
58   Double_t fA;            // interval limits [a,b] which should bracket the root
59   Double_t fB;            // interval limits [a,b] which should bracket the root
60   Double_t fRoot;         // the equation's root
61 };
62
63 #include "EquationSolver.icc"
64
65 #endif