Help for fit panel and next proccess

Hello dear root users,
I have tried to explain what I want as follows :

I am writing a code to analyse a gamma spectrum.
I have written the first part of the code as folllows to draw the spectrum.
As you know, after drawing the spectrum we can use the fit panel.
I want to set fit limits by mause and fit the peak with gaussian function using the fit panel.
There is no any problem for this process.
But I want to use these fit limits and the fit parameters for the rest of the code.
I mean, program should save these parameters, and the rest of the code should go on using this parameters.

Thanks in advance for your help

// Row spectrum drawing
TCanvas *c = new TCanvas ("c","gamma spectrum",10,10,1600,800);

sprintf(tmp, "%s",sourcename.c_str());
TH1F *hspec = new TH1F("hspec", tmp , 16000, 0, 16000);

sprintf(tmp, "%s%s.Spe",fileway.c_str(), sourcename.c_str());
  myfile.open (tmp,ios::in);
  for (int m=0; m<23; m++) 
  {
    if(!myfile.eof()){
      myfile >>tmp;
    }
  }
  myfile >> ch;
  for (int m=0; m<ch; m++) 
  {
    if(!myfile.eof()){
      myfile >>spec[m];
	  hspec->SetBinContent(m+1, spec[m]);
    }
  }
  myfile.close();
    c->cd();
	gPad->SetLogy();
  hspec->Draw();

After clicking the “Fit” button in the “Fit Panel”, try (warning: the address of the function created by the “Fit Panel” will change each time one clicks the “Fit” button): { Double_t xmin = hspec->GetXaxis()->GetXmin(); Double_t xmax = hspec->GetXaxis()->GetXmax(); std::cout << "xmin = " << xmin << " , xmax = " << xmax << std::endl; // a "temporary function" (pointer changes when the "Fit" button is clicked) TF1 *f = hspec->GetFunction("PrevFitTMP"); // function created by Fit Panel if (f) { xmin = f->GetXmin(); // f->GetXmin(); ... or ... f->GetXaxis()->GetXmin(); xmax = f->GetXmax(); // f->GetXmax(); ... or ... f->GetXaxis()->GetXmax(); std::cout << "xmin = " << xmin << " , xmax = " << xmax << std::endl; } else std::cout << "Fit function not found." << std::endl; }

I am sorry. Maybe I explained my question not enough. What I want is that the rest of the code I have already written, should use these parameters coming from the fit panel. For example, if the minimum and maximum fit limits coming from the fit panel are xmin and xmax respectively, my code should go on using these parameters as follows. Please do not forget to read the explanation lines before the last two code lines.

Thanks in advance for your help

float spec[20000];
char tmp[100];
int ch ;
		
fstream myfile;	
	
TCanvas *c ;
c = new TCanvas ("c","test",10,10,1600,800);

TH1F *hspec = new TH1F("hspec", tmp , 16000, 0, 16000);
                                                                     // TEST
sprintf(tmp, "data_file.dat");

myfile.open (tmp,ios::in);
  for (int m=0; m<23; m++) 
  {
    if(!myfile.eof()){
      myfile >>tmp;
    }
  }
  myfile >> ch;
  for (int m=0; m<ch; m++) 
  {
    if(!myfile.eof()){
      myfile >>spec[m];
	  hspec->SetBinContent(m+1, spec[m]);
    }
  }
  myfile.close();
 	gPad->SetLogy();

 hspec->Draw();

// here is the code should wait at this point and should allow me to use the fit panel
// and after using the fit panel, manimum and maximum fit limits should be saved as for example "xmin" and "xmax"
// and the rest of the code should go on using these minimum and maximum parameters as in the lines below.


TF1 *ffit = new TF1("ffit", "([0]*exp(-0.5*(x-[2])^2/[4]^2) + [0]*[1]*exp((x-[2])/[3]/[4])*TMath::Erfc((x-[2])/[4]+0.5/[3]) + [0]*[5]*0.5*TMath::Erfc((x-[2])/[4])) + ([6]+[7]*x+[8]*x*x)", xmin, xmax);

hspec->Fit("ffit", "", "", xmin, xmax);

}

Hi,

There is no easy way of doing what you’re asking for. The fit panel has been designed for interactive use only, and it is not a modal dialog returning values, You can only access its fitting functions (and xmin/xmax values) while it is open.
So why don’t you use the xmin/xmax values from your histogram?

Cheers, Bertrand.