Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6568)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6569)
@@ -35,8 +35,47 @@
 
 
+
  2005/02/17 Thomas Bretz
 
    * mjobs/MJStar.cc:
      - fixed some missing containers in case of MC files
+
+   * callisto.cc:
+     - removed obsolete second check for kModeC
+
+   * mars.rc:
+     - added a lot of option to be able to use a 
+       different signal extractor looking into uncalibrated
+       data
+
+   * manalysis/MCameraData.[h,cc]:
+     - added Print() member function
+
+   * manalysis/MCerPhotAnal2.[h,cc]:
+     - switched off writing into MCerPhotEvt
+
+   * mdata/MDataChain.[h,cc]:
+     - added code to handle priorities of operators correctly
+
+   * mhist/MHEvent.cc:
+     - fixed display for MPedestalRMS
+
+   * mjobs/MJCalib.cc:
+     - fixed treatment of PixelCheck resource
+
+   * mjobs/MJCalibrateSignal.cc:
+     - added some comments about Monte Carlo
+
+   * mjobs/MJPedestal.cc: 
+     - do not allow 'UseData' for Monte Carlos. Reason is given as 
+       comment in the code
+
+   * mmain/MEventDisplay.[h,cc]:
+     - changed such, that mars.cc allows to set the used extractor
+     - removed the obsolete cam.root, ped.root option
+
+   * mmain/MCameraDisplay.cc:
+     - adapted to change in MEventDisplay
+
 
 
Index: trunk/MagicSoft/Mars/callisto.cc
===================================================================
--- trunk/MagicSoft/Mars/callisto.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/callisto.cc	(revision 6569)
@@ -385,38 +385,35 @@
         }
 
-        if (kModeC)
-        {
-            //
-            // Do calibration
-            //
-            MJCalibration job3(Form("MJCalibration #%d", seq.GetSequence()));
-            job3.SetSequence(seq);
-            job3.SetEnv(&env);
-            job3.SetEnvDebug(kDebugEnv);
-            job3.SetDisplay(d);
-            job3.SetOverwrite(kOverwrite);
-            job3.SetPathOut(kOutpathC);
-            job3.SetPathData(kInpathD);
-            job3.SetDataType(kDataType);
-            // job2.SetPathIn(kInpathC); // not yet needed
-
-            job3.SetBadPixels(job2.GetBadPixels());
-            job3.SetExtractor(job2.GetExtractor());
-            job3.SetExtractorCam(job2.GetPedestalCam());
-
-            if (!job3.ProcessFile(job1.GetPedestalCam()))
-            {
-                gLog << err << "Calculation of calibration failed." << endl << endl;
-                return -1;
-            }
-
-            if (kDebugEnv>0)
-                env.PrintUntouched();
-
-            if (!job3.GetDisplay())
-            {
-                gLog << warn << "Display closed by user... execution aborted." << endl << endl;
-                return 1;
-            }
+        //
+        // Do calibration
+        //
+        MJCalibration job3(Form("MJCalibration #%d", seq.GetSequence()));
+        job3.SetSequence(seq);
+        job3.SetEnv(&env);
+        job3.SetEnvDebug(kDebugEnv);
+        job3.SetDisplay(d);
+        job3.SetOverwrite(kOverwrite);
+        job3.SetPathOut(kOutpathC);
+        job3.SetPathData(kInpathD);
+        job3.SetDataType(kDataType);
+        // job2.SetPathIn(kInpathC); // not yet needed
+
+        job3.SetBadPixels(job2.GetBadPixels());
+        job3.SetExtractor(job2.GetExtractor());
+        job3.SetExtractorCam(job2.GetPedestalCam());
+
+        if (!job3.ProcessFile(job1.GetPedestalCam()))
+        {
+            gLog << err << "Calculation of calibration failed." << endl << endl;
+            return -1;
+        }
+
+        if (kDebugEnv>0)
+            env.PrintUntouched();
+
+        if (!job3.GetDisplay())
+        {
+            gLog << warn << "Display closed by user... execution aborted." << endl << endl;
+            return 1;
         }
 
Index: trunk/MagicSoft/Mars/manalysis/MCameraData.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 6569)
@@ -420,2 +420,10 @@
     *fLog << warn << "MCameraData::DrawPixelContent - not available." << endl;
 }
