source: trunk/FACT++/spectrum/simulation.sql@ 19932

Last change on this file since 19932 was 19915, checked in by tbretz, 5 years ago
Improved comments
File size: 2.2 KB
Line 
1WITH Table0 AS
2(
3 SELECT
4 Weight, Energy, LogEnergyEst,
5
6 -- Convert variable to bin index
7 INTERVAL(Theta, %107:theta) AS `.theta`,
8 INTERVAL(LogEnergyEst, %108:sparse) AS `.sparse_est`,
9 INTERVAL(LogEnergyEst, %109:dense) AS `.dense_est`,
10 INTERVAL(LOG10(Energy), %108:sparse) AS `.sparse_sim`,
11 INTERVAL(LOG10(Energy), %109:dense) AS `.dense_sim`,
12
13 (%110:spectrum)/POW(Energy, SpectralIndex) AS SpectralWeight, -- FIXME: Is this correct for files with different Slopes?
14 LogEnergyEst - log10(Energy) AS Residual
15 FROM
16 Excess
17-- Instead of using %%0:columns, we could join back with the data we need
18-- INNER JOIN
19-- factmc.EventsMC USING(FileId, EvtNumber, CorsikaNumReuse)
20-- INNER JOIN
21-- factmc.RunInfoMC USING(FIleId)
22)
23SELECT
24 `.theta`,
25 `.sparse_est`,
26 `.sparse_sim`,
27 `.dense_est`,
28 `.dense_sim`,
29
30 -- Without any weight applied
31 COUNT(IF(Weight>0, 1, NULL)) AS SignalN,
32 COUNT(IF(Weight<0, 1, NULL)) AS BackgroundN,
33
34 -- Without ZdWeight applied
35/*
36 SUM( IF(Weight>0, SpectralWeight, 0)) AS Signal,
37 SUM( IF(Weight<0, SpectralWeight, 0)) AS Background,
38 SUM( IF(Weight>0, POW(SpectralWeight,2), 0)) AS Signal2,
39 SUM( IF(Weight<0, POW(SpectralWeight,2), 0)) AS Background2,
40*/
41
42 -- Binning in estimated energy: Signal, Background
43 SUM( IF(Weight>0, ZdWeight*SpectralWeight, 0)) AS SignalW,
44 SUM( IF(Weight<0, ZdWeight*SpectralWeight, 0)) AS BackgroundW,
45 SUM( IF(Weight>0, POW(ErrZdWeight*SpectralWeight,2), 0)) AS SignalW2,
46 SUM( IF(Weight<0, POW(ErrZdWeight*SpectralWeight,2), 0)) AS BackgroundW2,
47
48 -- Energy Estimation: Bias=ResidualW/SignalW; Resolution=sigma(Bias)
49 SUM(IF(Weight>0, Residual* ZdWeight*SpectralWeight, 0)) AS ResidualW,
50 SUM(IF(Weight>0, POW(Residual,2)*ZdWeight*SpectralWeight, 0)) AS ResidualW2,
51
52 -- Average Energy: SumEnergyX/SignalW
53 SUM(IF(Weight>0, Energy *ZdWeight*SpectralWeight, 0)) AS SumEnergySimW,
54 SUM(IF(Weight>0, POW(10, LogEnergyEst)*ZdWeight*SpectralWeight, 0)) AS SumEnergyEstW
55
56FROM
57 Table0
58INNER JOIN
59 ThetaDist USING(`.theta`)
60GROUP BY
61 `.theta`, `.sparse_est`, `.sparse_sim`, `.dense_est`, `.dense_sim`
Note: See TracBrowser for help on using the repository browser.