Hello everyone,

I want to define Moyal distribution as a user defined function using ROOT. Can someone help me?

I attached the function definition also one can find the definition from ,

stat.rice.edu/~dobelman/text … ndbook.pdf

Page number is 91.

Thank you very much.

Best

Something like (not tested) should work

[code]Double_t f_Moyal(Double_t *x, Double_t *par) {*

return 1./TMath::Sqrt(TMath::TwoPi()) * TMath::Exp(-0.5(x[0]+TMath::Exp(-x[0])));

}

Double_t g_Moyal(Double_t *x, Double_t *par) {

return 1./par[0]*f_Moyal((x[0]-par[1])/par[0]);

}

int main() {

TF1 *f = new TF1(“f”,g_Moyal,-5,10);

f->Draw();

}[/code]

Thank you very much. It gave me this error

Error in TFormula::Compile: Bad numerical expression : "g_Moyal"

Error in TF1::TF1: function: f/g_Moyal has 0 parameters instead of 1

Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1

Warning in TCanvas::ResizePad: c1 height changed from 64000 to 10

Error in TGaxis::PaintAxis: length of axis is 0

root [1] Warning in TCanvas::ResizePad: c1 height changed from 64000 to 10

Warning in TCanvas::ResizePad: c1 height changed from 64000 to 10

Do you know why it is?

I guess the reason is missing parameter. I changed abit like,

int fit() {

TCanvas *c1 = new TCanvas(“c1”, “asdf”, 1800, 800);

TF1 *f = new TF1(“f”,g_Moyal,-5,10,4);

f->SetParameter(0,140.0);

f->Draw();

}

However afterwards it gave this error,

Error: Function f_Moyal((x[0]-par[1])/par[0]) is not defined in current scope fit.C:344:

*** Interpreter error recovered ***

root [1] Error: Function f_Moyal((x[0]-par[1])/par[0]) is not defined in current scope fit.C:344:

,

Error: Symbol , is not defined in current scope (tmpfile):1:

*** Interpreter error recovered ***

Hope you can help me

Hi,

```
Double_t f_Moyal(Double_t *xx, Double_t *par) {
auto x = *xx;
auto theexp = TMath::Exp(-0.5*(x+TMath::Exp(-x)));
return theexp / TMath::Sqrt(TMath::TwoPi());
}
Double_t g_Moyal(Double_t *x, Double_t *par) {
double xx = (x[0]-par[0])/par[1];
return f_Moyal(&xx, nullptr)/par[1];
}
void moyal() {
auto f = new TF1("f",g_Moyal,-5,10,2);
f->SetParameters(1,1);
auto c = new TCanvas();
f->Draw();
}
```

Cheers,

Danilo

Thank you so much for your prompt answer and help me in this matter.

Cheers