+
+void MCameraData::Print(Option_t *o) const
+{
+    MParContainer::Print(o);
+    *fLog << "Size = " << fData.GetSize() << endl;
+    for (int i=0; i<fData.GetSize(); i++)
+        cout << i << ": " << fData[i] << endl;
+}
Index: trunk/MagicSoft/Mars/manalysis/MCameraData.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 6568)
+++ trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 6569)
@@ -52,4 +52,6 @@
     Double_t operator[](int i) { return fData[i]; }
 
+    void Print(Option_t *o="") const;
+
     Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
     void DrawPixelContent(Int_t num) const;
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.cc	(revision 6569)
@@ -31,5 +31,5 @@
 //
 //  Input Containers:
-//   MRawEvtData, MPedPhotCam
+//   MRawEvtData, MPedestalCam
 //
 //  Output Containers:
@@ -48,6 +48,6 @@
 #include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
 #include "MCerPhotEvt.h"
-#include "MPedPhotPix.h"
-#include "MPedPhotCam.h"
+#include "MPedestalPix.h"
+#include "MPedestalCam.h"
 #include "MRawEvtPixelIter.h"
 
@@ -78,5 +78,5 @@
 //  - MRawRunHeader
 //  - MRawEvtData
-//  - MPedPhotCam
+//  - MPestalCam
 //
 // The following output containers are also searched and created if
@@ -124,5 +124,5 @@
     }
 
-    fPedestals = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
+    fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
     if (runheader && !fPedestals)
         return kFALSE;
@@ -263,5 +263,5 @@
 
         Int_t idx = pixel.GetPixelId();
-        fCerPhotEvt->AddPixel(idx, s, sigs);
+//        fCerPhotEvt->AddPixel(idx, s, sigs);
 
         // Preliminary: Do not overwrite pedestals calculated by
@@ -271,6 +271,6 @@
     }
 
-    fCerPhotEvt->FixSize();
-    fCerPhotEvt->SetReadyToSave();
+//    fCerPhotEvt->FixSize();
+//    fCerPhotEvt->SetReadyToSave();
 
     if (fPedestals)
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.h	(revision 6568)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.h	(revision 6569)
@@ -16,5 +16,5 @@
 
 class MRawEvtData;
-class MPedPhotCam;
+class MPedestalCam;
 class MCerPhotEvt;
 class MRawRunHeader;
