Index: trunk/FACT++/spectrum/display.C
===================================================================
--- trunk/FACT++/spectrum/display.C	(revision 19894)
+++ trunk/FACT++/spectrum/display.C	(revision 19897)
@@ -35,4 +35,7 @@
     f0.SetLineStyle(kDashed);
     f0.SetLineColor(kBlack);
+
+    TF1 f("spectrum", "[0]*pow(pow(10, x)/1000, -[1])", 2.8, 4.5);
+    f.SetLineColor(kBlue);
 
     // --------------------------------
@@ -209,10 +212,37 @@
     // --------------------------------
 
-    c = new TCanvas("Spectrum", "Spectrum");
+    c = new TCanvas("Integral Spectrum", "Integral Spectrum");
+    c->SetLogy();
+    file.GetObject("Data/Energy/IntegratedSpectrum", h1);
+    h1->SetLineColor(kGray);
+    h1->SetMarkerColor(kGray);
+    h1->DrawCopy("P");
+    file.GetObject("Data/Energy/IntegralSpectrum", h1);
+    h1->DrawCopy("P same");
+
+    f.SetParameters(h1->GetMaximum(), 2.4);
+    h1->Fit(&f, "N0EM", "");
+    f.DrawCopy("same");
+
+    cout << endl;
+    cout << "ChiSq " << f.GetChisquare() << " / " << f.GetNDF() << endl;
+    cout << "Prob. " << f.GetProb() << endl;
+    cout << endl;
+
+    file.GetObject("Data/Energy/RolkeIntegralUL", h1);
+    h1->SetMarkerStyle(23);
+    h1->DrawCopy("P same");
+
+    //file.GetObject("RolkeLL", h1);
+    //h1->SetMarkerStyle(22);
+    //h1->DrawCopy("P same");
+
+    // --------------------------------
+
+    c = new TCanvas("Differential Spectrum", "Differential Spectrum");
     c->SetLogy();
     file.GetObject("Data/Energy/Spectrum", h1);
     h1->DrawCopy("P");
 
-    TF1 f("spectrum", "[0]*pow(pow(10, x)/1000, -[1])", 2.8, 4.5);
     f.SetParameters(h1->GetMaximum(), 2.4);
     h1->Fit(&f, "N0EM", "");
Index: trunk/FACT++/spectrum/spectrum.sql
===================================================================
--- trunk/FACT++/spectrum/spectrum.sql	(revision 19894)
+++ trunk/FACT++/spectrum/spectrum.sql	(revision 19897)
@@ -3,4 +3,5 @@
    SELECT
       %101:bin,
+
       SUM(`Signal`)        AS  `Signal`,
       SUM(`Background`)/5  AS  `Background`,
@@ -12,15 +13,16 @@
       %101:bin
 ),
-ResultData AS -- Calculate results for all bins
+Data AS -- Integral is a placeholder for the bin and all following bins
 (
    SELECT
       *,
-      SQRT(`Signal`)                  AS  ErrSignal,
-      SQRT(`Background`)              AS  ErrBackground,
-      `Signal` - `Background`         AS  Excess,
-      ExcErr(`Signal`, `Background`)  AS  ErrExcess,
-      LiMa(  `Signal`, `Background`)  AS  Significance
+      SUM(`Signal`)     OVER Integral     AS  IntegralSignal,
+      SUM(`Background`) OVER Integral /5  AS  IntegralBackground,
+      SUM(SumEnergyEst) OVER Integral     AS  IntegralEnergyEst,
+      SUM(SumW)         OVER Integral     AS  IntegralSumW
    FROM
       BinnedData
+   WINDOW
+      Integral AS (ORDER BY %101:bin DESC)
 ),
 CombinedData AS -- Joind data together and for conveninece (easier reading of the query) rename the columns
@@ -31,40 +33,90 @@
       %102:id.hi,
       (%102:id.lo+%102:id.hi)/2  AS  center,
