NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcSpectrum Class Reference

Facilities for advanced spectral analysis. More...

#include "NcSpectrum.h"

Inheritance diagram for NcSpectrum:

Detailed Description

Facilities for advanced spectral analysis.

Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
All rights reserved. *
*
For the licensing terms see $ROOTSYS/LICENSE. *
For the list of contributors see $ROOTSYS/README/CREDITS. *
// Class NcSpectrum
// Facilities for advanced spectral analysis.
//
// This class contains advanced spectra processing functions for:
//
// One-dimensional background estimation
// One-dimensional smoothing
// One-dimensional deconvolution
// One-dimensional peak search
//
// Author:
// Miroslav Morhac
// Institute of Physics
// Slovak Academy of Sciences
// Dubravska cesta 9, 842 28 BRATISLAVA
// SLOVAKIA
// email:fyzimiro@savba.sk, fax:+421 7 54772479
//
// The original code in C has been repackaged as a C++ class by R.Brun.
//
// The algorithms in this class have been published in the following references:
//
// Background elimination methods for multidimensional coincidence gamma-ray spectra.
// Nuclear Instruments and Methods in Physics Research A 401 (1997) 113-132.
//
// Efficient one- and two-dimensional Gold deconvolution and its application to gamma-ray spectra decomposition.
// Nuclear Instruments and Methods in Physics Research A 401 (1997) 385-408.
//
// Identification of peaks in multidimensional coincidence gamma-ray spectra.
// Nuclear Instruments and Methods in Research Physics A 443(2000), 108-125.
//
// This is a copy of the file TSpectrum.cxx from ROOT 5.34/38
// which was created by Miroslav Morhac (27/05/99).
// It has been introduced as NcSpectrum.cxx in order to provide compatible
// functionality within all ROOT versions, such that all the NCFS (based) code
// can remain unchanged, and as such 100% backward (and forward) compatible.
// The incompatibility that was introduced starting from ROOT6 consisted of
// the fact that the Float_t* return arguments were changed into Double_t*.
//
//- Modified: Nick van Eijndhoven, IIHE-VUB, Brussel, May 7, 2025 07:09Z

Definition at line 26 of file NcSpectrum.h.

Public Types

enum  {
  kBackOrder2 =0 , kBackOrder4 =1 , kBackOrder6 =2 , kBackOrder8 =3 ,
  kBackIncreasingWindow =0 , kBackDecreasingWindow =1 , kBackSmoothing3 =3 , kBackSmoothing5 =5 ,
  kBackSmoothing7 =7 , kBackSmoothing9 =9 , kBackSmoothing11 =11 , kBackSmoothing13 =13 ,
  kBackSmoothing15 =15
}
 

Public Member Functions

 NcSpectrum ()
 
 NcSpectrum (Int_t maxpositions, Float_t resolution=1)
 
virtual ~NcSpectrum ()
 
virtual TH1 * Background (const TH1 *hist, Int_t niter=20, Option_t *option="")
 
const char * Background (float *spectrum, Int_t ssize, Int_t numberIterations, Int_t direction, Int_t filterOrder, bool smoothing, Int_t smoothWindow, bool compton)
 
