[ROOT] function from a user defined library

From: Hermine Woehri (Hermine.Woehri@cern.ch)
Date: Mon Jun 17 2002 - 18:20:12 MEST


Hello,

I want to use a function from a user defined library, which I load
whenever I start a root session (this function is a convolution of a
Landau with a Gauss).

When I draw this function or add a print-out statement if this function is
known, there is no problem: I indeed see the function drawn on a canvas.
However, when I try to define a new function
using this predefined function, 
  TF1 *fFit = new TF1("fFit", "fFitLandGaus", 0, 20,4);
or
  TF1 *fFit = new TF1("fFit", fFitLandGaus, 0, 20,4);

I get the following error message:

   Function:fFit cannot be compiled	

I have attached a few lines of code, where you can follow up the steps,
that I want to do.

The final command that I want to use is:

   TF1 *fFit = new TF1("fFit", "fFit+f1", 0, 20,7);

I saw that it is possible to "add" two predefined function on the webpage
for the TF1 - class (http://root.cern.ch/root/html302/TF1.html)


  Example:
{
  TF1 *fcos = new TF1 ("fcos", "[0]*cos(x)", 0., 10.);
  fcos->SetParNames( "cos");
  fcos->SetParameter( 0, 1.1);

  TF1 *fsin = new TF1 ("fsin", "[0]*sin(x)", 0., 10.);
  fsin->SetParNames( "sin");
  fsin->SetParameter( 0, 2.1);

  TF1 *fsincos = new TF1 ("fsc", "fcos+fsin");
}


I hope it is a trivial problem to solve,

Thank you,

Hermine Woehri



+------------------------------------------------------+
|Hermine Katharina Woehri	hermine.woehri@cern.ch |
+------------------------------------------------------|
|EP Division 		       office:  +41 22 767 9408|	
|CERN			       mobile:  +41 79 201 0715| 
|CH-1211 Geneve 23	       fax:     +41 22 767 9780| 
|Switzerland                   private: +33 450 42 4415| 
+------------------------------------------------------+


#include <iostream.h>
#include <math.h>

TF1 *fFitLandGaus;

static Double_t FitLandGaus(Double_t *x, Double_t *par)
{
   double fun,xp[5];

   if ( fabs(par[3])<=1.e-3 ) {
      double yy  = ( *x - par[1] )/par[0];
      double lnd = (yy<-10. ? 0. : DenLandau(&yy))/par[0];
      return lnd;
   }
   xp[0] = par[0];
   xp[1] = par[1]-0.2225*par[0];
   xp[2] = par[2];
   xp[3] = fabs(par[3]);
   xp[4] = *x;
   double l1 =  (*x) -15.*xp[3];
   double l2 =  (*x) +15.*xp[3];
   fun = Gauss(LGconvl,xp,l1,l2,0.00001*fabs(xp[3]));

   return par[2]*fun/(par[3]*2.506628275);
}


Int_t InitFunctions(Int_t x){

  fFitLandGaus = new TF1("fFitLandGaus",FitLandGaus,0.,25.,4);
  fFitLandGaus ->SetParameters(0.25,3.5,1000.,0.1);
  fFitLandGaus ->SetParName(0,"Scale");
  fFitLandGaus ->SetParName(1,"Peak");
  fFitLandGaus ->SetParName(2,"Norm");
  fFitLandGaus ->SetParName(3,"Sigma");

}


static Double_t DenLandau( Double_t *x, Double_t *par=0)
{
    static Double_t p1[5] = { .4259894875,-.124976255,.039842437,
            -.006298287635,.001511162253 };
    static Double_t q5[5] = { 1.,156.9424537,3745.310488,9834.698876,
            66924.28357 };
    static Double_t p6[5] = { 1.000827619,664.9143136,62972.92665,
            475554.6998,-5743609.109 };
    static Double_t q6[5] = { 1.,651.4101098,56974.73333,165917.4725,
            -2815759.939 };
    static Double_t a1[3] = { .04166666667,-.01996527778,.02709538966 };
    static Double_t a2[2] = { -1.84556867,-4.284640743 };
    static Double_t q1[5] = { 1.,-.3388260629,.09594393323,-.01608042283,
            .003778942063 };
    static Double_t p2[5] = { .1788541609,.1173957403,.01488850518,
            -.001394989411,1.283617211e-4 };
    static Double_t q2[5] = { 1.,.7428795082,.3153932961,.06694219548,
            .008790609714 };
    static Double_t p3[5] = { .1788544503,.09359161662,.006325387654,
            6.611667319e-5,-2.031049101e-6 };
    static Double_t q3[5] = { 1.,.6097809921,.2560616665,.04746722384,
            .006957301675 };
    static Double_t p4[5] = { .9874054407,118.6723273,849.279436,
            -743.7792444,427.0262186 };
    static Double_t q4[5] = { 1.,106.8615961,337.6496214,2016.712389,
            1597.063511 };
    static Double_t p5[5] = { 1.003675074,167.5702434,4789.711289,
            21217.86767,-22324.9491 };

    /* System generated locals */
    Double_t ret_val, d__1;

    /* Local variables */
    static Double_t u, v;

    v = *x;
    if (v < -5.5) {
        u = exp(v + 1.);
        ret_val = exp(-1 / u) / sqrt(u) * .3989422803 * ((a1[0] + (a1[
                1] + a1[2] * u) * u) * u + 1);
    } else if (v < -1.) {
        u = exp(-v - 1);
        ret_val = exp(-u) * sqrt(u) * (p1[0] + (p1[1] + (p1[2] + (p1[3] + p1[
                4] * v) * v) * v) * v) / (q1[0] + (q1[1] + (q1[2] + (q1[3] + 
                q1[4] * v) * v) * v) * v);
    } else if (v < 1.) {
        ret_val = (p2[0] + (p2[1] + (p2[2] + (p2[3] + p2[4] * v) * v) * v) * 
                v) / (q2[0] + (q2[1] + (q2[2] + (q2[3] + q2[4] * v) * v) * v) 
                * v);
    } else if (v < 5.) {
        ret_val = (p3[0] + (p3[1] + (p3[2] + (p3[3] + p3[4] * v) * v) * v) * 
                v) / (q3[0] + (q3[1] + (q3[2] + (q3[3] + q3[4] * v) * v) * v) 
                * v);
    } else if (v < 12.) {
        u = 1 / v;
/* Computing 2nd power */
        d__1 = u;
        ret_val = d__1 * d__1 * (p4[0] + (p4[1] + (p4[2] + (p4[3] + p4[4] * u)
                 * u) * u) * u) / (q4[0] + (q4[1] + (q4[2] + (q4[3] + q4[4] * 
                u) * u) * u) * u);
    } else if (v < 50.) {
        u = 1 / v;
/* Computing 2nd power */
        d__1 = u;
        ret_val = d__1 * d__1 * (p5[0] + (p5[1] + (p5[2] + (p5[3] + p5[4] * u)
                 * u) * u) * u) / (q5[0] + (q5[1] + (q5[2] + (q5[3] + q5[4] * 
                u) * u) * u) * u);
    } else if (v < 300.) {
        u = 1 / v;
/* Computing 2nd power */
        d__1 = u;
        ret_val = d__1 * d__1 * (p6[0] + (p6[1] + (p6[2] + (p6[3] + p6[4] * u)
                 * u) * u) * u) / (q6[0] + (q6[1] + (q6[2] + (q6[3] + q6[4] * 
                u) * u) * u) * u);
    } else {
        u = 1 / (v - v * log(v) / (v + 1));
/* Computing 2nd power */
        d__1 = u;
        ret_val = d__1 * d__1 * ((a2[0] + a2[1] * u) * u + 1);
    }
    return ret_val;
}






void tryFit(){


}



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:57 MET