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

Last change on this file since 19952 was 19915, checked in by tbretz, 5 years ago
Improved comments
File size: 5.7 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 SumEnergyEstW,
61 SUM(SumEnergyEstW) AS SumEnergySimW
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 SignalW - BackgroundW AS ExcessW,
75 SignalW2 + BackgroundW2 AS ExcessW2
76 FROM
77 Simulated
78 INNER JOIN
79 Triggered USING (%102:bin)
80 INNER JOIN
81 Analyzed USING (%102:bin)
82 INNER JOIN
83 Binning ON Simulated.%102:bin=bin
84),
85Table0 AS -- Derive valued
86(
87 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
88 *,
89
90 SQRT(SimCountN) AS ErrSimCountN,
91 SQRT(TrigCountN) AS ErrTrigCountN,
92 SQRT(SignalN) AS ErrSignalN,
93 SQRT(BackgroundN) AS ErrBackgroundN,
94
95 SimSumW /Width/AreaTime AS SimFluxW,
96 TrigSumW /Width/AreaTime AS TrigFluxW,
97 SignalW /Width/AreaTime AS SignalFluxW,
98 BackgroundW /Width/AreaTime AS BackgroundFluxW,
99 ExcessW /Width/AreaTime AS ExcessFluxW,
100
101 SQRT(SimSumW2) /Width/AreaTime AS ErrSimFluxW,
102 SQRT(TrigSumW2) /Width/AreaTime AS ErrTrigFluxW,
103 SQRT(SignalW2) /Width/AreaTime AS ErrSignalFluxW,
104 SQRT(BackgroundW2) /Width/AreaTime AS ErrBackgroundFluxW,
105 SQRT(ExcessW2) /Width/AreaTime AS ErrExcessFluxW,
106
107 SumEnergyEstW/SignalW AS AvgEnergyEstW,
108 SumEnergySimW/SignalW AS AvgEnergySimW,
109
110 Area*TriggerEfficiencyN AS EffectiveAreaN,
111 Area*TriggerEfficiencyW AS EffectiveAreaW,
112
113 SignalN/TrigCountN AS CutEfficiencyN,
114 IF(ExcessW<0, 0, ExcessW/TrigSumW) AS CutEfficiencyW,
115
116 TriggerEfficiencyN * SQRT(1/TrigCountN + 1/SimCountN) AS ErrTriggerEfficiencyN,
117 TriggerEfficiencyW * SQRT(TrigSumW2/POW(TrigSumW,2) + SimSumW2/POW(SimSumW,2)) AS ErrTriggerEfficiencyW,
118
119 IF(SignalW>0, ResidualW/SignalW, NULL) AS BiasW,
120 IF(SignalW>0, ResidualW/SignalW*SQRT(ResidualW2/POW(ResidualW,2) + SignalW2/POW(SignalW,2)), NULL) AS ErrBiasW,
121 IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)), NULL) AS ResolutionW,
122
123 (SUM(SignalW) OVER Integral) AS IntegralSignalW,
124 (SUM(SignalW) OVER Integral) / AreaTime AS IntegralSignalFluxW,
125 (SUM(BackgroundW) OVER Integral) / AreaTime AS IntegralBackgroundFluxW,
126 (SUM(SignalW2) OVER Integral) / POW(AreaTime, 2) AS IntegralSignalFluxW2,
127 (SUM(BackgroundW2) OVER Integral) / POW(AreaTime, 2) AS IntegralBackgroundFluxW2,
128
129 (SUM(SimSumW) OVER Integral) / AreaTime AS IntegralSimFluxW,
130 (SUM(SimSumW2) OVER Integral) / POW(AreaTime, 2) AS IntegralSimFluxW2,
131
132 (SUM(SumEnergySimW) OVER Integral) AS IntegralEnergySimW,
133 (SUM(SumEnergyEstW) OVER Integral) AS IntegralEnergyEstW
134 FROM
135 CombinedData
136 WINDOW
137 Integral AS (ORDER BY %102:bin DESC)
138)
139SELECT -- Return derived values and result
140 *,
141
142 Area*ErrTriggerEfficiencyN AS ErrEffectiveAreaN,
143 Area*ErrTriggerEfficiencyW AS ErrEffectiveAreaW,
144
145 CutEfficiencyN*SQRT(1/SignalN + 1/TrigCountN) AS ErrCutEfficiencyN,
146 CutEfficiencyW*SQRT(ExcessW2/POW(ExcessW,2) + TrigSumW2/POW(TrigSumW,2)) AS ErrCutEfficiencyW,
147
148 IntegralSignalFluxW - IntegralBackgroundFluxW AS IntegralExcessFluxW,
149 SQRT(IntegralSignalFluxW2+IntegralBackgroundFluxW2) AS ErrIntegralExcessFluxW,
150 SQRT(IntegralSignalFluxW2) AS ErrIntegralSignalFluxW,
151 SQRT(IntegralBackgroundFluxW2) AS ErrIntegralBackgroundFluxW,
152 SQRT(IntegralSimFluxW2) AS ErrIntegralSimFluxW,
153
154 IntegralEnergyEstW/IntegralSignalW AS AvgIntegralEnergyEstW,
155 IntegralEnergySimW/IntegralSignalW AS AvgIntegralEnergySimW
156
157FROM
158 Table0
Note: See TracBrowser for help on using the repository browser.