TH1 Weighted Fill. Problem with errors and draw.
Hello I’m using ROOT version 5.99/01
I’m having a peculiar error when filling a histogram directly from stored files.
Specifically when using weighted fill:
TH1::Fill(x, w)
When I fill using this method the error in each bin is set to the bin value rather than sqrt N. Also the draw option is forced to draw “simple errors” which cannot be turned in the editor.
I have found ways around this, TH1::fill(x) and TH1::AddBinContent(bin, w) both work. Or errors can be corrected manually and TH1::Draw(“HIST”) used.
Is this a known error or is there an issue with the installation on our system?
I’ve included code and an example file to show the problem:
{
TH1F *hista = new TH1F("firsthist","thefirsthist",20,0,10);
ifstream theinfileA;
theinfileA.open("data.dat");
if(theinfileA.is_open()){
while(!theinfileA.eof()){
Double_t x,value;
theinfileA >> x >> value;
hista->Fill(x,value); //OPTION A Errors and Drawing problems
//for(int i=0;i<value;i++)hista->Fill(x); //OPTION B This works, but obviously is slow.
//int bin = hista->FindBin(x); //OPTION C This works fine.
//hista->AddBinContent(bin, value);
}
}
theinfileA.close();
for(int j=1;j<=20;j++) cout << hista->GetBinContent(j) << " " << hista->GetBinError(j) << endl;
//hista->Draw();
hista->Draw("HIST"); //This fixes the drawing option but not the errors are still wrong
}
data.dat
0.0 3354569.0
0.5 3257999.0
1.0 4168587.0
1.5 3872104.0
2.0 2201810.0
2.5 1091245.0
3.0 819896.0
3.5 881504.0
4.0 1226076.0
4.5 1770540.0
5.0 2007821.0
5.5 1578562.0
6.0 1194769.0
6.5 1016185.0
7.0 940008.0
7.5 898785.0
8.0 904193.0
8.5 966456.0
9.0 983741.0
9.5 963953.0
data.dat (272 Bytes)
code.C (704 Bytes)