source: trunk/FACT++/spectrum/analysis.sql@ 20115

Last change on this file since 20115 was 19907, checked in by tbretz, 5 years ago
Fixed Error calculation for final spectrum, it is difficult to keep usage of the zenith angle consistent. To avoid strange features in the plots, the best is to use the telescope pointing for data and correlate it with the particle direction for simulations.
File size: 3.4 KB
Line 
1/* ************************************************************************
2
3 This is the analysis query. It returns two columns for all
4 signal/background events.
5
6 - `Weight` (Positive for signal (typ. 1),
7 negative for background (typ. -0.2))
8 - `LogEnergyEst` logarithm of estimated energy in GeV
9
10 In additon, all columns provided by the 100-clause must be
11 returned. (Note that you must not add a comma behind it)
12
13 100| %100:files:: table containing the `FileId`s to analyze.
14 101| %101:runinfo:: table with the run info data
15 102| %102:events:: table with the image parameters
16 103| %103:positions:: table with the source positions in the camera
17 104| %105:zenith:: zenith angle in degrees
18 105| %104:columns
19 106| %105:estimator:: estimator for log10 energy
20
21 WARNING:
22 Right now, we correlate the mean zenith angle of the data
23 file with the particle direction in the simulation!
24
25*************************************************************************** */
26
27WITH Table0 AS
28(
29 SELECT
30 %105:columns -- this could be removed if we can join events via the same columns (without CorsikaNumResuse)
31 %104:zenith AS Theta,
32 Weight,
33 Size,
34 NumUsedPixels,
35 NumIslands,
36 Leakage1,
37 MeanX,
38 MeanY,
39 CosDelta,
40 SinDelta,
41 M3Long,
42 SlopeLong,
43 Width/Length AS WdivL,
44 PI()*Width*Length AS Area,
45 cosa*X - sina*Y AS PX,
46 cosa*Y + sina*X AS PY
47 FROM
48 %100:files
49 LEFT JOIN
50 %101:runinfo USING (FileId)
51 LEFT JOIN
52 %102:events USING (FileId) -- This could be replaced by a user uploaded temporary table
53 LEFT JOIN
54 %103:positions USING (FileId, EvtNumber)
55 CROSS JOIN
56 Wobble
57 WHERE
58 NumUsedPixels>5.5
59 AND
60 NumIslands<3.5
61 AND
62 Leakage1<0.1
63),
64
65Table1 AS
66(
67 SELECT
68 %105:columns
69 Theta, Weight,
70 Size, CosDelta, SinDelta, M3Long, SlopeLong, Leakage1, WdivL,
71 MeanX - PX/1.02e0 AS DX,
72 MeanY - PY/1.02e0 AS DY
73 FROM
74 Table0
75 WHERE
76 Area < LOG10(Size)*898e0 - 1535e0
77),
78
79Table2 AS
80(
81 SELECT
82 %105:columns
83 Theta, Weight,
84 Size, CosDelta, SinDelta, DX, DY, M3Long, SlopeLong, Leakage1, WdivL,
85 SQRT(DX*DX + DY*DY) AS Norm
86 FROM
87 Table1
88),
89
90Table3 AS
91(
92 SELECT
93 %105:columns
94 Theta, Weight,
95 Size, M3Long, SlopeLong, Leakage1, WdivL, Norm,
96 LEAST(GREATEST((CosDelta*DY - SinDelta*DX)/Norm, -1), 1) AS LX,
97 SIGN(CosDelta*DX + SinDelta*DY) AS Sign
98 FROM
99 Table2
100),
101
102Table5 AS
103(
104 SELECT
105 %105:columns
106 Theta, Weight,
107 Size, Leakage1, WdivL, LX,
108 Norm *0.0117193246260285378e0 AS Dist,
109 M3Long *Sign*0.0117193246260285378e0 AS M3L,
110 SlopeLong*Sign/0.0117193246260285378e0 AS Slope
111 FROM
112 Table3
113),
114
115Table6 AS
116(
117 SELECT
118 %105:columns
119 Theta, Weight,
120 Size, WdivL, Dist, LX, M3L, Slope,
121 1.39252e0 + 0.154247e0*Slope + 1.67972e0*(1-1/(1+4.86232e0*Leakage1)) AS Xi
122 FROM
123 Table5
124),
125
126Table7 AS
127(
128 SELECT
129 %105:columns
130 Theta, Weight,
131 Size, Dist, LX,
132 IF (M3L<-0.07 OR (Dist-0.5e0)*7.2e0-Slope<0, -Xi, Xi) * (1-WdivL) AS Disp
133 FROM
134 Table6
135)
136
137SELECT
138 %105:columns
139 Theta, Weight,
140 (Disp*Disp + Dist*Dist - 2*Disp*Dist*SQRT(1-LX*LX)) AS ThetaSq,
141 %106:estimator AS LogEnergyEst
142FROM
143 Table7
144HAVING
145 ThetaSq<0.024
Note: See TracBrowser for help on using the repository browser.