Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2146)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2147)
@@ -1,3 +1,25 @@
                                                  -*-*- END OF LINE -*-*-
+ 2003/06/02: Thomas Bretz
+
+   * manalysis/AnalysisLinkDef.h, manalysis/Makefile:
+     - added MCurrents
+     
+   * manalysis/MCerPhotEvt.[h,cc]:
+     - added MGeomCam argument to GetRatioMin/Max
+     
+   * mfileio/FileIOLinkDef.h, mfileio/Makefile:
+     - added MReadCurrents
+
+   * mfileio/MReadCurrents.[h,cc]:
+     - added
+     
+   * manalysis/MCurrents.[h,cc]:
+     - added
+     
+   * mgui/MCamDisplay.[h,cc]:
+     - added current support
+
+
+
  2003/05/30: Wolfgang Wittek
 
Index: trunk/MagicSoft/Mars/macros/readcurrents.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readcurrents.C	(revision 2147)
+++ trunk/MagicSoft/Mars/macros/readcurrents.C	(revision 2147)
@@ -0,0 +1,97 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+Bool_t HandleInput()
+{
+    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
+    while (1)
+    {
+        //
+        // While reading the input process gui events asynchronously
+        //
+        timer.TurnOn();
+        TString input = Getline("Type 'q' to exit, <return> to go on: ");
+        timer.TurnOff();
+
+        if (input=="q\n")
+            return kFALSE;
+
+        if (input=="\n")
+            return kTRUE;
+    };
+
+    return kFALSE;
+}
+
+void readcurrents(const char *fname="../currents/dcs_vega.dat")
+{
+    MParList plist;
+
+    MGeomCamMagic geomcam;
+    MCurrents     cur;
+    MTaskList     tlist;
+
+    plist.AddToList(&geomcam);
+    plist.AddToList(&cur);
+    plist.AddToList(&tlist);
+
+    MReadCurrents read(fname);
+    /*
+     read.AddFile("../currents/dcs_arcturus2.dat");
+     read.AddFile("../currents/dcs_arcturus3.dat");
+     read.AddFile("../currents/dcs_arcturus4.dat");
+     read.AddFile("../currents/dcs_arcturus5.dat");
+     read.AddFile("../currents/dcs_arcturus6.dat");
+     read.AddFile("../currents/dcs_arcturus7.dat");
+     read.AddFile("../currents/dcs_arcturus8.dat");
+     read.AddFile("../currents/dcs_arcturus9.dat");
+     read.AddFile("../currents/dcs_arcturus10.dat");
+     */
+    tlist.AddToList(&read);
+
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    if (!evtloop.PreProcess())
+        return;
+
+    MCamDisplay display(&geomcam);
+    display.Draw();
+
+    int gifcnt = 0;
+
+    while (tlist.Process())
+    {
+        // cur.Print();
+        display.FillCurrents(cur);
+        gPad->Modified();
+        gPad->Update();
+        // Remove the comments if you want to go through the file
+        // event-by-event:
+        //        if (!HandleInput())
+        //            break;
+    } 
+
+    evtloop.PostProcess();
+}
Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2146)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2147)
@@ -12,4 +12,6 @@
 #pragma link C++ class MBlindPixels+;
 #pragma link C++ class MBlindPixelCalc+;
+
+#pragma link C++ class MCurrents+;
 
 #pragma link C++ class MPedestalPix+;
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 2146)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 2147)
@@ -236,5 +236,5 @@
 // get the minimum ratio of photons/error
 //
-Float_t MCerPhotEvt::GetRatioMin() const
+Float_t MCerPhotEvt::GetRatioMin(const MGeomCam *geom) const
 {
     if (fNumPixels <= 0)
@@ -250,4 +250,7 @@
 
         Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
+        if (geom)
+            testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
+
         if (testval < minval)
             minval = testval;
@@ -261,5 +264,5 @@
 // get the maximum ratio of photons/error
 //
-Float_t MCerPhotEvt::GetRatioMax() const
+Float_t MCerPhotEvt::GetRatioMax(const MGeomCam *geom) const
 {
     if (fNumPixels <= 0)
@@ -275,4 +278,7 @@
 
         Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
+        if (geom)
+            testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
+
         if (testval > maxval)
             maxval = testval;
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 2146)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 2147)
@@ -41,6 +41,6 @@
     Float_t GetNumPhotonsMax(const MGeomCam *geom=NULL) const;
 
-    Float_t GetRatioMin() const;
-    Float_t GetRatioMax() const;
+    Float_t GetRatioMin(const MGeomCam *geom=NULL) const;
+    Float_t GetRatioMax(const MGeomCam *geom=NULL) const;
 
     Float_t GetErrorPhotMin(const MGeomCam *geom=NULL) const;
Index: trunk/MagicSoft/Mars/manalysis/MCurrents.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCurrents.cc	(revision 2147)
+++ trunk/MagicSoft/Mars/manalysis/MCurrents.cc	(revision 2147)
@@ -0,0 +1,76 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MCurrents (PRELIMINARY)
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCurrents.h"
+
+#include <TMath.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MCurrents);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MCurrents::MCurrents(Int_t size, const char *name, const char *title)
+    : fArray(size)
+{
+    fName  = name  ? name  : "MCurrents";
+    fTitle = title ? title : "Storage container for the pixel currents";
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the hillas Parameters to *fLog
+//
+void MCurrents::Print(Option_t *) const
+{
+    *fLog << all << underline << GetDescriptor() << endl;
+    for (int i=0; i<fArray.GetSize(); i++)
+        *fLog << " " << GetCurrent(i);
+    *fLog << endl;
+}
+
+UInt_t MCurrents::GetMin() const
+{
+    UInt_t val = (UInt_t)-1;
+    for (int i=0; i<fArray.GetSize(); i++)
+        val = TMath::Min(val, GetCurrent(i));
+    return val;
+}
+
+UInt_t MCurrents::GetMax() const
+{
+    UInt_t val = 0;
+    for (int i=0; i<fArray.GetSize(); i++)
+        val = TMath::Max(val, GetCurrent(i));
+    return val;
+}
Index: trunk/MagicSoft/Mars/manalysis/MCurrents.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCurrents.h	(revision 2147)
+++ trunk/MagicSoft/Mars/manalysis/MCurrents.h	(revision 2147)
@@ -0,0 +1,42 @@
+#ifndef MARS_MCurrents
+#define MARS_MCurrents
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
+
+class MCurrents : public MParContainer
+{
+private:
+    /*
+       "DC %s %s %02d %02d %02d %03d 577*%05d \n",
+       status1, status2, hour, minute, second, ms,
+       577 * pixel_DC_readout_in_nAmp
+       */
+    TString fStatus[2];
+    TArrayI fArray; // [nA] Unsigned Int!
+
+public:
+    MCurrents(Int_t size=577, const char *name=NULL, const char *title=NULL);
+
+    void SetCurrent(Int_t i, UInt_t val) { fArray[i] = (Int_t)val; }
+    UInt_t GetCurrent(Int_t i) const { return (*this)[i]; }
+    UInt_t &operator[](Int_t i) { return (UInt_t&)fArray[i]; }
+    const UInt_t &operator[](Int_t i) const { return ((TArrayI)fArray)[i]; }
+
+    UInt_t GetMin() const;
+    UInt_t GetMax() const;
+
+    void SetStatus1(const TString &str) { fStatus[0] = str; }
+    void SetStatus2(const TString &str) { fStatus[1] = str; }
+
+    void Print(Option_t *opt=NULL) const;
+
+    ClassDef(MCurrents, 1) // Storage Container for the Currents (PRELIMINARY)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2146)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2147)
@@ -33,4 +33,5 @@
            MMcPedestalCopy.cc \
            MMcPedestalNSBAdd.cc \
+           MCurrents.cc \
            MEnergyEst.cc \
            MEnergyEstimate.cc \
Index: trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h	(revision 2146)
+++ trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h	(revision 2147)
@@ -9,4 +9,5 @@
 #pragma link C++ class MReadTree+;
 #pragma link C++ class MReadMarsFile+;
+#pragma link C++ class MReadCurrents+;
 #pragma link C++ class MReadRflFile+;
 
Index: trunk/MagicSoft/Mars/mfileio/MReadCurrents.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadCurrents.cc	(revision 2147)
+++ trunk/MagicSoft/Mars/mfileio/MReadCurrents.cc	(revision 2147)
@@ -0,0 +1,227 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MReadCurrents                                                         //
+//                                                                         //
+//  Input Containers:                                                      //
+//   -/-                                                                   //
+//                                                                         //
+//  Output Containers:                                                     //
+//   MCerPhotEvt                                                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MReadCurrents.h"
+
+#include <stdlib.h>  // atoi
+#include <fstream.h>
+
+#include <TList.h>
+#include <TSystem.h>
+
+#include "MTime.h"
+#include "MCurrents.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+ClassImp(MReadCurrents);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. Creates an array which stores the file names of
+// the files which should be read. If a filename is given it is added
+// to the list.
+//
+MReadCurrents::MReadCurrents(const char *fname,
+			     const char *name, 
+                             const char *title)
+    : fIn(NULL)
+{
+    fName  = name  ? name  : "MReadCurrents";
+    fTitle = title ? title : "Task to loop over events in CT1 ascii file";
+
+    //
+    // remember file name for opening the file in the preprocessor
+    //
+    fFileNames = new TList;
+    fFileNames->SetOwner();
+
+    if (fname)
+        AddFile(fname);
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the filename list and the input stream if one exists.
+//
+MReadCurrents::~MReadCurrents()
+{
+    delete fFileNames;
+    if (fIn)
+        delete fIn;
+}
+
+// --------------------------------------------------------------------------
+//
+// Add this file as the last entry in the chain
+//
+Int_t MReadCurrents::AddFile(const char *txt, Int_t)
+{
+    TNamed *name = new TNamed(txt, "");
+    fFileNames->AddLast(name);
+    return 1;
+}
+
+// --------------------------------------------------------------------------
+//
+// This opens the next file in the list and deletes its name from the list.
+//
+Bool_t MReadCurrents::OpenNextFile()
+{
+    //
+    // open the input stream and check if it is really open (file exists?)
+    //
+    if (fIn)
+        delete fIn;
+    fIn = NULL;
+
+    //
+    // Check for the existance of a next file to read
+    //
+    TNamed *file = (TNamed*)fFileNames->First();
+    if (!file)
+        return kFALSE;
+
+    //
+    // open the file which is the first one in the chain
+    //
+    const char *name = file->GetName();
+
+    const char *expname = gSystem->ExpandPathName(name);
+    fIn = new ifstream(expname);
+    delete [] expname;
+
+    const Bool_t noexist = !(*fIn);
+
+    if (noexist)
+        *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
+    else
+        *fLog << "Open file: '" << name << "'" << endl;
+
+    //
+    // Remove this file from the list of pending files
+    //
+    fFileNames->Remove(file);
+
+    return !noexist;
+}
+
+// --------------------------------------------------------------------------
+//
+// Open the first file in the list. Check for the output containers or create
+// them if they don't exist.
+//
+// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
+//
+Bool_t MReadCurrents::PreProcess(MParList *pList)
+{
+    //
+    // Preprocessing
+    //
+
+    //
+    // Try to open at least one (the first) file
+    //
+    if (!OpenNextFile())
+        return kFALSE;
+
+    //
+    // 
+    //
+    fTime = (MTime*)pList->FindCreateObj("MTime", "MTimeCurrents");
+    if (!fTime)
+        return kFALSE;
+
+    //
+    // 
+    //
+    fCurrents = (MCurrents*)pList->FindCreateObj("MCurrents");
+    if (!fCurrents)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Check for the event number and depending on this number decide if
+// pedestals or event data has to be read.
+//
+// If the end of the file is reached try to open the next in the list. If
+// there is now next file stop the eventloop.
+//
+Bool_t MReadCurrents::Process()
+{
+    //
+    // check if we are done. Try to open the next file in chain.
+    // If it was possible start reading. If not break the event loop
+    //
+    //
+    //   "DC %s %s %02d %02d %02d %03d 577*%05d \n",
+    //   status1, status2, hour, minute, second, ms,
+    //   577 * pixel_DC_readout_in_nAmp
+    //
+    TString str;
+    *fIn >> str;
+    while (!(*fIn))
+    {
+        if (!OpenNextFile())
+            return kFALSE;
+        *fIn >> str;
+    }
+    if (str!=TString("DC"))
+    {
+        *fLog << err << "DC not found in file..." << endl;
+        return kFALSE;
+    }
+
+    *fIn >> str;
+    fCurrents->SetStatus1(str);
+
+    *fIn >> str;
+    fCurrents->SetStatus2(str);
+
+    Int_t h, m, s, ms;
+    *fIn >> h >> m >> s >> ms;
+    fTime->SetTime(h, m, s, ms*1000000);
+
+    for (int i=0; i<577; i++)
+        *fIn >> (*fCurrents)[i];
+
+    return (bool)*fIn;
+}
Index: trunk/MagicSoft/Mars/mfileio/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfileio/Makefile	(revision 2146)
+++ trunk/MagicSoft/Mars/mfileio/Makefile	(revision 2147)
@@ -35,4 +35,5 @@
            MChain.cc \
 	   MReadTree.cc \
+           MReadCurrents.cc \
            MReadMarsFile.cc \
            MReadRflFile.cc \
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 2146)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 2147)
@@ -59,4 +59,6 @@
 #include "MPedestalCam.h"
 
+#include "MCurrents.h"
+
 #include "MImgCleanStd.h"
 
@@ -249,6 +251,15 @@
     // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
     //
-    const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
-    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
+    // *OLD* const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
+    //    if (entry * ratio <= fCleanLvl1 * noise)
+
+    const Float_t  entry = pix.GetNumPhotons();
+    const Float_t  noise = pix.GetErrorPhot();
+    const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(pix.GetPixId()));
+
+    const Float_t r = entry*ratio/noise;
+    //const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
+
+    (*this)[pix.GetPixId()].SetFillColor(GetColor(r, min, max));
 }
 
