Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8359)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8360)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -53,5 +53,4 @@
 #include "MGeomCam.h"
 #include "MHCamEvent.h"
-//#include "MHCamEventTH.h"
 #include "MPedestalCam.h"
 #include "MBadPixelsCam.h"
@@ -91,4 +90,5 @@
 #include "MTriggerPatternDecode.h"
 #include "MFTriggerPattern.h"
+#include "MFilterList.h"
 #include "MGeomApply.h"
 #include "MPedestalSubtract.h"
@@ -96,4 +96,5 @@
 #include "MPointingPosCalc.h"
 #include "MPedCalcFromLoGain.h"
+#include "MPedestalSubtract.h"
 #include "MExtractor.h"
 #include "MExtractTimeAndCharge.h"
@@ -261,5 +262,5 @@
     MHCalibrationRelTimeCam     hrelcam;
     //MHCalibrationHiLoCam        hilocam;
-    MHCalibrationPulseTimeCam   hpulcam;
+    //MHCalibrationPulseTimeCam   hpulcam;
 
     hchacam.SetOscillations(kFALSE);
@@ -455,60 +456,56 @@
     pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
 
-    if (extractor1)
-    {
-        extractor1->SetPedestals(&pedcamab);
-
-        // Setup to use the hi-gain extraction window in the lo-gain
-        // range (the start of the lo-gain range is added automatically
-        // by MPedCalcFromLoGain)
-        //
-        // The window size of the extractor is not yet initialized,
-        // so we have to stick to the extraction range
-        //
-        // Even if we would like to use a range comparable to the
-        // hi-gain extraction we use the lo-gain range to make
-        // sure that exclusions (eg. due to switching noise)
-        // are correctly handled.
-        //
-        const Int_t f = extractor1->GetLoGainFirst();
-        const Int_t l = extractor1->GetLoGainLast();
-        const Int_t w = (l-f+1);
-        //const Int_t f = extractor1->GetHiGainFirst();
-        //const Int_t l = extractor1->GetHiGainLast();
-        //const Int_t w = (l-f+1)&~1;
-
-        pedlo1.SetExtractWindow(f, w);
-
-        if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
-        {
-            pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
-            pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
-            /*
-            const Int_t win = ((MExtractTimeAndCharge*)extractor1)->GetWindowSizeHiGain();
-            pedlo1.SetExtractWindow(15, win);
-            pedlo2.SetExtractWindow(15, win//obsolete//);
-            pedlo3.SetExtractWindow(15, win//obsolete//);
-            */
-        }
-        else
-        {
-            /*
-            // FIXME: How to get the fixed value 15 automatically?
-            const Int_t f = (Int_t)(15.5+extractor1->GetHiGainFirst());
-            const Int_t n = (Int_t)(15.5+extractor1->GetNumHiGainSamples());
-            pedlo1.SetExtractWindow(f, n);
-            pedlo2.SetExtractWindow(f, n);
-            pedlo3.SetExtractWindow(f, n);
-            */
-            pedlo2.SetExtractWindow(f, w);
-            pedlo3.SetExtractWindow(f, w);
-
-        }
-    }
+    if (!extractor1)
+    {
+        *fLog << err << "ERROR - extractor1 == NULL" << endl;
+        return kFALSE;
+    }
+
+    extractor1->SetPedestals(&pedcamab);
+
+    // Setup to use the hi-gain extraction window in the lo-gain
+    // range (the start of the lo-gain range is added automatically
+    // by MPedCalcFromLoGain)
+    //
+    // The window size of the extractor is not yet initialized,
+    // so we have to stick to the extraction range
+    //
+    // Even if we would like to use a range comparable to the
+    // hi-gain extraction we use the lo-gain range to make
+    // sure that exclusions (eg. due to switching noise)
+    // are correctly handled.
+    //
+    pedlo1.SetRangeFromExtractor(*extractor1);
+
+    if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
+    {
+        pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
+        pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
+    }
+    else
+    {
+        pedlo2.SetRangeFromExtractor(*extractor1);
+        pedlo3.SetRangeFromExtractor(*extractor1);
+    }
+
     if (extractor2)
-      extractor2->SetPedestals(&pedcamab);
+        extractor2->SetPedestals(&pedcamab);
 
     if (extractor3)
-      extractor3->SetPedestals(&pedcamab);
+        extractor3->SetPedestals(&pedcamab);
+
+    //------------------------------
+    MFTriggerPattern ftp2;
+    ftp2.SetDefault(kTRUE);
+    ftp2.DenyCalibration();
+    if (!extractor1->HasLoGain())
+        ftp2.RequirePedestal();
+
+    pedlo1.SetFilter(&ftp2);
+    pedlo2.SetFilter(&ftp2);
+    pedlo3.SetFilter(&ftp2);
+
+    MContinue contftp2(&ftp2, "ContPedestal");
+    //------------------------------
 
     MFCosmics fcosmics;
@@ -525,5 +522,16 @@
     taskenv3.SetDefault(extractor3);
 
-    // 
+    MFilterList flistftp2("PedestalFilter");
+    flistftp2.SetInverted();
+    flistftp2.AddToList(&ftp2);
+
+    if (!extractor1->HasLoGain())
+    {
+        taskenv1.SetFilter(&flistftp2);
+        taskenv2.SetFilter(&flistftp2);
+        taskenv3.SetFilter(&flistftp2);
+    }
+
+    //
     // This is new calibration to photo-electrons, hard-coded
     // as decided at the Wuerzburg software meeting 26.01.05
@@ -531,5 +539,5 @@
     MCalibrateData calib;
     calib.SetSignalType(MCalibrateData::kPhe);
-    calib.AddPedestal("Fundamental");
+    //calib.AddPedestal("Fundamental");
     calib.AddPedestal("FromExtractor");
     calib.AddPedestal("FromExtractorRndm");
@@ -567,5 +575,5 @@
     MFillH filtme(&hrelcam, "MArrivalTimeCam",            "FillRelTime");
     //MFillH filhil(&hilocam, "MExtractedSignalCam",        "FillHiLoRatio");
-    MFillH filpul(&hpulcam, "MRawEvtData",                "FillPulseTime");
+    //MFillH filpul(&hpulcam, "MRawEvtData",                "FillPulseTime");
     filpin.SetBit(MFillH::kDoNotDisplay);
     filbnd.SetBit(MFillH::kDoNotDisplay);
@@ -573,5 +581,5 @@
     filtme.SetBit(MFillH::kDoNotDisplay);
     //filhil.SetBit(MFillH::kDoNotDisplay);
-    filpul.SetBit(MFillH::kDoNotDisplay);
+    //filpul.SetBit(MFillH::kDoNotDisplay);
 
     MCalibrateRelTimes caltm;
@@ -579,6 +587,8 @@
     MBadPixelsTreat    treat;
 
-    bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
-    treat.AddNamePedPhotCam("MPedPhotFundamental");
+    //bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
+    bpcal.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
+
+    //treat.AddNamePedPhotCam("MPedPhotFundamental");
     treat.AddNamePedPhotCam("MPedPhotFromExtractor");
     treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
@@ -677,7 +687,9 @@
     tlist2.AddToList(&merge);
     tlist2.AddToList(&pedsub);
+    tlist2.AddToList(&ftp2);
     tlist2.AddToList(&pedlo1);
     tlist2.AddToList(&pedlo2);
     tlist2.AddToList(&pedlo3);
+
     //-----------------------------------------------------------
 
@@ -709,11 +721,13 @@
 
     // Continue for all non-cosmic events
-    tlist2.AddToList(&conttp);
+    tlist2.AddToList(&fill0);        // fill pedestal events
+    tlist2.AddToList(&fill1);        // fill pedestal events
+    if (!extractor1->HasLoGain())
+        tlist2.AddToList(&contftp2); // remove pedestal events from processing
+    tlist2.AddToList(&conttp);       // remove calib events from processing
     if (extractor1)
       tlist2.AddToList(&taskenv1);
     if (extractor2)
       tlist2.AddToList(&taskenv2);
-    tlist2.AddToList(&fill0);
-    tlist2.AddToList(&fill1);
     tlist2.AddToList(&contcos);
     /*
@@ -723,5 +737,5 @@
         tlist2.AddToList(&filhil);
         }
-        */
+
     if (fIsPulsePosCheck)
     {
@@ -729,5 +743,5 @@
         tlist2.AddToList(&filpul);
     }
-
+    */
     tlist2.AddToList(&fill2);
     tlist2.AddToList(&calib);
@@ -745,7 +759,9 @@
     //    tlist2.AddToList(&fill7);
     tlist2.AddToList(&fill9);
-    tlist2.AddToList(&fillR);
-    tlist2.AddToList(&fillO);
-
+    if (extractor1->HasLoGain())
+    {
+        tlist2.AddToList(&fillR);
+        tlist2.AddToList(&fillO);
+    }
     tlist2.AddToList(&fillflorian);
 
@@ -800,4 +816,5 @@
     DisplayResult(plist);
 
+    /*
     if (fIsPixelCheck)
       {
@@ -808,5 +825,5 @@
 	//    hilocam[fCheckedPixId].DrawClone("");
       }
-
+    */
     interlacedcont.Add(&pulcam);
 
@@ -814,6 +831,6 @@
     //  interlacedcont.Add(&hilcam);
 
-    if (fIsPulsePosCheck)
-        interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
+    //if (fIsPulsePosCheck)
+    //    interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
 
     //if (fIsHiLoCalibration)
