Re: [ROOT] function can not be compiled

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jun 06 2000 - 17:36:10 MEST


Thanks for sending me your data file and your macro.
In the current implementation of TF1, not more than one TF1 object can
be built from the same CINT interpreted function.
This is a small restriction since you can easily change any TF1 parameter.
I have modified your macro to create only one instance of a "RatioFit" function.
This also simplifies considerably your logic.

Rene Brun



#include "TGraphErrors.h"
#include "TROOT.h"
#include "TFile.h"
#include "TH1.h"
#include "TF1.h"
#include "TMinuit.h"
#include "iostream.h"
#include <TString.h>
TFile *f[24];

TH1F *Ratio(int det) {
  f[17] = new TFile("w4330-4669_18.root");
  int i, n;
  Float_t uu, vv, rr, rr_error;
  TH1F *ratio;
  TH1F *u = (TH1F*)f[det-1]->Get("h8010");
  TH1F *v = (TH1F*)f[det-1]->Get("h8010");
  TH1F *r = (TH1F*)f[det-1]->Get("h8010");

  TH1F *h8010 = (TH1F*)f[det-1]->Get("h8010");
  TH1F *h8020 = (TH1F*)f[det-1]->Get("h8020");
  TH1F *h8030 = (TH1F*)f[det-1]->Get("h8030");
  TH1F *h8040 = (TH1F*)f[det-1]->Get("h8040");

  n=u->GetNbinsX();
  for(i=0; i<=n; i++) {
    u->SetBinContent(i, 0); u->SetBinError(i, 0);
    v->SetBinContent(i, 0); v->SetBinError(i, 0);
    r->SetBinContent(i, 0); r->SetBinError(i, 0);
  }
  for(i=8; i<=n-8; i++) {
    uu=h8010->GetBinContent(i-4)+h8020->GetBinContent(i+4);
    vv=h8030->GetBinContent(i)+h8040->GetBinContent(i);
    u->SetBinContent(i, uu); u->SetBinError(i, (Float_t)sqrt(uu));
    v->SetBinContent(i, vv); v->SetBinError(i, (Float_t)sqrt(vv));
    if(uu+vv>0) {
      rr=(uu-vv)/(uu+vv);
      rr_error=(Float_t)sqrt((1-rr*rr)/(uu+vv));
      r->SetBinContent(i, rr); r->SetBinError(i, rr_error);
    }
  }
  ratio=(TH1F*)r->Clone();
  return ratio;
}


Double_t RatioFunc(Double_t *t, Double_t *par) {
  Double_t R;
  R=par[0]*cos(2*3.14159265*0.0002291*(1-par[1]*1.0e-6)*t[0]+par[2])+par[3];
  return R;
}

int StartTime() {
  int det=18;
  int k;
  Float_t t;
  TH1F *h;
  TF1 *fit=new TF1("RatioFit", RatioFunc, 0, 700000, 4);
  fit->SetParNames("A", "R", "'f#", "offset");
   
  h=Ratio(det);
  k=0;
//  fit=RatioFit(h, 40000, 100000.); /**************/
  for (t=40000.0; t<42000.0; t=t+545.6) {
    fit->SetRange(t, 400000);
    fit->SetParameters(0.4, 120, 0, 0);

    h->Fit("RatioFit", "R");
    if (gMinuit->fCstatu=="CONVERGED ") {
      cerr<<"here\n";
      k++;
      cerr<<"k="<<k<<'\n';
    }
  }
  delete fit;
  delete h;
  return 1;
}
Huaizhang Deng wrote:
> 
> I wrote the following program.
> 
> Double_t RatioFunc(Double_t *t, Double_t *par) {
>   Double_t R;
>   R=par[0]*cos(2*3.14159265*0.0002291*(1-par[1]*1.0e-6)*t[0]+par[2])+par[3];
>   return R;
> }
> 
> TF1* RatioFit(TH1F* h, Float_t t_start, Float_t t_end) {
> 
>   TF1 *RatioFit=new TF1("RatioFit", RatioFunc, 0, 700000, 4);
> 
>   RatioFit->SetParNames("A", "R", "'f#", "offset");
>   RatioFit->SetRange(t_start, t_end);
>   RatioFit->SetParameters(0.4, 120, 0, 0);
> 
>   h->Fit("RatioFit", "R");
>   return RatioFit;
> }
> 
> Then I tried to do
> 
> int i;
> TF1* fit;
> for(i=0; i<5; i++) fit=RatioFit(hist, t, 400000.);
> 
> After the first fit, which is o.k., it complain "Function:RatioFit cannot be
> compiled".
> However, the following program works well.
> 
> int i;
> TF* fit;
> fit=RatioFit(h, t, 40000);
> for(i=1; i<5; i++) fit=RatioFit(hist, t, 40000);
> 
> I wonder why those two programs make difference.
> 
> Huaizhang Deng



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET