Ignore:
Timestamp:
11/18/05 17:15:30 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/BaseIncl.h

    r7181 r7409  
    11#ifndef __CINT__
    22
     3#include <TArrayD.h>
    34#include <TVector3.h>
    45
    5 /*
    6 #include <fstream.h>
    7 
    8 #include <TFile.h>
    9 #include <TTree.h>
    10 
    11 #include <TGListBox.h>
    12 */
    13 
    146#endif // __CINT__
  • trunk/MagicSoft/Mars/mbase/MLogHtml.cc

    r6870 r7409  
    3030//////////////////////////////////////////////////////////////////////////////
    3131#include "MLogHtml.h"
     32
     33#include <string.h>  // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
     34#include <errno.h>   // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
    3235
    3336#include <fstream>  // ofstream
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r7386 r7409  
    3636#endif
    3737
     38#ifndef ROOT_TArrayD
     39#include <TArrayD.h>
     40#endif
    3841// --------------------------------------------------------------------------
    3942//
     
    248251    return InterpolParabLin(vx0, vy, TMath::Cos(x));
    249252}
     253
     254// --------------------------------------------------------------------------
     255//
     256// Analytically calculated result of a least square fit of:
     257//    y = A*e^(B*x)
     258// Equal weights
     259//
     260// It returns TArrayD(2) = { A, B };
     261//
     262// see: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html
     263//
     264TArrayD MMath::LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y)
     265{
     266    Double_t sumxsqy  = 0;
     267    Double_t sumylny  = 0;
     268    Double_t sumxy    = 0;
     269    Double_t sumy     = 0;
     270    Double_t sumxylny = 0;
     271    for (int i=0; i<n; i++)
     272    {
     273        sumylny  += y[i]*TMath::Log(y[i]);
     274        sumxy    += x[i]*y[i];
     275        sumxsqy  += x[i]*x[i]*y[i];
     276        sumxylny += x[i]*y[i]*TMath::Log(y[i]);
     277        sumy     += y[i];
     278    }
     279
     280    const Double_t dev = sumy*sumxsqy - sumxy*sumxy;
     281
     282    const Double_t a = (sumxsqy*sumylny - sumxy*sumxylny)/dev;
     283    const Double_t b = (sumy*sumxylny - sumxy*sumylny)/dev;
     284
     285    TArrayD rc(2);
     286    rc[0] = TMath::Exp(a);
     287    rc[1] = b;
     288    return rc;
     289}
     290
     291// --------------------------------------------------------------------------
     292//
     293// Analytically calculated result of a least square fit of:
     294//    y = A*e^(B*x)
     295// Greater weights to smaller values
     296//
     297// It returns TArrayD(2) = { A, B };
     298//
     299// see: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html
     300//
     301TArrayD MMath::LeastSqFitExp(Int_t n, Double_t *x, Double_t *y)
     302{
     303    // -------- Greater weights to smaller values ---------
     304    Double_t sumlny  = 0;
     305    Double_t sumxlny = 0;
     306    Double_t sumxsq  = 0;
     307    Double_t sumx    = 0;
     308    for (int i=0; i<n; i++)
     309    {
     310        sumlny  += TMath::Log(y[i]);
     311        sumxlny += x[i]*TMath::Log(y[i]);
     312
     313        sumxsq  += x[i]*x[i];
     314        sumx    += x[i];
     315    }
     316
     317    const Double_t dev = n*sumxsq-sumx*sumx;
     318
     319    const Double_t a = (sumlny*sumxsq - sumx*sumxlny)/dev;
     320    const Double_t b = (n*sumxlny - sumx*sumlny)/dev;
     321
     322    TArrayD rc(2);
     323    rc[0] = TMath::Exp(a);
     324    rc[1] = b;
     325    return rc;
     326}
     327
     328// --------------------------------------------------------------------------
     329//
     330// Analytically calculated result of a least square fit of:
     331//    y = A+B*ln(x)
     332//
     333// It returns TArrayD(2) = { A, B };
     334//
     335// see: http://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
     336//
     337TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y)
     338{
     339    Double_t sumylnx  = 0;
     340    Double_t sumy     = 0;
     341    Double_t sumlnx   = 0;
     342    Double_t sumlnxsq = 0;
     343    for (int i=0; i<n; i++)
     344    {
     345        sumylnx  += y[i]*TMath::Log(x[i]);
     346        sumy     += y[i];
     347        sumlnx   += TMath::Log(x[i]);
     348        sumlnxsq += TMath::Log(x[i])*TMath::Log(x[i]);
     349    }
     350
     351    const Double_t b = (n*sumylnx-sumy*sumlnx)/(n*sumlnxsq-sumlnx*sumlnx);
     352    const Double_t a = (sumy-b*sumlnx)/n;
     353
     354    TArrayD rc(2);
     355    rc[0] = a;
     356    rc[1] = b;
     357    return rc;
     358}
     359
     360// --------------------------------------------------------------------------
     361//
     362// Analytically calculated result of a least square fit of:
     363//    y = A*x^B
     364//
     365// It returns TArrayD(2) = { A, B };
     366//
     367// see: http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
     368//
     369TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y)
     370{
     371    Double_t sumlnxlny  = 0;
     372    Double_t sumlnx   = 0;
     373    Double_t sumlny    = 0;
     374    Double_t sumlnxsq   = 0;
     375    for (int i=0; i<n; i++)
     376    {
     377        sumlnxlny  += TMath::Log(x[i])*TMath::Log(y[i]);
     378        sumlnx     += TMath::Log(x[i]);
     379        sumlny     += TMath::Log(y[i]);
     380        sumlnxsq   += TMath::Log(x[i])*TMath::Log(x[i]);
     381    }
     382
     383    const Double_t b = (n*sumlnxlny-sumlnx*sumlny)/(n*sumlnxsq-sumlnx*sumlnx);
     384    const Double_t a = (sumlny-b*sumlnx)/n;
     385
     386    TArrayD rc(2);
     387    rc[0] = TMath::Exp(a);
     388    rc[1] = b;
     389    return rc;
     390}
  • trunk/MagicSoft/Mars/mbase/MMath.h

    r7384 r7409  
    77
    88class TVector3;
     9class TArrayD;
    910
    1011namespace MMath
     
    3132    Double_t InterpolParabCos(const TVector3 &vx, const TVector3 &vy, Double_t x);
    3233
     34    TArrayD LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y);
     35    TArrayD LeastSqFitExp(Int_t n, Double_t *x, Double_t *y);
     36    TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y);
     37    TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y);
     38
    3339    inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; }
    3440}
Note: See TracChangeset for help on using the changeset viewer.