Good afternoon,
I am analyzing a spectrum using the tools provided by the TSpectrum class.
There is some bug in my macro I could not find yet.
When performing a background subtraction from the original histogram
// Calculating and substracting background
//
TSpectrum* spect= new TSpectrum(12,1.) ;
TSpectrum* spectsb= new TSpectrum(30,2.0) ;
hdyne1back=(TH1F*)spect->Background(hdyne1,160,"BackDecreasingWindow BackOrder8 nosmoothing Compton same") ;
hdyne1back->SetLineColor(kGreen) ;
hdyne1sb->Add(hdyne1,hdyne1back,1,-1) ;
hdyne1sb->SetLineColor(kBlue) ;
, the result looks fine.
Then I want to search peaks on the histogram obtained after subtracting the background:
// Peak Research
spectsb->Search(hdyne1sb,2.5,"nobackground",0.2) ;
TList *functions = hdyne1sb->GetListOfFunctions();
TPolyMarker *pm = (TPolyMarker*)functions->FindObject("TPolyMarker");
pm->SetMarkerSize(0.7) ;
pm->SetMarkerColor(kRed) ;
npeakssb=spectsb->GetNPeaks() ;
cout << " NPeaks= " << npeakssb << endl ;
xpeaksb=spectsb->GetPositionX() ;
xpeakmaxsb=0.0 ; // Peak Max (for 137Cs)
//Reordering peaks list
for(Int_t ipc=0;ipc<npeakssb;ipc++) {
cout << "Dyne1 X Peak " << ipc << " " << xpeaksb[ipc] << endl ;
if(xpeaksb[ipc]>=xpeakmaxsb) xpeakmaxsb=(Double_t)xpeaksb[ipc] ;
for(Int_t ipcorder=ipc+1;ipcorder<npeakssb;ipcorder++) { // Loop of reordering
if(xpeaksb[ipcorder]<xpeaksb[ipc]) { // Begin if
a=xpeaksb[ipc] ;
b=xpeaksb[ipcorder] ;
xpeaksb[ipcorder]=a ;
xpeaksb[ipc]=b ;
} // Endif
} // End loop of reordering
}
cout << "Max peak: " << xpeakmaxsb << endl ;
The fact is that the Polymarker positions along the X-axis are not consistent with the values stored in the xpeaksb pointer. Indeed, the peak located around channel 600 is not stored although a polymarker is drawn on the histogram at this position … When dumping on screen I have:
Reading File: …/data09122011/22Na_60Co_137Cs_LaBr3_2x2_R7723-100_1800V.dat.root
Entries: 100001
NPeaks= 4
Dyne1 X Peak 0 771.123
Dyne1 X Peak 1 771.123
Dyne1 X Peak 2 1353.84
Dyne1 X Peak 3 1528.75
Max peak: 1528.75
The second peak is repeted twice …
Up to now I did not find out where the bug could be. Does anyone have any suggestion ? I am using Root version 5.27/06b.
I attached the root file and the macro.
In the macro you could have to change the path to the root file to execute the macro properly:
char* filename="../data09122011/22Na_60Co_137Cs_LaBr3_2x2_R7723-100_1800V.dat.root" ;
Thanks a lot for the help