Index: /fact/tools/marsmacros/singlepe.C
===================================================================
--- /fact/tools/marsmacros/singlepe.C	(revision 14230)
+++ /fact/tools/marsmacros/singlepe.C	(revision 14231)
@@ -421,14 +421,8 @@
     // ======================================================
 
-    const char *drsfile = "/fact/raw/2012/03/09/20120309_012.drs.fits.gz";
-//    const char *drsfile = "/fact/raw/2012/01/13/20120113_003.drs.fits.gz";
+    const char *drsfile = "/fact/raw/2012/05/18/20120518_012.drs.fits.gz";
 
     MDirIter iter;
-//    iter.AddDirectory("/fact/raw/2012/03/09", "20120309_014.fits.gz");
-//    iter.AddDirectory("/fact/raw/2012/03/09", "20120309_032.fits.gz");
-//    iter.AddDirectory("/fact/raw/2012/03/09", "20120309_038.fits.gz");
-    iter.AddDirectory("/fact/raw/2012/03/09", "20120309_017.fits.gz");
-//    iter.AddDirectory("/fact/raw/2012/03/09", "20120309_018.fits.gz");
-//    iter.AddDirectory("/fact/raw/2012/01/13", "20120113_007.fits.gz");
+     iter.AddDirectory("/fact/raw/2012/05/18", "20120518_005.fits.gz");
 
     // ======================================================
@@ -519,5 +513,11 @@
     plist1.AddToList(&header);
 
-    MEvtLoop loop1("DetermineCalConst");
+    TString Title;
+    Title =  iter.Next();
+    iter.Reset();
+    Title += "; ";
+    Title += max1;
+
+    MEvtLoop loop1(Title);
     loop1.SetDisplay(d);
     loop1.SetParList(&plist1);
@@ -602,7 +602,10 @@
     TH1F hSum       ("Sum1",      "Sum of all pixel amplitude Spectra",
                      100,    0,  2000);
+    hSum.Sumw2();
+
     TH1F hSumScale  ("Sum2",
                      "Sum of all pixel amplitude Spectra (scaled with gain)",
-                     100,    0,   10);
+                     100,    0.05,   10.05);
+    hSumScale.Sumw2();
 
     // define fit function for Amplitudespectrum
@@ -648,20 +651,5 @@
 
     // List of Pixel that should be ignored in camera view
-    suspicous[802]       = true;
-    suspicous[543]     = true;
-    suspicous[465]     = true;
-    suspicous[1154]     = true;
-    suspicous[342]     = true;
-    suspicous[1319]      = true;
-    suspicous[1401]      = true;
-    suspicous[1318]      = true;
-    suspicous[1400]     = true;
-    suspicous[243]      = true;
-    suspicous[1299]     = true;
-    suspicous[764]     = true;
-    suspicous[762]     = true;
-    suspicous[1427]      = true;
-    suspicous[1319]     = true;
-    suspicous[118]     = true;
+    //    suspicous[802]       = true;
 
     //------------------------------------------------------------------------
@@ -684,9 +672,15 @@
         }
     }
+    for(UInt_t bin = 1; bin < hSum.GetNbinsX()+1; bin++)
+    {
+        hSum.SetBinError(bin, hSum.GetBinContent(bin)*0.1);
+    }
 
     gROOT->SetSelectedPad(0);
     TCanvas &c11 = d->AddTab("SumHist");
     gPad->SetLogy();
-    hSum.DrawCopy();
+    gPad->SetGridx();
+    gPad->SetGridy();
+    hSum.DrawCopy("hist");
     //------------------------fit sum spectrum-------------------------------
     const Int_t    maxbin   = hSum.GetMaximumBin();
@@ -716,7 +710,7 @@
 
     //calculate fit range
-    const double min = sum_par[1]-fwhm2*1.4;
+    const double min = sum_par[1]-fwhm2*2;
     const double max = sum_par[1]*(maxOrder+1);
-    func2.SetRange(min-2*fwhm2, max);
+    func2.SetRange(min, max);
 
     //Fit and draw spectrum
@@ -762,5 +756,6 @@
     TF1 fExpo1( "fExpo1","expo", min, max);
     fExpo1.SetLineColor(kRed);
-    hMaxHeightsSum.Fit(&fExpo1, "N0S" );
+    hMaxHeightsSum.Fit(&fExpo1, "WLN0S" );
+    hMaxHeightsSum.DrawCopy("SAME");
     fExpo1.DrawCopy("SAME");
 
@@ -784,4 +779,9 @@
         TH1D *hist = hsignal->ProjectionY("proj", pixel+1, pixel+1);
         hist->SetDirectory(0);
+
+        for(UInt_t bin = 1; bin < hSum.GetNbinsX()+1; bin++)
+        {
+            hist->SetBinError(bin, hSum.GetBinContent(bin)*0.1);
+        }
 
         const Int_t    maxbin   = hist->GetMaximumBin();
@@ -835,6 +835,10 @@
                  << fwhm << "\t" << endl;
         }
+
+        //Rebin Projection
+        hist->Rebin(2);
+
         //Fit Pixels spectrum
-        const TFitResultPtr rc = hist->Fit(&func, "N0QS", "", fit_min, fit_max);
+        const TFitResultPtr rc = hist->Fit(&func, "WLN0QS", "", fit_min, fit_max);
 
         const bool ok = int(rc)==0;
@@ -878,5 +882,5 @@
         for (int b=1; b<=hist->GetNbinsX(); b++)
         {
-            hSum.Fill(hist->GetBinCenter(b), hist->GetBinContent(b));
+//            hSum.Fill(hist->GetBinCenter(b), hist->GetBinContent(b));
             hSumScale.Fill((hist->GetBinCenter(b)-fOffset)/fGain, hist->GetBinContent(b));
         }
@@ -891,5 +895,5 @@
             c.cd();
             hist->SetName(Form("Pix%d", pixel));
-            hist->DrawCopy()->SetDirectory(0);
+            hist->DrawCopy("hist")->SetDirectory(0);
 //            hist->Draw();
             func.DrawCopy("SAME");
@@ -916,5 +920,12 @@
     TCanvas &c12 = d->AddTab("GainHist");
     gPad->SetLogy();
-    hSumScale.DrawCopy();
+    gPad->SetGridx();
+    gPad->SetGridy();
+    for(UInt_t bin = 1; bin < hSum.GetNbinsX()+1; bin++)
+    {
+        hSumScale.SetBinError(bin, hSum.GetBinContent(bin)*0.1);
+    }
+    hSumScale.DrawCopy("hist");
+
 
     //-------------------- fit gain corrected sum spectrum -------------------
@@ -939,13 +950,15 @@
     Double_t par2[5] =
     {
-        ampl2, hSumScale.GetBinCenter(maxbin2), fwhm2*1.4, 0.1, -0.2
+        ampl2, 1, fwhm2*1.4, Crosstlk, 0
     };
 
     func3.SetParameters(par2);
+    func3.FixParameter(1,1);
+    func3.FixParameter(4,0);
 
     const double min2 = par2[1]-fwhm2*1.4;
     const double max2 = par2[1]*maxOrder;
 //    func.SetRange(min2-fwhm2, max);
-    hSumScale.Fit(&func3, "N0QS", "", min2, max2);
+    hSumScale.Fit(&func3, "WLN0QS", "", min2, max2);
     func3.DrawCopy("SAME");
 
@@ -987,5 +1000,9 @@
     c2.cd(2);
     gPad->SetLogy();
+    TF1 GainGaus( "GainGaus", "gaus");
+    hGain.Fit(&GainGaus, "N0QS");
+//    hGain.Scale(1/GainGaus.GetParameter(1));
     hGain.DrawCopy();
+    GainGaus.DrawCopy("SAME");
 
     c2.cd(3);
@@ -1070,5 +1087,5 @@
 //            xTalk *= cross;
 //        }
-        cross *= TMath::Exp(-powOfX*cross);
+//        cross *= TMath::Exp(-powOfX*cross);
         xTalk *= cross;
     }
