其他分享
首页 > 其他分享> > 给繁多的xspec拟合脚本注释一下,方便理解

给繁多的xspec拟合脚本注释一下,方便理解

作者:互联网

组里流传的脚本五花八门,基本都是陆老师写的。

但每一行每一句,好像谁都没有仔细看过,就只管拿去用就完事了,故打算学习一下tcl语言,读完后注释做个笔记。

tcl语言参考:https://wenku.baidu.com/view/47a65f7931b765ce050814b2.html?rec_flag=default&sxts=1553137274198

proc shakefit {} {                             //用户自己定义的过程
    tclout datagrp                                //输出数据组,datagrp [n] ,输出第n个谱的数据组数,n没定义则输出数据组的总数
    set numdatagrp $xspec_tclout         //定义numdatagrp为 tclout创建的变量xspec_tclout
    tclout modpar ;# find number of parameters      //输出模型参数的数量    
    set nopar [expr $xspec_tclout / $numdatagrp ]    //定义expr
    set mod_params ""
        for {set j 1} {$j <= $nopar} {incr j} {
    tclout pinfo $j
        set paramname [lindex $xspec_tclout 0]
        set paramunits ""
        if {[llength $xspec_tclout] > 1} {
        set paramunits "([lindex $xspec_tclout 1])"
           }
        tclout param $j
        set paramvalue [lindex $xspec_tclout 0]
        tclout sigma $j
        set err [lindex $xspec_tclout 0]
        set modparam "$j, $paramname, $paramunits, $paramvalue, $err "
        lappend mod_params $modparam
        } ;# End FOR
        tclout stat
        set chi $xspec_tclout
        tclout dof
        set dof [lindex $xspec_tclout 0]
        set rechi2 [expr $chi/$dof ]
        set chiparam "rechisq, $chi/$dof, $rechi2"
        lappend mod_params $chiparam
        energies extend low 8
        energies extend high 4E4
        fit 100 0.01
        flux 8 4E4 err 1000
        for {set j 1} {$j <= $numdatagrp} {incr j} {
            tclout flux $j
            set flux "flux spec $j $xspec_tclout"
            lappend mod_params $flux  
            }
       return $mod_params
} ;# End PROC
# ----------------------------------------------------------
data 1:1 bn160509374_n3_srcspectra.pha{1}
back 1 bn160509374_n3_bkgspectra.bak{1}
resp 1 bn160509374_n3_weightedrsp.rsp{1}
ignore 1:**-8.0 1000.0-**
setplot rebin 3 5 1
data 2:2 bn160509374_b0_srcspectra.pha{1}
back 2 bn160509374_b0_bkgspectra.bak{1}
resp 2 bn160509374_b0_weightedrsp.rsp{1}
ignore 2:**-200.0 40000.0-**
setplot rebin 3 5 2
data 3:3 bn160509374_LAT-LLE_srcspectra.pha{1}
back 3 bn160509374_LAT-LLE_bkgspectra.bak{1}
resp 3 bn160509374_LAT-LLE_weightedrsp.rsp{1}
ignore 3:**-20000.0 100000000.0-**
setplot rebin 3 5 3
method leven ;# leven XSPEC is required to calculate all derivatives numerically, noticeably slower
mo bb+po & /*
#newpar 1 30
#freeze 1
#thaw 1
statistic cstat
fit 100 0.01
query yes
set fitresults [shakefit ]
set fileout [open bb+po2.txt w]
    foreach param $fitresults {
        puts $fileout "$param " }
close $fileout
cpd bb+po2.eps/cps
setplot energy
setplot command rescal x 8 1e8
setplot command rescal y 1e0 1e6
setplot command Tim off
tclout model
set modelname [lindex $xspec_tclout 1]
setplot command lable top bn160509374 13.300-13.400 s
plot eeuf chi
cpd none
exit

标签:bn160509374,set,setplot,注释,tclout,xspec,lindex,拟合
来源: https://www.cnblogs.com/zijichihuoguowy/p/10578083.html