Hi,
Kazuyoshi Furutaka wrote:
> Dear rooters,
>
> Could someone teach me
>
> 1. why the attached script (named 'peakSearchTest.C'),
>    which try to find candidate of peaks from TH1F "hpx"
>    in "hsimple.root" using TSpectrum::Search(), DISPLAYS
>    the histogram when run as an unnamed script
>    (.x peakSearchTest.C), whereas it does not when run
>    as a named one (by invoking peakSearchTest() after
>    loading the script (or `.x peakSearchTest.C`), of
>    course after uncommenting the function name in the
>    script and commenting out the first curly brace.)?
>
>    In the latter, only an empty canvas is displayed...
>    (though a candidate is successfully found)
>   
Replace
  TFile f("hsimple.root");
by
  TFile *f = new TFile("hsimple.root");
For more details read chapter about Object Ownership in Users Guide
> 2. whether it is possible to seach peaks using TSpectrum::Search()
>    without displaying any canvas/histogram (or control
>    its display) in interactive root sessions (i.e. w/o
>    -b option) or not?
>
>    Even though the histogram is not explicitly drawn,
>    the attached script (when run as unnamed one) displays
>    it.
>
>   
Use option "goff", ie
  Int_t npfound = s->Search(h,2,"goff",0.10);
see doc at http://root.cern.ch/root/htmldoc/TSpectrum.html#TSpectrum:Search
Rene Brun
>   
> Thanks in advance.
>
> Yours,
> Kazuyoshi
> --
> Kazuyoshi Furutaka
> furutaka _dot_ kazuyoshi _at_ jaea _dot_ go _dot_ jp
>   
> ------------------------------------------------------------------------
>
> #if !defined(__CINT__)
> #  include "TCanvas.h"
> #  include "TH1.h"
> #  include "TFile.h"
> #  include "TSpectrum.h"
> #endif
>
> {
> //void peakSearchTest() {
>
>   // create a canvas
>   TCanvas *c1 = new TCanvas("c1","c1",10,10,800,500);
>
>   // read and draw a histogram from a file
>   TFile f("hsimple.root");
>   TH1F *h = (TH1F*)f.Get("hpx");
>   //h->Draw();
>
>   // search a peak, maxpositions=1, resolution=1(default)
>   TSpectrum *s = new TSpectrum(2);
>   // in histogram 'h', sigma=2, options="", thresh.=0.10
>   Int_t npfound = s->Search(h,2,"",0.10);
>   if ( npfound > 0 ) {
>     Float_t *xpeaks = s->GetPositionX();
>     for ( Int_t np=0 ; np < npfound ; np++ ) {
>       Float_t xp = *(xpeaks+np);
>       Int_t    bin    = h->GetXaxis()->FindBin(xp);
>       printf("Found a candidate of peak at %d channel.\n", bin);
>     }
>   }
> }
>   
Received on Thu Dec 14 2006 - 09:40:27 MET
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:02 MET