Spectrum analysis

Hello everyone, I am new to root, but want to use it to analyse spectrums recorded with a new GRIPS-detector I am building for my bachelor thesis.

The raw data consists of equidistant wavelenghts (x-axis) and a recorded intensities (y-axis).

Now I need to find the peaks in the recorded spectrum; I already managed to use TSpectrum with a little help from this topic: Newbie: Using TSpectrum with Graphs

But for some reason I am unable to retrieve the x-values of the found peaks.
I tried using s->GetPositionX(); but it returns a very high value which has nothing to do with any of the raw data (~80mio).

Source code - a little modified from root’s graph.C-example:

[code]void graph() {
char filename[] = “Cd-Lampe_07.txt”;
Int_t npeaks = 14;

TCanvas *c1 = new TCanvas(“c1”,“A Simple Graph Example”,200,10,1200,500);

c1->SetFillColor(42);
c1->SetGrid();

char line[80];
const Int_t n = 10000;
float elapsed_seconds;
float wavelenght[n];
float voltage[n];
int direction;
fr = fopen (filename, "rt");
int i = 0;
while(fgets(line, 80, fr) != NULL)

{
sscanf (line, “%f\t%f\t%f\t%d”, &elapsed_seconds, &wavelenght[i], &voltage[i], &direction);
i++;
}
fclose(fr);

gr = new TGraph(i, wavelenght, voltage);
gr->SetLineColor(0);
gr->SetLineWidth(0);
gr->SetMarkerColor(1);
gr->SetMarkerStyle(1);
gr->SetTitle(filename);
gr->GetXaxis()->SetTitle(“wavelenght in Å”);
gr->GetYaxis()->SetTitle(“Voltage in V”);
gr->Draw(“ACP”);

// TCanvas::Update() draws the frame, after which one can change it
c1->Update();
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(12);
c1->Modified();

TCanvas *c2 = new TCanvas(“c2”,“spectrum asdf”,200,10,1200,500);

TH1F h = new TH1F(“h”,“spectrum”,i,0,wavelenght[i-1]+0.5);
//h->SetContents(voltage);
for (int j=0; j<i; j++)
{
h->SetBinContent(j, voltage[j]);
}
TSpectrum s = new TSpectrum(npeaks);
Int_t nfound = s->Search(h,2);
Float_t
wavelenght_peak_x[20];
Float_t
wavelenght_peak_y[20];
wavelenght_peak_x = s->GetPositionX();
wavelenght_peak_y = s->GetPositionY();
printf(“Found %d candidate peaks to fit:\n”,nfound);
for (int j=0; j<20; j++)
{
printf(“Peak position: \t %.1f \t %.1f\n”,wavelenght_peak_x[j],wavelenght_peak_y[j]);
}
c2->Update();
}[/code]

I hope someone can help me or maybe know a better way to analyse xy-spectrums :slight_smile:

Thank you
Cd-Lampe_07.txt (231 KB)

I used some different code now, and it works! sorry for you time :slight_smile:

TSpectrum *s = new TSpectrum(npeaks); Int_t nfound = s->Search(h,2); Float_t* wavelenght_peak_x = s->GetPositionX(); Float_t* wavelenght_peak_y = s->GetPositionY();