FitFunctions.cpp

00001 #include "FitFunctions.h"
00002 #include "TMath.h"
00003 #include <cmath>
00004 #include "CachedFunction1D.h"
00005 
00006 using namespace std;
00007 
00008 namespace SctData {
00009     
00010     //Private function to hold the cache and to make sure 
00011     //the cache is only created if necessary
00012     CachedFunction1D& getErfCache() throw() {
00013         static CachedFunction1D cachedErf(-4., 4., 0.0001, &::erf );
00014         return cachedErf;
00015     }
00016     
00017     Double_t erf(double *x, double *par) throw() {
00018     double xx, y;
00019     
00020     // if width==0, return zero:
00021     if(par[2] == 0){
00022         xx = 0.;
00023     }else{
00024         xx = ( (par[1]-x[0]) / par[2]) / 1.414213562; 
00025     }
00026     
00027     //y  = (par[0]/2.) * ( 1 - TMath::Erf(xx) );
00028     //y  = (par[0]/2.) * ( 1 - ::erf(xx) );
00029     y = (par[0]/2.) * ( 1 - getErfCache().eval(xx)) ;
00030     return y;
00031     }
00032     
00033     Double_t erfc(double *x, double *par) throw() {
00034         //static CachedFunction1D cachedErf(-4., 4., 0.0001, &::erf );
00035     double xx, y;
00036     
00037     // if width==0, return zero:
00038     if(par[2] == 0.){
00039         xx = 0.;
00040     }else{
00041         xx = ( (par[1]-x[0]) / par[2]) / 1.414213562; 
00042     }
00043     
00044     //y  = (par[0]/2.) * ( 1 + TMath::Erf(xx) );
00045     //y  = (par[0]/2.) * ( 1 + ::erf(xx) );
00046     y  = (par[0]/2.) * ( 1 + getErfCache().eval(xx));
00047     return y;
00048     }
00049     
00050     Double_t tophat(double *x, double *par) throw() {
00051         //static CachedFunction1D cachedErf(-4., 4., 0.0001, &::erf );
00052     double trailPart = 2;
00053     double leadPart = 2;
00054     
00055     if (par[2]<0) par[2]=-par[2];
00056     if (par[4]<0) par[4]=-par[4];
00057     
00058     if (par[2]>1e-100) {
00059         double rise = ( (par[1]-x[0]) / par[2]) / 1.414213562;
00060         leadPart = 1 - getErfCache().eval(rise);
00061     } else {
00062         if (x[0] < par[1]) leadPart = 0;
00063     }
00064     if (par[4]>1e-100) {
00065         double fall = ( (par[3]-x[0]) / par[4]) / 1.414213562;
00066         trailPart = 1 + getErfCache().eval(fall);
00067     } else {
00068         if (x[0] > par[3]) trailPart = 0;
00069     }   
00070         
00071     //   double y=(par[0]/4.)*( 1 - TMath::Erf(rise) ) * ( 1 + TMath::Erf(fall) );
00072     //   double y=(par[0]/4.)*( 1 - erf(rise) ) * ( 1 + erf(fall) );
00073     double y=(par[0]/4.)*leadPart*trailPart;
00074     return y;
00075     }
00076 }

Generated on Mon Feb 6 14:01:20 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6