TProfile gives negative RMS?

I’m trying to make a profile plot of the RMS values belonging to a function f, but I get both positive and negative values for what I assume is the RMS. What am I doing wrong?

f has both negative and positive values, and is distributet along w.
I essentially use the following to make the plot:

TProfile *plot = new TProfile((const char*)Pplot,"Profile plot",nbins,-5,5); for(i = 0, i < max; i++){ chain->GetEntry(i); plot->Fill(w->at(1), f->at(1)); }

and I get the following:

Is f->at(1) returning the function value or the rms?
In your example, you should see along y the distribution of the result of f->at(1).

Rene

Thanks for your reply.

Sorry if I was unclear. f-at(1) is not returning rms. It is returning the value of a function evaluated for event i. I need to plot the rms for each bin of the resulting distribution. Is there a standard way of doing this?

I looked through the reference guide. Should I do something like this (Really not sure about the syntax for getting RMS from an individual bin):

TH1F *Distribution = new TH1F((const char*)Ddistribution,"Distribution",nbins,-5,5);
for(j= 0, j < max; j++){
    chain->GetEntry(j);
    plot->Fill(f->at(1));
}
Int_t firstBin = Distribution->GetFirst();
Int_t lastBin = Distribution->GetLast();
TProfile *plot = new TProfile((const char*)Pplot,"Profile plot",nbins,-5,5);
for(Int_t binN = firstBin, binN <= max, binN++){
    Double_t rms = Distribution->GetRMS(1)->at(binN);
    plot->Fill(w->at(1), rms); 
}

Do:

TProfile *profile = new TProfile((const char*)Pplot,"Profile plot",nbins,-5,5,"S"); for(j= 0, j < max; j++){ chain->GetEntry(j); profile->Fill(w->at(1),f->at(1)); } TH1F *plot = new TH1F((const char*)Ddistribution,"Distribution",nbins,-5,5); for(Int_t binN = 1, binN <= nbins, binN++){ Double_t rms = profile->GetBinError(binN); plot->Fill(plot->GetBinCenter(binN), rms); }

Rene

Sorry again for being unclear.

I need a profile plot of the RMS.
I ran an analysis using the code you gave me. That, of course provided a usual histogram. So I changed your code to

TProfile *profile = new TProfile((const char*)Pplot,"Profile plot",nbins,-5,5,"S"); for(j= 0, j < max; j++){ chain->GetEntry(j); profile->Fill(w->at(1),f->at(1)); } TProfile *plot = new TProfile((const char*)Ddistribution,"Distribution",nbins,-5,5); for(Int_t binN = 1, binN <= nbins, binN++){ Double_t rms = profile->GetBinError(binN); plot->Fill(plot->GetBinCenter(binN), rms); }

But now I don’t get any vertical error bars (see below), even when I try using the graphical Draw Panel.

So I’ll try to be as clear as I can. I need a profile plot of the rms of a distribution. The profile plot should show the rms with errors for each bin.

Thank you for your patience.