-      %102:id.Scale,
-      Data.Excess,
-      Data.Signal,
-      Data.Background,
-      Data.ErrExcess,
-      Data.ErrSignal,
-      Data.ErrBackground,
-      Significance,
+      %102:id.Width,
+      %102:id.AreaTime,
+
+      `Signal`,
+      `Background`,
+
+      IntegralSignal,
+      IntegralBackground,
+
+      `Signal` - `Background`                     AS  Excess,
+      SQRT(`Signal`)                              AS  ErrSignal,
+      SQRT(`Background`)                          AS  ErrBackground,
+      ExcErr(`Signal`, `Background`)              AS  ErrExcess,
+      LiMa(  `Signal`, `Background`)              AS  Significance,
+
+      IntegralSignal - IntegralBackground         AS  IntegralExcess,
+      SQRT(IntegralSignal)                        AS  ErrIntegralSignal,
+      SQRT(IntegralBackground)                    AS  ErrIntegralBackground,
+      ExcErr(IntegralSignal, IntegralBackground)  AS  ErrIntegralExcess,
+      LiMa(  IntegralSignal, IntegralBackground)  AS  IntegralSignificance,
+
       SumEnergyEst/SumW  AS  AvgEnergyEst,
+      IntegralEnergyEst/IntegralSumW  AS  IntegralAvgEnergyEst,
+
       %102:id.ExcessFluxW  AS  SimExcess,
       %102:id.ErrExcessFluxW  AS  ErrSimExcess,
-      Sim.SimFluxW/%103:weight  AS  SimFluxW,          -- Possible correcton for already applied ZdWeights
-      Sim.ErrSimFluxW/%104:errweight  AS  ErrSimFluxW  -- Possible correcton for already applied ZdWeights
+      %102:id.IntegralExcessFluxW  AS  IntegralSimExcess,
+      %102:id.ErrIntegralExcessFluxW  AS  ErrIntegralSimExcess,
+
+      -- For flux-vs-theta: Correction for already applied ZdWeights
+      Sim.SimFluxW/%103:weight  AS  SimFluxW,
+      Sim.ErrSimFluxW/%104:errweight  AS  ErrSimFluxW,
+      Sim.IntegralSimFluxW/%103:weight  AS  IntegralSimFluxW,
+      Sim.ErrIntegralSimFluxW/%104:errweight  AS  ErrIntegralSimFluxW
    FROM
-      ResultData Data
+      Data
    INNER JOIN
       %105:join1
    INNER JOIN
       %106:join2
-)
+),
+Spectrum AS
+(
 SELECT -- Return final result
    *,
-   SimExcess/SimFluxW      AS  Efficiency,
-   Excess/SimExcess*Scale  AS  ExcessRatio,
-   Excess/SimExcess*Scale
+
+   -- Differetial Spectrum
+
+   SimExcess/SimFluxW  AS  Efficiency,
+
+   Excess/SimExcess/Width/AreaTime  AS  ExcessRatio,
+   Excess/SimExcess/Width/AreaTime
       * SQRT(
           + POW(ErrExcess    / Excess,    2)
           + POW(ErrSimExcess / SimExcess, 2)
         )  AS  ErrExcessRatio,
-   Excess/SimExcess*SimFluxW*Scale  AS  Flux,
-   Excess/SimExcess*SimFluxW*Scale
+
+
+   Excess/SimExcess*SimFluxW/Width/AreaTime  AS  Flux,
+   Excess/SimExcess*SimFluxW/Width/AreaTime
       * SQRT(
           + POW(ErrExcess    / Excess,    2)
           + POW(ErrSimExcess / SimExcess, 2)
           + POW(ErrSimFluxW  / SimFluxW,  2)
-        )  AS  ErrFlux
+        )  AS  ErrFlux,
+
+   -- Integral Spectrum
+
+   IntegralSimExcess/IntegralSimFluxW  AS  IntegralEfficiency,
+
+   IntegralExcess/IntegralSimExcess/AreaTime  AS  IntegralExcessRatio,
+   IntegralExcess/IntegralSimExcess/AreaTime
+      * SQRT(
+          + POW(ErrIntegralExcess    / IntegralExcess,    2)
+          + POW(ErrIntegralSimExcess / IntegralSimExcess, 2)
+        )  AS  ErrIntegralExcessRatio,
+
+
+   IntegralExcess/IntegralSimExcess*IntegralSimFluxW/AreaTime  AS  IntegralFlux,
+   IntegralExcess/IntegralSimExcess*IntegralSimFluxW/AreaTime
+      * SQRT(
+          + POW(ErrIntegralExcess    / IntegralExcess,    2)
+          + POW(ErrIntegralSimExcess / IntegralSimExcess, 2)
+          + POW(ErrIntegralSimFluxW  / IntegralSimFluxW,  2)
+        )  AS  ErrIntegralFlux
+
 FROM
    CombinedData
