TH1F questions

Hi Rooters,

I have some questions to ask …

1.) How could I split an histogram in two?
I would like to remove the background from the histogram, and after that save it in a new histogram. The difference should be the rest ( in my case some peaks) …

I use this code … but without success.

TSpectrum *s = new TSpectrum(npeaks);

(…)

//Estimate background using TSpectrum::Background
TH1 *hb = s->Background(t_hist1,4,“same”); // (TH1,niteractions,"")
c1->cd(2);
hb->Draw();//draw background

TH1F t_hist1_b = (TH1F)t_hist1->Clone(“t_hist1_b”);
t_hist1_b->Add(hb,-1);// sub hb from t_hist1

(…)

There are any other way to do that?

2.) Supose that I have two histograms (the splited ones):

  • one for the background
  • one for the peaks

What is the best way to fit them?

3.) How could I put the outputs from cout’s or from print’s in a popup window or in a canvas? … like a window for debug…
I have my GUI interface but by now I don’t now exactly how to do this…

Cheers,

JP

Instead of:

TH1 *hb = s->Background(t_hist1,4,"same"); // (TH1,niteractions,"") c1->cd(2); hb->Draw();//draw background you can do:

TH1 *hb = s->Background(t_hist1,4,"same"); // (TH1,niteractions,"")

TH1F *t_hist1_b = (TH1F*)t_hist1->Clone("t_hist1_b"); t_hist1_b->Add(hb,-1);// sub hb from t_hist1 What is wrong with these two lines?

[quote]2.) Supose that I have two histograms (the splited ones):

  • one for the background
  • one for the peaks

What is the best way to fit them?
[/quote]
Why do you want fit background+peaks where the background is obtained
from TSpectrum::Background?
If your question is more general, ie how to find the fraction of
signal(s) and background, see classes like TFractionFitter and TSPlot
root.cern.ch/root/htmldoc/TFractionFitter.html
root.cern.ch/root/htmldoc/TSPlot.html

[quote]3.) How could I put the outputs from cout’s or from print’s in a popup window or in a canvas? … like a window for debug…
I have my GUI interface but by now I don’t now exactly how to do this…
[/quote]
When executing your script or command, pipe the output to a log file,
then read this log file (or part of it).
Bertrand may add some additional info.

Rene

Hi,

Maybe something like this could help :

[code] // form temporary file path
TString pathtmp = Form("%s/my_tmpfile", gSystem->TempDirectory());
// redirect stdout/stderr in the temporary file
// “w” means write, could be “a” to append
if (gSystem->RedirectOutput(pathtmp.Data(), “w”) != 0) {
Error(“ShowStatus”, “stdout/stderr redirection failed; skipping”);
return;
}
// execute command(s) to be monitored

[…]

// restore back stdout/stderr
if (gSystem->RedirectOutput(0) != 0) {
Error(“ShowStatus”, “stdout/stderr retore failed; skipping”);
return;
}
// load (display) temp file in a text view
fInfoTextView->LoadFile(pathtmp.Data());
[/code]
Cheers,
Bertrand.

First of all thanks for the help. I’ll try yours suggestions.

Well, in the second point I really want to split an TH1F (who as background + signal) into 2 TH1F’s that I could fit after.

Any sugestion?

Cheers,

JP