WaitPrimitive and TF1 from fit

Hello,

I want to make a double gaussian (“gaus(0)+gaus(3)”) fit of an histogram. The idea is to use the fit panel to fit two different peaks with gaussian and then to get automatically the parameters from each fit to set them as input parameters for the double gaussian to help the fitting process.

So, I use the WaitPrimitive function to wait for two TF1 with given names (f1 and f2). The problem is that, once I fitted one of the peak with the fit panel and then right-clicked on the drawn TF1 and gave the expected name (f1) via “SetName”, nothing happens and ROOT is still waiting …

I used this technique a lot with TCutG without any problem. I guess there is something different with TF1 :frowning:

Thanks in advance.

[code]#include
#include
#include <TH1.h>
#include <TF1.h>
#include <TMath.h>
#include <TPad.h>
#include <TStyle.h>

void DoubleGaus(TH1D *hist)
{
// Hand-made fit of the first peak
cout << " Please define a TF1 named f1" << endl;
TF1 f1 = (TF1)gPad->WaitPrimitive(“f1”,“TF1”);

// Hand-made fit of the second peak
cout << " Please define a TF1 named f2" << endl;
TF1 f2 = (TF1)gPad->WaitPrimitive(“f2”,“TF1”);

// Getting the range of the histogram for the complete fit
int xmin = hist->GetXaxis()->GetXmin();
int xmax = hist->GetXaxis()->GetXmax();

// Definition of the complete fit
TF1 *fc = new TF1(“fc”,“gaus(0)+gaus(3)”,xmin,xmax);

// Feeding with the former fits to help the complete fit to converge
fc->SetParameter(0,f1->GetParameter(0));
fc->SetParameter(1,f1->GetParameter(1));
fc->SetParameter(2,f1->GetParameter(2));
fc->SetParameter(3,f2->GetParameter(0));
fc->SetParameter(4,f2->GetParameter(1));
fc->SetParameter(5,f2->GetParameter(2));

// Fitting with the complete function
hist->Fit(“fc”,"");

// Display results
f1->SetLineColor(3);
f1->SetLineStyle(9);
f1->Draw(“same”);

f2->SetLineColor(5);
f2->SetLineStyle(9);
f2->Draw(“same”);

fc->SetLineColor(1);
fc->SetLineWidth(3);
fc->Draw(“same”);
}[/code]

According to the reference manual, the type of objects with which WaitPrimitve is working, is limited to the ones from editor bar :

root.cern.ch/root/html534/TPad.h … tPrimitive

[quote]The possible values for emode are:
emode = “” (default). User will select the mode via the editor bar
= “Arc”, “Line”, “Arrow”, “Button”, “Diamond”, “Ellipse”,
= “Pad”,“pave”, “PaveLabel”,“PaveText”, “PavesText”,
= “PolyLine”, “CurlyLine”, “CurlyArc”, “Text”, “Marker”, "CutG"
if emode is specified and it is not valid, “PolyLine” is assumed.[/quote]
So the way I wanted to do it cannot work.