void sumw2_test() { Info("sumw2_test","I. Fill histo to 100 by different methods:\n"); // 1. Sumw2 histo filled with Fill(x,100) TH1F* h = new TH1F("h","Sumw2 histo filled with Fill(x,100)",1,0,1); h->Sumw2(kTRUE); h->Fill(0.5,100); Info("sumw2_test","1. Sumw2 histo filled with Fill(x,100): %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 2. None-sumw2 histo filled with Fill(x,100) h = new TH1F("h","None-sumw2 histo filled with Fill(x,100)",1,0,1); h->Sumw2(kFALSE); h->Fill(0.5,100); Info("sumw2_test","2. None-sumw2 histo filled with Fill(x,100): %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 3. Sumw2 histo filled 100 times with Fill(x[,1]) h = new TH1F("h","Sumw2 histo filled 100 times with Fill(x[,1])",1,0,1); h->Sumw2(kTRUE); for (int i=0; i<100; i++) h->Fill(0.5); Info("sumw2_test","3. Sumw2 histo filled 100 times with Fill(x[,1]): %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 4. Non-Sumw2 histo filled with Fill(x[,1]) h = new TH1F("h","None-sumw2 histo filled 100 times with Fill(x[,1])",1,0,1); h->Sumw2(kFALSE); for (int i=0; i<100; i++) h->Fill(0.5); Info("sumw2_test","4. None-sumw2 histo filled 100 times with Fill(x[,1]): %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 5. None-sumw2 histo filled with SetBinContent=100 h = new TH1F("h","None-sumw2 histo filled with SetBinContent=100",1,0,1); h->Sumw2(kFALSE); h->SetBinContent(1,100); Info("sumw2_test","5. None-sumw2 histo filled with SetBinContent=100: %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 6. None-sumw2 histo filled with AddBinContent=100 h = new TH1F("h","Sumw2 histo filled with AddBinContent=100",1,0,1); h->Sumw2(kFALSE); h->AddBinContent(1,100); Info("sumw2_test","6. None-sumw2 histo filled with AddBinContent=100: %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 7. Sumw2 histo filled with SetBinContent=100 h = new TH1F("h","Sumw2 histo filled with SetBinContent=100 and zero Entries",1,0,1); h->Sumw2(kTRUE); h->SetBinContent(1,100); Info("sumw2_test","7. Sumw2 histo filled with SetBinContent=100 and zero Entries: %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 8. Sumw2 histo filled with SetBinContent=100 h = new TH1F("h","Sumw2 histo filled with AddBinContent=100 and zero Entries",1,0,1); h->Sumw2(kTRUE); h->AddBinContent(1,100); Info("sumw2_test","8. Sumw2 histo filled with AddBinContent=100 and zero Entries: %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // it was claimed here https://root-forum.cern.ch/t/sumw2-with-setbincontent/19329/1 // that Sumw2 works correctly onlye if histo have number of entries > 0. // 9. Sumw2 histo filled with SetBinContent=100 h = new TH1F("h","Sumw2 histo filled with SetBinContent=100 and none-zero Entries(=100)",1,0,1); h->Sumw2(kTRUE); h->SetEntries(100); h->SetBinContent(1,100); Info("sumw2_test","9. Sumw2 histo filled with SetBinContent=100 and none-zero Entries(=100): %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; // 10.Sumw2 histo filled with SetBinContent=100 h = new TH1F("h","Sumw2 histo filled with AddBinContent=100 and none-zero Entries(=100)",1,0,1); h->Sumw2(kTRUE); h->SetEntries(100); h->AddBinContent(1,100); Info("sumw2_test","10.Sumw2 histo filled with AddBinContent=100 and none-zero Entries(=100): %g +/- %g\n", h->GetBinContent(1),h->GetBinError(1)); delete h; Info("sumw2_test","II. Divide same histos with errors:\n"); // 11. None-sumw2 histo filled with SetBinContent=100 h = new TH1F("h","histo",1,0,1); h->Sumw2(kFALSE); h->SetBinContent(1,100); TH1* h1 = (TH1*) h->Clone("ht"); h->Divide(h1); Info("sumw2_test","11. None-sumw2 histo: 100+/-10 divide on 100+/-10: %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; delete h1; // 12. Sumw2 histo filled with SetBinContent=100 h = new TH1F("h","histo",1,0,1); h->Sumw2(kFALSE); h->SetBinContent(1,100); h1 = (TH1*) h->Clone("ht"); h->Sumw2(kTRUE); h1->Sumw2(kTRUE); h->Divide(h1); Info("sumw2_test","12. Sumw2 histo: 100+/-10 divide on 100+/-10: %g +/- %g", h->GetBinContent(1),h->GetBinError(1)); delete h; delete h1; }