Index: trunk/Mars/fact/analysis/gain/fit_spectra.C
===================================================================
--- trunk/Mars/fact/analysis/gain/fit_spectra.C	(revision 17074)
+++ trunk/Mars/fact/analysis/gain/fit_spectra.C	(revision 17075)
@@ -9,4 +9,6 @@
 #include <TStyle.h>
 
+#include "MLog.h"
+#include "MLogManip.h"
 #include "MStatusArray.h"
 #include "MStatusDisplay.h"
@@ -15,4 +17,5 @@
 #include "MParameters.h"
 #include "MArrayI.h"
+#include "MRawRunHeader.h"
 
 using namespace std;
@@ -140,5 +143,5 @@
     if (file.IsZombie())
     {
-        cout << "Opening file '" << filename << "' failed." << endl;
+        gLog << err << "Opening file '" << filename << "' failed." << endl;
         return 1;
     }
@@ -147,5 +150,5 @@
     if (arr.Read()<=0)
     {
-        cout << "Reading of MStatusArray from '" << filename << "' failed." << endl;
+        gLog << err << "Reading of MStatusArray from '" << filename << "' failed." << endl;
         return 2;
     }
@@ -154,5 +157,5 @@
     if (!hsignal)
     {
-        cout << "Histogram Signal not found in '" << filename << "'." << endl;
+        gLog << err << "Histogram Signal not found in '" << filename << "'." << endl;
         return 3;
     }
@@ -160,18 +163,25 @@
     if (!htime)
     {
-        cout << "Histogram Time not found in '" << filename << "'." << endl;
-        return 3;
+        gLog << err << "Histogram Time not found in '" << filename << "'." << endl;
+        return 4;
     }
     TProfile2D *hpulse = (TProfile2D*)arr.FindObjectInCanvas("Pulse", "TProfile2D", "MHSingles");
     if (!hpulse)
     {
-        cout << "Histogram Pulse not found in '" << filename << "'." << endl;
-        return 3;
+        gLog << err << "Histogram Pulse not found in '" << filename << "'." << endl;
+        return 5;
     }
     TH2F *hbase = (TH2F*)arr.FindObjectInCanvas("Baseline", "TH2F", "MHBaseline");
     if (!hbase)
     {
-        cout << "Histogram Baseline not found in '" << filename << "'." << endl;
-        return 3;
+        gLog << err << "Histogram Baseline not found in '" << filename << "'." << endl;
+        return 6;
+    }
+
+    MRawRunHeader header;
+    if (header.Read()<=0)
+    {
+        gLog << err << "MRawRunheader not found in '" << filename << "'." << endl;
+        return 7;
     }
 
@@ -179,6 +189,6 @@
     if (par.Read()<=0)
     {
-        cout << "NumEvents not found in '" << filename << "'." << endl;
-        return 4;
+        gLog << err << "NumEvents not found in '" << filename << "'." << endl;
+        return 8;
     }
 
@@ -186,6 +196,6 @@
     if (ext.Read("ExtractionRange")<=0)
     {
-        cout << "ExtractionRange not found in '" << filename << "'." << endl;
-        return 5;
+        gLog << err << "ExtractionRange not found in '" << filename << "'." << endl;
+        return 9;
 
     }
@@ -226,5 +236,5 @@
 
     // Instantiate 1D histograms for the distributions
-    TH1F hRate     ("Rate",      "Dark count rate",       100,  0,    10);
+    TH1F hRate     ("Rate",      "Dark count rate",       150,  0,    15);
     TH1F hGain     ("Gain",      "Gain distribution",     100,  0,   400);
     TH1F hRelSigma ("RelSigma",  "Rel. Sigma",            160,  0,  0.40);
@@ -317,5 +327,5 @@
     if (fwhmSum==0)
     {
-        cout << "Could not determine start value for sigma." << endl;
+        gLog << warn << "Could not determine start value for sigma." << endl;
     }
 
@@ -393,5 +403,5 @@
         if (hist->GetEntries()<100)
         {
-            cout << pixel << " ...histogram empty." << endl;
+            gLog << warn << pixel << " ...histogram empty." << endl;
             usePixel[pixel] = 0;
             delete hist;
@@ -488,10 +498,10 @@
         // mark pixels suspicious with failed fit
         if (!ok)
-            cout <<  pixel << " ...fit failed!" << endl;
+            gLog << warn <<  pixel << " ...fit failed!" << endl;
 
         // mark pixels suspicious with negative GainRMS
         if (fabs(fGain/gain-1)>0.3)
         {
-            cout <<  pixel << " ...gain deviates more than 30% from sum-gain." << endl;
+            gLog << warn <<  pixel << " ...gain deviates more than 30% from sum-gain." << endl;
             ok = 0;
         }
@@ -499,5 +509,5 @@
         if (fabs(fOffset/integration_window)>3)
         {
-            cout <<  pixel << " ...baseline deviates." << endl;
+            gLog << warn <<  pixel << " ...baseline deviates." << endl;
             ok = 0;
         }
@@ -548,4 +558,6 @@
         hNormGain.Fill(  fGain/gain);
         hFitProb.Fill(   fit_prob);
+        hCrosstalkP.Fill(fCrosstalkP);
+        hCoeffR.Fill(    fCoeffR);
 
         // Fill sum spectrum
@@ -771,5 +783,5 @@
     // ================================================================
 
-    cout << "saving results to rootfile" << endl;
+    cout << "Saving results to '" << outfile << "'" << endl;
     d->SaveAs(outfile);
     cout << "..success!" << endl;
@@ -778,4 +790,5 @@
     par.Write();
     ext.Write("ExtractionRange");
+    header.Write();
 
     return 0;