@@ -73,2 +125,16 @@
 ORDER BY
    %101:bin
+)
+SELECT
+   *,
+
+   -- Integrated Spectrum
+
+   SUM(Flux*Width) OVER Integral AS IntegratedFlux,
+   SQRT(SUM(POW(ErrFlux*Width,2)) OVER Integral) AS ErrIntegratedFlux
+
+FROM
+   Spectrum
+
+WINDOW
+   Integral AS (ORDER BY %101:bin DESC)
Index: trunk/FACT++/spectrum/summary-est.sql
===================================================================
--- trunk/FACT++/spectrum/summary-est.sql	(revision 19894)
+++ trunk/FACT++/spectrum/summary-est.sql	(revision 19897)
@@ -11,5 +11,6 @@
    SELECT
       *,
-      1000/(POW(10,hi)-POW(10,lo))/Area/ObsTime  AS  Scale
+      (POW(10,hi)-POW(10,lo))/1000  AS  Width,
+      Area*ObsTime                  AS  AreaTime
    FROM
       BinningEnergy_%100:binning
@@ -21,12 +22,16 @@
    SELECT
       `.%100:binning:_est`,
+
       SUM(SignalN)        AS  SignalN,
       SUM(SignalW)        AS  SignalW,
       SUM(SignalW2)       AS  SignalW2,
+
       SUM(BackgroundN)    AS  BackgroundN,
       SUM(BackgroundW)    AS  BackgroundW,
       SUM(BackgroundW2)   AS  BackgroundW2,
+
       SUM(ResidualW)      AS  ResidualW,
       SUM(ResidualW2)     AS  ResidualW2,
+
       SUM(SumEnergySimW)  AS  SumEnergySimW,
       SUM(SumEnergyEstW)  AS  SumEnergyEstW
@@ -35,24 +40,56 @@
    GROUP BY
       `.%100:binning:_est`
