Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8893)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8894)
@@ -18,4 +18,31 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2008/05/20 Thomas Bretz
+
+   * mjobs/MJCalibrateSignal.cc:
+     - added a MH3-histogram to be filled. It contains the
+       rate of the trigger pattern per run.
+     - the filter selecting the calibration or pedestal
+       events has been renamed from ftp to fcalped
+     - the MContinue rejecting these events has been renamed
+       from conttp to contcalped
+     - the filter selecting the pedestal events have been 
+       renamed from ftp2 to fped
+     - In the case of MUX data (no lo-gain) this filter
+       is now also rejecting lvl1 and lvl2 triggered events
+     - the ftp2-filter for the pedestal extraction tasks and
+       the corresponding histogram fillers is obsolete
+     - the previouls "PedestalFilter" is obsolete.  
+     - it doesn't make sense not to extract the signal (filter
+       of teskenv1, taskenv2 and taskenv3) but process the 
+       rest of the tasklist
+     - the pedestal extraction (as the calibration was already)
+       has been moved to its own tasklist with the corresponding
+       filter applied.
+     - tlist3 has been renamed to tlist4
+     - contped has been removed from the tasklist
+
+
 
  2008/05/19 Thomas Bretz
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8893)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8894)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -59,4 +59,5 @@
 
 // General histograms
+#include "MH3.h"
 #include "MHCamEvent.h"
 #include "MHVsTime.h"
@@ -227,4 +228,5 @@
 }
 
+#include "MParameterCalc.h" // FIXME
 Bool_t MJCalibrateSignal::Process(MPedestalCam &pedcamab, MPedestalCam &pedcambias,
                                   MPedestalCam &pedcamextr)
@@ -401,19 +403,43 @@
     MTriggerPatternDecode     decode;
 
+    MH3 hpat("MRawRunHeader.fRunNumber", "MTriggerPattern.GetUnprescaled");
+    hpat.SetWeight("1./MRawRunHeader.GetRunLength");
+    hpat.SetName("TrigPat");
+    hpat.SetTitle("Rate of the trigger pattern [Hz];Run Number;Trigger Pattern;Rate [Hz]");
+    hpat.InitLabels(MH3::kLabelsXY);
+    //hpat.DefineLabelsY("1=Lvl1;2=Cal;3=Cal;4=Lvl2;5=Cal;7=Cal;8=Ped;9=Ped+Trig;13=Ped+Trig;16=Pin;32=Sum");
+    hpat.DefaultLabelY("UNKNOWN");
+    hpat.DefineLabelY( 0, "0");        // 0: No pattern
+    hpat.DefineLabelY( 1, "Trig");     // Lvl1
+    hpat.DefineLabelY( 2, "Cal");      // Cal
+    hpat.DefineLabelY( 3, "Cal");      // Cal+Lvl1
+    hpat.DefineLabelY( 4, "Trig");     // Lvl2
+    hpat.DefineLabelY( 5, "Trig");     // Lvl1+Lvl2
+    hpat.DefineLabelY( 7, "Cal");      // Cal+Lvl1+Lvl2
+    hpat.DefineLabelY( 8, "Ped");      // Ped
+    hpat.DefineLabelY( 9, "Ped+Trig"); // Ped+Lvl1
+    hpat.DefineLabelY(13, "Ped+Trig"); // Ped+Lvl2
+    hpat.DefineLabelY(16, "Pin");
+    hpat.DefineLabelY(32, "Sum");      // Sum
+    hpat.DefineLabelY(33, "Sum");      // Sum+Lvl1
+    hpat.DefineLabelY(37, "Sum");      // Sum+Lvl1+Lvl2
+
+    MFillH fillpat(&hpat, "", "FillPattern");
+    fillpat.SetDrawOption("box");
+
     // This will make that for data with version less than 5, where
     // trigger patterns were not yet correct, all the events in the real
     // data file will be processed. In any case there are no interleaved
     // calibration events in such data, so this is fine.
