Varaiable is defined in the scope

Hi,

This script is OK for me. I can run it line by lineBut I got the error message if running it in a script.

My macro is

oid testLinearFit(){
 // after create the SimulateData.root, we would like to tets the fit
  string OutFileName = DirName + "SimulatedData.root";
  TFile *fin = new TFile(OutFileName.c_str());
  if (!fin) {
    cout << " Error opening input file" << endl;
    return;
  }
  
  if(!gROOT->GetClass("TLinearFitter"))
    gSystem->Load("LibTMinuit")
  
  TLinearFitter *lf=new TLinearFitter();  // linear fitter
  cout<<"lf address is " << lf <<endl;
  
  if (!lf) { // This is where error happens
   cout <<"Cannot creat a linear fitter"<<endl;
   return; 
  }
  
  //TNtuple *t1 =  (TNtuple *) fin->Get("nt"); 
  
  Float_t AgeOfBusiness;
  Float_t BuildingCount;
  Float_t LossRatio;
 nt->SetBranchAddress("AgeOfBusiness",&AgeOfBusiness);
  nt->SetBranchAddress("BuildingCount",&BuildingCount);
  nt->SetBranchAddress("LossRatio",&LossRatio);
  
  Float_t x[2];
  
  for (Int_t i=0; i< (Int_t)nt->GetEntries();i++) {
   nt->GetEntries(i); 
   x[0]=AgeOfBusiness;
   x[1]=BuildingCount;
   lf->AddPoint(x,LossRatio);
    
  }
  
  lf->Eval();
  
  delete fin; 
  
}

Thank for your helps.

regards,

gma

Your script has a ";"missing at the end of statement

gSystem->Load("LibTMinuit")
Rene

Thanks,Brun.

I fixed the problem you mentioned. Though I still get the segmentation error. One change I did was

lf->AddPoint((Double_t*)x,(Double_t)LossRatio);

in order to use AddPoint method.

I may look at the reference again. Thanks.

regards,

gma

The error message is

Could you post the shortest possible RUNNING script (and data file) reproducing your problem?
Are you sure that your ntuple values are “float” and not “double” ?

Rene

Yes. Attached please find the script.

You need to change ten path to save the root file. Then you run SimulateData() first, then testLinearFitter().

I am using ROOT 5.22 now. Many thanks, Brun.

regards,

gma
simulation.cxx (7.29 KB)

I fixed several C++ problems in your script, see attachment.
Your script runs but you should set a formula for the LinearFitter indicating the type of expression to fit. See doc of TLinearFitter.

Rene
simulation.cxx (7.44 KB)

Many thanks, Brun. I will rewrite the test part of TLinearFit.

regards,

gma