Hi,
I would like to rescale the x axis of a histogram (essentially to convert a histogram with units GeV^2 to MeV^2, by rescaling the x axis by 10^6). The code posted at the end of
by Kara looks like it should do exactly what I want:
int nbins = tdataall->GetXaxis()->GetNbins();
cout<<" nbins="<<nbins<<endl;
float new_bins[nbins+1];
for(int i=0; i <= nbins; i++){
double old = tdataall->GetBinLowEdge(i+1);
new_bins[i]=1.E6*old;
}
tdataall->SetBins(nbins,new_bins);
However, it does not seem to work in ROOT6.06./08, producing multiple errors. To isolate things, if I just use the array definition, I get the following error:
Processing all.C…
/Users/sklein/twopifit/./all.C:476:8: error: variable length array declaration not allowed at file scope
float new_bins[nbins+1];
If I replace this line with:
float new_bins[61]; - not what I want, but OK for debugging purposes, then I get more errors:
Processing all.C…
/Users/sklein/twopifit/./all.C:483:11: error: no matching member function for call to ‘SetBins’
tdataall->SetBins(nbins,new_bins);
/opt/local/libexec/root6/include/root/TH1.h:365:21: note: candidate function not viable: no known conversion from
'float [61]' to 'const Double_t *' (aka 'const double *') for 2nd argument
virtual void SetBins(Int_t nx, const Double_t *xBins);
^
/opt/local/libexec/root6/include/root/TH1.h:364:21: note: candidate function not viable: requires 3 arguments, but 2 were
provided
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax);
^
/opt/local/libexec/root6/include/root/TH1.h:367:21: note: candidate function not viable: requires 4 arguments, but 2 were
provided
virtual void SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins);
^
/opt/local/libexec/root6/include/root/TH1.h:366:21: note: candidate function not viable: requires 6 arguments, but 2 were
provided
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax);
^
/opt/local/libexec/root6/include/root/TH1.h:370:21: note: candidate function not viable: requires 6 arguments, but 2 were
provided
virtual void SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t * yBins, Int_t nz,
^
/opt/local/libexec/root6/include/root/TH1.h:368:21: note: candidate function not viable: requires 9 arguments, but 2 were
provided
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax,
Is there a more up-to-date example for how to do this?
Thanks.
Spencer