source: trunk/FACT++/spectrum/summary-sim.sql@ 20013

Last change on this file since 20013 was 19983, checked in by tbretz, 4 years ago
Implemented ExcessN and ErrExcessN -- mainly for completeness
File size: 5.8 KB
Line 
1WITH Theta AS -- Get total Observation time
2(
3 SELECT SUM(OnTime) AS ObsTime FROM ThetaDist
4),
5Area AS -- Get total simulated area
6(
7 SELECT POW(MinImpactHi,2)*PI() AS Area FROM MonteCarloArea
8),
9Binning AS -- Create binning and calculate weights per bin
10(
11 SELECT
12 *,
13 (%103:binwidth) AS Width, -- Bin Windth in TeV or just 1
14 Area*ObsTime AS AreaTime -- Total scale dA*dT
15 FROM
16 %101:binning
17 CROSS JOIN
18 Theta, Area
19),
20Simulated AS -- Summarize simulated (corsika) data in bins
21(
22 SELECT
23 %102:bin,
24 SUM(CountN) AS SimCountN,
25 SUM(SumW) AS SimSumW,
26 SUM(SumW2) AS SimSumW2
27 FROM
28 WeightedOriginalMC
29 GROUP BY
30 %102:bin
31),
32Triggered AS -- Summarize triggered (ceres) data in bins
33(
34 SELECT
35 %102:bin,
36 SUM(CountN) AS TrigCountN,
37 SUM(SumW) AS TrigSumW,
38 SUM(SumW2) AS TrigSumW2
39 FROM
40 WeightedEventsMC
41 GROUP BY
42 %102:bin
43),
44Analyzed AS -- Summarize data after cuts (analyzed) in bins
45(
46 SELECT
47 %102:bin,
48
49 SUM(SignalN) AS SignalN,
50 SUM(SignalW) AS SignalW,
51 SUM(SignalW2) AS SignalW2,
52
53 SUM(BackgroundN)/5 AS BackgroundN,
54 SUM(BackgroundW)/5 AS BackgroundW,
55 SUM(BackgroundW2)/25 AS BackgroundW2,
56
57 SUM(ResidualW) AS ResidualW,
58 SUM(ResidualW2) AS ResidualW2,
59
60 SUM(SumEnergySimW) AS SumEnergySimW,
61 SUM(SumEnergyEstW) AS SumEnergyEstW
62 FROM
63 AnalysisMC
64 GROUP BY
65 %102:bin
66),
67CombinedData AS -- Combine all Data together
68(
69 SELECT
70 *,
71 TrigCountN/SimCountN AS TriggerEfficiencyN,
72 TrigSumW/SimSumW AS TriggerEfficiencyW,
73
74 SignalN - BackgroundN AS ExcessN,
75
76 SignalW - BackgroundW AS ExcessW,
77 SignalW2 + BackgroundW2 AS ExcessW2
78 FROM
79 Simulated
80 INNER JOIN
81 Triggered USING (%102:bin)
82 INNER JOIN
83 Analyzed USING (%102:bin)
84 INNER JOIN
85 Binning ON Simulated.%102:bin=bin
86),
87Table0 AS -- Derive valued
88(
89 SELECT -- Everything scaled is "Flux", Everything unscaled is without "Flux", Corsika Data is Sim*, Triggered Data is Trig* and data after cuts is without prefix
90 *,
91
92 SQRT(SimCountN) AS ErrSimCountN,
93 SQRT(TrigCountN) AS ErrTrigCountN,
94 SQRT(SignalN) AS ErrSignalN,
95 SQRT(BackgroundN) AS ErrBackgroundN,
96 SQRT(SignalN + BackgroundN) AS ErrExcessN,
97
98 SimSumW /Width/AreaTime AS SimFluxW,
99 TrigSumW /Width/AreaTime AS TrigFluxW,
100 SignalW /Width/AreaTime AS SignalFluxW,
101 BackgroundW /Width/AreaTime AS BackgroundFluxW,
102 ExcessW /Width/AreaTime AS ExcessFluxW,
103
104 SQRT(SimSumW2) /Width/AreaTime AS ErrSimFluxW,
105 SQRT(TrigSumW2) /Width/AreaTime AS ErrTrigFluxW,
106 SQRT(SignalW2) /Width/AreaTime AS ErrSignalFluxW,
107 SQRT(BackgroundW2) /Width/AreaTime AS ErrBackgroundFluxW,
108 SQRT(ExcessW2) /Width/AreaTime AS ErrExcessFluxW,
109
110 SumEnergyEstW/SignalW AS AvgEnergyEstW,
111 SumEnergySimW/SignalW AS AvgEnergySimW,
112
113 Area*TriggerEfficiencyN AS EffectiveAreaN,
114 Area*TriggerEfficiencyW AS EffectiveAreaW,
115
116 SignalN/TrigCountN AS CutEfficiencyN,
117 IF(ExcessW<0, 0, ExcessW/TrigSumW) AS CutEfficiencyW,
118
119 TriggerEfficiencyN * SQRT(1/TrigCountN + 1/SimCountN) AS ErrTriggerEfficiencyN,
120 TriggerEfficiencyW * SQRT(TrigSumW2/POW(TrigSumW,2) + SimSumW2/POW(SimSumW,2)) AS ErrTriggerEfficiencyW,
121
122 IF(SignalW>0, ResidualW/SignalW, NULL) AS BiasW,
123 IF(SignalW>0, ResidualW/SignalW*SQRT(ResidualW2/POW(ResidualW,2) + SignalW2/POW(SignalW,2)), NULL) AS ErrBiasW,
124 IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)), NULL) AS ResolutionW,
125
126 (SUM(SignalW) OVER Integral) AS IntegralSignalW,
127 (SUM(SignalW) OVER Integral) / AreaTime AS IntegralSignalFluxW,
128 (SUM(BackgroundW) OVER Integral) / AreaTime AS IntegralBackgroundFluxW,
129 (SUM(SignalW2) OVER Integral) / POW(AreaTime, 2) AS IntegralSignalFluxW2,
130 (SUM(BackgroundW2) OVER Integral) / POW(AreaTime, 2) AS IntegralBackgroundFluxW2,
131
132 (SUM(SimSumW) OVER Integral) / AreaTime AS IntegralSimFluxW,
133 (SUM(SimSumW2) OVER Integral) / POW(AreaTime, 2) AS IntegralSimFluxW2,
134
135 (SUM(SumEnergySimW) OVER Integral) AS IntegralEnergySimW,
136 (SUM(SumEnergyEstW) OVER Integral) AS IntegralEnergyEstW
137 FROM
138 CombinedData
139 WINDOW
140 Integral AS (ORDER BY %102:bin DESC)
141)
142SELECT -- Return derived values and result
143 *,
144
145 Area*ErrTriggerEfficiencyN AS ErrEffectiveAreaN,
146 Area*ErrTriggerEfficiencyW AS ErrEffectiveAreaW,
147
148 CutEfficiencyN*SQRT(1/SignalN + 1/TrigCountN) AS ErrCutEfficiencyN,
149 CutEfficiencyW*SQRT(ExcessW2/POW(ExcessW,2) + TrigSumW2/POW(TrigSumW,2)) AS ErrCutEfficiencyW,
150
151 IntegralSignalFluxW - IntegralBackgroundFluxW AS IntegralExcessFluxW,
152 SQRT(IntegralSignalFluxW2+IntegralBackgroundFluxW2) AS ErrIntegralExcessFluxW,
153 SQRT(IntegralSignalFluxW2) AS ErrIntegralSignalFluxW,
154 SQRT(IntegralBackgroundFluxW2) AS ErrIntegralBackgroundFluxW,
155 SQRT(IntegralSimFluxW2) AS ErrIntegralSimFluxW,
156
157 IntegralEnergyEstW/IntegralSignalW AS AvgIntegralEnergyEstW,
158 IntegralEnergySimW/IntegralSignalW AS AvgIntegralEnergySimW
159
160FROM
161 Table0
Note: See TracBrowser for help on using the repository browser.