forked from emrahk/IDL_LAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapcalib_str_sp_mix.pro
438 lines (317 loc) · 15.2 KB
/
wrapcalib_str_sp_mix.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
pro wrapcalib_str_sp_mix, instr, pix, outpar, ps=ps, filename=filename,$
binsize=binsize, instr2=inst2, pens=pens, npol=npol, canoc=canoc, anoc=anoc,$
ans=ans, cats=cats, ses=ses
; This program is a wrapper for calib_sp when the input is a event
; structure obtained from either the MPA system or the RENA system
;with mixed anodes and cathodes.
;INPUTS
;
;instr: input structure
;
;pix: input channel.
;
;OUTPUTS
;
;outpar: calibration parameters in the form of [a,b] energy=a+b*channel
;
;OPTIONAL INPUTS
;pens: peak energies for calibration, floating array [en1,en2]
;
;instr2: if there are two spectra for two different peaks,
;instr2 is the second structure
;
;binsize: bin parameter to aid fitting. if one spectrum a float, if two spectra fltarr[2]
;
;npol: polynomial degree in fitting.
;
;ps: if set encapsulated postscript output is produced
;
;filename: if set with ps, encapsulated postscript is given this name.
;
;canoc: cathode to use in anode and steering electrode calibration, if not set use all cathodes
;
;anoc: anode to use in cathode calibration, if not set use all anodes
;
;ans: calibrate anodes
;
;cats: calibrate cathodes
;
;ses: calibrate steering electrodes
;
;
;Used by:
;
;wrapcalib_mp_mix.pro
;
;Uses
;
;calib_sp.pro
;
;Created by Emrah Kalemci
;30/01/2012
;
;NOTES & BUG FIXES
;
;02/02/2012
;instr2 used instead of inst2 inside program, syntax error fixed.
;
;steering electrode implemented, 07/02/2012
;
;a bug about new binsize setting for steering electrode fixed, 24/02/2012
;
;it was realized that thresh must be used in anodes to get steering electrode
;calibration right because those are the events without charge sharing 27/02/2012
;
IF NOT keyword_set(ps) THEN ps=0
IF NOT keyword_set(ps) THEN filename='singlepixfit.eps'
IF NOT keyword_set(binsize) then binsize=[1,1]
IF NOT keyword_set(inst2) THEN inp2=0 ELSE inp2=1
IF NOT keyword_set(pens) THEN pens=[122.1, 136.5]
IF NOT keyword_set(npol) THEN npol=1
IF NOT keyword_set(ans) THEN ans=0
IF NOT keyword_set(cats) THEN cats=0
IF NOT keyword_set(ses) THEN ses=0
IF (ans+cats+ses) NE 1 THEN $
print,'You can only choose one of anodes, cathodes or steering electrodes, nothing to be done' $
ELSE BEGIN
IF NOT keyword_set(canoc) THEN canoc=-1
IF NOT keyword_set(anoc) THEN anoc=-1
IF (n_elements(binsize) eq 1) THEN binsize=[binsize,binsize]
;choose from a distribution of cathode to anode ratios
;Anodes
IF ans THEN BEGIN
print,'Choose a range by clicking on the right mouse button twice, and then push the left button to finish'
;if no cathode provided, use all cathodes
IF (canoc eq -1) THEN xast1=where((instr.flag eq 'single') and $
(instr.det[0] eq pix)) ELSE $
xast1=where((instr.flag eq 'single') and $
(instr.det[0] eq pix) and $
(instr.cadet[0] eq canoc))
plot,histogram(instr[xast1].car,min=0,bins=0.01),xr=[0,300] ;this assumes the cathode calibration is not far off from the anode calibration
moncurs, x_tab=x_tab
x_tab1=x_tab/100.
oplot,[1,1]*x_tab1[0]*100.,[0,!y.crange[1]]
oplot,[1,1]*x_tab1[1]*100.,[0,!y.crange[1]]
wait,0.5
;choose the data with the good cathode to anode ratio
IF (canoc eq -1) THEN xlst=where((instr.flag eq 'single') and $
(instr.det[0] eq pix) and $
((instr.car gt x_tab1[0]) and (instr.car lt x_tab1[1]))) ELSE $
xlst=where((instr.flag eq 'single') and (instr.cadet[0] eq canoc) $
and (instr.det[0] eq pix) and $
((instr.car gt x_tab1[0]) and (instr.car lt x_tab1[1])))
spe1=histogram(instr[xlst].toten,min=0,bins=binsize[0])
xr1=[1,n_elements(spe1)] ;this is required for plotting
ENDIF
IF cats THEN BEGIN
print,'Choose a range by clicking on the right mouse button twice, and then push the left button to finish'
;if an anode is provided, use that anode, otherwise use all anodes
IF (anoc eq -1) THEN xast1=where((instr.cflag eq 'single') and $
(instr.cadet[0] eq pix)) ELSE $
xast1=where((instr.cflag eq 'single') and $
(instr.cadet[0] eq pix) and $
(instr.det[0] eq anoc))
plot,histogram(instr[xast1].car,min=0,bins=0.01),xr=[0,300] ;this assumes the cathode calibration is not far off from the anode calibration
moncurs, x_tab=x_tab
x_tab1=x_tab/100.
oplot,[1,1]*x_tab1[0]*100.,[0,!y.crange[1]]
oplot,[1,1]*x_tab1[1]*100.,[0,!y.crange[1]]
wait,0.5
;choose the data with the good cathode to anode ratio
IF (anoc eq -1) THEN xlst=where((instr.cflag eq 'single') and $
(instr.cadet[0] eq pix) and $
((instr.car gt x_tab1[0]) and (instr.car lt x_tab1[1]))) ELSE $
xlst=where((instr.cflag eq 'single') and (instr.det[0] eq anoc) $
and (instr.cadet[0] eq pix) and $
((instr.car gt x_tab1[0]) and (instr.car lt x_tab1[1])))
spe1=histogram(instr[xlst].caten,min=0,bins=binsize[0])
xr1=[1,n_elements(spe1)] ;this is required for plotting
ENDIF
IF ses THEN BEGIN
print,'Choose a range by clicking on the right mouse button twice, and then push the left button to finish'
;if an cathode is provided, use that cathode, otherwise use all anodes
IF (canoc eq -1) THEN xsst1=where((instr.sflag eq 'single') and (instr.aflag eq 'thresh') and $
(instr.sedet[0] eq pix)) ELSE $
xsst1=where((instr.sflag eq 'single') and (instr.aflag eq 'thresh') and $
(instr.sedet[0] eq pix) and $
(instr.cadet[0] eq canoc))
secr=instr.caten/instr.seen
plot,histogram(secr[xsst1],min=0,bins=0.01),xr=[0,300] ;this assumes the cathode calibration is not far off from the se calibration
moncurs, x_tab=x_tab
x_tab1=x_tab/100.
oplot,[1,1]*x_tab1[0]*100.,[0,!y.crange[1]]
oplot,[1,1]*x_tab1[1]*100.,[0,!y.crange[1]]
wait,0.5
;choose the data with the good cathode to anode ratio
IF (canoc eq -1) THEN xsst=where((instr.sflag eq 'single') and (instr.aflag eq 'thresh') and $
(instr.sedet[0] eq pix) and $
((secr gt x_tab1[0]) and (secr lt x_tab1[1]))) ELSE $
xsst=where((instr.sflag eq 'single') and (instr.cadet[0] eq canoc) $
and (instr.sedet[0] eq pix) and (instr.aflag eq 'thresh') and $
((secr gt x_tab1[0]) and (secr lt x_tab1[1])))
spe1=histogram(instr[xsst].seen,min=0,bins=binsize[0])
xr1=[1,n_elements(spe1)] ;this is required for plotting
ENDIF
cond1='No'
cond2='No'
WHILE cond1 EQ 'No' DO BEGIN
WHILE cond2 EQ 'No' DO BEGIN
IF ans THEN spe1=histogram(instr[xlst].toten,min=0,bins=binsize[0])
IF cats THEN spe1=histogram(instr[xlst].caten,min=0,bins=binsize[0])
IF ses THEN spe1=histogram(instr[xsst].seen,min=0,bins=binsize[0])
;plot with the new binsize
plot,spe1,xtitle='Channel',ytitle='Counts/bin',xr=xr1
cond2 = DIALOG_MESSAGE('is this binsize ok for the spectrum?', /Ques)
IF cond2 eq 'No' THEN BEGIN
read, newbins, prompt='Please provide the new binsize : '
binsize[*]=newbins
ENDIF
ENDWHILE
xr_anode=xr1
plot,spe1,xtitle='Channel',ytitle='Counts/bin',xr=xr1
cond1 = DIALOG_MESSAGE('is this xrange ok for the spectrum?', /Ques)
IF cond1 eq 'No' THEN read, xr1, prompt='Please provide the new xrange as xr1,xr2 : '
ENDWHILE
;=====
;If two source, just do the other one....More straightforward then
;doing a for loop....
IF inp2 THEN BEGIN
IF ans THEN BEGIN
print,'For the second input structure, choose a range by clicking on the right mouse button twice, and then push the left button to finish'
IF (canoc eq -1) THEN xast2=where((inst2.flag eq 'single') and $
(inst2.det[0] eq pix)) ELSE $
xast2=where((inst2.flag eq 'single') and $
(inst2.det[0] eq pix) and $
(inst2.cadet[0] eq canoc))
plot,histogram(inst2[xast2].car,min=0,bins=0.01),xr=[0,300] ;this assumes the cathode calibration is not far off from the anode calibration
moncurs, x_tab=x_tab
x_tab1=x_tab/100.
oplot,[1,1]*x_tab1[0]*100.,[0,!y.crange[1]]
oplot,[1,1]*x_tab1[1]*100.,[0,!y.crange[1]]
wait,0.5
;choose the data with the good cathode to anode ratio
IF (canoc eq -1) THEN xlst2=where((inst2.flag eq 'single') and $
(inst2.det[0] eq pix) and $
((inst2.car gt x_tab1[0]) and (inst2.car lt x_tab1[1]))) ELSE $
xlst2=where((inst2.flag eq 'single') and (inst2.cadet[0] eq canoc) $
and (inst2.det[0] eq pix) and $
((inst2.car gt x_tab1[0]) and (inst2.car lt x_tab1[1])))
spe2=histogram(inst2[xlst2].toten,min=0,bins=binsize[0])
xr2=[1,n_elements(spe2)] ;this is required for plotting
ENDIF
IF cats THEN BEGIN
print,'For the second structure, choose a range by clicking on the right mouse button twice, and then push the left button to finish'
IF (anoc eq -1) THEN xast2=where((inst2.cflag eq 'single') and $
(inst2.cadet[0] eq pix)) ELSE $
xast2=where((inst2.cflag eq 'single') and $
(inst2.cadet[0] eq pix) and $
(inst2.det[0] eq anoc))
plot,histogram(inst2[xast2].car,min=0,bins=0.01),xr=[0,300] ;this assumes the cathode calibration is not far off from the anode calibration
moncurs, x_tab=x_tab
x_tab1=x_tab/100.
oplot,[1,1]*x_tab1[0]*100.,[0,!y.crange[1]]
oplot,[1,1]*x_tab1[1]*100.,[0,!y.crange[1]]
wait,0.5
;choose the data with the good cathode to anode ratio
IF (anoc eq -1) THEN xlst2=where((inst2.cflag eq 'single') and $
(inst2.cadet[0] eq pix) and $
((inst2.car gt x_tab1[0]) and (inst2.car lt x_tab1[1]))) ELSE $
xlst2=where((inst2.cflag eq 'single') and (inst2.det[0] eq anoc) $
and (inst2.cadet[0] eq pix) and $
((inst2.car gt x_tab1[0]) and (inst2.car lt x_tab1[1])))
spe2=histogram(inst2[xlst2].caten,min=0,bins=binsize[0])
xr2=[1,n_elements(spe2)] ;this is required for plotting
ENDIF
IF ses THEN BEGIN
print,'For the second input structure, choose a range by clicking on the right mouse button twice, and then push the left button to finish'
IF (canoc eq -1) THEN xsst2=where((inst2.sflag eq 'single') and (inst2.aflag eq 'thresh') and $
(inst2.sedet[0] eq pix)) ELSE $
xsst2=where((inst2.sflag eq 'single') and (inst2.aflag eq 'thresh') and $
(inst2.sedet[0] eq pix) and $
(inst2.cadet[0] eq canoc))
secr2=inst2.caten/inst2.seen
plot,histogram(secr2[xsst2],min=0,bins=0.01),xr=[0,300] ;this assumes the cathode calibration is not far off from the steering electrode calibration
moncurs, x_tab=x_tab
x_tab1=x_tab/100.
oplot,[1,1]*x_tab1[0]*100.,[0,!y.crange[1]]
oplot,[1,1]*x_tab1[1]*100.,[0,!y.crange[1]]
wait,0.5
;choose the data with the good cathode to anode ratio
IF (canoc eq -1) THEN xsst2=where((inst2.sflag eq 'single') and (inst2.aflag eq 'thresh') and $
(inst2.sedet[0] eq pix) and $
((secr2 gt x_tab1[0]) and (secr2 lt x_tab1[1]))) ELSE $
xsst2=where((inst2.sflag eq 'single') and (inst2.cadet[0] eq canoc) $
and (inst2.sedet[0] eq pix) and (inst2.aflag eq 'thresh') and $
((secr2 gt x_tab1[0]) and (secr2 lt x_tab1[1])))
spe2=histogram(inst2[xsst2].seen,min=0,bins=binsize[0])
xr2=[1,n_elements(spe2)] ;this is required for plotting
ENDIF
cond1='No'
cond2='No'
WHILE cond1 EQ 'No' DO BEGIN
WHILE cond2 EQ 'No' DO BEGIN
IF ans THEN spe2=histogram(inst2[xlst2].toten,min=0,bins=binsize[0])
IF cats THEN spe2=histogram(inst2[xlst2].caten,min=0,bins=binsize[0])
IF ses THEN spe2=histogram(inst2[xsst2].seen,min=0,bins=binsize[0])
plot,spe2,xtitle='Channel',ytitle='Counts/bin',xr=xr2
cond2 = DIALOG_MESSAGE('is this binsize ok for the spectrum?', /Ques)
IF cond2 eq 'No' THEN BEGIN
read, newbins, prompt='Please provide the new binsize : '
binsize[*]=newbins
ENDIF
ENDWHILE
plot,spe2,xtitle='Channel',ytitle='Counts/bin',xr=xr2
cond1 = DIALOG_MESSAGE('is this xrange ok for the spectrum?', /Ques)
IF cond1 eq 'No' THEN read, xr2, prompt='Please provide the new xrange as xr1,xr2 : '
ENDWHILE
calib_sp, spe1, outpar, pens=pens, inspe2=spe2, binsize=binsize, npol=npol,xr1=xr1,xr2=xr2
ENDIF ELSE calib_sp, spe1, outpar, pens=pens, binsize=binsize, npol=npol, xr1=xr1
!p.multi=[0,1,2]
;Now plot the results and check
IF cats THEN evlall1=instr[xast1].caten
IF ans THEN evlall1=instr[xast1].toten
IF ses THEN evlall1=instr[xsst1].seen
;calibrate and randomize for nice plotting
evlkev1=(evlall1*outpar[1])+outpar[0]+randomu(s,n_elements(evlall1))-0.5
enspe1=histogram(evlkev1,min=0)
maxc=max(enspe1[1:n_elements(enspe1)-1L])*1.2
plot, enspe1, xr=[0,pens[1]*1.5],/xstyle,yr=[0,maxc],xtitle='Energy (keV)',psym=10,/ystyle
oplot,[pens[0],pens[0]],[0,maxc]
oplot,[pens[1],pens[1]],[0,maxc]
IF inp2 THEN BEGIN
IF cats THEN evlall2=inst2[xast2].caten
IF ans THEN evlall2=inst2[xast2].toten
IF ses THEN evlall2=inst2[xsst2].seen
evlkev2=(evlall2*outpar[1])+outpar[0]+randomu(s,n_elements(evlall2))-0.5
enspe2=histogram(evlkev2,min=0)
maxc=max(enspe2[1:n_elements(enspe2)-1L])*1.2
plot, enspe2, xr=[0,pens[1]*1.5],/xstyle,yr=[0,maxc],xtitle='Energy (keV)',psym=10,/ystyle
oplot,[pens[0],pens[0]],[0,maxc]
oplot,[pens[1],pens[1]],[0,maxc]
ENDIF
print, 'Calibration parameters: '
print, 'offset: ',outpar[0]
print, 'gain: ',outpar[1]
IF ps THEN BEGIN
set_plot,'ps'
device,/encapsulated
device,filename=filename
maxc=max(enspe1[1:n_elements(enspe1)-1L])*1.2
plot, enspe1, xr=[0,pens[1]*1.5],/xstyle,yr=[0,maxc],xtitle='Energy (keV)',/ystyle,psym=10
oplot,[pens[0],pens[0]],[0,maxc]
oplot,[pens[1],pens[1]],[0,maxc]
IF inp2 THEN BEGIN
maxc=max(enspe2[1:n_elements(enspe2)-1L])*1.2
plot, enspe2, xr=[0,pens[1]*1.5],/xstyle,yr=[0,maxc],xtitle='Energy (keV)',/ystyle,psym=10
oplot,[pens[0],pens[0]],[0,maxc]
oplot,[pens[1],pens[1]],[0,maxc]
ENDIF
ENDIF
!p.multi=0
wait,0.25
IF ps THEN BEGIN
device,/close
set_plot,'x'
ENDIF
ENDELSE
END