Logo ROOT   6.10/09
Reference Guide
SearchHR1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_spectrum
3 /// \notebook
4 /// Example to illustrate high resolution peak searching function (class TSpectrum).
5 ///
6 /// \macro_output
7 /// \macro_image
8 /// \macro_code
9 ///
10 /// \authors Miroslav Morhac, Olivier Couet
11 
12 void SearchHR1() {
13  Double_t fPositionX[100];
14  Double_t fPositionY[100];
15  Int_t fNPeaks = 0;
16  Int_t i,nfound,bin;
17  const Int_t nbins = 1024;
18  Double_t xmin = 0;
20  Double_t a;
21  Double_t source[nbins], dest[nbins];
22  gROOT->ForceStyle();
23 
24  TString dir = gROOT->GetTutorialDir();
25  TString file = dir+"/spectrum/TSpectrum.root";
26  TFile *f = new TFile(file.Data());
27  TH1F *h = (TH1F*) f->Get("back2");
28  h->SetTitle("High resolution peak searching, number of iterations = 3");
29  h->GetXaxis()->SetRange(1,nbins);
30  TH1F *d = new TH1F("d","",nbins,xmin,xmax);
31  h->Draw("L");
32 
33  for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
34 
35  h->Draw("L");
36 
37  TSpectrum *s = new TSpectrum();
38 
39  nfound = s->SearchHighRes(source, dest, nbins, 8, 2, kTRUE, 3, kTRUE, 3);
40  Double_t *xpeaks = s->GetPositionX();
41  for (i = 0; i < nfound; i++) {
42  a=xpeaks[i];
43  bin = 1 + Int_t(a + 0.5);
44  fPositionX[i] = h->GetBinCenter(bin);
45  fPositionY[i] = h->GetBinContent(bin);
46  }
47 
48  TPolyMarker * pm = (TPolyMarker*)h->GetListOfFunctions()->FindObject("TPolyMarker");
49  if (pm) {
50  h->GetListOfFunctions()->Remove(pm);
51  delete pm;
52  }
53  pm = new TPolyMarker(nfound, fPositionX, fPositionY);
54  h->GetListOfFunctions()->Add(pm);
55  pm->SetMarkerStyle(23);
56  pm->SetMarkerColor(kRed);
57  pm->SetMarkerSize(1.3);
58 
59  for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,dest[i]);
60  d->SetLineColor(kRed);
61  d->Draw("SAME");
62 
63  printf("Found %d candidate peaks\n",nfound);
64  for( i=0;i<nfound;i++) printf("posx= %f, posy= %f\n",fPositionX[i], fPositionY[i]);
65 }
float xmin
Definition: THbookFile.cxx:93
Definition: Rtypes.h:56
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
TH1 * h
Definition: legend2.C:5
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:375
Basic string class.
Definition: TString.h:129
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
int nbins[3]
Int_t SearchHighRes(Double_t *source, Double_t *destVector, Int_t ssize, Double_t sigma, Double_t threshold, bool backgroundRemove, Int_t deconIterations, bool markov, Int_t averWindow)
One-dimensional high-resolution peak search function.
Definition: TSpectrum.cxx:2142
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
Double_t * GetPositionX() const
Definition: TSpectrum.h:58
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:328
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition: TH1.cxx:8325
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
float xmax
Definition: THbookFile.cxx:93
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
A PolyMarker is defined by an array on N points in a 2-D space.
Definition: TPolyMarker.h:31
double f(double x)
double Double_t
Definition: RtypesCore.h:55
Advanced Spectra Processing.
Definition: TSpectrum.h:18
Definition: file.py:1
#define dest(otri, vertexptr)
Definition: triangle.c:1040
const Bool_t kTRUE
Definition: RtypesCore.h:91
const char * Data() const
Definition: TString.h:347