Index: /trunk/MagicSoft/Mars/manalysis/MPedCalUpdate.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedCalUpdate.cc	(revision 3779)
+++ /trunk/MagicSoft/Mars/manalysis/MPedCalUpdate.cc	(revision 3779)
@@ -0,0 +1,236 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz 03/2004 <mailto:tbretz@astro.uni.wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MPedCalUpdate
+//
+//  This task reads files stored by MJ* storing pedestals (F2) and
+//  calibration constants (F1) while an eventloop is running.
+//
+//  The update is done according to the run-number. The information
+//  which ped/cal files corresponds to which run-number is stored in
+//  an ascii file. In a next step this ascii file can be created
+//  automatically (hopefully from the Database)
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MPedCalUpdate.h"
+
+#include <fstream>
+#include <TFile.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MRawRunHeader.h"
+#include "MPedPhotCam.h"
+#include "MCalibrationChargeCam.h"
+#include "MBadPixelsCam.h"
+
+ClassImp(MPedCalUpdate);
+
+using namespace std;
+
+static const TString gsDefName  = "MPedCalUpdate";
+static const TString gsDefTitle = "";
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MPedCalUpdate::MPedCalUpdate(const char *fname, const char *name, const char *title)
+    : fPedPhot(0), fCalCam(0), fFileName(fname)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+    fLast=0;
+}
+
+Bool_t MPedCalUpdate::ReadPed(const char *fname)
+{
+    TFile file(fname, "READ");
+    if (fPedPhot->Read()<=0)
+    {
+        *fLog << err << "Unable to read MPedPhotCam from " << fname << endl;
+        return kFALSE;
+    }
+
+    if (file.FindKey("MBadPixelsCam"))
+    {
+        MBadPixelsCam bad;
+        if (bad.Read()<=0)
+        {
+            *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
+            return kFALSE;
+        }
+        fBadPix->Merge(bad);
+    }
+    return kTRUE;
+}
+
+Bool_t MPedCalUpdate::ReadCal(const char *fname)
+{
+    TFile file(fname, "READ");
+    if (fCalCam->Read()<=0)
+    {
+        *fLog << err << "Unable to read MCalibrationChargeCam from " << fname << endl;
+        return kFALSE;
+    }
+
+    if (file.FindKey("MBadPixelsCam"))
+    {
+        MBadPixelsCam bad;
+        if (bad.Read()<=0)
+        {
+            *fLog << "Unable to read MBadPixelsCam from " << fname << endl;
+            return kFALSE;
+        }
+        fBadPix->Merge(bad);
+    }
+    return kTRUE;
+}
+
+Bool_t MPedCalUpdate::ReadPC(TString &line)
+{
+    const Int_t f = line.First(' ');
+    if (f<0)
+    {
+        *fLog << err << "Entry for pedestal file not found!" << endl;
+        return kFALSE;
+    }
+
+    const Int_t l = line.Last(' ')+1;
+    if (l<0)
+    {
+        *fLog << err << "Entry for calibration file not found!" << endl;
+        return kFALSE;
+    }
+
+    const TString fname1 = line(0, f);
+    const TString fname2 = line(l, line.Length());
+
+    TString mid(line(f, l-f));
+    mid=mid.Strip(TString::kBoth);
+    if (!mid.IsNull())
+    {
+        *fLog << err << "Found three filenames '" << fname1 << "' '" << mid << "' '" << fname2 << "'" << endl;
+        return kFALSE;
+    }
+
+    if (!ReadPed(fname1))
+        return kFALSE;
+
+    if (!ReadCal(fname2))
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//
+Bool_t MPedCalUpdate::ReInit(MParList *pList)
+{
+    MRawRunHeader *header = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!header)
+    {
+        *fLog << err << "MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+    fPedPhot = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
+    if (!fPedPhot)
+        return kFALSE;
+    fBadPix = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
+    if (!fBadPix)
+        return kFALSE;
+    fCalCam = (MCalibrationChargeCam*)pList->FindCreateObj("MCalibrationChargeCam");
+    if (!fCalCam)
+        return kFALSE;
+
+    const Int_t run = header->GetRunNumber();
+
+    ifstream fin(fFileName);
+    if (!fin)
+    {
+        *fLog << err << "Cannot open file: " << fFileName << endl;
+        return kFALSE;
+    }
+
+    Int_t last = 0;
+
+    TString readline;
+
+    while (1)
+    {
+        // Read line from file
+        TString line;
+        line.ReadLine(fin);
+        if (!fin && !readline.IsNull() && fLast!=last)
+        {
+            *fLog << dbg << "Reading line " << readline << endl;
+            fLast = last;
+            return ReadPC(readline);
+        }
+
+        if (!fin)
+            break;
+
+        line = line.Strip(TString::kBoth);
+
+        // Interprete line
+        Int_t len, num;
+        if (sscanf(line.Data(), "%d %n", &num, &len)!=1)
+            continue;
+
+        // Check whether entries are in increasing order
+        if (num<=last)
+        {
+            *fLog << err << "Runs must be in increasing order..." << endl;
+            return kFALSE;
+        }
+        last = num;
+
+        // Check if a new set of files must be read
+        if (num<=run)
+        {
+            readline=line;
+            readline.Remove(0, len);
+            continue;
+        }
+
+        // This is the case if the correct files were already read
+        if (fLast==num)
+            return kTRUE;
+
+        // Read files given in new line
+        *fLog << dbg << "Reading line " << readline << endl;
+        fLast = num;
+        return ReadPC(readline);
+    }
+
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/manalysis/MPedCalUpdate.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedCalUpdate.h	(revision 3779)
+++ /trunk/MagicSoft/Mars/manalysis/MPedCalUpdate.h	(revision 3779)
@@ -0,0 +1,35 @@
+#ifndef MARS_MPedCalUpdate
+#define MARS_MPedCalUpdate
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MPedPhotCam;
+class MCalibrationChargeCam;
+class MBadPixelsCam;
+
+class MPedCalUpdate : public MTask
+{
+private:
+    MPedPhotCam           *fPedPhot;
+    MCalibrationChargeCam *fCalCam;
+    MBadPixelsCam         *fBadPix;
+
+    TString fFileName;
+
+    Int_t fLast;
+
+    Bool_t ReadCal(const char *name);
+    Bool_t ReadPed(const char *name);
+    Bool_t ReadPC(TString &line);
+    Bool_t ReInit(MParList *pList);
+
+public:
+    MPedCalUpdate(const char *filename, const char *name=NULL, const char *title=NULL);
+
+    ClassDef(MPedCalUpdate, 1) // Task to update Pedestals and Cal-Constants while an eventloop is running
+}; 
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mhist/MHAlpha.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHAlpha.cc	(revision 3778)
+++ /trunk/MagicSoft/Mars/mhist/MHAlpha.cc	(revision 3779)
@@ -27,76 +27,12 @@
 // MHAlpha
 //
-// Create a false source plot. For the Binning in x,y the object MBinning
-// "BinningFalseSource" is taken from the paremeter list.
-//
-// The binning in alpha is currently fixed as 18bins from 0 to 90deg.
-//
-// If MTime, MObservatory and MPointingPos is available in the paremeter
-// list each image is derotated.
-//
-// MHAlpha fills a 3D histogram with alpha distribution for
-// each (derotated) x and y position.
-//
-// Only a radius of 1.2deg around the camera center is taken into account.
-//
-// The displayed histogram is the projection of alpha<fAlphaCut into
-// the x,y plain and the projection of alpha>90-fAlphaCut
-//
-// By using the context menu (find it in a small region between the single
-// pads) you can change the AlphaCut 'online'
-//
-// Here is a slightly simplified version of the algorithm:
-// ------------------------------------------------------
-//    MHillas hil; // Taken as second argument in MFillH
-//
-//    MSrcPosCam src;
-//    MHillasSrc hsrc;
-//    hsrc.SetSrcPos(&src);
-//
-//    for (int ix=0; ix<nx; ix++)
-//        for (int iy=0; iy<ny; iy++)
-//        {
-//            TVector2 v(cx[ix], cy[iy]); //cx center of x-bin ix
-//            if (rho!=0)                 //cy center of y-bin iy
-//                v.Rotate(-rho);         //image rotation angle
-//
-//            src.SetXY(v);               //source position in the camera
-//
-//            if (!hsrc.Calc(hil))        //calc source dependant hillas
-//                return;
-//
-//            //fill absolute alpha into histogram
-//            const Double_t alpha = hsrc.GetAlpha();
-//            fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
-//        }
-//    }
-//
-// Use MHFalse Source like this:
-// -----------------------------
-//    MFillH fill("MHAlpha", "MHillas");
-// or
-//    MHAlpha hist;
-//    hist.SetAlphaCut(12.5);  // The default value
-//    hist.SetBgmean(55);      // The default value
-//    MFillH fill(&hist, "MHillas");
-//
-// To be implemented:
-// ------------------
-//  - a switch to use alpha or |alpha|
-//  - taking the binning for alpha from the parlist (binning is
-//    currently fixed)
-//  - a possibility to change the fit-function (eg using a different TF1)
-//  - a possibility to change the fit algorithm (eg which paremeters
-//    are fixed at which time)
-//  - use a different varaible than alpha
-//  - a possiblity to change the algorithm which is used to calculate
-//    alpha (or another parameter) is missing (this could be done using
-//    a tasklist somewhere...)
-//  - a more clever (and faster) algorithm to fill the histogram, eg by
-//    calculating alpha once and fill the two coils around the mean
-//  - more drawing options...
-//  - Move Significance() to a more 'general' place and implement
-//    also different algorithms like (Li/Ma)
-//  - implement fit for best alpha distribution -- online (Paint)
+// Create a single Alpha-Plot. The alpha-plot is fitted online. You can
+// check the result when it is filles in the MStatusDisplay
+// For more information see MHFalseSource::FitSignificance
+//
+// For convinience (fit) the output significance is stored in a
+// container in the parlisrt
+//
+// PRELIMINARY!
 //
 //////////////////////////////////////////////////////////////////////////////
Index: /trunk/MagicSoft/Mars/mhist/MHAlpha.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHAlpha.h	(revision 3778)
+++ /trunk/MagicSoft/Mars/mhist/MHAlpha.h	(revision 3779)
@@ -48,5 +48,5 @@
     static Double_t Significance(Double_t s, Double_t b);
 
-    ClassDef(MHAlpha, 1) //3D-histogram in alpha, x and y
+    ClassDef(MHAlpha, 1) // Alpha-Plot which is fitted online
 };
 
