Hi Ville,
When the number of entries in an histogram is 0, TH1::Sumw2
does not compute the bin errors. I have now changed this behaviour
in my version.
To make your program working, add the statement
folded->SetEntries(nf); in your fold function.
A better solution ios to call Sumw2 before calling AddbinContent.
In this case, the errors will be correctly computed and you do not need
to call folded->SetEntries.
Rene Brun
Ville Axel Bergholm wrote:
>
> Hi,
>
> when I use Sumw2() (to prepare a histogram with errors for rescaling),
> it produces strange results when used on the output of my folding
> function. The folding function works fine by itself, as does Sumw2().
> When I try to Sumw2() a folded histogram, all the errors get set to zero.
>
> Here is a CINT command sequence that produces the unwanted results:
>
> gROOT->Reset();
> .L fold.C
> TF1 *f1=new TF1("y1", "0.1*x", 0,5);
> TF1 *f2=new TF1("y2", "(sin(4*x))^2", 0,5);
> TH1D *h = new TH1D("h1","name", 20, 0, 5);
> h->FillRandom("y2", 500);
> TH1D *a = foldgauss(h, f1);
> cout << a->GetBinError(3) << endl; // gives something
> a->Sumw2();
> cout << a->GetBinError(3) << endl; // supposed to give the same, gives 0
>
> And the function foldgauss in fold.C:
>
> // fold.C
> //______________________________________________________________________
> // Folds a histogram (orig) with a gaussian with varying sigma
> // Preserves the original.
>
> TH1D *foldgauss(TH1D *orig, TF1 *sigma) {
>
> Double_t af, bf, d;
> Int_t n, nf, offset;
>
> d = orig->GetBinWidth(1); // assume all bins alike
> n = orig->GetNbinsX();
>
> // folder-histogram properties
> // position zero to the middle of a bin
> offset = -n-1;
> af = -d*(n+0.5);
> nf = 2*n+1;
> bf = -af;
>
> TF1 *f = new TF1("ffunct", "gaus(0)", -1, 1);
>
> TH1D *folder = new TH1D("folder", "Folding function", nf, af, bf);
>
> TH1D *folded = new TH1D(*orig);
> folded->Reset();
>
> Double_t temp, stdev, x;
>
> for(Int_t i=1; i<=n; i++) {
> temp = orig->GetBinContent(i);
>
> // folding function into histogram
> x = orig->GetBinCenter(i);
> stdev = sigma->Eval(x);
> f->SetParameters(1, 0, stdev);
> folder->Eval(f);
>
> // normalize
> folder->Scale(1/(folder->Integral()));
>
> for(Int_t j=1; j<=nf; j++)
> if ((i+j+offset >= 1) && (i+j+offset <= n))
> folded->AddBinContent(i+j+offset, folder->GetBinContent(j) * temp);
> }
>
> delete folder;
> delete f;
> return folded;
> }
>
> Again, please reply also to my e-mail address. Thanks!
>
> Ville
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:31 MET