Index: trunk/FACT++/src/spectrum.cc
===================================================================
--- trunk/FACT++/src/spectrum.cc	(revision 19912)
+++ trunk/FACT++/src/spectrum.cc	(revision 19913)
@@ -147,15 +147,9 @@
         ;
 
-    po::options_description queries("Analysis Query");
-    queries.add_options()
+    po::options_description analysis("Analysis Setup");
+    analysis.add_options()
         ("analysis",    var<string>("analysis.sql"),   "File with the analysis query. A default file is created automatically in the <prefix> directory it does not exist.")
-        //("data",        var<string>("data.sql"),       "File with the query which creates the data summary. A default file is created automatically in the <prefix> directory it does not exist.")
-        //("simulation",  var<string>("simulation.sql"), "File with the query which creates the simulation summary. A default file is created automatically in the <prefix> directory it does not exist.")
-        ;
-
-    po::options_description preparation("Preparation");
-    preparation.add_options()
-        ("source-key", var<uint16_t>(5),          "Source key to be used in file selection.")
-        ("selector",   vars<string>(),            "WHERE clause to be used in file selection.")
+        ("source-key", var<uint16_t>(5),          "Source key to be used in data file selection.")
+        ("selector",   vars<string>(),            "WHERE clause to be used in data file selection.")
         ("estimator",  var<string>()->required(), "Energy estimator to be used.")
         ("spectrum",   var<string>()->required(), "Spectral shape for re-weighting of simulated 'Energy'")
@@ -181,6 +175,5 @@
     conf.AddOptions(control);
     conf.AddOptions(binnings);
-    conf.AddOptions(queries);
-    conf.AddOptions(preparation);
+    conf.AddOptions(analysis);
     conf.AddOptions(debug);
     //conf.SetArgumentPositions(p);
@@ -369,7 +362,7 @@
 
     const auto vec = bins.vec();
-    for (size_t i=1; i<vec.size()-2; i++)
+    for (size_t i=1; i<vec.size()-1; i++)
         query1 << "  ( " << i << ", " << vec[i-1] << ", " << vec[i] << " ),\n";
-    query1 << "  ( " << vec.size()-2 << ", " << vec[vec.size()-2] << ", " << vec[vec.size()-1] << " )\n";
+    query1 << "  ( " << vec.size()-1 << ", " << vec[vec.size()-2] << ", " << vec[vec.size()-1] << " )\n";
 
     qlog << query1 << ";\n" << endl;
@@ -787,6 +780,6 @@
 
     query1.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query1.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query1.template_defaults[it->first.c_str()] = it->second.c_str();
 
     query1.template_defaults["source"] = to_string(source_key).c_str();
@@ -842,6 +835,6 @@
 
     query2.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query2.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query2.template_defaults[it->first.c_str()] = it->second.c_str();
 
     query2.template_defaults["bins"] = str_theta.c_str();
@@ -896,6 +889,6 @@
 
     query3.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query3.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query3.template_defaults[it->first.c_str()] = it->second.c_str();
 
     if (print_queries)
@@ -942,6 +935,6 @@
 
     query4.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query4.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query4.template_defaults[it->first.c_str()] = it->second.c_str();
 
     if (print_queries)
@@ -1017,6 +1010,6 @@
 
     query5.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query5.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query5.template_defaults[it->first.c_str()] = it->second.c_str();
 
     query5.template_defaults["table"]    = "OriginalMC";
@@ -1111,6 +1104,6 @@
 
     query6.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query6.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query6.template_defaults[it->first.c_str()] = it->second.c_str();
 
     if (print_queries)
@@ -1212,6 +1205,6 @@
 
     query7.parse();
-    for (auto it=env.cbegin(); it!=env.cend(); it++)
-        query7.template_defaults[it->first.c_str()] = it->second.c_str();
+    //for (auto it=env.cbegin(); it!=env.cend(); it++)
+    //    query7.template_defaults[it->first.c_str()] = it->second.c_str();
 
     query7.template_defaults["table"] = "OriginalMC";
@@ -1482,6 +1475,6 @@
 
         query9.parse();
-        for (auto it=env.cbegin(); it!=env.cend(); it++)
-            query9.template_defaults[it->first.c_str()] = it->second.c_str();
+        //for (auto it=env.cbegin(); it!=env.cend(); it++)
+        //    query9.template_defaults[it->first.c_str()] = it->second.c_str();
 
         query9.template_defaults["table"]    = table.c_str();