+),
+Integrated AS
+(
+   SELECT -- Return Result
+      *,
+
+      SignalN - BackgroundN/5                           AS  ExcessN,
+
+      SQRT(SignalN + BackgroundN/25)                    AS  ErrExcessN,
+      SQRT(SignalN)                                     AS  ErrSignalN,
+      SQRT(BackgroundN)                                 AS  ErrBackgroundN,
+
+      SignalW                          /Width/AreaTime  AS  SignalFluxW,
+      BackgroundW/5                    /Width/AreaTime  AS  BackgroundFluxW,
+      (SignalW - BackgroundW/5)        /Width/AreaTime  AS  ExcessFluxW,
+      SQRT(SignalW2)                   /Width/AreaTime  AS  ErrSignalFluxW,
+      SQRT(BackgroundW2)/5             /Width/AreaTime  AS  ErrBackgroundFluxW,
+      SQRT(SignalW2 + BackgroundW2/25) /Width/AreaTime  AS  ErrExcessFluxW,
+
+      SumEnergyEstW/SignalW                             AS  AvgEnergyEstW,
+      SumEnergySimW/SignalW                             AS  AvgEnergySimW,
+
+      IF(SignalW>0, ResidualW/SignalW,                                                             NULL)  AS  BiasW,
+      IF(SignalW>0, ResidualW/SignalW*SQRT(ResidualW2/POW(ResidualW,2) + SignalW2/POW(SignalW,2)), NULL)  AS  ErrBiasW,
+      IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)),                          NULL)  AS  ResolutionW,
+
+      (SUM(SignalW)       OVER Integral)                     AS  IntegralSignalW,
+      (SUM(SignalW)       OVER Integral) / AreaTime          AS  IntegralSignalFluxW,
+      (SUM(BackgroundW)   OVER Integral) / AreaTime          AS  IntegralBackgroundFluxW,
+      (SUM(SignalW2)      OVER Integral) / POW(AreaTime, 2)  AS  IntegralSignalFluxW2,
+      (SUM(BackgroundW2)  OVER Integral) / POW(AreaTime, 2)  AS  IntegralBackgroundFluxW2,
+
+      (SUM(SumEnergySimW) OVER Integral)                     AS  IntegralEnergySimW,
+      (SUM(SumEnergyEstW) OVER Integral)                     AS  IntegralEnergyEstW
+   FROM
+      Analyzed
+   INNER JOIN
+      Binning ON `.%100:binning:_est`=bin
+   WINDOW
+      Integral AS (ORDER BY `.%100:binning:_est` DESC)
 )
-SELECT -- Return Result
+SELECT
    *,
-   SignalN - BackgroundN/5                 AS  ExcessN,
-   SQRT(SignalN + BackgroundN/25)          AS  ErrExcessN,
-   SQRT(SignalN)                           AS  ErrSignalN,
-   SQRT(BackgroundN)                       AS  ErrBackgroundN,
-   Scale*SignalW                           AS  SignalFluxW,
-   Scale*BackgroundW/5                     AS  BackgroundFluxW,
-   Scale*(SignalW - BackgroundW/5)         AS  ExcessFluxW,
-   Scale*SQRT(SignalW2)                    AS  ErrSignalFluxW,
-   Scale*SQRT(BackgroundW2)/5              AS  ErrBackgroundFluxW,
-   Scale*SQRT(SignalW2 + BackgroundW2/25)  AS  ErrExcessFluxW,
-   SumEnergyEstW/SignalW                   AS  AvgEnergyEstW,
-   SumEnergySimW/SignalW                   AS  AvgEnergySimW,
-   IF(SignalW>0, ResidualW/SignalW,                                                             NULL)  AS  BiasW,
-   IF(SignalW>0, ResidualW/SignalW*SQRT(ResidualW2/POW(ResidualW,2) + SignalW2/POW(SignalW,2)), NULL)  AS  ErrBiasW,
-   IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)),                          NULL)  AS  ResolutionW
+
+   IntegralSignalFluxW-IntegralBackgroundFluxW/5           AS  IntegralExcessFluxW,
+   SQRT(IntegralSignalFluxW2+IntegralBackgroundFluxW2/25)  AS  ErrIntegralExcessFluxW,
+   SQRT(IntegralSignalFluxW2)                              AS  ErrIntegralSignalFluxW,
+   SQRT(IntegralBackgroundFluxW2)                          AS  ErrIntegralBackgroundFluxW,
+
+   IntegralEnergyEstW/IntegralSignalW                      AS  AvgIntegralEnergyEstW,
+   IntegralEnergySimW/IntegralSignalW                      AS  AvgIntegralEnergySimW
+
 FROM
-   Analyzed
-INNER JOIN
-   Binning ON `.%100:binning:_est`=bin
+   Integrated
Index: trunk/FACT++/spectrum/summary-sim.sql
===================================================================
--- trunk/FACT++/spectrum/summary-sim.sql	(revision 19894)
+++ trunk/FACT++/spectrum/summary-sim.sql	(revision 19897)
@@ -11,5 +11,6 @@
    SELECT
       *,
-      (%103:binwidth)/Area/ObsTime  AS  Scale
+      (%103:binwidth)  AS  Width,
+      Area*ObsTime  AS  AreaTime
    FROM
       %101:binning
@@ -45,12 +46,16 @@
    SELECT
       %102:bin,
+
       SUM(SignalN)        AS  SignalN,
       SUM(SignalW)        AS  SignalW,
       SUM(SignalW2)       AS  SignalW2,
+
       SUM(BackgroundN)    AS  BackgroundN,
       SUM(BackgroundW)    AS  BackgroundW,
       SUM(BackgroundW2)   AS  BackgroundW2,
+
       SUM(ResidualW)      AS  ResidualW,
       SUM(ResidualW2)     AS  ResidualW2,
+
       SUM(SumEnergySimW)  AS  SumEnergyEstW,
       SUM(SumEnergyEstW)  AS  SumEnergySimW
@@ -66,4 +71,5 @@
       TrigCountN/SimCountN        AS  TriggerEfficiencyN,
       TrigSumW/SimSumW            AS  TriggerEfficiencyW,
+
       SignalW  - BackgroundW/5    AS  ExcessW,
       SignalW2 + BackgroundW2/25  AS  ExcessW2
@@ -81,37 +87,70 @@
    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
       *,
-      SQRT(SimCountN)             AS  ErrSimCountN,
-      SQRT(TrigCountN)            AS  ErrTrigCountN,
-      SQRT(SignalN)               AS  ErrSignalN,
-      Scale*SimSumW               AS  SimFluxW,
-      Scale*TrigSumW              AS  TrigFluxW,
-      Scale*SignalW               AS  SignalFluxW,
-      Scale*BackgroundW/5         AS  BackgroundFluxW,
-      Scale*ExcessW               AS  ExcessFluxW,
-      Scale*SQRT(SimSumW2)        AS  ErrSimFluxW,
-      Scale*SQRT(TrigSumW2)       AS  ErrTrigFluxW,
-      Scale*SQRT(SignalW2)        AS  ErrSignalFluxW,
-      Scale*SQRT(BackgroundW2)/5  AS  ErrBackgroundFluxW,
-      Scale*SQRT(ExcessW2)        AS  ErrExcessFluxW,
-      SumEnergyEstW/SignalW       AS  AvgEnergyEstW,
-      SumEnergySimW/SignalW       AS  AvgEnergySimW,
-      Area*TriggerEfficiencyN     AS  EffectiveAreaN,
-      Area*TriggerEfficiencyW     AS  EffectiveAreaW,
-      SignalN/TrigCountN          AS  CutEfficiencyN,
-      IF(ExcessW<0, 0, ExcessW/TrigSumW)  AS  CutEfficiencyW,
+
+      SQRT(SimCountN)                       AS  ErrSimCountN,
+      SQRT(TrigCountN)                      AS  ErrTrigCountN,
+      SQRT(SignalN)                          AS  ErrSignalN,
+
+      SimSumW              /Width/AreaTime   AS  SimFluxW,
+      TrigSumW             /Width/AreaTime   AS  TrigFluxW,
+      SignalW              /Width/AreaTime   AS  SignalFluxW,
+      BackgroundW/5        /Width/AreaTime   AS  BackgroundFluxW,
+      ExcessW              /Width/AreaTime   AS  ExcessFluxW,
+      SQRT(SimSumW2)       /Width/AreaTime   AS  ErrSimFluxW,
+      SQRT(TrigSumW2)      /Width/AreaTime   AS  ErrTrigFluxW,
+      SQRT(SignalW2)       /Width/AreaTime   AS  ErrSignalFluxW,
+      SQRT(BackgroundW2)/5 /Width/AreaTime   AS  ErrBackgroundFluxW,
+      SQRT(ExcessW2)       /Width/AreaTime   AS  ErrExcessFluxW,
+
+      SumEnergyEstW/SignalW                  AS  AvgEnergyEstW,
+      SumEnergySimW/SignalW                  AS  AvgEnergySimW,
+
+      Area*TriggerEfficiencyN                AS  EffectiveAreaN,
+      Area*TriggerEfficiencyW                AS  EffectiveAreaW,
+
+      SignalN/TrigCountN                     AS  CutEfficiencyN,
+      IF(ExcessW<0, 0, ExcessW/TrigSumW)     AS  CutEfficiencyW,
+
       TriggerEfficiencyN * SQRT(1/TrigCountN + 1/SimCountN)                          AS  ErrTriggerEfficiencyN,
       TriggerEfficiencyW * SQRT(TrigSumW2/POW(TrigSumW,2) + SimSumW2/POW(SimSumW,2)) AS  ErrTriggerEfficiencyW,
