I wonder if it is possible to store histogram error by using Sumw2, if the histogram is fill with the SetBinContent method? Actually we have to use Sumw2 before the Fill() method, but would something like this work:
Try (ROOT 5.34 or newer): {
TH1F *h = new TH1F("h", "", 30, 0, 30);
h->Sumw2(kFALSE); // make sure we "delete" fSumw2, if it exists
for(int i=0; i<30; i++) h->SetBinContent(i+1, gRandom->Rndm() );
h->Sumw2(kTRUE); // create a new fSumw2 (from the bin contents)
cout<< "Error: " << h->GetBinError(1) << endl;
} Note also that you can use the TH1::SetBinError(Int_t bin, Double_t error) method, if you want to set your own errors.
thank you for your help. When I used: h->Sumw2(kFALSE); I had the error message:
#############
Error: Can’t call TH1F::Sumw2(kFALSE) in current scope testError.C:7:
Possible candidates are…
(in TH1F)
(in TH1)
/cvmfs/cms.cern.ch/slc5_amd64_gcc462/lcg/root/5.32.00-cms21/lib/libHist.so -1:-1 0 public: virtual void TH1::Sumw2(void);
#############