Is Backgroundbackground() in TSpectrum2 working?

I want to filter the background from my TH2D histogram file. From the link of root.cern.ch/root/html/TSpectrum2.html, there is a solution of TWO-DIMENSIONAL BACKGROUND ESTIMATION FUNCTION, namely, “Background(float** spectrum, Int_t ssizex, Int_t ssizey, Int_t numberIterationsX, Int_t numberIterationsY, Int_t direction, Int_t filterType)”.

Also in the same page, an example script named as “Back_gamma64.C” is posted. I have simply modified it for my purpose (attched here), and also correct several typos there (e.g. nbinsx cannot be double in any case).

The problem is that;
when I run the script (root -b -q Back_gamma64.C), either it shows error like:
Error: Symbol kBackDecreasingWindow is not defined in current scope Back_gamma64.C:61:
Error: Symbol kBackSuccessiveFiltering is not defined in current scope Back_gamma64.C:61:

(this is wired, since I have include )

or if I define the two symbols by myself, it shows error message below
Error: Can’t call TSpectrum::Background(source,nbinsx,nbinsy,4,4,kBackDecreasingWindow,kBackSuccessiveFiltering) in current scope Back_gamma64.C:63:
Possible candidates are…
(in TSpectrum)
/home/sun/root/lib/libSpectrum.so -1:-1 0 public: virtual TH1* TSpectrum::Background(const TH1* hist,Int_t niter=20,Option_t* option="");
/home/sun/root/lib/libSpectrum.so -1:-1 0 public: const char* TSpectrum::Background(float* spectrum,Int_t ssize,Int_t numberIterations,Int_t direction,Int_t filterOrder,bool smoothing,Int_t smoothWindow,bool compton);
*** Interpreter error recovered ***

Please some experts help… Thanks in advance!

[code] // Example to illustrate the background estimator (class TSpectrum).
// To execute this example, do
// root > .x Back_gamma64.C
#include
#include
#include
#include
#include
#include <stdlib.h>
#include “TCanvas.h”
#include “TMath.h”
#include “TH1.h”
#include “TF1.h”
#include “TH2.h”
#include “TF2.h”
#include “TRandom.h”
#include “TSpectrum.h”
#include “TVirtualFitter.h”
#include “TFile.h”
#include “TSpectrum2.h”
#include "TROOT.h"
using namespace std;

//#define kBackDecreasingWindow 1
//#define kBackSuccessiveFiltering 0

void Back_gamma64(string filename = “20100417-134057-3375350541.root”) {

Int_t i, j;
Int_t nbinsx = 64;
Int_t nbinsy = 64;
Int_t xmin = 0;
Int_t xmax = (Double_t)nbinsx;
Int_t ymin = 0;
Int_t ymax = (Double_t)nbinsy;

TFile *f = new TFile(filename.c_str(),“UPDATE”);
//TH2D RAW = (TH2D)froot->Get(“RAW”); // 2D-RAW spectrum
TH2D back = (TH2D) f->Get(“RAW;1”);
nbinsx = back->GetNbinsX();
nbinsy = back->GetNbinsY();
xmin = back->GetXaxis()->GetXmin();
xmax = back->GetXaxis()->GetXmax();
ymin = back->GetYaxis()->GetXmin();
ymax = back->GetYaxis()->GetXmax();

cout << " nbinsx: " << nbinsx << “, xmin:” << xmin << “, xmax:” << xmax << endl;
cout << " nbinsy: " << nbinsy << “, ymin:” << ymin << “, ymax:” << ymax << endl;

double ** source = new double *[nbinsx];
for (i=0;i<nbinsx;i++)
source[i] = new double[nbinsy];

TSpectrum *s = new TSpectrum();
for (i = 0; i < nbinsx; i++)
{
for (j = 0; j < nbinsy; j++)
{
source[i][j] = back->GetBinContent(i+1,j+1); // forget [0][0] component
}
}
//back->Draw(“colz”);

cout << "checking background " << endl;
s->Background(source,nbinsx,nbinsy,4,4,kBackDecreasingWindow,kBackSuccessiveFiltering);
for (i = 0; i < nbinsx; i++)
{
for (j = 0; j < nbinsy; j++)
back->SetBinContent(i + 1,j + 1, source[i][j]);
}
cout << "backgroud done " <<endl;

TCanvas *Background = new TCanvas(“Background”,“Estimation of background with increasing window”,10,10,1000,700);
back->Write();
//back->Draw(“SURF”);

}
[/code]

you have 3 problems in your code:
-you create a TSpectrum in stead of TSpectrrum2
-you use double instead of float
-you do not specify the class scope when using the TSpectrum2 enums.
The correct piece of code is as shown below.

Rene

[code] float ** source = new float *[nbinsx];
for (i=0;i<nbinsx;i++)
source[i] = new float[nbinsy];

TSpectrum2 *s = new TSpectrum2();
for (i = 0; i < nbinsx; i++)
{
for (j = 0; j < nbinsy; j++)
{
source[i][j] = back->GetBinContent(i+1,j+1); // forget [0][0] component
}
}
//back->Draw(“colz”);

cout << "checking background " << endl;
s->Background(source,nbinsx,nbinsy,4,4,TSpectrum2::kBackDecreasingWindow,TSpectrum2::kBackSuccessiveFiltering);
[/code]

Thank you very much, Rene.

Just to make sure, after using the following: s->Background(source,nbinsx,nbinsy,8,8,TSpectrum2::kBackDecreasingWindow,TSpectrum2::kBackSuccessiveFiltering);

“source” here actually pointer to the pure background, but not the “original spectrum-background”. Is this right?
If so, my true peaks actually was reduced a lot…

Thank you very much.

source is your original distribution (signal+background)

Rene

Thanks for the quick reply. TO be more precise, I mean after I excute the line for estimating the background:

s->Background(source,nbinsx,nbinsy,8,8,kBackIncreasingWindow,kBackSuccessiveFiltering);
for (i = 0; i < nbinsx; i++)
{
for (j = 0; j < nbinsy; j++)
{
back->SetBinContent(i + 1,j + 1, source[i][j]); // I thought here source is actually the pure background
}
}

If source is always my original spectrum, then where the background is save into and how come TH2D *back differs from my original?

Sorry, I misunderstood your question.
Yes, the result is stored in the array source (replacing the original source).

Rene