Fill Histograms with array

I have 2 arrays, the first one contain 8000 entries, the other one contain 69 entries that are the edge of all the bins. Now I want to make an Histogram with on the x the bins of the second array Filled with the data contained in the first one, How can I do???

Thax

Hi Stefano,
I’m afraid I don’t understand exactly what you’re trying to do. What’s the problem - defining the histogram bin edges by array2, and filling the histogram by array1? You can do that like this:

Int_t numDataPoints=6000; Double_t *array1=GetWoldsBestData(numDataPoints); // you have your array 1 Int_t numEdges=69; Double_t* array2=GetMagicEdges(69); // and your array 2 // create a new histo // we pass it the bin edges as an array // as 69 edges contain only 68 bins, we have to specify numEdges-1 TH1F* hMyData=new TH1F("hMyData","my data", numEdges-1, array2); // fill with a whole array at once hMyData->FillN(numDataPoints, array1, 0); hMyData->Draw();
Axel.

see example below

Rene

void vbins() {
const int np = 8000;
const int nbins = 68;
double y[np];
double xbins[nbins+1];
TRandom r;
int i;
for (i=0;i<np;i++) y[i] = r.Gaus(600,200);
xbins[0] = 0;
for (i=1;i<=nbins;i++) xbins[i] = xbins[i-1] + 1 +i/2;

TH1D *h = new TH1D(“h”,“my var bins histo”,nbins,xbins);
for (i=0;i<np;i++) {
h->Fill(y[i]);
}
h->Draw();
}

I’ve done it, but it gaves me this error…

Warning in TH1::Build: Replacing existing histogram: h1 (Potential memory leak).
TCanvas::MakeDefCanvas: created default TCanvas with name c1
Warning in TCanvas::ResizePad: c1 width changed from 64000 to 10

root [7] Warning in TCanvas::ResizePad: c1 width changed from 64000 to 10

???

see: root.cern.ch/root/roottalk/RoottalkRules.html

Please send the shortest possible running script reproducing your problem.

Rene