@@ -259,5 +270,12 @@
     MHexagon &hex = (*this)[pix.GetPixId()];
 
-    const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
+    // *OLD* const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
+    //    if (entry * ratio <= fCleanLvl1 * noise)
+
+    const Float_t  entry = pix.GetNumPhotons();
+    const Float_t  noise = pix.GetErrorPhot();
+    const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(pix.GetPixId()));
+
+    const Float_t r = entry*ratio/noise;
 
     if (r>lvl1)
@@ -618,6 +636,6 @@
     if (fAutoScale)
     {
-        min = event.GetRatioMin();
-        max = event.GetRatioMax();
+        min = event.GetRatioMin(fGeomCam);
+        max = event.GetRatioMax(fGeomCam);
 
         UpdateLegend(min, max);
@@ -637,4 +655,40 @@
 
         SetPixColorRatio(pix, min, max);
+    }
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the currents
+//
+void MCamDisplay::FillCurrents(const MCurrents &event)
+{
+    //
+    // Reset pixel colors to default value
+    //
+    Reset();
+
+    //
+    //  if the autoscale is true, set the values for the range for
+    //  each event
+    //
+    Float_t min = 0;
+    Float_t max = 20;
+    if (fAutoScale)
+    {
+        min = event.GetMin();
+        max = event.GetMax();
+
+        UpdateLegend(min, max);
+    }
+
+    //
+    //   update the colors in the picture
+    //
+    // FIXME: Security check missing!
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        //const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
+        (*this)[i].SetFillColor(GetColor(event[i], min, max));
     }
 }
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 2146)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 2147)
@@ -19,4 +19,5 @@
 class MHexagon;
 class MRflEvtData;
+class MCurrents;
 class MCerPhotEvt;
 class MCerPhotPix;
@@ -80,4 +81,5 @@
     void FillPedestals(const MPedestalCam &event);
     void FillRflEvent(const MRflEvtData &event);
+    void FillCurrents(const MCurrents &event);
     void ShowRflEvent(const MRflEvtData *event=NULL, EMarkerStyle m=kFullDotMedium);
 
