Fitting Spline functions but get NaN value

Dear Experts

I want to read some values from several files, and fit the points to several spline functions, but when I check the output file, only the points from the first input file were successfully fitted, others give NaN value when I use Eval(). Here are codes:

// includes
static constexpr double Pi = 3.1415926535897932384626433832795;

int main(){

  TFile* f_out = new TFile("fx2t.root", "RECREATE");
  TSpline3* spline[4][72];
  for(int i=0; i<4; i++){

    double dis, time, phi, l[72];
    TGraph* g[72];
    for(int j=0;j<72;j++){
      g[j] = new TGraph();
    }

    TFile* f = new TFile(Form("x2t_beta%d_1.00T.root", i));
    if(!f) std::cout<<"cannot find input file"<<std::endl;
    TTree* t = (TTree*)f->Get("t");
    t->SetBranchAddress("driftDistance", &dis);
    t->SetBranchAddress("t1", &time);
    t->SetBranchAddress("phi", &phi);

    f->cd();

    for(int j=0; j<t->GetEntries(); j++){
      t->GetEntry(j);
      for(int k=0; k<72; k++){
        if(phi==k*Pi*2/72){
          g[k]->SetPoint(l[k], dis,time);
          l[k]++;
        }
      }
    }


    f_out->cd();
    for(int k=0; k<72; k++){
      spline[i][k] = new TSpline3(Form("spline_beta%d_phi%d", i, k), g[k]);
      spline[i][k]->Write(Form("spline_beta%d_phi%d", i, k));
    }
    f->Close();
  }
  f_out->Close();
  return 0;
}

and the output file contains all 4*72=288 spline functions.


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/02
Platform: CentOS
Compiler: GCC


You probably need to initialize all elements “l[...] = 0”, e.g.:
int l[72] = {}; // use an empty initializer list

Actually, the 'l" array seems to be redundant. You can simply use:
g[k]->SetPoint(g[k]->GetN(), dis, time); // append a new point

The condition “phi==k*Pi*2/72” looks suspicious. Try, e.g.:
TMath::Abs(phi - k * TMath::TwoPi() / 72.) < 1.e-11

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.