Hi Constantin, Constantin Vaman wrote: > > Hi All, > I am trying to use Root in acquisition system for gamma spectroscopy, and > have a couple of probably naive questions. > After creating a TCanvas instance, ToggleEventStatus() method will display > in the status bar the cross hair position as nr. of channels. What I am > interested in, is to display the cursor position in terms of energy. E.g. > for a 0.25 keV/ch, I want an energy of 100 to be displayed as the x coordinate > in the status bar, when the cursor is above channel 400. This is already the case > Also, I would like to know how can avoid having the x coordinate being > displayed in scientific format for x > 1000, when the cross hair is not > precisely on the histogram contour. Take the version from CVS. I have modified the format. > Finally, I can find the peaks automatically, but I can't figure out how to > display automatically and nicely the energy corresponding to a particular > peak, above the peak, on the histogram. > see an example in the macro in attachement Rene Brun > I would very much appreciate any help, and/or references to samples of > code. > > Best regards, > > Constantin Vaman, > SUNY at Stony Brook. // Example to illustrate the peak finder (class TSpectrum). // This script generates a random number of gaussian peaks // on top of a linear background. // The position of the peaks is found via TSpectrum // To execute this example, do // root > .x showpeaks.C (generate 20 peaks by default) // root > .x showpeaks.C(30) (generates 30 peaks) // // Author: Rene Brun #include "TCanvas.h" #include "TH1.h" #include "TF1.h" #include "TRandom.h" #include "TSpectrum.h" Int_t npeaks; Double_t fpeaks(Double_t *x, Double_t *par) { Double_t result = par[0] + par[1]*x[0]; for (Int_t p=0;p<npeaks;p++) { Double_t norm = par[3*p+2]; Double_t mean = par[3*p+3]; Double_t sigma = par[3*p+4]; result += norm*TMath::Gaus(x[0],mean,sigma); } return result; } void showpeaks(Int_t np=20) { npeaks = np; TH1F *h = new TH1F("h","test",500,0,1000); //generate n peaks at random Double_t par[3000]; par[0] = 0.8; par[1] = -0.6/1000; Int_t p; for (p=0;p<npeaks;p++) { par[3*p+2] = 1; par[3*p+3] = 10+gRandom->Rndm()*980; par[3*p+4] = 3+2*gRandom->Rndm(); } TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks); f->SetNpx(1000); f->SetParameters(par); TCanvas *c1 = new TCanvas("c1","c1",10,10,1000,600); h->FillRandom("f",200000); h->Draw(); //Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(2*npeaks); Int_t nfound = s->Search(h,1,""); Float_t *xpeaks = s->GetPositionX(); TArrow arrow; arrow.SetFillColor(kBlue); Double_t dy = 0.1*h->GetMaximum(); for (p=0;p<nfound;p++) { Float_t xp = xpeaks[p]; Int_t bin = h->GetXaxis()->FindBin(xp); Float_t yp = h->GetBinContent(bin); arrow.DrawArrow(xp,yp+dy,xp,yp+0.2*dy,0.02,"|>"); } }
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:17 MET