Non-static-const variable in array dimension

Hello co-rooters!

I am trying to create a “particlular” binning in a historgram. My code is the following

[code]void ascii2root()

TFile *f = new TFile("refXS_tot.root","RECREATE");

//~~~~~~~~~~~~~~~~~~~~~ 235U ~~~~~~~~~~~~~~~~~~~~~~//

TTree *TU = new TTree("U235_ENDFtot","data from ascii file");
Long64_t nlines = TU->ReadFile("U5_cross_section_eV.txt","E:XS");
printf(" found %lld pointsn",nlines);

// Create neutron energy binning
Int_t     N_BPDEC = 2000;// bins per decade
Int_t     E_MIN = -3;// lower energy limit (log10)
Int_t     E_MAX = 8;// upper energy limit (log10)
Int_t     ndec = E_MAX - E_MIN;//total energy range (log 10)
Int_t     nbins = (Int_t) ndec*N_BPDEC;//total numer of bins
Double_t  ebins[nbins+1];//<-------------------- Here is where I get the error
Double_t  step = (Double_t) ndec / nbins;

for(Int_t i=0; i <= nbins; i++) {
  ebins[i] = (float) pow(10., step * (Double_t) i + E_MIN);

//X-Section Histogram
//TH1F *hXSU5 = new TH1F("hXSU5","^{235}U Evaluated Cross Section; Neutron energy (eV); Cross Section (barns)",nbins,ebins);

int n = TU->Draw(“E:XS”);
TGraph *g = new TGraph(nlines,TU->GetV1(),TU->GetV2());



When I try to run this macro (using root -l ascii2root.C ) I get the following output

[quote]Processing ascii2root.C…
Error: Non-static-const variable in array dimension ascii2root.C:22:
(cint allows this only in interactive command and special form macro which
is special extension. It is not allowed in source code. Please ignore
subsequent errors.)
*** Interpreter error recovered ***
found 45433 pointsnroot [1][/quote]

It seems that I cannot define the array ebins.
Any idea how to get through this?

Thanks in advance!

The problem is exactly what the error message says: CINT does not allow to dimension array with a non static variable. ROOT 6 (Cling) is ok. With ROOT5 try to un-named you macro … or make the dimension “static” if possible.

What do you mean to un-name my macro?

How can I make the dimension static? I have no idea how to do it!


void ascii2root()

The dimension of your vector is obtained by a computation. With CINT you can only do

Double_t  ebins[100];


static N = 100;
Double_t  ebins[N];

Thank you very much for your help!
I think I will go with un-maning the macro!

Dear Olivier ,

just out of curiosity: is there any reason against using the heap in this case? I.e.:

Double_t *ebins = new Double_t[nbins+1];

// do things with ebins

delete[] ebins;


No, I just pointed you some working solutions but there is may be more.