Commit 531a0737 authored by Gonzalez, Miguel's avatar Gonzalez, Miguel
Browse files

(On progress) Work on event_file handler, incorporating the reading of the...

(On progress) Work on event_file handler, incorporating the reading of the channels in the current experiment in D22 and the possibility of giving a pattern, e.g. xxo, to select the desired triggers.
parent 0e895570
......@@ -60,24 +60,54 @@ pro read_lst_d22, filename, nEvents, nBoards, Xdet, Ydet, Dtimer, Mtimer, Stimer
boards = ishft(eventsA, -22) and (2ULL^6-1)
; get times (in ns) for monitor events from board 0
; get times (in ns) for monitor, top & pickup events from board 0
Mtimer = [-1] ;channel 2 for monitor
Stimer = [-1] ;channel 1 for top
Ctimer = [-1] ;channel 4 for chopper pickup
idx = where(boards eq 4)
if idx[0] gt -1 then begin
time1 = ishft(eventsA[idx], -32) and (2ULL^32-1)
time2 = ishft(eventsA[idx], 0) and (2ULL^16-1)
Mtimer = time2 * 2ULL^32 + time1
time1 = 0
time2 = 0
;first get channel to discriminate different types of event in GGPICKUP
channel = ishft(eventsA[idx], -16) and (2ULL^6-1)
;channel 1 --> Pickup sample
idx_channel = where(channel eq 1)
if idx_channel[0] gt -1 then begin
time1 = ishft(eventsA[idx[idx_channel]], -32) and (2ULL^32-1)
time2 = ishft(eventsA[idx[idx_channel]], 0) and (2ULL^16-1)
Stimer = time2 * 2ULL^32 + time1
time1 = 0
time2 = 0
endif
endif
;channel 2 --> Monitor
idx_channel = where(channel eq 2)
if idx_channel[0] gt -1 then begin
time1 = ishft(eventsA[idx[idx_channel]], -32) and (2ULL^32-1)
time2 = ishft(eventsA[idx[idx_channel]], 0) and (2ULL^16-1)
Mtimer = time2 * 2ULL^32 + time1
time1 = 0
time2 = 0
endif
;channel 4 --> Pickup chopper
idx_channel = where(channel eq 4)
if idx_channel[0] gt -1 then begin
time1 = ishft(eventsA[idx[idx_channel]], -32) and (2ULL^32-1)
time2 = ishft(eventsA[idx[idx_channel]], 0) and (2ULL^16-1)
Ctimer = time2 * 2ULL^32 + time1
time1 = 0
time2 = 0
endif
endif
; get times and positions from boards 1-4 (detector)
Dtimer = []
Xdet = []
Ydet = []
order_boards = [3, 0, 1, 2] ;good order of the boards to reconstruct detector image
order_boards = [0, 1, 2, 3] ;good order of the boards to reconstruct detector image
ipos = 0
for iboard=0,3 do begin
......@@ -92,8 +122,7 @@ pro read_lst_d22, filename, nEvents, nBoards, Xdet, Ydet, Dtimer, Mtimer, Stimer
time1 = 0
time2 = 0
Ydet = [Ydet, ishft(eventsB[idx], 0) and (2ULL^8-1)]
detTube = ishft(eventsB[idx], -16) and (2ULL^5-1)
detTube += (iboard-1)*32 ;each card corresponds to 32 detector tubes
detTube = (ishft(eventsB[idx], -16) and (2ULL^5-1)) + iboard*32 ;each card corresponds to 32 detector tubes
Xdet = [Xdet, detTube]
detTube = 0
......@@ -193,10 +222,10 @@ function read_lst, filename, X_DETECTOR=Xdet, Y_DETECTOR=Ydet, T_DETECTOR=Dtimer
Ydet = Ydet[idx]
; Get number of events of each type
if (Dtimer[0] gt 0 or n_elements(Dtimer) gt 1) then Dhits = n_elements(Dtimer) else Dhits = 0
if (Mtimer[0] gt 0 or n_elements(Mtimer) gt 1) then Mhits = n_elements(Mtimer) else Mhits = 0
if (Stimer[0] gt 0 or n_elements(Stimer) gt 1) then Shits = n_elements(Stimer) else Chits = 0
if (Ctimer[0] gt 0 or n_elements(Ctimer) gt 1) then Chits = n_elements(Ctimer) else Shits = 0
if Dtimer[0] gt 0 then Dhits = n_elements(Dtimer) else Dhits = 0
if Mtimer[0] gt 0 then Mhits = n_elements(Mtimer) else Mhits = 0
if Stimer[0] gt 0 then Shits = n_elements(Stimer) else Shits = 0
if Ctimer[0] gt 0 then Chits = n_elements(Ctimer) else Chits = 0
; Reading finished. Write summary and return histogram.
print, ' '
......@@ -441,18 +470,38 @@ pro remove_bad_events, timeVector, totalRemoved, xVector=xVector, yVector=yVecto
end
pro remove_forbidden_events, timeVector, totalRemoved, xVector=xVector, yVector=yVector, tolerance=tolerance
pro remove_forbidden_events, timeVector, totalRemoved, xVector=xVector, yVector=yVector, tolerance=tolerance, pattern=pattern
actual_time = timeVector[0] & keepVector = timeVector & nLast = 0
for i = 1, n_elements(timeVector)-1 do begin
if (timeVector[i] - actual_time) gt tolerance then begin
nLast += 1
actual_time = timeVector[i]
keepVector[nLast] = timeVector[i]
endif
endfor
totalRemoved = n_elements(timeVector) - nLast - 1
timeVector = keepVector[0:nLast]
if n_elements(pattern) gt 0 then begin
bpattern = boolarr(strlen(pattern))
for i = 0, strlen(pattern)-1 do begin
if strmid(pattern, i, 1) eq 'o' then bpattern[i] = 'True'
endfor
nrepeat = n_elements(timeVector)/strlen(pattern)+1
bpattern = reform(rebin(bpattern, strlen(pattern), nrepeat), nrepeat*strlen(pattern))
keepVector = timeVector & nLast = 0
for i = 0, n_elements(timeVector)-1 do begin
if bpattern[i] then begin
keepVector[nLast] = timeVector[i]
nLast += 1
endif
endfor
totalRemoved = n_elements(timeVector) - nLast
timeVector = keepVector[0:nLast-1]
endif else begin
actual_time = timeVector[0] & keepVector = timeVector & nLast = 0
for i = 1, n_elements(timeVector)-1 do begin
if (timeVector[i] - actual_time) gt tolerance then begin
nLast += 1
actual_time = timeVector[i]
keepVector[nLast] = timeVector[i]
endif
endfor
totalRemoved = n_elements(timeVector) - nLast - 1
timeVector = keepVector[0:nLast]
endelse
end
......@@ -539,9 +588,17 @@ pro event_file_treat, flag, struc, file=file, Message=Mess, Mess2=Mess2, Mess3=M
;trigger (get minimum time between valid triggers)
widget_control, struc.bdelay, get_value = tmp
if strtrim(tmp[0],2) gt '' then tmp = float(tmp[0])*1.e-3 else tmp = 0 ;forbidden time in seconds
forbidden_trigger = long64(tmp * struc.clock)
tmp = strtrim(tmp[0],2)
if tmp gt '' then begin
if valid_num(tmp) then begin
tmp = float(tmp[0])*1.e-3
forbidden_trigger = long64(tmp * struc.clock)
endif else begin
forbidden_pattern = tmp
forbidden_trigger = 0.0
endelse
endif else forbidden_trigger = 0.0
;Remove bad events in detector
total_removed = 0
remove_bad = struc.removeBad ;remove "bad" events (1) or not (0)
......@@ -587,7 +644,9 @@ pro event_file_treat, flag, struc, file=file, Message=Mess, Mess2=Mess2, Mess3=M
if n_elements(Stimer) gt 1 then begin
stime = systime(1)
remove_bad_events, Stimer, total_removed, tolerance=tolerance
if forbidden_trigger gt 0 then remove_forbidden_events, Stimer, forbidden_removed, tolerance=forbidden_trigger
if n_elements(forbidden_pattern) gt 0 then begin
remove_forbidden_events, Stimer, forbidden_removed, pattern=forbidden_pattern
endif else if forbidden_trigger gt 0 then remove_forbidden_events, Stimer, forbidden_removed, tolerance=forbidden_trigger
endif
struc.Strigg = n_elements(Stimer)
lamp_journal, strtrim(total_removed)+ ' sample_trigger events removed because of suspicious times!'
......@@ -603,7 +662,9 @@ pro event_file_treat, flag, struc, file=file, Message=Mess, Mess2=Mess2, Mess3=M
if n_elements(Ctimer) gt 1 then begin
stime = systime(1)
remove_bad_events, Ctimer, total_removed, tolerance=tolerance
if forbidden_trigger gt 0 then remove_forbidden_events, Ctimer, forbidden_removed, tolerance=forbidden_trigger
if n_elements(forbidden_pattern) gt 0 then begin
remove_forbidden_events, Ctimer, forbidden_removed, pattern=forbidden_pattern
endif else if forbidden_trigger gt 0 then remove_forbidden_events, Ctimer, forbidden_removed, tolerance=forbidden_trigger
endif
struc.Ctrigg = n_elements(Ctimer)
lamp_journal, strtrim(total_removed)+ ' chopper_trigger events removed because of suspicious times!'
......@@ -1725,3 +1786,84 @@ if (xregistered('event_file_win') eq 0) or (n_elements(EV_struct) eq 0) then beg
endif
end
;+
; NAME:
; VALID_NUM()
; PURPOSE:
; Check if a string is a valid number representation.
; EXPLANATION:
; The input string is parsed for characters that may possibly
; form a valid number. It is more robust than simply checking
; for an IDL conversion error because that allows strings such
; as '22.3qwert' to be returned as the valid number 22.3
;
; This function had a major rewrite in August 2008 to use STREGEX
; and allow vector input. It should be backwards compatible.
; CALLING SEQUENCE:
; IDL> status = valid_num(string [,value] [,/integer])
;
; INPUTS:
; string - the string to be tested, scalar or array
;
; RETURNS
; status - byte scalar or array, same size as the input string
; set to 1 where the string is a valid number, 0 for invalid
; OPTIONAL OUTPUT:
; value - The value the string decodes to, same size as input string.
; This will be returned as a double precision number unless
; /INTEGER is present, in which case a long integer is returned.
;
; OPTIONAL INPUT KEYWORD:
; /INTEGER - if present code checks specifically for an integer.
; EXAMPLES:
; (1) IDL> print,valid_num(3.2,/integer)
; --> 0 ;Since 3.2 is not an integer
; (2) IDL> str =['-0.03','2.3g', '3.2e12']
; IDL> test = valid_num(str,val)
; test = [1,0,1] & val = [-0.030000000 ,NaN ,3.2000000e+12]
; REVISION HISTORY:
; Version 1, C D Pike, RAL, 24-May-93
; Version 2, William Thompson, GSFC, 14 October 1994
; Added optional output parameter VALUE to allow
; VALID_NUM to replace STRNUMBER in FITS routines.
; Version 3 Wayne Landsman rewrite to use STREGEX, vectorize
; Version 4 W.L. (fix from C. Markwardt) Better Stregex expression,
; was missing numbers like '134.' before Jan 1 2010
;-
FUNCTION valid_num, string, value, INTEGER=integer
On_error,2
compile_opt idl2
; A derivation of the regular expressions below can be found on
; http://wiki.tcl.tk/989
if keyword_set(INTEGER) then $
st = '^[-+]?[0-9][0-9]*$' else $ ;Integer
st = '^[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eEdD][-+]?[0-9]+)?$' ;F.P.
;Simple return if we just need a boolean test.
if N_params() EQ 1 then return, stregex(strtrim(string,2),st,/boolean)
vv = stregex(strtrim(string,2),st,/boolean)
if size(string,/N_dimen) EQ 0 then begin ;Scalar
if vv then $
value= keyword_set(integer) ? long(string) : double(string)
endif else begin ;Array
g = where(vv,Ng)
if Ng GT 0 then begin ;Need to create output vector
if keyword_set(integer) then begin
value = vv*0L
value[g] = long(string[g])
endif else begin
value = replicate(!VALUES.D_NAN,N_elements(vv))
value[g] = double(string[g])
endelse
endif
endelse
return,vv
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment