For TProfile, the “TEXT” option for draw will display the mean values as TEXT. This is a very nice feature, especially when mean values are written in a 2D grid for a TProfile2D.
I would also like to view the error (or RMS) for each bin in a similar fashion.
Is there a drawing option for TProfile (or histograms) to display the errors as text?
Or else, is there an elegant way to extract the error values and display them like the mean values are displayed using the TEXT option?
The option TEXT display only the histogram bins’ contents not the errors.
Full doc here: https://root.cern.ch/doc/master/classTHistPainter.html#HP15
EDIT : In the case of profile histograms it is possible to print the number of entries instead of the bin content. It is enough to combine the option “E” (for entries) with the option “TEXT”.
When using a “text” option: Is a setter for the text content above particular bin available (I couldn’t find it quickly in documentation) or the text content above particular bin is always hardwired to be the value of a particular bin content?
Yes it is always the bin content (cf doc)
For a 1D profile I am looking for a way to represent on the same plot both the bin content and number of bin entries for each bin. Drawing with option “text” would perfectly serve the purpose if what is written in text would represent the number of bin entries instead of the bin content as it is now done by default.
1.) Does it really hurt to provide a setter for the text content above particular bin?
2.) Any other suggestion how I can elegantly represent on the same plot both the bin content and number of entries for each bin for 1D profile?
Thanks and cheers,
You can use the option B in ProjectionX to create a new histogram containing the number of entries per bin. Then you plot this histogram using option TEXT. You can also use option the option SAME if you want to superimpose it on top of the original histogram
Thanks for a quick reply - your proposed solution sounds OK, however it could be that I have still misunderstood something. With following piece of code:
TProfile *p = new TProfile("p","p",2,0,2);
cout<<"1st bin entries: "<<p->GetBinEntries(1)<<endl;
cout<<"2nd bin entries: "<<p->GetBinEntries(2)<<endl;
TH1D *h = p->ProjectionX("B");
I am getting for the text above first bin 1 instead of 2 that I want to see there in this example. Could you please indicate what I am still missing?
Thanks and cheers,
P.S. ROOT 5.26/00b (tags/v5-26-00b@32327, Apr 12 2010, 16:36:00 on linux)
I see. May be a new option will be needed (like TEXTE). I’ ll look.
In fact you did a mistake. You should do:
TH1D *h = p->ProjectionX("h1","B");
let me know
By taking into account your comment and in order to get rid of the error bars I have in addition modify:
Attached is the resulting plot - however this is not what I need. The contents of both bins are 1, only bin entries are different. In the resulting superimposed plot also the bin contents appear different.
Thanks and cheers,
Yes, when you do that the number of entries is plotted at the a Y position equal to the number of entries, not at the histogram content. To do what you are asking a new option is needed. TEXTE for instance.
dealing at the moment with text option as well, I would very much push for the following option to be added ( in histpainter and/or TStyle )
- control the number of digits ( quite useful to make 2D plots ( when one does
"matrix-like" plots )
- possibility to add the error on the number
all the best,
awsome ! I didn’t catch-up these, I must have used an old doc.
thanks a lot,
I have implemented the option you where looking for.
TCanvas *c02 = new TCanvas("c02","c02",700,400);
TProfile *profile = new TProfile("profile","profile",10,0,10);
c02->cd(1); profile->Draw("HIST TEXT0");
c02->cd(2); profile->Draw("HIST TEXT0E");
Beginning with which ROOT version is the option TEXTE for TProfiles working?