-    MFTriggerPattern ftp;
-    ftp.SetDefault(kTRUE);
+    MFTriggerPattern fcalped;
+    fcalped.SetInverted();
+    fcalped.SetDefault(kTRUE);
     //    ftp.RequireCalibration();
-    ftp.DenyCalibration();
-    ftp.DenyPedestal();
+    fcalped.DenyCalibration();
+    fcalped.DenyPedestal();
     //    ftp.DenyPinDiode();
-    ftp.SetInverted();
-
-    // This will skip interleaved calibration events and pedestal events (if any)
-    // --> tlist2
-    MContinue conttp(&ftp, "ContTrigPattern");
+
+    // This will skip interleaved events with a cal- or ped-trigger
+    MContinue contcalped(&fcalped, "ContTrigPattern");
 
     // Create the pedestal subtracted raw-data
@@ -468,15 +494,14 @@
 
     //------------------------------
-    MFTriggerPattern ftp2;
-    ftp2.SetDefault(kTRUE);
-    ftp2.DenyCalibration();
+    MFTriggerPattern fped;
+    fped.SetDefault(kTRUE);
+    fped.DenyCalibration();
     if (!extractor1->HasLoGain())
-        ftp2.RequirePedestal();
-
-    pedlo1.SetFilter(&ftp2);
-    pedlo2.SetFilter(&ftp2);
-    pedlo3.SetFilter(&ftp2);
-
-    MContinue contftp2(&ftp2, "ContPedestal");
+    {
+        fped.RequirePedestal();
+        fped.DenyTriggerLvl1();
+        fped.DenyTriggerLvl2();
+    }
+
     //------------------------------
 
@@ -493,15 +518,4 @@
     taskenv2.SetDefault(extractor2);
     taskenv3.SetDefault(extractor3);
-
-    MFilterList flistftp2("PedestalFilter");
-    flistftp2.SetInverted();
-    flistftp2.AddToList(&ftp2);
-
-    if (!extractor1->HasLoGain())
-    {
-        taskenv1.SetFilter(&flistftp2);
-        taskenv2.SetFilter(&flistftp2);
-        taskenv3.SetFilter(&flistftp2);
-    }
 
     //
@@ -523,4 +537,5 @@
     fcalib.SetDefault(kFALSE);
     fcalib.RequireCalibration();
+    //fcalib.DenyPedestal(); // This should never happen!
 
     MCalibrationChargeCalc  chcalc;
@@ -617,10 +632,4 @@
      fillP.SetNameTab("Pulse");
      */
-
-    if (!extractor1->HasLoGain())
-    {
-        fill0.SetFilter(&ftp2);
-        fill1.SetFilter(&ftp2);
-    }
 
     /*
@@ -693,23 +702,36 @@
     */
 
-    // Now setup tasklist for events
+    //-----------------------------------------------------------
+    // Build tasklist
+
     MTaskList tlist2;
 
     tlist2.AddToList(&caldec);
     tlist2.AddToList(&decode);
+    tlist2.AddToList(&fillpat);
     tlist2.AddToList(&apply);
     //tlist2.AddToList(&merge);
     tlist2.AddToList(&pedsub);
-    tlist2.AddToList(&ftp2);
-    tlist2.AddToList(&pedlo1);
-    tlist2.AddToList(&pedlo2);
-    tlist2.AddToList(&pedlo3);
-    tlist2.AddToList(&fill0);        // fill pedestal events
-    tlist2.AddToList(&fill1);        // fill pedestal events
 
     //-----------------------------------------------------------
+    // Pedestal extraction
 
     MTaskList tlist3;