const char * Deconvolution (float *source, const float *response, Int_t ssize, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
 
const char * DeconvolutionRL (float *source, const float *response, Int_t ssize, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
 
TH1 * GetHistogram () const
 
Int_t GetNPeaks () const
 
Float_t * GetPositionX () const
 
Float_t * GetPositionY () const
 
virtual void Print (Option_t *option="") const
 
virtual Int_t Search (const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05)
 
Int_t Search1HighRes (float *source, float *destVector, Int_t ssize, float sigma, Double_t threshold, bool backgroundRemove, Int_t deconIterations, bool markov, Int_t averWindow)
 
Int_t SearchHighRes (float *source, float *destVector, Int_t ssize, float sigma, Double_t threshold, bool backgroundRemove, Int_t deconIterations, bool markov, Int_t averWindow)
 
void SetResolution (Float_t resolution=1)
 
const char * SmoothMarkov (float *source, Int_t ssize, Int_t averWindow)
 
const char * Unfolding (float *source, const float **respMatrix, Int_t ssizex, Int_t ssizey, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
 

Static Public Member Functions

static void SetAverageWindow (Int_t w=3)
 
static void SetDeconIterations (Int_t n=3)
 
static TH1 * StaticBackground (const TH1 *hist, Int_t niter=20, Option_t *option="")
 
static Int_t StaticSearch (const TH1 *hist, Double_t sigma=2, Option_t *option="goff", Double_t threshold=0.05)
 

Protected Attributes

TH1 * fHistogram
 
Int_t fMaxPeaks
 
Int_t fNPeaks
 
Float_t * fPosition
 
Float_t * fPositionX
 
Float_t * fPositionY
 
Float_t fResolution
 

Static Protected Attributes

static Int_t fgAverageWindow = 3
 
static Int_t fgIterations = 3
 

Private Member Functions

 NcSpectrum (const NcSpectrum &)
 
NcSpectrumoperator= (const NcSpectrum &)
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kBackOrder2 
kBackOrder4 
kBackOrder6 
kBackOrder8 
kBackIncreasingWindow 
kBackDecreasingWindow 
kBackSmoothing3 
kBackSmoothing5 
kBackSmoothing7 
kBackSmoothing9 
kBackSmoothing11 
kBackSmoothing13 
kBackSmoothing15 

Definition at line 44 of file NcSpectrum.h.

Constructor & Destructor Documentation

◆ NcSpectrum() [1/3]

NcSpectrum::NcSpectrum ( const NcSpectrum & )
private

◆ NcSpectrum() [2/3]

NcSpectrum::NcSpectrum ( )
// Constructor.

Definition at line 83 of file NcSpectrum.cxx.

◆ NcSpectrum() [3/3]

NcSpectrum::NcSpectrum ( Int_t maxpositions,
Float_t resolution = 1 )
// maxpositions: maximum number of peaks
// resolution: determines resolution of the neighboring peaks
// default value is 1 correspond to 3 sigma distance
// between peaks. Higher values allow higher resolution
// (smaller distance between peaks.
// May be set later through SetResolution.

Definition at line 103 of file NcSpectrum.cxx.

◆ ~NcSpectrum()

NcSpectrum::~NcSpectrum ( )
virtual
// Destructor.

Definition at line 130 of file NcSpectrum.cxx.

Member Function Documentation

◆ Background() [1/2]

virtual TH1 * NcSpectrum::Background ( const TH1 * hist,
Int_t niter = 20,
Option_t * option = "" )
virtual

◆ Background() [2/2]

const char * NcSpectrum::Background ( float * spectrum,
Int_t ssize,
Int_t numberIterations,
Int_t direction,
Int_t filterOrder,
bool smoothing,
Int_t smoothWindow,
bool compton )

◆ Deconvolution()

const char * NcSpectrum::Deconvolution ( float * source,
const float * response,
Int_t ssize,
Int_t numberIterations,
Int_t numberRepetitions,
Double_t boost )
// One-dimensional deconvolution function
//
// This function calculates deconvolution from source spectrum according to
// response spectrum using Gold deconvolution algorithm. The result is placed
// in the vector pointed by source pointer. On successful completion it
// returns 0. On error it returns pointer to the string describing error. If
// desired after every numberIterations one can apply boosting operation
// (exponential function with exponent given by boost coefficient) and repeat
// it numberRepetitions times.
//
// Function parameters:
//
// source: pointer to the vector of source spectrum
// response: pointer to the vector of response spectrum
// ssize: length of source and response spectra
// numberIterations, for details we refer to the reference given below
// numberRepetitions, for repeated boosted deconvolution
// boost, boosting coefficient
//
// The goal of this function is the improvement of the resolution in spectra,
// decomposition of multiplets. The mathematical formulation of
// the convolution system is:
//
// <img width=585 height=84 src="gif/NcSpectrum_Deconvolution1.gif">
//
// where h(i) is the impulse response function, x, y are input and output
// vectors, respectively, N is the length of x and h vectors. In matrix form
// we have:
//
// <img width=597 height=360 src="gif/NcSpectrum_Deconvolution2.gif">
//
// Let us assume that we know the response and the output vector (spectrum) of
// the above given system. The deconvolution represents solution of the
// overdetermined system of linear equations, i.e., the calculation of the
// vector x. From numerical stability point of view the operation of
// deconvolution is extremely critical (ill-posed problem) as well as time
// consuming operation. The Gold deconvolution algorithm proves to work very
// well, other methods (Fourier, VanCittert etc) oscillate. It is suitable to
// process positive definite data (e.g. histograms).
//
// Gold deconvolution algorithm:
//
// <img width=551 height=233 src="gif/NcSpectrum_Deconvolution3.gif">
//
// Where L is given number of iterations (numberIterations parameter).
//
// Boosted deconvolution:
//
// Set the initial solution:
// x^{(0)} = [1,1,...,1]^{T}
// Set required number of repetitions R and iterations L.
// Set r = 1.
// Using Gold deconvolution algorithm for k=1,2,...,L find x^(L)
// If r = R stop calculation, else
//
// Apply boosting operation, i.e., set
// x^{(0)}(i) = [x^{(L)}(i)]^{p}
// i=0,1,...N-1 and p is boosting coefficient &gt;0.
// r = r + 1
// continue in 4.
//
//
// References:
// Gold R., ANL-6984, Argonne National Laboratories, Argonne Ill, 1964.
// Coote G.E., Iterative smoothing and deconvolution of one- and two-dimensional
// elemental distribution data, NIM B 130 (1997) 118.
// Efficient one- and two-dimensional Gold deconvolution and
// its application to gamma-ray spectra decomposition. NIM, A401 (1997) 385-408.
// Efficient algorithm of multidimensional deconvolution and its application to nuclear data processing
// Digital Signal Processing 13 (2003) 144.
//
// Example 8 - script Deconvolution.c :
//
// response function (usually peak) should be shifted left to the first
// non-zero channel (bin) (see Figure 9)
//
// <img width=600 height=340 src="gif/NcSpectrum_Deconvolution1.jpg">
//
// Figure 9 Response spectrum.
//
// <img width=946 height=407 src="gif/NcSpectrum_Deconvolution2.jpg">
//
// Figure 10 Principle how the response matrix is composed inside of the
// Deconvolution function.
// <img width=601 height=407 src="gif/NcSpectrum_Deconvolution3.jpg">
//
// Figure 11 Example of Gold deconvolution. The original source spectrum is
// drawn with black color, the spectrum after the deconvolution (10000
// iterations) with red color.
//
// Script:
//
// Example to illustrate deconvolution function (class NcSpectrum).
// To execute this example, do
// root > .x Deconvolution.C
//
// #include <NcSpectrum>
//
// void Deconvolution() {
// Int_t i;
// Double_t nbins = 256;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * response = new float[nbins];
// TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
// TH1F *d = new TH1F("d","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("decon1;1");
// TFile *fr = new TFile("spectra\\NcSpectrum.root");
// d=(TH1F*) fr->Get("decon_response;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
// TCanvas *Decon1 = gROOT->GetListOfCanvases()->FindObject("Decon1");
// if (!Decon1) Decon1 = new TCanvas("Decon1","Decon1",10,10,1000,700);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// s->Deconvolution(source,response,256,1000,1,1);
// for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
// d->SetLineColor(kRed);
// d->Draw("SAME L");
// }
//
// Examples of Gold deconvolution method:
//
// First let us study the influence of the number of iterations on the
// deconvolved spectrum (Figure 12).
//
// <img width=602 height=409 src="gif/NcSpectrum_Deconvolution_wide1.jpg">
//
// Figure 12 Study of Gold deconvolution algorithm.The original source spectrum
// is drawn with black color, spectrum after 100 iterations with red color,
// spectrum after 1000 iterations with blue color, spectrum after 10000
// iterations with green color and spectrum after 100000 iterations with
// magenta color.
//
// For relatively narrow peaks in the above given example the Gold
// deconvolution method is able to decompose overlapping peaks practically to
// delta - functions. In the next example we have chosen a synthetic data
// (spectrum, 256 channels) consisting of 5 very closely positioned, relatively
// wide peaks (sigma =5), with added noise (Figure 13). Thin lines represent
// pure Gaussians (see Table 1); thick line is a resulting spectrum with
// additive noise (10% of the amplitude of small peaks).
//
// <img width=600 height=367 src="gif/NcSpectrum_Deconvolution_wide2.jpg">
//
// Figure 13 Testing example of synthetic spectrum composed of 5 Gaussians with
// added noise.
//
// In ideal case, we should obtain the result given in Figure 14. The areas of
// the Gaussian components of the spectrum are concentrated completely to
// delta-functions. When solving the overdetermined system of linear equations
// with data from Figure 13 in the sense of minimum least squares criterion
// without any regularization we obtain the result with large oscillations
// (Figure 15). From mathematical point of view, it is the optimal solution in
// the unconstrained space of independent variables. From physical point of
// view we are interested only in a meaningful solution. Therefore, we have to
// employ regularization techniques (e.g. Gold deconvolution) and/or to
// confine the space of allowed solutions to subspace of positive solutions.
//
// <img width=589 height=189 src="gif/NcSpectrum_Deconvolution_wide3.jpg">
//
// Figure 14 The same spectrum like in Figure 13, outlined bars show the
// contents of present components (peaks).
// <img width=585 height=183 src="gif/NcSpectrum_Deconvolution_wide4.jpg">
//
// Figure 15 Least squares solution of the system of linear equations without
// regularization.
//
// Example 9 - script Deconvolution_wide.c
//
// When we employ Gold deconvolution algorithm we obtain the result given in
// Fig. 16. One can observe that the resulting spectrum is smooth. On the
// other hand the method is not able to decompose completely the peaks in the
// spectrum.
//
// <img width=601 height=407 src="gif/NcSpectrum_Deconvolution_wide5.jpg">
// Figure 16 Example of Gold deconvolution for closely positioned wide peaks.
// The original source spectrum is drawn with black color, the spectrum after
// the deconvolution (10000 iterations) with red color.
//
// Script:
//
// Example to illustrate deconvolution function (class NcSpectrum).
// To execute this example, do
// root > .x Deconvolution_wide.C
//
// #include <NcSpectrum>
//
// void Deconvolution_wide() {
// Int_t i;
// Double_t nbins = 256;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * response = new float[nbins];
// TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
// TH1F *d = new TH1F("d","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("decon3;1");
// TFile *fr = new TFile("spectra\\NcSpectrum.root");
// d=(TH1F*) fr->Get("decon_response_wide;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
// TCanvas *Decon1 = gROOT->GetListOfCanvases()->FindObject("Decon1");
// if (!Decon1) Decon1 = new TCanvas("Decon1",
// "Deconvolution of closely positioned overlapping peaks using Gold deconvolution method",10,10,1000,700);
// h->SetMaximum(30000);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// s->Deconvolution(source,response,256,10000,1,1);
// for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
// d->SetLineColor(kRed);
// d->Draw("SAME L");
// }
//
// Example 10 - script Deconvolution_wide_boost.c :
//
// Further let us employ boosting operation into deconvolution (Fig. 17).
//
// <img width=601 height=407 src="gif/NcSpectrum_Deconvolution_wide6.jpg">
//
// Figure 17 The original source spectrum is drawn with black color, the
// spectrum after the deconvolution with red color. Number of iterations = 200,
// number of repetitions = 50 and boosting coefficient = 1.2.
//
// One can observe that peaks are decomposed practically to delta functions.
// Number of peaks is correct, positions of big peaks as well as their areas
// are relatively well estimated. However there is a considerable error in
// the estimation of the position of small right hand peak.
//
// Script:
//
// Example to illustrate deconvolution function (class NcSpectrum).
// To execute this example, do
// root > .x Deconvolution_wide_boost.C
//
// #include <NcSpectrum>
//
// void Deconvolution_wide_boost() {
// Int_t i;
// Double_t nbins = 256;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * response = new float[nbins];
// TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
// TH1F *d = new TH1F("d","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("decon3;1");
// TFile *fr = new TFile("spectra\\NcSpectrum.root");
// d=(TH1F*) fr->Get("decon_response_wide;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
// TCanvas *Decon1 = gROOT->GetListOfCanvases()->FindObject("Decon1");
// if (!Decon1) Decon1 = new TCanvas("Decon1",
// "Deconvolution of closely positioned overlapping peaks using boosted Gold deconvolution method",10,10,1000,700);
// h->SetMaximum(110000);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// s->Deconvolution(source,response,256,200,50,1.2);
// for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
// d->SetLineColor(kRed);
// d->Draw("SAME L");
// }

Definition at line 1659 of file NcSpectrum.cxx.

◆ DeconvolutionRL()

const char * NcSpectrum::DeconvolutionRL ( float * source,
const float * response,
Int_t ssize,
Int_t numberIterations,
Int_t numberRepetitions,
Double_t boost )
// One-dimensional deconvolution function.
//
// This function calculates deconvolution from source spectrum according to
// response spectrum using Richardson-Lucy deconvolution algorithm. The result
// is placed in the vector pointed by source pointer. On successful completion
// it returns 0. On error it returns pointer to the string describing error.
// If desired after every numberIterations one can apply boosting operation
// (exponential function with exponent given by boost coefficient) and repeat
// it numberRepetitions times (see Gold deconvolution).
//
// Function parameters:
//
// source: pointer to the vector of source spectrum
// response: pointer to the vector of response spectrum
// ssize: length of source and response spectra
// numberIterations, for details we refer to the reference given above
// numberRepetitions, for repeated boosted deconvolution
// boost, boosting coefficient
//
// Richardson-Lucy deconvolution algorithm:
//
// For discrete systems it has the form:
//
// <img width=438 height=98 src="gif/NcSpectrum_DeconvolutionRL1.gif">
//
// <img width=124 height=39 src="gif/NcSpectrum_DeconvolutionRL2.gif">
//
// for positive input data and response matrix this iterative method forces
// the deconvoluted spectra to be non-negative. The Richardson-Lucy
// iteration converges to the maximum likelihood solution for Poisson statistics
// in the data.
//
// References:
//
// Abreu M.C. et al., A four-dimensional deconvolution method to correct NA38
// experimental data, NIM A 405 (1998) 139.
// Lucy L.B., A.J. 79 (1974) 745.
// Richardson W.H., J. Opt. Soc. Am. 62 (1972) 55.
//
// Examples of Richardson-Lucy deconvolution method:
//
// Example 11 - script DeconvolutionRL_wide.c :
//
// When we employ Richardson-Lucy deconvolution algorithm to our data from
// Fig. 13 we obtain the result given in Fig. 18. One can observe improvements
// as compared to the result achieved by Gold deconvolution. Neverthless it is
// unable to decompose the multiplet.
//
// <img width=601 height=407 src="gif/NcSpectrum_DeconvolutionRL_wide1.jpg">
// Figure 18 Example of Richardson-Lucy deconvolution for closely positioned
// wide peaks. The original source spectrum is drawn with black color, the
// spectrum after the deconvolution (10000 iterations) with red color.
//
// Script:
//
// Example to illustrate deconvolution function (class NcSpectrum).
// To execute this example, do
// root > .x DeconvolutionRL_wide.C
//
// #include <NcSpectrum>
//
// void DeconvolutionRL_wide() {
// Int_t i;
// Double_t nbins = 256;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * response = new float[nbins];
// TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
// TH1F *d = new TH1F("d","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("decon3;1");
// TFile *fr = new TFile("spectra\\NcSpectrum.root");
// d=(TH1F*) fr->Get("decon_response_wide;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
// TCanvas *Decon1 = gROOT->GetListOfCanvases()->FindObject("Decon1");
// if (!Decon1) Decon1 = new TCanvas("Decon1",
// "Deconvolution of closely positioned overlapping peaks using Richardson-Lucy deconvolution method",
// 10,10,1000,700);
// h->SetMaximum(30000);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// s->DeconvolutionRL(source,response,256,10000,1,1);
// for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
// d->SetLineColor(kRed);
// d->Draw("SAME L");
// }
//
// Example 12 - script DeconvolutionRL_wide_boost.c :
//
// Further let us employ boosting operation into deconvolution (Fig. 19).
// <img width=601 height=407 src="gif/NcSpectrum_DeconvolutionRL_wide2.jpg">
//
// Figure 19 The original source spectrum is drawn with black color, the
// spectrum after the deconvolution with red color. Number of iterations = 200,
// number of repetitions = 50 and boosting coefficient = 1.2.
//
// One can observe improvements in the estimation of peak positions as compared
// to the results achieved by Gold deconvolution.
//
// Script:
//
// Example to illustrate deconvolution function (class NcSpectrum).
// To execute this example, do
// root > .x DeconvolutionRL_wide_boost.C
//
// #include <NcSpectrum>
//
// void DeconvolutionRL_wide_boost() {
// Int_t i;
// Double_t nbins = 256;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * response = new float[nbins];
// TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
// TH1F *d = new TH1F("d","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("decon3;1");
// TFile *fr = new TFile("spectra\\NcSpectrum.root");
// d=(TH1F*) fr->Get("decon_response_wide;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
// TCanvas *Decon1 = gROOT->GetListOfCanvases()->FindObject("Decon1");
// if (!Decon1) Decon1 = new TCanvas("Decon1",
// "Deconvolution of closely positioned overlapping peaks using boosted Richardson-Lucy deconvolution method",
// 10,10,1000,700);
// h->SetMaximum(110000);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// s->DeconvolutionRL(source,response,256,200,50,1.2);
// for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
// d->SetLineColor(kRed);
// d->Draw("SAME L");
// }

Definition at line 2063 of file NcSpectrum.cxx.

◆ GetHistogram()

TH1 * NcSpectrum::GetHistogram ( ) const
inline

Definition at line 64 of file NcSpectrum.h.

◆ GetNPeaks()

Int_t NcSpectrum::GetNPeaks ( ) const
inline

Definition at line 65 of file NcSpectrum.h.

◆ GetPositionX()

Float_t * NcSpectrum::GetPositionX ( ) const
inline

Definition at line 66 of file NcSpectrum.h.

◆ GetPositionY()

Float_t * NcSpectrum::GetPositionY ( ) const
inline

Definition at line 67 of file NcSpectrum.h.

◆ operator=()

NcSpectrum & NcSpectrum::operator= ( const NcSpectrum & )
private

◆ Print()

void NcSpectrum::Print ( Option_t * option = "") const
virtual
// Print the array of positions.

Definition at line 279 of file NcSpectrum.cxx.

◆ Search()

Int_t NcSpectrum::Search ( const TH1 * hist,
Double_t sigma = 2,
Option_t * option = "",
Double_t threshold = 0.05 )
virtual
// One-dimensional peak search function
//
// This function searches for peaks in source spectrum in hin
// The number of found peaks and their positions are written into
// the members fNpeaks and fPositionX.
// The search is performed in the current histogram range.
//
// Function parameters:
//
// hin: pointer to the histogram of source spectrum
// sigma: sigma of searched peaks, for details we refer to manual
// threshold: (default=0.05) peaks with amplitude less than
// threshold*highest_peak are discarded. 0<threshold<1
//
// By default, the background is removed before deconvolution.
// Specify the option "nobackground" to not remove the background.
//
// By default the "Markov" chain algorithm is used.
// Specify the option "noMarkov" to disable this algorithm
// Note that by default the source spectrum is replaced by a new spectrum
//
// By default a polymarker object is created and added to the list of
// functions of the histogram. The histogram is drawn with the specified
// option and the polymarker object drawn on top of the histogram.
// The polymarker coordinates correspond to the npeaks peaks found in the histogram.
//
// A pointer to the polymarker object can be retrieved later via:
//
// TList *functions = hin->GetListOfFunctions();
// TPolyMarker *pm = (TPolyMarker*)functions->FindObject("TPolyMarker");
//
// Specify the option "goff" to disable the storage and drawing of the polymarker.
//
// To disable the final drawing of the histogram with the search results (in case
// you want to draw it yourself) specify "nodraw" in the options parameter.

Definition at line 295 of file NcSpectrum.cxx.

◆ Search1HighRes()

Int_t NcSpectrum::Search1HighRes ( float * source,
float * destVector,
Int_t ssize,
float sigma,
Double_t threshold,
bool backgroundRemove,
Int_t deconIterations,
bool markov,
Int_t averWindow )
// Old name of SearcHighRes introduced for back compatibility.
// This function will be removed after the June 2006 release

Definition at line 3215 of file NcSpectrum.cxx.

◆ SearchHighRes()

Int_t NcSpectrum::SearchHighRes ( float * source,
float * destVector,
Int_t ssize,
float sigma,
Double_t threshold,
bool backgroundRemove,
Int_t deconIterations,
bool markov,
Int_t averWindow )
// One-dimensional high-resolution peak search function
//
// This function searches for peaks in source spectrum. It is based on
// deconvolution method. First the background is removed (if desired), then
// Markov smoothed spectrum is calculated (if desired), then the response
// function is generated according to given sigma and deconvolution is
// carried out. The order of peaks is arranged according to their heights in
// the spectrum after background elimination. The highest peak is the first in
// the list. On success it returns number of found peaks.
//
// Function parameters:
//
// source: pointer to the vector of source spectrum.
// destVector: pointer to the vector of resulting deconvolved spectrum.
// ssize: length of source spectrum.
// sigma: sigma of searched peaks, for details we refer to manual.
// threshold: threshold value in % for selected peaks, peaks with
// amplitude less than threshold*highest_peak/100 are ignored, see manual.
// backgroundRemove: logical variable, set if the removal of background before deconvolution is desired.
// deconIterations-number of iterations in deconvolution operation.
// markov: logical variable, if it is true, first the source spectrum
// is replaced by new spectrum calculated using Markov chains method.
// averWindow: averanging window of searched peaks, for details
// we refer to manual (applies only for Markov method).
//
// Peaks searching:
//
// The goal of this function is to identify automatically the peaks in spectrum
// with the presence of the continuous background and statistical
// fluctuations - noise.
//
// The common problems connected with correct peak identification are:
//
// non-sensitivity to noise, i.e., only statistically relevant peaks should be identified.
// non-sensitivity of the algorithm to continuous background.
// ability to identify peaks close to the edges of the spectrum region.
// Usually peak finders fail to detect them.
// resolution, decomposition of doublets and multiplets.
// The algorithm should be able to recognize close positioned peaks.
// ability to identify peaks with different sigma.
//
// <img width=600 height=375 src="gif/NcSpectrum_Searching1.jpg">
//
// Fig. 27 An example of one-dimensional synthetic spectrum with found peaks
// denoted by markers.
//
// References:
//
// A method for identification of peaks in the presence of
// background and its application to spectrum analysis. NIM 50 (1967), 309-320.
// Identification of peaks in multidimensional coincidence gamma-ray spectra.
// NIM, A443 (2000) 108-125.
// A new algorithm for automatic photopeak searches. NIM A 376 (1996), 451.
//
// Examples of peak searching method:
//
// The SearchHighRes function provides users with the possibility to vary the
// input parameters and with the access to the output deconvolved data in the
// destination spectrum. Based on the output data one can tune the parameters.
//
// Example 15 - script SearchHR1.c:
// <img width=600 height=321 src="gif/NcSpectrum_Searching1.jpg">
//
// Fig. 28 One-dimensional spectrum with found peaks denoted by markers, 3
// iterations steps in the deconvolution.
//
// <img width=600 height=323 src="gif/NcSpectrum_Searching2.jpg">
// Fig. 29 One-dimensional spectrum with found peaks denoted by markers, 8
// iterations steps in the deconvolution.
//
// Script:
//
// Example to illustrate high resolution peak searching function (class NcSpectrum).
// To execute this example, do
// root > .x SearchHR1.C
//
// #include <NcSpectrum>
//
// void SearchHR1() {
// Float_t fPositionX[100];
// Float_t fPositionY[100];
// Int_t fNPeaks = 0;
// Int_t i,nfound,bin;
// Double_t nbins = 1024,a;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * dest = new float[nbins];
// TH1F *h = new TH1F("h","High resolution peak searching, number of iterations = 3",nbins,xmin,xmax);
// TH1F *d = new TH1F("d","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("search2;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// TCanvas *Search = gROOT->GetListOfCanvases()->FindObject("Search");
// if (!Search) Search = new TCanvas("Search","Search",10,10,1000,700);
// h->SetMaximum(4000);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// nfound = s->SearchHighRes(source, dest, nbins, 8, 2, kTRUE, 3, kTRUE, 3);
// Float_t *xpeaks = s->GetPositionX();
// for (i = 0; i < nfound; i++) {
// a=xpeaks[i];
// bin = 1 + Int_t(a + 0.5);
// fPositionX[i] = h->GetBinCenter(bin);
// fPositionY[i] = h->GetBinContent(bin);
// }
// TPolyMarker * pm = (TPolyMarker*)h->GetListOfFunctions()->FindObject("TPolyMarker");
// if (pm) {
// h->GetListOfFunctions()->Remove(pm);
// delete pm;
// }
// pm = new TPolyMarker(nfound, fPositionX, fPositionY);
// h->GetListOfFunctions()->Add(pm);
// pm->SetMarkerStyle(23);
// pm->SetMarkerColor(kRed);
// pm->SetMarkerSize(1.3);
// for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,dest[i]);
// d->SetLineColor(kRed);
// d->Draw("SAME");
// printf("Found %d candidate peaks\n",nfound);
// for(i=0;i<nfound;i++)
// printf("posx= %d, posy= %d\n",fPositionX[i], fPositionY[i]);
// }
//
// Example 16 - script SearchHR3.c:
//
// <img width=600 height=328 src="gif/NcSpectrum_Searching3.jpg">
//
// Fig. 30 Influence of number of iterations (3-red, 10-blue, 100- green,
// 1000-magenta), sigma=8, smoothing width=3.
//
// <img width=600 height=321 src="gif/NcSpectrum_Searching4.jpg">
//
// Fig. 31 Influence of sigma (3-red, 8-blue, 20- green, 43-magenta),
// num. iter.=10, sm. width=3.
//
// <img width=600 height=323 src="gif/NcSpectrum_Searching5.jpg"></p>
//
// Fig. 32 Influence smoothing width (0-red, 3-blue, 7- green, 20-magenta), num.
// iter.=10, sigma=8.
//
// Script:
//
// Example to illustrate the influence of number of iterations in deconvolution in high resolution peak searching function (class NcSpectrum).
// To execute this example, do
// root > .x SearchHR3.C
//
// #include <NcSpectrum>
//
// void SearchHR3() {
// Float_t fPositionX[100];
// Float_t fPositionY[100];
// Int_t fNPeaks = 0;
// Int_t i,nfound,bin;
// Double_t nbins = 1024,a;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// Float_t * dest = new float[nbins];
// TH1F *h = new TH1F("h","Influence of # of iterations in deconvolution in peak searching",nbins,xmin,xmax);
// TH1F *d1 = new TH1F("d1","",nbins,xmin,xmax);
// TH1F *d2 = new TH1F("d2","",nbins,xmin,xmax);
// TH1F *d3 = new TH1F("d3","",nbins,xmin,xmax);
// TH1F *d4 = new TH1F("d4","",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("search3;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// TCanvas *Search = gROOT->GetListOfCanvases()->FindObject("Search");
// if (!Search) Search = new TCanvas("Search","Search",10,10,1000,700);
// h->SetMaximum(1300);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// nfound = s->SearchHighRes(source, dest, nbins, 8, 2, kTRUE, 3, kTRUE, 3);
// Float_t *xpeaks = s->GetPositionX();
// for (i = 0; i < nfound; i++) {
// a=xpeaks[i];
// bin = 1 + Int_t(a + 0.5);
// fPositionX[i] = h->GetBinCenter(bin);
// fPositionY[i] = h->GetBinContent(bin);
// }
// TPolyMarker * pm = (TPolyMarker*)h->GetListOfFunctions()->FindObject("TPolyMarker");
// if (pm) {
// h->GetListOfFunctions()->Remove(pm);
// delete pm;
// }
// pm = new TPolyMarker(nfound, fPositionX, fPositionY);
// h->GetListOfFunctions()->Add(pm);
// pm->SetMarkerStyle(23);
// pm->SetMarkerColor(kRed);
// pm->SetMarkerSize(1.3);
// for (i = 0; i < nbins; i++) d1->SetBinContent(i + 1,dest[i]);
// h->Draw("");
// d1->SetLineColor(kRed);
// d1->Draw("SAME");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// s->SearchHighRes(source, dest, nbins, 8, 2, kTRUE, 10, kTRUE, 3);
// for (i = 0; i < nbins; i++) d2->SetBinContent(i + 1,dest[i]);
// d2->SetLineColor(kBlue);
// d2->Draw("SAME");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// s->SearchHighRes(source, dest, nbins, 8, 2, kTRUE, 100, kTRUE, 3);
// for (i = 0; i < nbins; i++) d3->SetBinContent(i + 1,dest[i]);
// d3->SetLineColor(kGreen);
// d3->Draw("SAME");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// s->SearchHighRes(source, dest, nbins, 8, 2, kTRUE, 1000, kTRUE, 3);
// for (i = 0; i < nbins; i++) d4->SetBinContent(i + 1,dest[i]);
// d4->SetLineColor(kMagenta);
// d4->Draw("SAME");
// printf("Found %d candidate peaks\n",nfound);
// }

Definition at line 2564 of file NcSpectrum.cxx.

◆ SetAverageWindow()

void NcSpectrum::SetAverageWindow ( Int_t w = 3)
static
// Static function: Set average window of searched peaks
// (see NcSpectrum::SearchHighRes).

Definition at line 146 of file NcSpectrum.cxx.

◆ SetDeconIterations()

void NcSpectrum::SetDeconIterations ( Int_t n = 3)
static
// Static function: Set max number of decon iterations in deconvolution
// operation (see NcSpectrum::SearchHighRes).

Definition at line 160 of file NcSpectrum.cxx.

◆ SetResolution()

void NcSpectrum::SetResolution ( Float_t resolution = 1)
// resolution: determines resolution of the neighboring peaks
// default value is 1 correspond to 3 sigma distance
// between peaks. Higher values allow higher resolution
// (smaller distance between peaks.
// May be set later through SetResolution.

Definition at line 414 of file NcSpectrum.cxx.

◆ SmoothMarkov()

const char * NcSpectrum::SmoothMarkov ( float * source,
Int_t ssize,
Int_t averWindow )
// One-dimensional markov spectrum smoothing function
//
// This function calculates smoothed spectrum from source spectrum based on
// Markov chain method. The result is placed in the array pointed by source
// pointer. On successful completion it returns 0. On error it returns pointer
// to the string describing error.
//
// Function parameters:
//
// source: pointer to the array of source spectrum
// ssize: length of source array
// averWindow: width of averaging smoothing window
//
// The goal of this function is the suppression of the statistical fluctuations.
// The algorithm is based on discrete Markov chain, which has very simple
// invariant distribution:
// <img width=551 height=63 src="gif/NcSpectrum_Smoothing1.gif">
//
// <img width=28 height=36 src="gif/NcSpectrum_Smoothing2.gif"> being defined
// from the normalization condition
// <img width=70 height=52 src="gif/NcSpectrum_Smoothing3.gif">.
// n is the length of the smoothed spectrum and
// <img width=258 height=60 src="gif/NcSpectrum_Smoothing4.gif">
//
// Reference:
//
// A new algorithm for automatic photopeak searches.
// NIM A 376 (1996), 451.
//
// Example 14 - script Smoothing.c
//
// <img width=296 height=182 src="gif/NcSpectrum_Smoothing1.jpg">
// Fig. 23 Original noisy spectrum
//
// <img width=296 height=182 src="gif/NcSpectrum_Smoothing2.jpg">
// Fig. 24 Smoothed spectrum m=3
//
// <img width=299 height=184 src="gif/NcSpectrum_Smoothing3.jpg">
// Fig. 25 Smoothed spectrum
//
// <img width=299 height=184 src="gif/NcSpectrum_Smoothing4.jpg">
// Fig.26 Smoothed spectrum m=10
//
// Script:
//
// Example to illustrate smoothing using Markov algorithm (class NcSpectrum).
// To execute this example, do
// root > .x Smoothing.C
//
// void Smoothing() {
// Int_t i;
// Double_t nbins = 1024;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbins;
// Float_t * source = new float[nbins];
// TH1F *h = new TH1F("h","Smoothed spectrum for m=3",nbins,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("smooth1;1");
// for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
// TCanvas *Smooth1 = gROOT->GetListOfCanvases()->FindObject("Smooth1");
// if (!Smooth1) Smooth1 = new TCanvas("Smooth1","Smooth1",10,10,1000,700);
// NcSpectrum *s = new NcSpectrum();
// s->SmoothMarkov(source,1024,3); //3, 7, 10
// for (i = 0; i < nbins; i++) h->SetBinContent(i + 1,source[i]);
// h->SetAxisRange(330,880);
// h->Draw("L");
// }

Definition at line 1516 of file NcSpectrum.cxx.

◆ StaticBackground()

TH1 * NcSpectrum::StaticBackground ( const TH1 * hist,
Int_t niter = 20,
Option_t * option = "" )
static
// Static function, interface to NcSpectrum::Background.

Definition at line 3247 of file NcSpectrum.cxx.

◆ StaticSearch()

Int_t NcSpectrum::StaticSearch ( const TH1 * hist,
Double_t sigma = 2,
Option_t * option = "goff",
Double_t threshold = 0.05 )
static
// Static function, interface to NcSpectrum::Search.

Definition at line 3233 of file NcSpectrum.cxx.

◆ Unfolding()

const char * NcSpectrum::Unfolding ( float * source,
const float ** respMatrix,
Int_t ssizex,
Int_t ssizey,
Int_t numberIterations,
Int_t numberRepetitions,
Double_t boost )
// One-dimensional unfolding function
//
// This function unfolds source spectrum according to response matrix columns.
// The result is placed in the vector pointed by source pointer.
// The coefficients of the resulting vector represent contents of the columns
// (weights) in the input vector. On successful completion it returns 0. On
// error it returns pointer to the string describing error. If desired after
// every numberIterations one can apply boosting operation (exponential
// function with exponent given by boost coefficient) and repeat it
// numberRepetitions times. For details we refer to [1].
//
// Function parameters:
//
// source: pointer to the vector of source spectrum
// respMatrix: pointer to the matrix of response spectra
// ssizex: length of source spectrum and # of columns of the response matrix. ssizex must be >= ssizey.
// ssizey: length of destination spectrum and # of rows of the response matrix.
// numberIterations: number of iterations
// numberRepetitions: number of repetitions for boosted deconvolution. It must be greater or equal to one.
// boost: boosting coefficient, applies only if numberRepetitions is greater than one.
//
// Unfolding:
//
// The goal is the decomposition of spectrum to a given set of component spectra.
//
// The mathematical formulation of the discrete linear system is:
//
// <img width=588 height=89 src="gif/NcSpectrum_Unfolding1.gif">
//
// <img width=597 height=228 src="gif/NcSpectrum_Unfolding2.gif">
//
// References:
//
// Decomposition of continuum gamma-ray spectra using synthetized response matrix.
// NIM A 516 (2004), 172-183.
//
// Example of unfolding:
//
// Example 13 - script Unfolding.c:
//
// <img width=442 height=648 src="gif/NcSpectrum_Unfolding3.gif">
//
// Fig. 20 Response matrix composed of neutron spectra of pure chemical elements.
// <img width=604 height=372 src="gif/NcSpectrum_Unfolding2.jpg">
//
// Fig. 21 Source neutron spectrum to be decomposed
//
// <img width=600 height=360 src="gif/NcSpectrum_Unfolding3.jpg">
//
// Fig. 22 Spectrum after decomposition, contains 10 coefficients, which
// correspond to contents of chemical components (dominant 8-th and 10-th
// components, i.e. O, Si)
//
// Script:
//
// Example to illustrate unfolding function (class NcSpectrum).
// To execute this example, do
// root > .x Unfolding.C
//
// #include <NcSpectrum>
//
// void Unfolding() {
// Int_t i, j;
// Int_t nbinsx = 2048;
// Int_t nbinsy = 10;
// Double_t xmin = 0;
// Double_t xmax = (Double_t)nbinsx;
// Double_t ymin = 0;
// Double_t ymax = (Double_t)nbinsy;
// Float_t * source = new float[nbinsx];
// Float_t ** response = new float *[nbinsy];
// for (i=0;i<nbinsy;i++) response[i]=new float[nbinsx];
// TH1F *h = new TH1F("h","",nbinsx,xmin,xmax);
// TH1F *d = new TH1F("d","Decomposition - unfolding",nbinsx,xmin,xmax);
// TH2F *decon_unf_resp = new TH2F("decon_unf_resp","Root File",nbinsy,ymin,ymax,nbinsx,xmin,xmax);
// TFile *f = new TFile("spectra\\NcSpectrum.root");
// h=(TH1F*) f->Get("decon_unf_in;1");
// TFile *fr = new TFile("spectra\\NcSpectrum.root");
// decon_unf_resp = (TH2F*) fr->Get("decon_unf_resp;1");
// for (i = 0; i < nbinsx; i++) source[i] = h->GetBinContent(i + 1);
// for (i = 0; i < nbinsy; i++){
// for (j = 0; j< nbinsx; j++){
// response[i][j] = decon_unf_resp->GetBinContent(i + 1, j + 1);
// }
// }
// TCanvas *Decon1 = gROOT->GetListOfCanvases()->FindObject("Decon1");
// if (!Decon1) Decon1 = new TCanvas("Decon1","Decon1",10,10,1000,700);
// h->Draw("L");
// NcSpectrum *s = new NcSpectrum();
// s->Unfolding(source,response,nbinsx,nbinsy,1000,1,1);
// for (i = 0; i < nbinsy; i++) d->SetBinContent(i + 1,source[i]);
// d->SetLineColor(kRed);
// d->SetAxisRange(0,nbinsy);
// d->Draw("");
// }

Definition at line 2312 of file NcSpectrum.cxx.

Member Data Documentation

◆ fgAverageWindow

Int_t NcSpectrum::fgAverageWindow = 3
staticprotected

Definition at line 40 of file NcSpectrum.h.

◆ fgIterations

Int_t NcSpectrum::fgIterations = 3
staticprotected

Definition at line 41 of file NcSpectrum.h.

◆ fHistogram

TH1* NcSpectrum::fHistogram
protected

Definition at line 39 of file NcSpectrum.h.

◆ fMaxPeaks

Int_t NcSpectrum::fMaxPeaks
protected

Definition at line 33 of file NcSpectrum.h.

◆ fNPeaks

Int_t NcSpectrum::fNPeaks
protected

Definition at line 34 of file NcSpectrum.h.

◆ fPosition

Float_t* NcSpectrum::fPosition
protected

Definition at line 35 of file NcSpectrum.h.

◆ fPositionX

Float_t* NcSpectrum::fPositionX
protected

Definition at line 36 of file NcSpectrum.h.

◆ fPositionY

Float_t* NcSpectrum::fPositionY
protected

Definition at line 37 of file NcSpectrum.h.

◆ fResolution

Float_t NcSpectrum::fResolution
protected

Definition at line 38 of file NcSpectrum.h.


The documentation for this class was generated from the following files: