Index: trunk/FACT++/src/spectrum.cc
===================================================================
--- trunk/FACT++/src/spectrum.cc	(revision 19979)
+++ trunk/FACT++/src/spectrum.cc	(revision 19980)
@@ -154,4 +154,5 @@
         ("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.")
+        ("selsim",     vars<string>(),            "WHERE clause to be used in monte carlo file selection.")
         ("estimator",  var<string>()->required(), "Energy estimator to be used.")
         ("spectrum",   var<string>()->required(), "Spectral shape for re-weighting of simulated 'Energy'")
@@ -190,4 +191,7 @@
         "Usage: spectrum [-u URI] [options]\n"
         "\n"
+        "Note that default analysis query is built into the executable. If a changed "
+        "query should be used, it is not enough to just change the file, but the "
+        "--analysis command line option has to be explicitly specified.\n"
         ;
     cout << endl;
@@ -547,5 +551,5 @@
         catch (const mysqlpp::BadConversion &b)
         {
-            cerr << b.what() << endl;
+            cerr << "\033[31m" << b.what() << "\033[0m" << endl;
         }
     }
@@ -636,5 +640,6 @@
     Binning binning_impact = conf.Get<Binning>("impact");
 
-    cout << '\n';
+    cout << "\nIt is " << start.Iso() << "\n\n";
+
     cout << "Binning 'theta':  " << binning_theta.str()  << endl;
     cout << "Binning 'dense':  " << binning_dense.str()  << endl;
@@ -644,4 +649,5 @@
     const uint16_t source_key = conf.Get<uint16_t>("source-key");
     const string   where      = boost::join(conf.Vec<string>("selector"), " AND\n      ");
+    const string   where_sim  = boost::join(conf.Vec<string>("selsim"), " AND\n      ");
     const string   estimator  = conf.Get<string>("estimator");
     const string   spectrum   = conf.Get<string>("spectrum");
@@ -888,7 +894,8 @@
         "   ON\n"
         "      (ThetaMin>=lo AND ThetaMin<hi) OR (ThetaMax>lo AND ThetaMax<=hi)\n"
+        "   LEFT JOIN\n"
+        "      factmc.SetInfo USING (SetKEY, PartId)\n"
         "   WHERE\n"
-        "      PartId=1 AND\n"
-        "      FileId%%2=0\n"
+        "      PartId=1 %101:where\n"
         "   ORDER BY\n"
         "      FileId\n" // In order: faster
@@ -898,4 +905,7 @@
     //for (auto it=env.cbegin(); it!=env.cend(); it++)
     //    query3.template_defaults[it->first.c_str()] = it->second.c_str();
+
+    if (!where_sim.empty())
+        query3.template_defaults["where"] = ("AND\n      "+where_sim).c_str();
 
     if (print_queries)
@@ -1098,4 +1108,5 @@
         "      OnTime,\n"
         "      OnTime/CountN AS ZdWeight,\n"
+        /*                             1s per 300s  1/CountN = [sqrt(CountN)/CountN]^2  */
         "      (OnTime/CountN)*SQRT(POW(1/300, 2) + 1/CountN) AS ErrZdWeight\n"
         "   FROM\n"
@@ -2332,5 +2343,16 @@
         "mg.DrawClone(\"A\");\n\n"
         "gPad->SetLogx();\n"
-        "gPad->SetLogy();\n";
+        "gPad->SetLogy();\n"
+        "\n"
+        "TF1 f(\"Power Law\", \"[0]*(x/1000)^[1]\", g->GetX()[0], g->GetX()[g->GetN()-1]);\n"
+        "f.SetParameter(0, 1e-11);\n"
+        "f.SetParameter(1, -2.6);\n"
+        "g->Fit(&f, \"\", \"NOQ\");\n"
+        "f.SetLineColor(kBlue);\n"
+        "f.DrawCopy(\"same\");\n"
+        "\n"
+        "cout << \"\\nChi^2/NDF:   \" << f.GetChisquare() << \" / \" << f.GetNDF() << '\\n';\n"
+        "cout << \"Probability: \" << f.GetProb() << '\\n' << endl;\n";
+
     mlog << indent(0) << "}" << endl;
 
