Dear rooters,
Say that there is a signal and you need to find it’s baseline. What I thought of doing was fir the signal with a linear function. Off course I should not take into account the real signal To do that I am using this function
double exclude(Double_t *x, Double_t *par){//Exclusion fit
bool reject;
double minimum;
int minimumBin;
if (reject && x[0] > minimumBin-300 && x[0] < minimumBin+300){
TF1::RejectPoint();
return 0;
}
return par[0] + par[1]*x[0];
}
and then in my code to make the fit
minimum = h1->GetMinimum(0);
cout << "The minimum value is : " << minimum << endl;
h1->GetBinWithContent(minimum,minimumBin,0);
cout << "The minimum value is in bin # : " << minimumBin << endl;
reject = kTRUE;
TF1 *baselineFit = new TF1("baselineFit",exclude,0,channels,2);
baselineFit->SetParameters(0,0);
h1->Fit("baselineFit","WNCQ");//Don't print fit parameters, don't calculate chi-square
reject = kFALSE;
Double_t baseline = baselineFit->GetParameter(0);
TH1F *hnew = (TH1F*)h1->Clone("hnew");
hnew->Add(baselineFit, -1);//Put the baseline to zero
The point is that you I would like to be able to have this reject function in a “library”, therefore the exclusion range should be given by the user as well as the option to do or not the rejection (i.e. variable reject)
How can I do that?
Thanks in advance
The easiest way would be to add two parameters to your “exclude” function and then:
if (reject && x[0] > minimumBin+p[2] && x[0] < minimumBin+p[3])
In your main code use:
TF1 *baselineFit = new TF1(“baselineFit”, exclude, 0, channels, 4);
baselineFit->SetParNames(“constant”, “slope”, “left border”, “right border”);
baselineFit->SetParameters(0, 0);
baselineFit->FixParameter(2, -300); // left border
baselineFit->FixParameter(3, 300); // right border
[quote=“Pepe Le Pew”]The easiest way would be to add two parameters to your “exclude” function and then:
if (reject && x[0] > minimumBin+p[2] && x[0] < minimumBin+p[3])
In your main code use:
TF1 *baselineFit = new TF1(“baselineFit”, exclude, 0, channels, 4);
baselineFit->SetParameters(0, 0);
baselineFit->FixParameter(2, -300); // left border
baselineFit->FixParameter(3, 300); // right border[/quote]
I thought of changing the function to
double exclude(Double_t *x, Double_t *par){//Exclusion fit
bool reject;
if (reject && x[0] > par[2]-par[3] && x[0] < par[2]+par[3]){
TF1::RejectPoint();
return 0;
}
return par[0] + par[1]*x[0];
}
but the problem is how to have the reject as a parameter
if (p[4] && x[0] > par[2]-par[3] && x[0] < par[2]+par[3])
TF1 *baselineFit = new TF1(“baselineFit”, exclude, 0, channels, 5);
baselineFit->SetParNames(“constant”, “slope”, “minimumBin”, “width”, “reject”);
baselineFit->SetParameters(0, 0); // “constant” and "slope"
baselineFit->FixParameter(2, minimumBin); // "minimumBin"
baselineFit->FixParameter(3, 300); // "width"
baselineFit->FixParameter(4, 1); // “reject” (set 1 or 0)
[quote=“Pepe Le Pew”]if (p[4] && x[0] > par[2]-par[3] && x[0] < par[2]+par[3])
TF1 *baselineFit = new TF1(“baselineFit”, exclude, 0, channels, 5);
baselineFit->SetParNames(“constant”, “slope”, “minimumBin”, “width”, “reject”);
baselineFit->SetParameters(0, 0); // “constant” and "slope"
baselineFit->FixParameter(2, minimumBin); // "minimumBin"
baselineFit->FixParameter(3, 300); // "width"
baselineFit->FixParameter(4, 1); // “reject” (set 1 or 0)[/quote]
So reject can be interpreted 0 or 1!
I didn’t think about it!
Thanks a lot!