In TTree I have simple array with 512 elements. If I draw the array and pipe it into a histogram interactively using the TTree Draw method, I am getting a histogram with a different number of elememets than what I allocated. For example:
tree->Draw(“myarray:Iteration$>>h(512,0,512)”)
At this point it returns a value (Long64_t) 512.
but h->GetNbinsX() returns 515, not 512.
This is causing problems when I try and add “h” to other histograms that really do have 512 elements. Any ideas? Below is a simple macro that reproduces the problem.
ROOT Version 4.04/02g on Mac OSX 10.3.9
{
Float_t myarray[512];
for(Int_t i=0;i<512;i++)
{
myarray[i]=i;
}
// create tree
TTree *tree=new TTree("tree","test");
tree->Branch("myarray",myarray,"myarray[512]/F");
tree->Fill();
// create histogram from TTree draw method
tree->Draw("myarray:Iteration$>>abc(512,0,512)","Entry$==0");
cout << "number of x bins for histogram abc: " << abc->GetNbinsX() << endl;
// returns 515 on my machine
// create the same histogram by hand
TH1F *xyz=new TH1F("xyz","xyz",512,0,512);
for(Int_t i=0;i<512;i++)
{
xyz->Fill(i,i);
}
cout << "number of x bins for histogram xyz: " << xyz->GetNbinsX() << endl;
// returns 512 on my machine
// try and add xyz and abc
TH1F *def=xyz->Clone();
def->Add(abc);
// tells me histograms have different number of bins
}
The output during a root session is:
root [0] .x histbin.C
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
number of x bins for histogram abc: 515
number of x bins for histogram xyz: 512
Error in <TH1F::Add>: Attempt to add histograms with different number of bins