Fitting multiple sub ranges

Hi,

I’m trying to do a fit in multiple sub ranges, and although I the fit succeeds (at least it looks nice) I get the following error:

root [1] .L plot_turnon
root [2] plot_turnon()

*ERROR 30 :
Bad numerical expression : “turnon(0)”
Error in TF1::TF1: function: total/turnon(0)+polynom2(3) has 0 parameters instead of 1
FCN=18.0048 FROM MIGRAD STATUS=CONVERGED 82 CALLS 83 TOTAL
EDM=8.71404e-15 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 2.1 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 2.15748e+01 9.53365e-02 -3.64421e-08 -6.05982e-07
2 p1 4.62781e-01 2.92781e-02 5.14287e-07 -5.98571e-06
3 p2 8.86164e-01 1.05567e-02 1.25521e-07 8.83793e-06
FCN=8.98149 FROM MIGRAD STATUS=CONVERGED 36 CALLS 37 TOTAL
EDM=4.66791e-18 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 0.0 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 7.44003e-01 6.27771e-02 1.73107e-07 -1.24675e-08
2 p1 7.50543e-03 3.00214e-03 -2.81615e-09 7.50252e-07
3 p2 -6.55469e-05 3.53638e-05 -2.39593e-11 -3.66582e-05
Error in TH1F::Fit: function is zombie
root [3] TCanvas::MakeDefCanvas: created default TCanvas with name c1_n2

The macro I’m using is attached. So what am I doing wrong? I need the resulting TF1 since it’s a turn-on curve.

Cheers,
Carsten
plot_turnon.C (1.97 KB)

your file is unreadable

Rene

Hi,

I’m not sure why there’s a problem with the attachement, so I’ve enclosed it below. I’m assuming that there’s something wrong with the definition of TF1 *total, but I can’t figure out what… Thanks in advance for any help.

Carsten

Double_t turnon(Double_t *x, Double_t *par)
{
double halfpoint = par[0];
double slope = par[1];
double plateau = par[2];

//double offset = par[3];
//double plateau = 1.0;
double offset = 0;

double pt = TMath::Max(x[0],0.000001);

double arg = 0;
arg = (pt - halfpoint)/(TMath::Sqrt(pt)slope);
double fitval = offset+0.5
plateau*(1+TMath::Erf(arg));
return fitval;
}

Double_t polynom2(Double_t *x, Double_t *par)
{
double p0 = par[0];
double p1 = par[1];
double p2 = par[2];

double pt = TMath::Max(x[0],0.000001);

double fitval = p0+p1pt+p2pt*pt;
return fitval;
}

void plot_turnon(void) {
gROOT->SetStyle(“Plain”);
gROOT->ForceStyle();
gStyle->SetOptTitle(1);
gStyle->SetOptStat(0);

sht20_seta->Rebin(2);
sht20_seta->Sumw2();
allem_seta->Rebin(2);
allem_seta->Sumw2();

TH1F sht20_res = new TH1F(“sht20_res”,"|#eta|<1.6, E_SHT20",80,0.,80.);
sht20_res->Rebin(2);
sht20_res->Divide(sht20_seta,allem_seta,1,1,“B”);

TCanvas *c1 = new TCanvas(“c1”,“c1”,700,400);
c1->Divide();
sht20_res->Draw();

TF1 *f1 = new TF1(“f1”,turnon,0,27,3);
TF1 *f2 = new TF1(“f2”,polynom2,28,60,3);
TF1 *total =new TF1(“total”,“turnon(0)+polynom2(3)”,28,60);

f1->SetParameters(14.,0.9,0.9);
f2->SetParameters(7.44003e-01,7.50543e-03,-6.55469e-05);

Double_t par[6];
sht20_res->Fit(“f1”,“Rr”);
sht20_res->Fit(“f2”,“R+”);
f1->GetParameters(&par[0]);
f2->GetParameters(&par[0]);

total->SetParameters(par);
sht20_res->Fit(total,“R+”);

}

Carsten,

Please send a script ready to be executed.
In your file, sht20_meta is not defined.

Rene

Hi Rene,

I’ve attached both the input file “presel.root” and the macro as an attachment. Just in case I’ve also put everything in my public_html directory:

james.physik.uni-freiburg.de/~noeding/root

I’m using root v4.00/08, doing the following steps:

root presel.root
.L plot_turnon.C
plot_turnon()

Cheers,
Carsten
plot_turnon.C (1.5 KB)
presel.root (26.8 KB)

In your example, you fit “total” in the same sub-range as “f2”.
The fit will not proceed as it cannot find any improvement to
the parameters. My guess is that you want to extend the range
of the fit.
Also have a look at the documentation of TF1. You can only add
expressions of type A or/and B, not type C.
Proceed exactly as we recommend in the tutorial FittingDemo.C.
See your macro modified in the attachement.

Rene
plot_turnon.C (1.83 KB)