@@ -23,5 +23,5 @@
 {
 private:
-    MPedPhotCam   *fPedestals;  // Pedestals of all pixels in the camera
+    MPedestalCam  *fPedestals;  // Pedestals of all pixels in the camera
     MRawEvtData   *fRawEvt;     // raw event data (time slices)
     MCerPhotEvt   *fCerPhotEvt; // Cerenkov Photon Event used for calculation
Index: trunk/MagicSoft/Mars/mars.rc
===================================================================
--- trunk/MagicSoft/Mars/mars.rc	(revision 6568)
+++ trunk/MagicSoft/Mars/mars.rc	(revision 6569)
@@ -20,4 +20,68 @@
 
 # -------------------------------------------------------------------------
+# Define here which signal extractor you are going to use for the
+# whole calibration chain
+# -------------------------------------------------------------------------
+ExtractSignal: MExtractTimeAndChargeDigitalFilter
+# -------------------------------------------------------------------------
+# Define here an extractor which can be used for the December 04 data.
+# -------------------------------------------------------------------------
+#ExtractSignal: MExtractTimeAndChargeSpline, MExtractTimeAndChargeDigitalFilterPeakSearch, MExtractTimeAndChargeSlidingWindow
+# -------------------------------------------------------------------------
+# Define here parameters valid for all extractors above
+# -------------------------------------------------------------------------
+#ExtractSignal.HiGainFirst:         0
+#ExtractSignal.HiGainLast:         15
+#ExtractSignal.LoGainFirst:         3
+#ExtractSignal.LoGainLast:         14
+#ExtractSignal.SaturationLimit:   250
+#ExtractSignal.OffsetLoGain:     1.51
+#ExtractSignal.OffsetLoGain:        0
+#ExtractSignal.LoGainSwitch:      150
+#ExtractSignal.LoGainStartShift: -2.8
+#ExtractSignal.LoGainStartShift: -2.8
+# -------------------------------------------------------------------------
+# Define here parameters valid for the spline:
+# -------------------------------------------------------------------------
+#ExtractSignal.Resolution:        0.05
+#ExtractSignal.RiseTimeHiGain:    0.5
+#ExtractSignal.FallTimeHiGain:    1.5
+#ExtractSignal.LoGainStretch:     1.5
+#ExtractSignal.ExtractionType: Integral <default>
+#ExtractSignal.ExtractionType: Amplitude
+# -------------------------------------------------------------------------
+# Define here parameters valid for the sliding window:
+# -------------------------------------------------------------------------
+#ExtractSignal.HiGainWindowSize:     6
+#ExtractSignal.LoGainWindowSize:     6
+# -------------------------------------------------------------------------
+# Define here parameters valid for the digital filter with peak search:
+# -------------------------------------------------------------------------
+#ExtractSignal.OffsetLeftFromPeak:   3
+#ExtractSignal.OffsetRightFromPeak:  3
+#ExtractSignal.PeakSearchWindowSize: 2
+#ExtractSignal.HiGainFailureLimit:  10
+#ExtractSignal.LoGainFailureLimit:  25
+
+# -------------------------------------------------------------------------
+# In the case of the Digital filter you have to overwrite the default
+# weights file depending on what you are extracting
+# -------------------------------------------------------------------------
+#ExtractSignal.WeightsFile: msignal/cosmics_weights.dat
+
+# -------------------------------------------------------------------------
+# Setup level for determining of bad pixels
+# -------------------------------------------------------------------------
+#MBadPixelsCalc.PedestalLevel:         3.0
+#MBadPixelsCalc.PedestalLevelVariance: 3.0
+#MBadPixelsTreat.NumMinNeighbors:      3
+#MBadPixelsTreat.UseInterpolation:     yes
+#MBadPixelsTreat.ProcessPedestalEvt:   yes
+#MBadPixelsTreat.ProcessPedestalRun:   no
+#MBadPixelsTreat.ProcessTimes:         yes
+#MBadPixelsTreat.UseCentralPixel:      no
+#MBadPixelsTreat.HardTreatment:        no
+
+# -------------------------------------------------------------------------
 # This is how you can setup the Image cleaning used in the Camera Display
 # -------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mdata/MDataChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 6569)
@@ -52,18 +52,18 @@
 // ---------
 //
-// The allowed operations are: +, -, *, /, %, ^
+// The allowed operations are: +, -, *, /, %, ^ and ** for ^
 //
 // While a%b returns the floating point reminder of a/b.
 // While a^b returns a to the power of b
 //
-// Warning: There is no priority rule build in. So better use parantheses
-//   to get correct results. The rule is parsed/evaluated from the left
-//   to the right, which means:
-//
-//   "MHillas.fWidth + MHillas.fLength / HillasSource.fDist"
-//
-//    is parses as
-//
-//   "(MHillas.fWidth + MHillas.fLength) / HillasSource.fDist"
+// Priority
+// --------
+//
+//  The priority of the operators is build in as:
+//    ^ (highest),  %, *, /, +, -
+//
+//  Priorities are evaluated before parsing the rule by inserting
+//  artificial paranthesis. If you find ANY problem with this please
+//  report it immediatly! It is highly recommended to check the result!
 //
 // You can also use mathmatical operators, eg:
@@ -168,4 +168,5 @@
 #include <stdlib.h>       // strtod, ...
 
+#include <TRegexp.h>
 #include <TRandom.h>
 #include <TMethodCall.h>
@@ -371,6 +372,14 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Remove all whitespaces
+// Replace all kind of double +/- by a single + or -
+//
 void MDataChain::SimplifyString(TString &txt) const
 {
+    txt.ReplaceAll(" ",  "");
+    txt.ReplaceAll("**", "^");
+
     while (txt.First("--")>=0 || txt.First("++")>=0 ||
            txt.First("+-")>=0 || txt.First("-+")>=0)
@@ -385,4 +394,72 @@
 // --------------------------------------------------------------------------
 //
+// Add Parenthesis depending on the priority of the operators. The
+// priorities are defined by the default of the second argument.
+//
+void MDataChain::AddParenthesis(TString &test, const TString op) const
+{
+    const TString low = op(1, op.Length());
+    if (low.Length()==0)
+        return;
+
+    //cout << "--- " << Form("[%c]", op[0]) << " ---" << endl;
+
+    int offset = 0;
+    while (1)
+    {
+        const TString check = test(offset, test.Length());
+        if (check.IsNull())
+            break;
+
+        const Ssiz_t pos = check.First(op[0]);
+        if (pos<0)
+            break;
+
+        int cnt=0;
+
+        int i;
+        for (i=pos-1; i>=0; i--)
+        {
+            if (check[i]==')')
+                cnt++;
+            if (check[i]=='(')
+                cnt--;
+            if (cnt>0 || low.First(check[i])<0)
+                continue;
+            break;
+        }
+
+        cnt=0;
+        int j;
+        for (j=pos; j<check.Length(); j++)
+        {
+            if (check[j]=='(')
+                cnt++;
+            if (check[j]==')')
+                cnt--;
+            if (cnt>0 || low.First(check[j])<0)
+                continue;
+            break;
+        }
+
+        const TString sub = test(offset+i+1, j-i-1);
+
+        // Check if it contains operators,
+        // otherwise we can simply skip it
+        static const TRegexp regexp("[%/*^+-]");
+        if (sub.Index(regexp)>0)
+        {
+            test.Insert(offset+j,   ")");
+            test.Insert(offset+i+1, "(");
+            offset += 2;
+        }
+        offset += j+1;
+    }
+
+    AddParenthesis(test, low);
+}
+
+// --------------------------------------------------------------------------
+//
 // Core of the data chain. Here the chain is constructed out of the rule.
 //
@@ -390,5 +467,8 @@
 {
     if (level==0)
+    {
         SimplifyString(txt);
+        AddParenthesis(txt);
+    }
 
     MData *member0=NULL;
@@ -828,2 +908,18 @@
     return kTRUE;
 }
+/*
+void MDataChain::ReconstructElements()
+{
+    if (!fMember)
+        return;
+
+    if (fMember->InheritsFrom(MDataElement::Class()))
+    {
+        MData *data = ((MDataElement*)fMember)->CloneColumn();
+        delete fMember;
+        fMember = data;
+    }
+
+    fMember->ReconstructElements();
+}
+*/
Index: trunk/MagicSoft/Mars/mdata/MDataChain.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 6568)
+++ trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 6569)
@@ -45,4 +45,5 @@
 
     void   SimplifyString(TString &txt) const;
