PengJiDing的个人博客分享 http://blog.sciencenet.cn/u/PengJiDing

博文

简单的谱处理程序

已有 4022 次阅读 2011-11-12 19:57 |个人分类:飞秒激光|系统分类:科研笔记| ROOT, 谱处理程序, 康普顿平台

  用ROOT里面的TSpectrum可以写自己想要的谱处理程序,包括扣除康普顿平台,寻峰,计算峰面积等功能。下面是我写的一段程序,仅供参考。程序必须要在ROOT下运行,你可以对程序做更多的扩展。

下面是用写的程序处理的谱的结果:

谱处理程序 - 木哈哈 - 小小书虫
 
    /* Author: PengJi Ding (丁鹏基)
     this program is writed for background-removing with SNIP algorithm  */

  {
     /*  input spectrum data and draw the original spectrum histogram h1 */
     FILE *fp=fopen("/home/dinghao/dinghao/Spectrum/Co60-1.txt","r");    // 所用的数据是Co-60的实验数据
     Int_t nbins=8193;
     Float_t m,n;
     TH1F *h1=new TH1F("h1","Original spectrum",8193,0,8192);
     TCanvas *Background = gROOT->GetListOfCanvases()->FindObject("Background");
       if (!Background) Background =
               new TCanvas("Background","Estimation of background with decreasing window",  
                 10,10,800,500);
    Background->Divide(1,2);
    Background->cd(1);
      for(Int_t i=0;i<nbins;i++) {
           fscanf(fp,"%f  %f",&(m[i]),&(n[i])); 
           h1->Fill(i,n[i]);
           h1->Draw();
        }
    fclose(fp);
    TFile f("/home/dinghao/dinghao/Spectrum/demo.root","recreate");     // save root file
    h1->Write();

 /* remove the background */
   int i;
   Double_t xmin  = 0;
   Double_t xmax  = 8192;
   Float_t *source = new float[nbins];
   TH1F *back = new TH1F("back","Original spectrum and Background",nbins,xmin,xmax);
   TH1F *d = new TH1F("d","",nbins,xmin,xmax);
   TH1F *d1 = new TH1F("d","",nbins,xmin,xmax);
   back=(TH1F*)f->Get("h1;1");
   TH1F *h3 = h1->Clone();
   Background->cd(2);

/* add searching peaks method and draw the result histogram  h3  */
    Float_t fPositionX[100];
    Float_t fPositionY[100];
    Int_t fNPeaks = 0;
    Int_t i,nfound,bin;
    Double_t a;
    Float_t *dest = new float[nbins];
    TSpectrum *s = new TSpectrum();
    for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1);
    nfound = s->SearchHighRes(source, dest, nbins, 2.3, 10, kTRUE, 10, 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] = h3->GetBinCenter(bin);
          fPositionY[i] = h3->GetBinContent(bin);
      }
   TPolyMarker * pm = (TPolyMarker*)h3->GetListOfFunctions()->FindObject("TPolyMarker");
       if (pm) {
           h3->GetListOfFunctions()->Remove(pm);
          delete pm;
        }
    pm = new TPolyMarker(nfound, fPositionX, fPositionY);
    h3->GetListOfFunctions()->Add(pm);
    pm->SetMarkerStyle(23);
    pm->SetMarkerColor(kRed);
    pm->SetMarkerSize(1.3); 
    h3->Draw();
    for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,dest[i]);
    d->SetLineColor(kMagenta);
    d->Draw("SAME");
    printf("Found %d candidate peaksn",nfound);
}



https://blog.sciencenet.cn/blog-653020-507334.html


下一篇:Ubuntu手动安装Adobe Flash Player
收藏 IP: 210.26.57.*| 热度|

1 田灿荣

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-28 10:17

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部