New Math Developm ents David’s W ork at CERN ( so far…) 1. TF1 methods delegation 2. TMath reimplementation 3. Hierarchy Restructure 4. Documentation and Testing 5. Genetic Minimizer 6. Future Work
TF1 : 1 -Dim function class TF1 * f a1 = new TF1( " f a1" , " si n( x) / x" , 0, 10) ; Some TF1 methods re ‐ implemented: • GetX() • GetMinimum() & GetMinimumX() • GetMaximum() & GetMaximumX() • Integral(), IntegralFast() & IntegralMultiple() • Derivate(), Derivate2() & Derivate3() • MinimBrent() & MinimStep()
TF1 : New Function I m plem entation TF1 Method New Class now uses GetX() BrentRootFinder GetMinimum(), GetMinimumX() now uses BrentMinimizer GetMaximum(), GetMaximumX() now uses MinimBrent(),MinimStep() BrentMethods now uses Derivate(),Derivate2(), Derivate3() RichardsonDerivator now uses GaussIntegrator Integral() now uses GaussLegendreIntegrator IntegralFast() now uses IntegralMultiple() AdaptiveIntegratorMultiDim
Exam ple of New I m plem entation Doubl e_t TF1: : Der i vat i ve( Doubl e_t x, Doubl e_t * par am s, Doubl e_t eps) const { RO O T: : M at h: : W r appedTF1 wf 1( * ( const _cast <TF1 * > ( t hi s) ) ) ; Wrap the function i f ( par am s ) wf 1. Set Par am et er s( par am s ) ; Choose the method RO O T: : M at h: : Ri char dsonDer i vat or Ri char dsonDer i vat or r d; doubl e xm i n, xm ax; G et Range( xm i n, xm ax) ; Set the parameters r d. Set Funct i on( wf 1, xm i n, xm ax) ; r d. Set Rel Tol er ance( eps) ; Calculate the derivative r et ur n r d. Der i vat i ve1( x) ; } Inconvenient: • There is a small time penalty with this new method. Advantages: • Can easily change the method used in the calculation. • Easy to implement new methods. � Derivate from the new Interfaces. • Better maintainability.
Using the Plug-in Manager to get a VirtualI ntegrator Code example with the plug-in manager doubl e f 2( const doubl e * x) { r et ur n x[ 0] + x[ 1] ; Function wrapped } 3 RO O T: : M at h: : W r appedM ul t i Funct i on<> wf ( f 2, 2) ; doubl e a[ 2] = { 0, 0} ; doubl e b[ 2] = { 1, 1} ; RO O T: : M at h: : I nt egr at or M ul t i Di m i g( RO O T: : M at h: : I nt egr at i onM ul t i Di m : : ADAPTI VE) ; AdaptiveIntegratorMultiDim i g. Set Funct i on( wf ) ; doubl e val = i g. I nt egr al ( a, b) ; st d: : cout << " i nt egr al r esul t i s " << val << st d: : endl ; RO O T: : M at h: : I nt egr at or M ul t i Di m Vegas Multidimensional i g2( RO O T: : M at h: : I nt egr at i onM ul t i Di m : : VEG AS) ; i g2. Set Funct i on( wf ) ; Integrator val = i g2. I nt egr al ( a, b) ; st d: : cout << " i nt egr al r esul t i s " << val << st d: : endl ;
TMath Nam espace Lots of code duplication. • Standard C/C++ Library • In ROOT::Math namespace (both MathCore and MathMore) Old interfaces. Look for best performance and maintainability Tests for: • Backward compatibility • Stress and Performance • Compiler and OS compatibility
TMath method STD method GSL method Perform ance Tim es
Reim plem ented Methods Templates Iterators STD Loc{Min,Max} X X X {Min,Max}Element X X Mean X X GeomMean X X RMS X X Median X X KOrdStat X BinarySearch X X X Sort X X X Norm X NormCross X Cross X IsInside X Normal2Plane X
Exam ple of New Tem plate Method Long64_t LocM i n( Long64_t n, const Shor t _t * a) ; Long64_t LocM i n( Long64_t n, const I nt _t * a) ; Long64_t LocM i n( Long64_t n, const Fl oat _t * a) ; Long64_t LocM i n( Long64_t n, const Doubl e_t * a) ; Long64_t LocM i n( Long64_t n, const Long_t * a) ; Long64_t LocM i n( Long64_t n, const Long64_t * a) ; t em pl at e <t ypenam e T> Long64_t LocM i n( Long64_t n, const T * a) ; t em pl at e <t ypenam e I t er at or > I t er at or LocM i n( I t er at or f i r st , I t er at or l ast ) ;
Tim e Perform ances for Real Time/Call (micro seconds) Mac OSX MathDev Branch ROOT 5.18 Loc{Min,Max} 317.703 84.9406 Sort 10589.1 22712.4 BinarySearch 0.0665884 0.0788558 Total Test Time 4.4 7.34 Time/Call (micro seconds) LXPlus (64 Bits) MathDev Branch ROOT 5.18 Loc{Min,Max} 398.70 129.113 Sort 12121.8 25815.9 BinarySearch 0.1 0.098 Total Test Time 7.56 7.85
Tim e Perform ances for Real 2 Time/Call (micro seconds) Linux (32 bits) MathDev Branch ROOT 5.18 Loc{Min,Max} 412.82 623.95 Sort 33780.3 70364.7 BinarySearch 0.21 0.49 Total Test Time 11.35 17.88 LocMin and LocMax were not finally replaced. As well as TMath::Permute. Also TMath::BinarySearch returned inconsistent results with repeated elements.
Special Functions • ROOT::Math proved to implement better the functionality • These changes produced secondary effects (like the TMath::Prob function!) TMath::Erf ROOT::Math::erf TMath::Erfc ROOT::Math::erfc TMath::Gamma(x) ROOT::Math::tgamma(x) TMath::Gamma(a,b) ROOT::Math::inc_gamma(a,b) TMath::LnGamma ROOT::Math::lgamma TMath::Beta ROOT::Math::beta TMath::BetaIncomplete ROOT::Math::inc_beta
Hierarchy Restructure Hierarchy restructure: • Integrate TMath into the MathCore library • Integration of Complex and random numbers into MathCore. o Mayor ROOT libraries depend now on MathCore (i.e. Hist). • MathCore is now a ‘must be built’ library. • Separate GenVector from MathCore. • Added classes for basic numerical algorithms. o Added interfaces for using the plug ‐ in manager. • Current size in the order of 1.5 ‐ 2 MB.
Docum entation and Testing Documentation: • For all the new methods and classes. o Compatible with Doxygen and the ROOT documentation system. • TMath new user’s guide: o Expanded with the new interfaces. o Linked with tutorials in ROOTSYS. Script to test any test directory plus roottest: • Make the tests to behave uniformly: o Return a value indicating whether the test worked fine o Compare to a template output. • Make the tests available to run in batch mode: o Force the test to be in compile mode o Make the test work with the option of showing no graphics
Genetic Minim izer Implement a GeneticMinimizer: • Derivates from ROOT::Math::Miminizer. • Uses the algorithms from TMVA. • Creation of a new package. Example of Use M i nui t 2 wi t h i ni t i al val ues ( 0, 0) M i ni m um Xs f ound ( 2. 00421 , 3. 83938) G enet i c M i ni m i zer ( bet ween 0- 10) M i ni m um Xs f ound ( 6. 84698, 2. 25318) M i nui t 2 wi t h i ni t i al val ues( 6. 84698 2. 25318) M i ni m um Xs f ound ( 6. 97915 , 1. 997)
Future W ork Design proposals for TF1 and THX: • Correct the use of const methods from TF1. • Code improvement in THX: Encapsulate code (projection, drawer...) . . . case 5: / / " yx“ i f ( i zbi n < i zm i n | | i zbi n > i zm ax) cont i nue; i f ( cont ) p2- >Fi l l ( f Xaxi s. G et Bi nCent er ( i xbi n) , f Yaxi s. G et Bi nCent er ( i ybi n) , f Zaxi s. G et Bi nCent er ( i zbi n) , cont ) ; br eak; case 6: / / " xz" i f ( i ybi n < i ym i n | | i ybi n > i ym ax) cont i nue; i f ( cont ) p2- >Fi l l ( f Zaxi s. G et Bi nCent er ( i zbi n) , f Xaxi s. G et Bi nCent er ( i xbi n) , f Yaxi s. G et Bi nCent er ( i zbi n) , cont ) ; br eak; case 7: / / " zx” i f ( i ybi n < i ym i n | | i ybi n > i ym ax) cont i nue; i f ( cont ) p2- >Fi l l ( f Xaxi s. G et Bi nCent er ( i xbi n) , f Zaxi s. G et Bi nCent er ( i zbi n) , f Yaxi s. G et Bi nCent er ( i zbi n) , cont ) ; br eak; . . . Create an User’s guide for the new classes added in MathCore. http://cern.ch/dmgonzal
Recommend
More recommend