+    void   AddParenthesis(TString &test, const TString op="^%*/+-") const;
     MData *ParseString(TString txt, Int_t level);
     MData *ParseDataMember(TString txt);
@@ -62,4 +63,5 @@
     TString GetRule() const;
     TString GetDataMember() const;
+    //void    ReconstructElements() { if (fMember) fMember->ReconstructElements(); }
 
     // MParContainer
Index: trunk/MagicSoft/Mars/mhist/MHEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 6569)
@@ -215,5 +215,5 @@
         break;
     case kEvtPedestalRMS:
-        fHist->SetCamContent(*event, 1);
+        fHist->SetCamContent(*event, 2);
         break;
     case kEvtPedPhot:
Index: trunk/MagicSoft/Mars/mjobs/MJCalib.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalib.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mjobs/MJCalib.cc	(revision 6569)
@@ -37,4 +37,5 @@
 
 const Int_t MJCalib::fgCheckedPixId = 100;
+
 // --------------------------------------------------------------------------
 //
@@ -54,10 +55,9 @@
 Bool_t MJCalib::CheckEnvLocal()
 {
-
     if (HasEnv("PixelCheck"))
-      SetPixelCheck();
+        SetPixelCheck(GetEnv("PixelCheck", fPixelCheck));
 
     if (HasEnv("CheckedPixId"))
-      SetCheckedPixId(GetEnv("CheckedPixId",fCheckedPixId));
+        SetCheckedPixId(GetEnv("CheckedPixId",fCheckedPixId));
 
     if (!HasEnv("DataType"))
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 6569)
@@ -464,5 +464,4 @@
     taskenv3.SetDefault(extractor3);
 
-    MCalibrateData         calib;
     // 
     // This is new calibration to eff. photo-electrons, hard-coded as decided 
@@ -470,6 +469,7 @@
     //
 #warning Default calibration now in equiv. photo-electrons!
+    MCalibrateData calib;
     calib.SetSignalType(MCalibrateData::kPhe);
-
+    //----- WORKAROUND: Currently MC has no lo-gain switch ------
     if (IsUseMC()) // MC file
     {
@@ -488,4 +488,5 @@
         calib.SetPedestalFlag(MCalibrateData::kEvent);
     }
+    //----------------------------------------------------------
 
     MExtractPINDiode        pinext;
@@ -621,4 +622,5 @@
     tlist2.AddToList(&apply);
     tlist2.AddToList(&merge);
+    //----- WORKAROUND: Currently MC has no lo-gain switch ------
     if (IsUseMC())
         tlist2.AddToList(&pcopy);
@@ -629,6 +631,7 @@
         tlist2.AddToList(&pedlo3);
     }
+    //-----------------------------------------------------------
     if (fIsInterlaced)
-      {
+    {
 	pinext.SetFilter(&fcalib);
 	bldext.SetFilter(&fcalib);
@@ -655,5 +658,5 @@
 	if (fIsRelTimesUpdate)
 	  tlist2.AddToList(&recalc);
-      }
+    }
 
     tlist2.AddToList(&conttp);
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 6569)
@@ -791,5 +791,19 @@
     
     if (HasEnv("UseData"))
-      fExtractType = GetEnv("UseData",kFALSE) ? kUseData : kUsePedRun;
+        fExtractType = GetEnv("UseData",kFALSE) ? kUseData : kUsePedRun;
+
+    if (IsUseMC() && fExtractType==kUseData)
+    {
+        // The reason is, that the standard data files contains empty
+        // (untriggered) events. If we would loop over the default 500
+        // first events of the data file you would calculate the
+        // pedestal from only some single events...
+        *fLog << inf;
+        *fLog << "Sorry, you cannot extract the starting pedestal from the first" << endl;
+        *fLog << "events in your data files... using pedestal file instead.  The" << endl;
+        *fLog << "result should not differ..." << endl;
+        fExtractType = kUsePedRun;
+    }
+
 
     if (HasEnv("UseHists"))
@@ -1002,5 +1016,5 @@
     
     if (fIsUseHists)
-      {
+    {
         pedcalc.SetIntermediateStorage();
         pedlogain.SetIntermediateStorage();
@@ -1009,8 +1023,9 @@
         //        plist.AddToList(&fPedestalHist);
         tlist.AddToList(&fillped);
-      }
+    }
 
     pedcalc.SetPedestalsIn(&fPedestalCamIn);
     pedlogain.SetPedestalsIn(&fPedestalCamIn);
+
     pedcalc.SetPedestalsInter(&pedinter);
     pedlogain.SetPedestalsInter(&pedinter);
@@ -1135,7 +1150,4 @@
         DisplayResult(plist);
 
-    if (fExtractionType!=kFundamental)
-      fExtractor->SetFilter(0);
-
     if (!WriteResult())
         return kFALSE;
Index: trunk/MagicSoft/Mars/mmain/MCameraDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MCameraDisplay.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mmain/MCameraDisplay.cc	(revision 6569)
@@ -90,5 +90,5 @@
         {
         case kButDisplay:
-            new MEventDisplay(fInputFile, "ped.root", "cal.root");
+            new MEventDisplay(fInputFile);
             return kTRUE;
         }
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 6568)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 6569)
@@ -70,10 +70,13 @@
 #include "MMcPedestalNSBAdd.h"    // MMcPedestalNSBAdd
 
-#include "MCerPhotAnal2.h"        // MCerPhotAnal2
+#include "MCerPhotAnal2.h"        // MPedestalCalc
+#include "MTaskEnv.h"             // MTaskEnv
+#include "MExtractTimeAndChargeDigitalFilter.h"
 #include "MImgCleanStd.h"         // MImgCleanStd
 #include "MHillasCalc.h"          // MHillasCalc
-//#include "MHillasSrcCalc.h"       // MHillasSrcCalc
-//#include "MBlindPixelCalc.h"      // MBlindPixelCalc
-#include "MArrivalTimeCalc.h"     // MArrivalTimeCalc
+#include "MCalibrationRelTimeCalc.h" // MHillasSrcCalc
+#include "MPrint.h"               // 
+#include "MBadPixelsCalc.h"       // MBadPixelsCalc
+#include "MBadPixelsTreat.h"      // MBadPixelsTreat
 #include "MFillH.h"               // MFillH
 #include "MExtractSignal.h"       // MExtractsignal
@@ -107,10 +110,10 @@
 //  Constructor.
 //
-MEventDisplay::MEventDisplay(const char *fname, const char *pname, const char *cname) : MStatusDisplay(), fEvtLoop(0)
+MEventDisplay::MEventDisplay(const char *fname) : MStatusDisplay(), fEvtLoop(0)
 {
     //
     // Setup Task list for hillas calculation
     //
-    SetupTaskList("Events", fname, pname, cname);
+    SetupTaskList("Events", fname);
 
     //
@@ -170,9 +173,8 @@
 //  preprocess tasks and read in first event (process)
 //
-void MEventDisplay::SetupTaskList(const char *tname, const char *fname,
-                                  const char *pname, const char *cname)
-{
-    MCalibrationChargeCam *ccam=0;
-    MPedPhotCam           *pcam=0;
+void MEventDisplay::SetupTaskList(const char *tname, const char *fname)
+{
+//    MCalibrationChargeCam *ccam=0;
+//    MPedPhotCam           *pcam=0;
 
     MBadPixelsCam *badpix = new MBadPixelsCam;
@@ -187,46 +189,4 @@
     }
 
-    if (type==2)
-    {
-        TFile file(pname, "READ");
-        if (!file.IsZombie())
-            pcam = new MPedPhotCam;
-        if (pcam)
-        {
-            if (pcam->Read()<=0)
-            {
-                delete pcam;
-                pcam = NULL;
-            }
-
-            if (file.FindKey("MBadPixelsCam"))
-            {
-                MBadPixelsCam bad;
-                if (bad.Read()>0)
-                    badpix->Merge(bad);
-            }
-        }
-        file.Close();
-        file.Open(cname, "READ");
-        if (!file.IsZombie())
-            ccam = new MCalibrationChargeCam;
-        if (ccam)
-        {
-            if (ccam->Read()<=0)
-            {
-                delete ccam;
-                ccam = NULL;
-            }
-
-            if (file.FindKey("MBadPixelsCam"))
-            {
-                MBadPixelsCam bad;
-                if (bad.Read()>0)
-                    badpix->Merge(bad);
-            }
-        }
-        file.Close();
-    }
-
     //
     // Setup an empty job, with a reader task only.
@@ -248,8 +208,4 @@
     plist->AddToList(tlist);
     plist->AddToList(badpix);
-    if (pcam)
-        plist->AddToList(pcam);
-    if (ccam)
-        plist->AddToList(ccam);
 
     //MArrivalTime *atime = new MArrivalTime;
@@ -290,13 +246,19 @@
     plist->AddToList(evt10);
 
+    MExtractTimeAndChargeDigitalFilter *digf = new MExtractTimeAndChargeDigitalFilter;
+    digf->ReadWeightsFile("msignal/MC_weights.dat");
+
+    MTaskEnv *taskenv1=new MTaskEnv("ExtractSignal");
+    taskenv1->SetDefault(digf);
+    taskenv1->SetOwner();
+
     MCerPhotAnal2      *nanal  = new MCerPhotAnal2;
     MFillH             *fill01 = new MFillH(evt01, "MCerPhotEvt", "MFillH01");
     MImgCleanStd       *clean  = new MImgCleanStd;
     MFillH             *fill02 = new MFillH(evt02, "MCerPhotEvt", "MFillH02");
-    MFillH             *fill03 = new MFillH(evt03, type==1?"MPedPhotFundamental":"MPedPhotCam", "MFillH03");
-    MFillH             *fill04 = new MFillH(evt04, type==1?"MPedPhotFromExtractorRndm":"MPedPhotCam", "MFillH04");
+    MFillH             *fill03 = new MFillH(evt03, type==1?"MPedPhotFundamental":"MPedestalCam",       "MFillH03");
+    MFillH             *fill04 = new MFillH(evt04, type==1?"MPedPhotFromExtractorRndm":"MPedestalCam", "MFillH04");
     MFillH             *fill06a= new MFillH(evt06a, "MCameraData", "MFillH06a");
     MFillH             *fill06b= new MFillH(evt06b, "MCameraData", "MFillH06b");
-    //MBlindPixelCalc   *blind = new MBlindPixelCalc;
     MHillasCalc        *hcalc  = new MHillasCalc;
     MMcTriggerLvl2Calc *trcal  = new MMcTriggerLvl2Calc;
@@ -304,58 +266,48 @@
     MFillH             *fill10 = new MFillH(evt10, "MCerPhotEvt",    "MFillH10");
 
+    MBadPixelsCalc     *bcalc  = new MBadPixelsCalc;
+    MBadPixelsTreat    *btreat = new MBadPixelsTreat;
+    btreat->SetProcessTimes(kFALSE);
     if (type==1)
+    {
+        bcalc->SetNamePedPhotCam("MPedPhotFromExtractor");
+        btreat->AddNamePedPhotCam("MPedPhotFromExtractorRndm");
         clean->SetNamePedPhotCam("MPedPhotFromExtractorRndm");
+    }
 
     // If no pedestal or no calibration file is availble
     if (type==2)
     {
-        if (!pcam || !ccam)
-        {
-            MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
-            MFilter *f2=new MFDataMember("MRawRunHeader.fRunType", '<', 255.5);
-            f1->SetName("MFMonteCarlo");
-            f2->SetName("MFRealData");
-
-            MMcPedestalCopy   *pcopy = new MMcPedestalCopy;
-            MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
-
-            MExtractSignal* extra = new MExtractSignal();
-            extra->SetRange(0, 14, 0, 14);
-            extra->SetSaturationLimit(240);
-
-            MMcCalibrationUpdate* mcupd = new MMcCalibrationUpdate;
-            mcupd->SetOuterPixelsGainScaling(kFALSE);
-
-            MCalibrateData* mccal = new MCalibrateData;
-            mccal->SetCalibrationMode(MCalibrateData::kFfactor);
-
-            // MC
-            extra->SetFilter(f1);
-            mcupd->SetFilter(f1);
-            mccal->SetFilter(f1);
-            trcal->SetFilter(f1);
-            //fill09->SetFilter(f1);
-
-            // Data
-            nanal->SetFilter(f2);
-
-            // TaskList
-            tlist->AddToList(f1);
-            tlist->AddToList(f2);
-            tlist->AddToList(pcopy);
-            tlist->AddToList(pdnsb);
-
-            tlist->AddToList(extra);
-            tlist->AddToList(mcupd);
-            tlist->AddToList(mccal);
-
-
-            tlist->AddToList(nanal);
-        }
-        else
-        {
-            MCalibrateData* calib = new MCalibrateData;
-            tlist->AddToList(calib);
-        }
+        MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
+        f1->SetName("MFMonteCarlo");
+
+        MMcPedestalCopy   *pcopy = new MMcPedestalCopy;
+        MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
+
+        MMcCalibrationUpdate* mcupd = new MMcCalibrationUpdate;
+        mcupd->SetOuterPixelsGainScaling(kFALSE);
+
+        MCalibrateData* calib = new MCalibrateData;
+        calib->SetCalibrationMode(MCalibrateData::kFlatCharge);
+        calib->SetPedestalFlag(MCalibrateData::kEvent);
+
+        //MCalibrationRelTimeCalc *tcalc = new MCalibrationRelTimeCalc;
+
+        // MC
+        mcupd->SetFilter(f1);
+        trcal->SetFilter(f1);
+
+        // TaskList
+        tlist->AddToList(f1);
+        tlist->AddToList(pcopy);
+        tlist->AddToList(pdnsb);
+
+        tlist->AddToList(nanal);    // Calculated MPedPhotCam
+        tlist->AddToList(taskenv1); // Calculates MExtractedSignalCam, MArrivalTimeCam
+        tlist->AddToList(mcupd);
+        tlist->AddToList(calib);    // MExtractedSignalCam --> MCerPhotEvt
+
+        tlist->AddToList(bcalc);    // Produce MBadPixelsCam
+        tlist->AddToList(btreat);   // Treat MBadPixelsCam
     }
 
@@ -367,13 +319,9 @@
     tlist->AddToList(fill06a);
     tlist->AddToList(fill06b);
-    //tlist->AddToList(blind);
     tlist->AddToList(fill10);
-    tlist->AddToList(hcalc);
-    if ((!pcam || !ccam) && type==2)
-    {
-        MArrivalTimeCalc  *tcalc = new MArrivalTimeCalc;
-        MFillH            *fill07 = new MFillH(evt07, "MRawEvtData",     "MFillH7");
-        MFillH            *fill08 = new MFillH(evt08, "MArrivalTimeCam", "MFillH8");
-        tlist->AddToList(tcalc);
+    if (type==2)
+    {
+        MFillH *fill07 = new MFillH(evt07, "MRawEvtData",     "MFillH7");
+        MFillH *fill08 = new MFillH(evt08, "MArrivalTimeCam", "MFillH8");
         tlist->AddToList(fill07);
         tlist->AddToList(fill08);
@@ -387,4 +335,5 @@
         tlist->AddToList(fill08);
     }
+    tlist->AddToList(hcalc);
 
     //
@@ -570,5 +519,6 @@
         }
 
-        if (!tlist->Process())
+        const Int_t rc = tlist->Process();
+        if (rc==kFALSE || rc==kERROR)
             return;
 
@@ -609,5 +559,6 @@
 void MEventDisplay::ReadFirstEvent()
 {
-    if (!fEvtLoop->PreProcess())
+    const Int_t rc = fEvtLoop->PreProcess();
+    if (rc==kFALSE || rc==kERROR)
         return;
 
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.h	(revision 6568)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.h	(revision 6569)
@@ -38,6 +38,5 @@
 
     void UpdateDisplay();
-    void SetupTaskList(const char *tname, const char *fname,
-                       const char *pname=0, const char *cname=0);
+    void SetupTaskList(const char *tname, const char *fname);
 
     void ReadFirstEvent();
@@ -49,5 +48,5 @@
 
 public:
-    MEventDisplay(const char *fname, const char *pname=0, const char *cname=0);
+    MEventDisplay(const char *fname);
     ~MEventDisplay();
 
