function testpulse_times,t if not keyword_set(t) then ctime,t s=tsample('hkp-sena',minmax(t),time=ts) c = round(alog(s)/alog(2)+1) u = uniq(c) cu=c[u] w = where(cu ge 1 and cu le 12) ts = (ts[u[w]] + ts[u[w-1]])/2 return,ts end ; start of main if not keyword_set(bname) then begin load_sstdat,bname tplot,'C dN_avg dN_sig r-np aout0_ hkp-sena Csum dacvals_ T_all' tplot_options,window=0 ts=0 tr=0 caldata=0 calfile = 'E:\DATA\THM\GSE\external_pulser_cal3.sav' restore,/verbose,calfile pshaped=ps tlimit,/full wset,0 stop makepng,bname[0]+'_summary' endif tplot_options,window=0 ;stop if not keyword_set(ts) then begin ;ts = testpulse_times(tr) print,'pick the time range' ctime,tr,npoi=2 a = tsample('aout0',tr,time=ts) ts = ts+3.5 help,ts stop endif if not keyword_set(caldata) then begin window,1 caldata = cal_pulser2(ts,/tailpulse,debug=debug) endif n=n_elements(caldata) ;caldata=reform(caldata,12,n/12) caldata.nwrap = floor(caldata.ep /5.5) xlim,lim1,0,100,0 ylim,lim1,0,128,0 options,lim1,xtitle='Pulse Height' box,lim1 cols = [1,2,3] cols = [2,4,6] psyms = [1,2,4,5] ptail3 = ptail ptail3.acode = 3 pdap = dap_response() pdaps = replicate(pdap,12) for i=0,11 do begin pdaps[i].channel = i+1 w = where(caldata.det eq (i+1) and caldata.ep gt 0 ,nw) if nw gt 1 then begin pdap.channel = i+1 title = bname[0] + string(pdap.channel,format='(" Ch",i02)') print,title cd=caldata[w] pdap.time = minmax(cd.t) tlimit,pdap.time+[-10,10] step = func(cd.ep,param=ptail3) ph = func(step,param=pshaped) x = ph adc = cd.pk2.pg.x0 ;+ cd.nwrap*128 tot = cd.pk2.pg.a width = cd.pk2.pg.s col = cols[i mod 3] col = 6 psym = psyms[i/4] psym = 1 options,lim1,title=title ok = finite(x) ok = ok and x gt 0 ok = ok and finite(adc) ok = ok and width gt .3 ok = ok and adc lt 104 ;ok = ok and width lt 1. ok = ok and tot gt .9*94. ok =ok and tot lt 1.1*94. ok = ok and adc gt 0 w = where(ok) if 0 then begin options,lim1,xtitle='Pulse Height xlim,lim1,0,200 scale = 59.5/16. x=x*scale pdap.x0 = 59.5*2 endif else scale=1. box,lim1 oplot,x,adc,col=col,psym=psym oplot,x[w],adc[w],psym=4 fit,x[w],adc[w],param = pdap pf,pdap,col=col pdaps[i] = pdap pdap0= pdap pdap0.a2=0 & pdap0.a3=0 & pdap0.a4=0 & pdap0.a5=0 pf,pdap0,linestyle=2 oplot,x,tot,col=4,psym=-psym oplot,x,width*10,col=3,psym=-psym string_out,pdap,.6,.6 makepng,title ;+'_kev' stop endif endfor bin0 = pdaps.b0-pdaps.x0*pdaps.gain title = bname[0] ;+ string(pdap.channel,format='(" Ch",i02)') plot,pdaps.channel,pdaps.gain,psym=-1,xstyle=1,xrange=[0,13],yrange=[-3,4],title=title oplot,pdaps.channel,bin0,psym=-4 makepng,bname[0]+'_gsum' save,ptail3,pshaped,caldata,pdaps,bname,ts,tr,file=bname[0]+'.sav' end