@@ -1713,6 +1706,6 @@
 
         query10.parse();
-        for (auto it=env.cbegin(); it!=env.cend(); it++)
-            query10.template_defaults[it->first.c_str()] = it->second.c_str();
+        //for (auto it=env.cbegin(); it!=env.cend(); it++)
+        //    query10.template_defaults[it->first.c_str()] = it->second.c_str();
 
         query10.template_defaults["binning"] = ib->c_str();
@@ -1831,6 +1824,6 @@
 
         query11.parse();
-        for (auto it=env.cbegin(); it!=env.cend(); it++)
-            query11.template_defaults[it->first.c_str()] = it->second.c_str();
+        //for (auto it=env.cbegin(); it!=env.cend(); it++)
+        //    query11.template_defaults[it->first.c_str()] = it->second.c_str();
 
         query11.template_defaults["binning"] = ib->c_str();
@@ -1943,4 +1936,13 @@
     // --------------------------- Spectrum ------------------------------
     // -------------------------------------------------------------------
+
+    sindent mindent(mlog);
+    mlog << "void spectrum()\n";
+    mlog << "{\n" << indent(4);
+    mlog <<
+        "TGraphErrors *g = new TGraphErrors;\n"
+        "g->SetMarkerStyle(kFullDotMedium);\n\n"
+        "TGraph *ul = new TGraph;\n"
+        "ul->SetMarkerStyle(23);\n\n";
 
     const vector<string> targets = { "Theta", "Energy" };
@@ -2001,6 +2003,6 @@
 
         query13.parse();
-        for (auto it=env.cbegin(); it!=env.cend(); it++)
-            query13.template_defaults[it->first.c_str()] = it->second.c_str();
+        //for (auto it=env.cbegin(); it!=env.cend(); it++)
+        //    query13.template_defaults[it->first.c_str()] = it->second.c_str();
 
         query13.template_defaults["table"]     = table.c_str();
@@ -2074,4 +2076,15 @@
                 const size_t bin = row[*ib=="Theta" ? ".theta" : ".sparse_est"];
 
+                const double flux   = row["Flux"];
+                const double error  = row["ErrFlux"];
+                const double center = row["center"];
+                const double sigma  = row["SigmaFlux"];
+
+                if (*ib=="Energy" && flux>0)
+                {
+                    mlog << "g->SetPoint(g->GetN(), pow(10, " << center << "), " << flux << ");\n";
+                    mlog << "g->SetPointError(g->GetN()-1, 0, " << error << ");\n";
+                }
+
 #ifdef HAVE_ROOT
                 const double dat_sig  = row["Signal"];
@@ -2098,12 +2111,16 @@
                 rolke.SetPoissonBkgKnownEff(dat_isig, dat_ibg*5, 5, ieff);
                 rolke_int[bin] = rolke.GetUpperLimit()/areatime;
+
+                if (*ib=="Energy" && (sigma<1 || dat_sig<10 || dat_bg<2))
+                    mlog << "ul->SetPoint(ul->GetN(), pow(10, " << center << "), " << double(rolke_ul[bin]) << ");\n";
 #endif
+
                 if (verbose>0)
                 {
-                    cout << setw(5)  << row["center"] << ":";
+                    cout << setw(5) << center << ":";
                     cout << " " << setw(10) << row["Excess"];
                     cout << " " << setw(10) << row["Significance"];
-                    cout << " " << setw(10) << row["Flux"];
-                    cout << " " << setw(10) << row["ErrFlux"];
+                    cout << " " << setw(10) << flux;
+                    cout << " " << setw(10) << error;
                     cout << endl;
                 }
@@ -2232,4 +2249,16 @@
     }
 
+    mlog << "\n"
+        //"g.DrawClone(\"AP\");\n"
+        //"ul.DrawClone(\"P\");\n\n"
+        "TMultiGraph mg;\n"
+        "mg.SetTitle(\"Differential Energy Spectrum;E [GeV];dN/dE [cm^{-2} s^{-1} TeV^{-1}]\");\n"
+        "mg.Add(g,  \"P\");\n"
+        "mg.Add(ul, \"P\");\n"
+        "mg.DrawClone(\"A\");\n\n"
+        "gPad->SetLogx();\n"
+        "gPad->SetLogy();\n";
+    mlog << indent(0) << "}" << endl;
+
     // -------------------------------------------------------------------
     // ----------------------------- Summary -----------------------------