+
       IF(SignalW>0, ResidualW/SignalW,                                                             NULL)  AS  BiasW,
       IF(SignalW>0, ResidualW/SignalW*SQRT(ResidualW2/POW(ResidualW,2) + SignalW2/POW(SignalW,2)), NULL)  AS  ErrBiasW,
-      IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)),                          NULL)  AS  ResolutionW
+      IF(SignalW>0, SQRT(ResidualW2/SignalW - POW(ResidualW/SignalW, 2)),                          NULL)  AS  ResolutionW,
+
+      (SUM(SignalW)       OVER Integral)                     AS  IntegralSignalW,
+      (SUM(SignalW)       OVER Integral) / AreaTime          AS  IntegralSignalFluxW,
+      (SUM(BackgroundW)   OVER Integral) / AreaTime          AS  IntegralBackgroundFluxW,
+      (SUM(SignalW2)      OVER Integral) / POW(AreaTime, 2)  AS  IntegralSignalFluxW2,
+      (SUM(BackgroundW2)  OVER Integral) / POW(AreaTime, 2)  AS  IntegralBackgroundFluxW2,
+
+      (SUM(SimSumW)       OVER Integral) / AreaTime          AS  IntegralSimFluxW,
+      (SUM(SimSumW2)      OVER Integral) / POW(AreaTime, 2)  AS  IntegralSimFluxW2,
+
+      (SUM(SumEnergySimW) OVER Integral)                     AS  IntegralEnergySimW,
+      (SUM(SumEnergyEstW) OVER Integral)                     AS  IntegralEnergyEstW
    FROM
       CombinedData
+   WINDOW
+      Integral AS (ORDER BY %102:bin DESC)
 )
 SELECT -- Return derived values and result
    *,
+
    Area*ErrTriggerEfficiencyN  AS  ErrEffectiveAreaN,
    Area*ErrTriggerEfficiencyW  AS  ErrEffectiveAreaW,
+
    CutEfficiencyN*SQRT(1/SignalN + 1/TrigCountN)                             AS  ErrCutEfficiencyN,
-   CutEfficiencyW*SQRT(ExcessW2/POW(ExcessW,2) + TrigSumW2/POW(TrigSumW,2))  AS  ErrCutEfficiencyW
+   CutEfficiencyW*SQRT(ExcessW2/POW(ExcessW,2) + TrigSumW2/POW(TrigSumW,2))  AS  ErrCutEfficiencyW,
+
+   IntegralSignalFluxW - IntegralBackgroundFluxW/5         AS  IntegralExcessFluxW,
+   SQRT(IntegralSignalFluxW2+IntegralBackgroundFluxW2/25)  AS  ErrIntegralExcessFluxW,
+   SQRT(IntegralSignalFluxW2)                              AS  ErrIntegralSignalFluxW,
+   SQRT(IntegralBackgroundFluxW2)                          AS  ErrIntegralBackgroundFluxW,
+   SQRT(IntegralSimFluxW2)                                 AS  ErrIntegralSimFluxW,
+
+   IntegralEnergyEstW/IntegralSignalW                      AS  AvgIntegralEnergyEstW,
+   IntegralEnergySimW/IntegralSignalW                      AS  AvgIntegralEnergySimW
+
 FROM
    Table0
