Home | News | Documentation | Download

Adding new Elements to the Statistic Box


#1

Hi, I have the following Problem. In my Canvas I displayed several histograms each with a statistic box. I then added a self written class called DoubleList to calculate the percentiles (1%, 2%, 5%, 10%). Additionally to the black percentile lines I am drawing at their position, I would like to add the corresponding value to the statistic box. I tried to follow the path in

https://root.cern.ch/doc/master/classTPaveStats.html

without any success. How can I integrate the freshly computed percentiles in the statistic box?
Kind regards Jim
PS: the executable is original.c

DoubleList.C (3.3 KB)
DoubleList.h (1.2 KB)
original.c (6.6 KB)
Penalty_8000_522000.txt (1.3 MB)
Penalty_4000_522000.txt (1.3 MB)
Penalty_2000_522000.txt (1.3 MB)
Penalty_100_522000.txt (1.3 MB)
Penalty_Chr_3.5_522000.txt (1.3 MB)
Penalty_1000_522000.txt (1.3 MB)


#2

https://root.cern/doc/master/statsEditing_8C.html


#3

Replace:

TPaveStats *s4 = (TPaveStats*)h4->GetListOfFunctions()->FindObject("stats");
// ...
s4->Draw();

with:

TPaveStats *s4 = (TPaveStats*)h4->GetListOfFunctions()->FindObject("stats");
s4->SetName("h4_stats");
h4->SetStats(0);
TList *lol = s4->GetListOfLines();
TLatex *ltx = 
  new TLatex(0, 0, TString::Format("1%% = %g", OnePercent4.getValue()));
ltx->SetTextFont(42); ltx->SetTextSize(0.03); ltx->SetTextColor(1);
lol->Add(ltx);
ltx = new TLatex(0, 0, TString::Format("2%% = %g", TwoPercent4.getValue()));
ltx->SetTextFont(42); ltx->SetTextSize(0.03); ltx->SetTextColor(1);
lol->Add(ltx);
ltx = new TLatex(0, 0, TString::Format("5%% = %g", FivePercent4.getValue()));
ltx->SetTextFont(42); ltx->SetTextSize(0.03); ltx->SetTextColor(1);
lol->Add(ltx);
ltx = new TLatex(0, 0, TString::Format("10%% = %g", TenPercent4.getValue()));
ltx->SetTextFont(42); ltx->SetTextSize(0.03); ltx->SetTextColor(1);
lol->Add(ltx);
s4->SetLineColor(1);
s4->SetX1NDC(0.78);
s4->SetX2NDC(0.98);
s4->SetY1NDC(0.48);
s4->SetY2NDC(0.18);
c->Modified();
// s4->Draw();

#4

Thanks for the quick replay but as I mentioned in my text I already tried that.
My command with s4->Draw(); where I am drawing the StatBox does not go well with h4->SetStats(0);
So how do I do that correctly, here is my “not working” version.

original.c (6.9 KB)


#5

I get many errors when I run your macro:

root [0] 
Processing original.c...
In file included from input_line_11:1:
/Users/couet/Downloads/original.c:31:47: error: invalid suffix '.' on floating constant
TH1* h5 = new TH1D("8000 Samples","", 260, 4.6., 13.6);
                                              ^
/Users/couet/Downloads/original.c:48:46: error: invalid suffix '.' on floating constant
TH1* h = new TH1D("4000 Samples","", 260, 4.6., 13.6);
                                             ^
/Users/couet/Downloads/original.c:63:47: error: invalid suffix '.' on floating constant
TH1* h1 = new TH1D("2000 Samples","", 260, 4.6., 13.6);
                                              ^
/Users/couet/Downloads/original.c:135:1: error: use of undeclared identifier 'value'
value = OnePercent4.getValue();
^
/Users/couet/Downloads/original.c:136:1: error: use of undeclared identifier 'bin'
bin = h4->GetXaxis()->FindBin(value);
^
/Users/couet/Downloads/original.c:136:31: error: use of undeclared identifier 'value'
bin = h4->GetXaxis()->FindBin(value);
                              ^
/Users/couet/Downloads/original.c:137:26: error: use of undeclared identifier 'value'
TLine *lOne4 = new TLine(value,-100,value,h4->GetBinContent(bin));
                         ^
/Users/couet/Downloads/original.c:137:37: error: use of undeclared identifier 'value'
TLine *lOne4 = new TLine(value,-100,value,h4->GetBinContent(bin));
                                    ^
/Users/couet/Downloads/original.c:137:61: error: use of undeclared identifier 'bin'
TLine *lOne4 = new TLine(value,-100,value,h4->GetBinContent(bin));
                                                            ^
/Users/couet/Downloads/original.c:140:35: error: use of undeclared identifier 'value'
TPaveText *Onept4 = new TPaveText(value-.2,-300,value+.2,-100);
                                  ^
/Users/couet/Downloads/original.c:140:49: error: use of undeclared identifier 'value'
TPaveText *Onept4 = new TPaveText(value-.2,-300,value+.2,-100);
                                                ^
/Users/couet/Downloads/original.c:142:27: error: use of undeclared identifier 'value'
Onept4->AddText(Form("%e",value));
                          ^
/Users/couet/Downloads/original.c:145:1: error: use of undeclared identifier 'value'
value = TwoPercent4.getValue();
^
/Users/couet/Downloads/original.c:146:1: error: use of undeclared identifier 'bin'
bin = h4->GetXaxis()->FindBin(value);
^
/Users/couet/Downloads/original.c:146:31: error: use of undeclared identifier 'value'
bin = h4->GetXaxis()->FindBin(value);
                              ^
/Users/couet/Downloads/original.c:147:26: error: use of undeclared identifier 'value'
TLine *lTwo4 = new TLine(value,-100,value,h4->GetBinContent(bin));
                         ^
/Users/couet/Downloads/original.c:147:37: error: use of undeclared identifier 'value'
TLine *lTwo4 = new TLine(value,-100,value,h4->GetBinContent(bin));
                                    ^
/Users/couet/Downloads/original.c:147:61: error: use of undeclared identifier 'bin'
TLine *lTwo4 = new TLine(value,-100,value,h4->GetBinContent(bin));
                                                            ^
/Users/couet/Downloads/original.c:151:1: error: use of undeclared identifier 'value'
value = FivePercent4.getValue();
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

#6

Thank you very much, this is exactly what I needed :slight_smile:


#7

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.