-    tlist3.SetFilter(&fcalib);
+    tlist3.SetFilter(&fped);         // Deny events with cal-trigger
+
+    tlist2.AddToList(&fped);         // If no lo-gain require ped-trigger
+    tlist2.AddToList(&tlist3);       //  and deny cosmics (lvl1/2) trigger
+
+    tlist3.AddToList(&pedlo1);       // extract pedestal events
+    tlist3.AddToList(&pedlo2);       // extract pedestal events
+    tlist3.AddToList(&pedlo3);       // extract pedestal events
+    tlist3.AddToList(&fill0);        // fill pedestal events
+    tlist3.AddToList(&fill1);        // fill pedestal events
+
+    //-----------------------------------------------------------
+    // Calibration
+
+    MTaskList tlist4;
+    tlist4.SetFilter(&fcalib);       // process only events with cal-trigger
 
     //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
@@ -717,11 +739,11 @@
     {
         tlist2.AddToList(&fcalib);     // MFTriggerPattern
-        tlist2.AddToList(&tlist3);
+        tlist2.AddToList(&tlist4);
         if (IsUsePINDiode())
-            tlist3.AddToList(&pinext); // MExtractPINDiode
+            tlist4.AddToList(&pinext); // MExtractPINDiode
         if (IsUseBlindPixel())
-            tlist3.AddToList(&bldext); // MExtractBlindPixel
-	tlist3.AddToList(&taskenv3);
-        tlist3.AddToList(&pacalc);     // MCalibCalcFromPast
+            tlist4.AddToList(&bldext); // MExtractBlindPixel
+	tlist4.AddToList(&taskenv3);
+        tlist4.AddToList(&pacalc);     // MCalibCalcFromPast
         /*
          tlist3.AddToList(&filcalco);   // CalibConstFilter (IsReadyToSave)
@@ -730,27 +752,37 @@
          */
 
-        tlist3.AddToList(&filcam);     // FillChargeCam
+        tlist4.AddToList(&filcam);     // FillChargeCam
 	if (fIsRelTimesUpdate)
-	  tlist3.AddToList(&filtme);   // FillRelTime
+	  tlist4.AddToList(&filtme);   // FillRelTime
         if (IsUseBlindPixel())
-            tlist3.AddToList(&filbnd); // FillBlindCam
+            tlist4.AddToList(&filbnd); // FillBlindCam
         if (IsUsePINDiode())
-            tlist3.AddToList(&filpin); // FillPINDiode
-        tlist3.AddToList(&chcalc);     // MCalibrationChargeCalc
+            tlist4.AddToList(&filpin); // FillPINDiode
+        tlist4.AddToList(&chcalc);     // MCalibrationChargeCalc
 	if (fIsRelTimesUpdate)
-            tlist3.AddToList(&recalc); // MCalibrationRelTimeCam
+            tlist4.AddToList(&recalc); // MCalibrationRelTimeCam
 
         //tlist3.AddToList(&writecal);   // MWriteRootFile
     }
 
-    // Continue for all non-cosmic events
-    if (!extractor1->HasLoGain())
-        tlist2.AddToList(&contftp2); // remove pedestal events from processing
-    tlist2.AddToList(&conttp);       // remove calib events from processing
+    //-----------------------------------------------------------
+    // Cosmics extraction
+
+    // remove all events with a cal- or ped-trigger (no matter
+    // whether they have lvl1 or lvl2 or any other flag
+    tlist2.AddToList(&contcalped);
+
+    // Extract the signal
     if (extractor1)
       tlist2.AddToList(&taskenv1);
+
+    // remove all events which definitly don#t have a signal
+    // using MFCosmics (ContTrigEvts)
+    tlist2.AddToList(&contcos);      
+
+    // Extract arrival time (if a dedicated extrator given)
     if (extractor2)
-      tlist2.AddToList(&taskenv2);
-    tlist2.AddToList(&contcos);      // MFCosmics (ContTrigEvts)
+        tlist2.AddToList(&taskenv2);
+
     /*
     if (fIsHiLoCalibration)
@@ -766,4 +798,5 @@
     }
     */
+
     tlist2.AddToList(&fill2);
     tlist2.AddToList(&fill8);        // FillConv
