source: trunk/FACT++/spectrum/summary-est.sql@ 20006

Last change on this file since 20006 was 19915, checked in by tbretz, 5 years ago
Improved comments
File size: 3.9 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 -- Get binning and calculate weights for each bin
10(
11 SELECT
12 *,
13 (POW(10,hi)-POW(10,lo))/1000 AS Width, -- Bin Windth in TeV
14 Area*ObsTime AS AreaTime -- Total scale dA*dT
15 FROM
16 BinningEnergy_%100:binning
17 CROSS JOIN
18 Theta, Area
19),
20Analyzed AS -- Summarizy data after cuts (analyzed) in bins
21(
22 SELECT
23 `.%100:binning:_est`,
24
25 SUM(SignalN) AS SignalN,
26 SUM(SignalW) AS SignalW,
27 SUM(SignalW2) AS SignalW2,
28
29 SUM(BackgroundN)/5 AS BackgroundN,
30 SUM(BackgroundW)/5 AS BackgroundW,
31 SUM(BackgroundW2)/25 AS BackgroundW2,
32
33 SUM(ResidualW) AS ResidualW,
34 SUM(ResidualW2) AS ResidualW2,
35
36 SUM(SumEnergySimW) AS SumEnergySimW,
37 SUM(SumEnergyEstW) AS SumEnergyEstW
38 FROM
39 AnalysisMC
40 GROUP BY
41 `.%100:binning:_est`
42),
43Integrated AS
44(
45 SELECT -- Return Result
46 *,
47
48 SignalW /Width/AreaTime AS SignalFluxW,
49 BackgroundW /Width/AreaTime AS BackgroundFluxW,
50 (SignalN - BackgroundN) AS ExcessN,
51 (SignalW - BackgroundW) AS ExcessW,
52 (SignalW - BackgroundW) /Width/AreaTime AS ExcessFluxW,
53
54 SQRT(SignalN) AS ErrSignalN,
55 SQRT(SignalW2) AS ErrSignalW,
56 SQRT(SignalW2) /Width/AreaTime AS ErrSignalFluxW,
57
58 SQRT(BackgroundN) AS ErrBackgroundN,
59 SQRT(BackgroundW2) AS ErrBackgroundW,
60 SQRT(BackgroundW2) /Width/AreaTime AS ErrBackgroundFluxW,
61
62 SQRT(SignalN + BackgroundN) AS ErrExcessN,
63 SQRT(SignalW2 + BackgroundW2) AS ErrExcessW,
64 SQRT(SignalW2 + BackgroundW2) /Width/AreaTime AS ErrExcessFluxW,
65
66 SumEnergyEstW/SignalW AS AvgEnergyEstW,
67 SumEnergySimW/SignalW AS AvgEnergySimW,
68
69 IF(SignalW>0, ResidualW/SignalW, NULL) AS BiasW,
70 IF(SignalW>0, ResidualW/SignalW*SQRT(ResidualW2/POW(ResidualW,2) + SignalW2/POW(SignalW,2)), NULL) AS ErrBiasW,
71 IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)), NULL) AS ResolutionW,
72
73 (SUM(SignalW) OVER Integral) AS IntegralSignalW,
74 (SUM(SignalW) OVER Integral) / AreaTime AS IntegralSignalFluxW,
75 (SUM(BackgroundW) OVER Integral) / AreaTime AS IntegralBackgroundFluxW,
76 (SUM(SignalW2) OVER Integral) / POW(AreaTime, 2) AS IntegralSignalFluxW2,
77 (SUM(BackgroundW2) OVER Integral) / POW(AreaTime, 2) AS IntegralBackgroundFluxW2,
78
79 (SUM(SumEnergySimW) OVER Integral) AS IntegralEnergySimW,
80 (SUM(SumEnergyEstW) OVER Integral) AS IntegralEnergyEstW
81 FROM
82 Analyzed
83 INNER JOIN
84 Binning ON `.%100:binning:_est`=bin
85 WINDOW
86 Integral AS (ORDER BY `.%100:binning:_est` DESC)
87)
88SELECT
89 *,
90
91 IntegralSignalFluxW-IntegralBackgroundFluxW AS IntegralExcessFluxW,
92 SQRT(IntegralSignalFluxW2+IntegralBackgroundFluxW2) AS ErrIntegralExcessFluxW,
93 SQRT(IntegralSignalFluxW2) AS ErrIntegralSignalFluxW,
94 SQRT(IntegralBackgroundFluxW2) AS ErrIntegralBackgroundFluxW,
95
96 IntegralEnergyEstW/IntegralSignalW AS AvgIntegralEnergyEstW,
97 IntegralEnergySimW/IntegralSignalW AS AvgIntegralEnergySimW
98
99FROM
100 Integrated
Note: See TracBrowser for help on using the repository browser.