Events number of a TH1F

Hi, i’ve this plot (in the attachment the macro):

In the stat box there is the number of entries…it is the number of simulated showers…but I’d like that ROOT writes in it the number of the particles too…for example in the box of gamma, i want the gamma number, in the box of e± I want the number of e± etc, is it possible?
thanks
hnsecondari.c (3.18 KB)

root.cern.ch/doc/master/statsEditing_8C.html

Hi couet and thanks. Before writing on the forum I saw that example but it is just to write something in the stat box…I searched something to write the number in automatic (As for the mean or the RMS)…As well, I tried to use the example and writing the numbers…but when i run it, ROOT stops to work …i add the macro in the attachment.
thanks
hnsecondari.c (3.88 KB)

I made a simplified version of your macro with 2 histograms only. But it gives you the idea.

void hnsecondari2()
{
   TFile *f = TFile::Open("cors_plot-gammatot.root");

   TH1F *hngam = (TH1F *)f->Get("hngam");
   TH1F *hnele = (TH1F *)f->Get("hnele");
   gStyle->SetOptStat();

   TCanvas *c5 = new TCanvas("c5","hists with different scales",1280,1024);
   c5->SetLogx();
   c5->SetLogy();

   hngam->Draw();
   hnele->Draw("sames");

   c5->Update();

   // Retrieve and edit the stat box for hngam
   TPaveStats *stats1 = (TPaveStats*)c5->GetPrimitive("stats");
   stats1->SetName("hngam-stats");
   TList *listOfLines1 = stats1->GetListOfLines();
   TLatex *myt1 = new TLatex(0,0,"N_{#gamma} = 5.574668e+007");
   myt1 ->SetTextSize(0.025);
   myt1 ->SetTextFont(42);
   listOfLines1->Add(myt1);
   stats1->SetTextColor(kBlack);
   stats1->SetX1NDC(0.80); stats1->SetX2NDC(0.98);
   stats1->SetY1NDC(0.77); stats1->SetY2NDC(0.92);
    hngam->SetStats(0);

   // Retrieve and edit the stat box for hnele
   TPaveStats *stats2 = (TPaveStats*)c5->GetPrimitive("stats");
   stats2->SetName("hnele-stats");
   TList *listOfLines2 = stats2->GetListOfLines();
   TLatex *myt2 = new TLatex(0,0,"N_{e^{#pm}} = 6678937");
   myt2 ->SetTextSize(0.025);
   myt2 ->SetTextFont(42);
   myt2->SetTextColor(kRed);
   listOfLines2->Add(myt2);
   stats2->SetTextColor(kRed);
   stats2->SetX1NDC(0.80); stats2->SetX2NDC(0.98);
   stats2->SetY1NDC(0.60); stats2->SetY2NDC(0.75);
   hnele->SetStats(0);

   c5->Modified();
}

Thanks couet…is it possible using it to set title on tgraph box too? in the th1f there is the title on the box…but in the tgraph there isn’t…

Just add a SetTitle call on the graph.

Hi couet and thanks, I tried to add SetTitle (See macro line 42), but I don’t have the title in the stat box…
denseprim.c (5.02 KB)

Try:

g->GetHistogram()->SetTitle()

Hi couet, unfortunatly it doesn’t work

ps. in the macro there is a multi graph…can it change something?

files missing:

Processing denseprim.c...
Error in <TGraphErrors::TGraphErrors>: Cannot open file: G:/cors/gamma/gammatot/distribuzioni-gammatot.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: G:/cors/gamma/gammatot/distribuzioni-eletot.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: G:/cors/gamma/gammatot/distribuzioni-muotot.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: G:/cors/gamma/gammatot/distribuzioni-hadtot.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 

also please write correct C++ … use sometimes use "."instead of "-> "… Because I am using ROOT 6 I have to correct your macros each time I get them…

Hi couet thanks.

About the txt files I attached them…
About the pointer…must I write “->” ? isn’t correct the “.” ?
distribuzioni-gammatot.txt (432 Bytes)
distribuzioni-hadtot.txt (432 Bytes)
distribuzioni-muotot.txt (432 Bytes)
distribuzioni-eletot.txt (432 Bytes)

Yes when using pointers you should use “->” not “.”

What you have on your plot are fit boxes.
They do not have the title like stat boxes.

Well ok…the I will not insert the title…
thanks