aboutsummaryrefslogtreecommitdiff
path: root/noao/onedspec/irsiids/coincor.x
blob: df572c0284baca984a354f4cc62e21f1c7112314 (plain) (blame)
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
# Coincidence correction options
define	CC_PHOTO_MODE	1	# Photometer style correction
define	CC_IIDS_MODE	2	# IIDS style
define	CC_POWER_MODE	3	# Power law correction
define	CC_USER_MODE	4	# User supplies a function


# COINCOR -- Coincidence correction for detector deadtime

procedure coincor (input, output, npts, expo, coflag, dt, power, mode)

real	input[npts]
real	output[npts]
real	expo
int	coflag
real	dt
real	power
int	mode, npts

begin
	# Check that exposure time is legit
	if (expo <= 0.0)
	    return

	# Select the method by which the correction is performed
	switch (mode) {
	    case CC_PHOTO_MODE:
	    	# Photoelectric photometer
		call ccphoto (input, output, npts, expo, coflag, dt)

	    case CC_IIDS_MODE:
		# IIDS style correction
		if (coflag == -1) {
		    call cciids (input, output, npts, expo, coflag, dt)
		    if (power != 1.0)
		        call ccpower (output, output, npts, expo, coflag,
			    power)
		} else if ((coflag == 0) && (power != 1.0))
		    call ccpower (input, output, npts, expo, coflag, power)
		else
		    call amovr (input, output, npts)

	    case CC_USER_MODE:
		# Provided by the user
		call ccuser (input, output, npts, expo, coflag, dt)
	}
end

# CCPHOTO -- Photoelectric photometer coincidence correction

procedure ccphoto (input, output, npts, expo, coflag, dt)

real	input[npts], output[npts], expo, dt
int	coflag
int	npts

int	i

begin
	do i = 1, npts
	    output[i] = input[i] * exp (input[i] * dt / expo)
	coflag = 2
end

# CCUSER -- User supplied correction scheme

procedure ccuser (input, output, npts, expo, coflag, dt)

real	input[npts], output[npts], expo, dt
int	coflag
int	npts

begin
	coflag = 3
end

# CCIIDS -- IIDS style correction scheme
# From Instrumentation for Astronomy III (SPIE Vol 172) p.88 by Larry Goad
#
# Note that only the "Detect" mode of observation is supported.

procedure cciids (input, output, npts, expo, coflag, dt)

real	input[npts], output[npts], expo, dt
int	npts, coflag

int	i
real	tsweep, value

begin
	# Allow tsweep to be the deadtime so that a different value
	# may be entered for other instruments.
	# For the IIDS, tsweep = 1.424e-3 sec
	tsweep = dt

	do i = 1, npts {
	    value = 1 - input[i] / expo * tsweep
	    if ((value < 0.) || (value > 1.))
		output[i] = input[i]
	    else
	        output[i] = -expo * log (value)/ tsweep
	}
	coflag = 0
end

# CCPOWER -- Power law correction
# Power law correction from Massey and De Veny, NOAO Newsletter #6.

procedure ccpower (input, output, npts, expo, coflag, power)

real	input[npts], output[npts], expo, power
int	npts, coflag

int	i

begin
	do i = 1, npts
	    if (input[i] > 0.)
	        output[i] = expo * (input[i] / expo) ** power
	    else
		output[i] = input[i]
	coflag = 1
end