Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8477)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8478)
@@ -19,4 +19,62 @@
                                                  -*-*- END OF LINE -*-*-
 
+ 2007/05/09 Thomas Bretz
+
+   * callisto.rc, callisto_Dec04Jan05.rc, callisto_MarApr05.rc,
+     callisto_mux.rc:
+     - changed ArrTimeRmsLimit in all cases to default 5.0
+       because of the new meaning
+
+   * showplot.cc:
+     - changed that it closes automatically if the file cannot
+       be read
+
+   * datacenter/macros/fillstar.C:
+     - commented the output of the query
+
+   * datacenter/macros/plotdb.C:
+     - adapted ranges to MUX data values
+     - added plots for new unsuitable columns
+
+   * mbadpixels/MBadPixelsPix.h:
+     - added a new member function IsUncalibrated
+     - further adapted the usuitable levels
+
+   * mcalib/MCalibrationChargeCalc.[h,cc]:
+     - changed the meaning of ArrTimeRmsLimit such that it is now
+       the deviation from the average rms expressed in significance
+       levels
+     - the new check is done similar to the check for the relative
+       arrival time (to be unified!)
+     - removed FinalizeArrivalTimes
+     - removed calibration levels for first and last bin, this 
+       has to be redone more properly taken the extractor properties
+       into account
+     - some updates to the output
+     - some simplifications to the code
+
+   * mcalib/MCalibrationRelTimeCalc.cc:
+     - when calculating the median check for UnsuitableRun not
+       unsuitable in general
+     - small changes to output
+     - calculate upper and lower limits only once
+
+   * mhvstime/MHVsTime.[h,cc]:
+     - added fMinimum and fMaximum data members similar to 
+       MHSectorVsTime
+     - to be unified with MHSectorVsTime
+     - fixed draw/paint
+     - increased version number
+
+   * mjobs/MJCalibration.cc:
+     - removed the bad pixel levels for first and last bins
+
+   * msignal/MExtractTimeAndChargeSpline.[h,cc]:
+     - changed to allow setup of the extraction type and the 
+       relative or absolute height for arrival
+     - accordingly increased version number by one
+
+
+
  2007/05/08 Daniel Hoehne
 
Index: trunk/MagicSoft/Mars/callisto.rc
===================================================================
--- trunk/MagicSoft/Mars/callisto.rc	(revision 8477)
+++ trunk/MagicSoft/Mars/callisto.rc	(revision 8478)
@@ -214,5 +214,5 @@
 #MJCalibration.MCalibColorSet.ExplicitColor: green,blue,uv,ct1
 
-#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    3.5
+#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    5.0
 #MJCalibration.MCalibrationChargeCalc.ChargeLimit:        2.5
 #MJCalibration.MCalibrationChargeCalc.ChargeErrLimit:     0
Index: trunk/MagicSoft/Mars/callisto_Dec04Jan05.rc
===================================================================
--- trunk/MagicSoft/Mars/callisto_Dec04Jan05.rc	(revision 8477)
+++ trunk/MagicSoft/Mars/callisto_Dec04Jan05.rc	(revision 8478)
@@ -238,5 +238,5 @@
 #MJCalibration.MCalibColorSet.ExplicitColor: green,blue,uv,ct1
 
-#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    3.5
+#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    5.0
 #MJCalibration.MCalibrationChargeCalc.ChargeLimit:        2.5
 #MJCalibration.MCalibrationChargeCalc.ChargeErrLimit:     0
Index: trunk/MagicSoft/Mars/callisto_MarApr05.rc
===================================================================
--- trunk/MagicSoft/Mars/callisto_MarApr05.rc	(revision 8477)
+++ trunk/MagicSoft/Mars/callisto_MarApr05.rc	(revision 8478)
@@ -238,5 +238,5 @@
 #MJCalibration.MCalibColorSet.ExplicitColor: green,blue,uv,ct1
 
-#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    3.5
+#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    5.0
 #MJCalibration.MCalibrationChargeCalc.ChargeLimit:        2.5
 #MJCalibration.MCalibrationChargeCalc.ChargeErrLimit:     0
Index: trunk/MagicSoft/Mars/callisto_mux.rc
===================================================================
--- trunk/MagicSoft/Mars/callisto_mux.rc	(revision 8477)
+++ trunk/MagicSoft/Mars/callisto_mux.rc	(revision 8478)
@@ -238,5 +238,5 @@
 #MJCalibration.MCalibColorSet.ExplicitColor: green,blue,uv,ct1
 
-MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    2.5
+#MJCalibration.MCalibrationChargeCalc.ArrTimeRmsLimit:    5.0
 #MJCalibration.MCalibrationChargeCalc.ChargeLimit:        2.5
 #MJCalibration.MCalibrationChargeCalc.ChargeErrLimit:     0
Index: trunk/MagicSoft/Mars/datacenter/macros/fillstar.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillstar.C	(revision 8477)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillstar.C	(revision 8478)
@@ -345,5 +345,5 @@
     }
 
-    cout << "Q: " << query << endl;
+//    cout << "Q: " << query << endl;
 
     if (dummy)
Index: trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 8477)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 8478)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.33 2007-02-28 13:50:06 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.34 2007-05-09 12:15:51 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -528,11 +528,15 @@
     //from calib*.root
     plot.SetDescription("Conversion Factor inner Camera;C_{I} [phe/fadc cnts]", "ConvI");
-    plot.Plot("Calibration.fConvFactorInner",  0, 0.5, 0.002);
+    plot.Plot("Calibration.fConvFactorInner",  0, 0.7, 0.002);
     plot.SetDescription("Mean Arrival Time inner Camera;T_{I} [sl]", "ArrTmI");
-    plot.Plot("Calibration.fArrTimeMeanInner", 0, 9.0, 0.1);
+    plot.Plot("Calibration.fArrTimeMeanInner", 0, 40.0, 0.1);
     plot.SetDescription("RMS Arrival Time inner Camera;\\sigma_{T,I} [sl]", "RmsArrTmI");
-    plot.Plot("Calibration.fArrTimeRmsInner",  0, 0.8, 0.01);
+    plot.Plot("Calibration.fArrTimeRmsInner",  0, 3.0, 0.01);
     plot.SetDescription("Number of unsuitable pixels inner Camera;N{I}", "UnsuitI");
-    plot.Plot("Calibration.fUnsuitableInner",  0, 25, 1);
+    plot.Plot("Calibration.fUnsuitableInner",  0, 75, 1);
+    plot.SetDescription("Number of unsuitable pixels >50%;N", "Unsuit50");
+    plot.Plot("Calibration.fUnsuitable50",  0, 75, 1);
+    plot.SetDescription("Number of unsuitable pixels >1%;N", "Unsuit01");
+    plot.Plot("Calibration.fUnsuitable01",  0, 75, 1);
 
     //from signal*.root
@@ -542,11 +546,11 @@
     plot.Plot("Calibration.fMeanSignalInner",  0, 7.0, 0.05);
     plot.SetDescription("Mean PulsePosCheck (falling edge) inner camera;T [sl]", "ChkPos");
-    plot.Plot("Calibration.fPulsePosCheckMean", 1, 15.0, 0.1);
+    plot.Plot("Calibration.fPulsePosCheckMean", 1, 40.0, 0.1);
     plot.SetDescription("Rms PulsePosCheck (falling edge) inner camera;T [sl]", "ChkRms");
     plot.Plot("Calibration.fPulsePosCheckRms", 0, 5.0, 0.1);
     plot.SetDescription("Mean calibrated PulsePos;T", "PulPos");
-    plot.Plot("Calibration.fPulsePosMean", 1, 15.0, 0.1);
+    plot.Plot("Calibration.fPulsePosMean", 1, 40.0, 0.1);
     plot.SetDescription("Rms calibrated PulsePos;T", "PulRms");
-    plot.Plot("Calibration.fPulsePosRms", 0, 2.0, 0.02);
+    plot.Plot("Calibration.fPulsePosRms", 0, 3.0, 0.02);
 
     plot.SetDescription("Hi-/Lo-Gain offset;", "PulOff");
@@ -606,9 +610,9 @@
     //from calib*.root
     plot.SetDescription("Conversion Factor outer Camera;C_{O} [phe/fadc cnts]", "ConvO");
-    plot.Plot("Calibration.fConvFactorOuter",  0, 2.0, 0.01);
+    plot.Plot("Calibration.fConvFactorOuter",  0, 3.0, 0.01);
     plot.SetDescription("Mean Arrival Time outer Camera;T_{O} [sl]", "ArrTmO");
-    plot.Plot("Calibration.fArrTimeMeanOuter", 0, 8.5, 0.1);
+    plot.Plot("Calibration.fArrTimeMeanOuter", 0, 45, 0.1);
     plot.SetDescription("RMS Arrival Time outer Camera;\\sigma_{T,O} [sl]", "RmsArrTmO");
-    plot.Plot("Calibration.fArrTimeRmsOuter",  0, 1.0, 0.01);
+    plot.Plot("Calibration.fArrTimeRmsOuter",  0, 3.0, 0.01);
     plot.SetDescription("Number of unsuitable pixels outer Camera;N{O}", "UnsuitO");
     plot.Plot("Calibration.fUnsuitableOuter",  0, 25, 1);
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h	(revision 8477)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h	(revision 8478)
@@ -82,6 +82,7 @@
     Bool_t IsHardwareBad (HardwareType_t     typ) const { return fInfo[2]&typ; }
 
-    Bool_t IsUnsuitable() const { return fInfo[0]&kUnsuitable; }
-    Bool_t IsUnreliable() const { return fInfo[0]&kUnreliable; }
+    Bool_t IsUnsuitable() const   { return fInfo[0]&kUnsuitable; }
+    Bool_t IsUnreliable() const   { return fInfo[0]&kUnreliable; }
+    Bool_t IsUncalibrated() const { return fInfo[1]!=0; }
 
     Bool_t IsOK()  const { return fInfo[0]==0; }
@@ -100,15 +101,15 @@
       if (IsUncalibrated( kChargeIsPedestal    ))    return 1;
       if (IsUncalibrated( kLoGainSaturation    ))    return 2;
-      if (IsUncalibrated( kMeanTimeInFirstBin  ))    return 3;
-      if (IsUncalibrated( kMeanTimeInLast2Bins ))    return 4;
-      if (IsUncalibrated( kHiGainOverFlow      ))    return 5;
-      if (IsUncalibrated( kLoGainOverFlow      ))    return 6;
-      if (IsUncalibrated( kDeadPedestalRms     ))    return 7;
-      if (IsUncalibrated( kFluctuatingArrivalTimes)) return 8;
-      if (IsUncalibrated( kDeviatingNumPhes    ))    return 9;
-      if (IsUncalibrated( kDeviatingTimeResolution)) return 10;
-      if (IsUncalibrated( kLoGainBlackout      ))    return 11;
-      if (IsUncalibrated( kPreviouslyExcluded  ))    return 12;
-      return 13;
+//      if (IsUncalibrated( kMeanTimeInFirstBin  ))    return 3;
+//      if (IsUncalibrated( kMeanTimeInLast2Bins ))    return 4;
+      if (IsUncalibrated( kHiGainOverFlow      ))    return 3;
+      if (IsUncalibrated( kLoGainOverFlow      ))    return 4;
+      if (IsUncalibrated( kDeadPedestalRms     ))    return 5;
+      if (IsUncalibrated( kDeviatingNumPhes    ))    return 6;
+      if (IsUncalibrated( kFluctuatingArrivalTimes)) return 7;
+      if (IsUncalibrated( kDeviatingTimeResolution)) return 8;
+      if (IsUncalibrated( kLoGainBlackout      ))    return 9;
+      if (IsUncalibrated( kPreviouslyExcluded  ))    return 10;
+      return 11;
     }
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 8477)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 8478)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.177 2007-04-27 10:04:46 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.178 2007-05-09 12:15:52 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -19,6 +19,7 @@
 !
 !   Author(s): Markus Gaug  02/2004 <mailto:markus@ifae.es>
+!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -213,4 +214,6 @@
 #include "MLogManip.h"
 
+#include "MMath.h"
+
 #include "MParList.h"
 
@@ -255,5 +258,5 @@
 const Float_t MCalibrationChargeCalc::fgPheErrUpperLimit       = 5.5;
 const Float_t MCalibrationChargeCalc::fgFFactorErrLimit        = 4.5;
-const Float_t MCalibrationChargeCalc::fgArrTimeRmsLimit        = 3.5;
+const Float_t MCalibrationChargeCalc::fgArrTimeRmsLimit        = 5.0;
 const Float_t MCalibrationChargeCalc::fgUnsuitablesLimit       = 0.1;
 const Float_t MCalibrationChargeCalc::fgUnreliablesLimit       = 0.3;
@@ -672,4 +675,92 @@
 }
 
+// ----------------------------------------------------------------------------------------------------
+//
+// Check for outliers. They are marked with
+// MBadPixelsPix::kFluctuatingArrivalTimes
+//
+// see also MCalibrationRelTimeCalc::FinalizeRelTimes
+//
+void MCalibrationChargeCalc::FinalizeAbsTimes()
+{
+    const Int_t npixels = fGeom->GetNumPixels();
+    const Int_t nareas  = fGeom->GetNumAreas();
+
+    // Create an array capable of holding all pixels
+    TArrayF arr(npixels);
+
+    for (Int_t aidx=0; aidx<nareas; aidx++)
+    {
+        Int_t n = 0;
+        for (Int_t i=0; i<npixels; i++)
+        {
+            // Check for this aidx only
+            if ((*fGeom)[i].GetAidx()!=aidx)
+                continue;
+
+            // check if pixel may not contain a valid value
+            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
+                continue;
+
+            // check if it was excluded for some reason
+            const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
+            if (pix.IsExcluded())
+                continue;
+
+            // if TimePrecision is valid fill it into array
+            if (pix.GetAbsTimeRms()>0)
+                arr[n++] = pix.GetAbsTimeRms();
+        }
+
+        // Check the ratio of valid entries to the ratio of pixels
+        const Float_t ratio = 100*n/fGeom->GetNumPixWithAidx(aidx);
+        if (3*ratio<2)
+            *fLog << warn << "Area   " << setw(4) << aidx << ": Only " << ratio << "% pixels with valid time resolution found." << endl;
+
+        // Calculate median and median deviation
+        Double_t med;
+        const Double_t dev = MMath::MedianDev(n, arr.GetArray(), med);
+
+        // Calculate upper and lower limit
+        const Float_t lolim = TMath::Max(med-fArrTimeRmsLimit*dev, 0.);
+        const Float_t hilim = TMath::Max(med+fArrTimeRmsLimit*dev, 0.);
+
+        // Now find the outliers
+        for (Int_t i=0; i<npixels; i++)
+        {
+            // Search only within this aidx
+            if ((*fGeom)[i].GetAidx()!=aidx)
+                continue;
+
+            // skip pixels already known to be unsuitable
+            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
+                continue;
+
+            // check if a pixel has been excluded. This
+            const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
+
+            // Check if time precision is valid (might be invalid
+            // for example in cae of empty histograms)
+            const Float_t res = pix.GetAbsTimeRms();
+            if (res<0) //FIXME!!! How does this happen?
+            {
+                *fLog << warn << "Pixel  " << setw(4) << i << ": Abs-time resolution could not be calculated." << endl;
+                (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kDeviatingTimeResolution);
+                continue;
+            }
+
+            // Now compare to a lower and upper limit
+            if (res<=lolim || res>=hilim)
+            {
+                *fLog << warn << "Pixel  " << setw(4) << i << ": Deviating abs-time resolution: "
+                    << Form("%5.2f", res) << " out of range "
+                    << Form("[%4.2f,%4.2f]", lolim, hilim) << endl;
+
+                (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kFluctuatingArrivalTimes);
+            }
+        }
+    }
+}
+
 // -----------------------------------------------------------------------
 //
@@ -723,28 +814,21 @@
   // First loop over pixels, call FinalizePedestals and FinalizeCharges
   //
-  Int_t   nvalid      = 0;
-
+  Int_t nvalid = 0;
   for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
-    {
-
-      MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[pixid];
+  {
       //
       // Check if the pixel has been excluded from the fits
       //
+      MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[pixid];
       if (pix.IsExcluded())
-        continue;
-
-      MPedestalPix  &ped = (*fPedestals)[pixid];
-      MBadPixelsPix &bad = (*fBadPixels)[pixid];
-
-      const Int_t aidx    = (*fGeom)[pixid].GetAidx();
-
-      FinalizePedestals(ped,pix,aidx);
-
-      if (FinalizeCharges(pix,bad,"pixel  "))
-        nvalid++;
-
-      FinalizeArrivalTimes(pix,bad,"pixel  ");
-    }
+          continue;
+
+      FinalizePedestals((*fPedestals)[pixid], pix, (*fGeom)[pixid].GetAidx());
+
+      if (FinalizeCharges(pix, (*fBadPixels)[pixid], "Pixel  "))
+          nvalid++;
+  }
+
+  FinalizeAbsTimes();
 
   *fLog << endl;  
@@ -779,10 +863,10 @@
       // (already done for calibration sigma in MHCalibrationCam::CalcAverageSigma()
       //
-      pix.SetPedRMS(pix.GetPedRms()*TMath::Sqrt((Float_t)arr[aidx]),
-                    pix.GetPedRmsErr()*TMath::Sqrt((Float_t)arr[aidx]));
+      const Double_t sqrtnum = TMath::Sqrt((Double_t)arr[aidx]);
+
+      pix.SetPedRMS(pix.GetPedRms()*sqrtnum, pix.GetPedRmsErr()*sqrtnum);
       pix.SetSigma (pix.GetSigma()/pix.GetFFactorFADC2Phe());
 
       FinalizeCharges(pix, fCam->GetAverageBadArea(aidx),"area id");
-      FinalizeArrivalTimes(pix, fCam->GetAverageBadArea(aidx), "area id");
     }
   
@@ -850,8 +934,8 @@
   PrintUncalibrated(MBadPixelsPix::kLoGainSaturation,    
                     "Low Gain Saturation:                              ");
-  PrintUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin, 
-                    Form("%s%2.1f%s","Mean Abs. Arr. Time in First ",1.," Bin(s):          "));
-  PrintUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins, 
-                    Form("%s%2.1f%s","Mean Abs. Arr. Time in Last ",2.," Bin(s):           "));
+//  PrintUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin,
+//                    Form("%s%2.1f%s","Mean Abs. Arr. Time in First ",1.," Bin(s):          "));
+//  PrintUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins,
+//                    Form("%s%2.1f%s","Mean Abs. Arr. Time in Last ",2.," Bin(s):           "));
   PrintUncalibrated(MBadPixelsPix::kHiGainOverFlow,    
                     "Pixels with High Gain Overflow:                   ");
@@ -974,4 +1058,18 @@
   const TString desc = Form("%7s%4d: ", what, cal.GetPixId());
 
+  if (cal.GetMean()<0)
+  {
+      *fLog << warn << desc << "Charge not fitted." << endl;
+      bad.SetUncalibrated( MBadPixelsPix::kChargeIsPedestal);
+      return kFALSE;
+  }
+
+  if (cal.GetSigma()<0)
+  {
+      *fLog << warn << desc << "Charge Sigma invalid." << endl;
+      bad.SetUncalibrated( MBadPixelsPix::kChargeIsPedestal);
+      return kFALSE;
+  }
+
   if (cal.GetMean() < fChargeLimit*cal.GetPedRms())
     {
@@ -1084,25 +1182,4 @@
 
   return kTRUE;
-}
-
-// -----------------------------------------------------------------------------------
-//
-// Test the arrival Times RMS of the pixel and set the bit
-// - MBadPixelsPix::kFluctuatingArrivalTimes
-//
-void MCalibrationChargeCalc::FinalizeArrivalTimes(MCalibrationChargePix &cal, MBadPixelsPix &bad, const char* what)
-{
-    if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
-        return;
-
-    const TString desc = Form("%7s%4d: ", what, cal.GetPixId());
-
-    if (cal.GetAbsTimeRms() > fArrTimeRmsLimit)
-    {
-        *fLog << warn;
-        *fLog << desc << "RMS of pulse arrival times: " << Form("%2.1f", cal.GetAbsTimeRms());
-        *fLog << " FADC sl. < " << Form("%2.1f", fArrTimeRmsLimit) << endl;
-        bad.SetUncalibrated( MBadPixelsPix::kFluctuatingArrivalTimes);
-    }
 }
 
@@ -1134,5 +1211,5 @@
             bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun   );
         }
-      
+/*
       if (IsCheckExtractionWindow())
         {
@@ -1143,5 +1220,5 @@
             bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
         }
-
+ */
       if (IsCheckDeviatingBehavior())
         {
@@ -1275,5 +1352,6 @@
           continue;
         }
-      
+
+      // FIXME: WHAT IS THIS FOR? It is overwritten!
       lowlim[i] = areaphes[i] - fPheErrLowerLimit*TMath::Sqrt(areavars[i]);
       upplim[i] = areaphes[i] + fPheErrUpperLimit*TMath::Sqrt(areavars[i]);
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 8477)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 8478)
@@ -83,5 +83,4 @@
 
   // Pointers
-//  MBadPixelsIntensityCam         *fIntensBad;      //!  Bad Pixels
   MBadPixelsCam                  *fBadPixels;      //!  Bad Pixels
   MCalibrationChargeCam          *fCam;            //!  Calibrated Charges results of all pixels
@@ -128,5 +127,4 @@
 
   // functions
-  void   FinalizeArrivalTimes    ( MCalibrationChargePix &cal, MBadPixelsPix &bad, const char* what);
   void   FinalizeBadPixels       ();
   Bool_t FinalizeBlindCam        ();  
@@ -141,4 +139,6 @@
   Bool_t FinalizeUnsuitablePixels();
 
+  void FinalizeAbsTimes();
+
   const char* GetOutputFile();
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 8477)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 8478)
@@ -17,6 +17,7 @@
 !
 !   Author(s): Markus Gaug  04/2004 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -242,4 +243,6 @@
 // MBadPixelsPix::kDeviatingTimeResolution
 //
+// see also MCalibrationChargeCalc::FinalizeAbsTimes
+//
 void MCalibrationRelTimeCalc::FinalizeRelTimes()
 {
@@ -260,5 +263,5 @@
 
             // check if pixel may not contain a valid value
-            if ((*fBadPixels)[i].IsUnsuitable())
+            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
                 continue;
 
@@ -281,4 +284,8 @@
         Double_t med;
         const Double_t dev = MMath::MedianDev(n, arr.GetArray(), med);
+
+        // Calculate upper and lower limit
+        const Float_t lolim = TMath::Max(med-fRelTimeResolutionLimit*dev, 0.);
+        const Float_t hilim = TMath::Max(med+fRelTimeResolutionLimit*dev, 0.);
 
         // Now find the outliers
@@ -290,5 +297,5 @@
 
             // skip pixels already known to be unsuitable
-            if ((*fBadPixels)[i].IsUnsuitable())
+            if ((*fBadPixels)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
                 continue;
 
@@ -301,5 +308,5 @@
             if (res<0) //FIXME!!! How does this happen?
             {
-                *fLog << warn << "Pixel  " << setw(4) << i << ": Time resolution could not be calculated." << endl;
+                *fLog << warn << "Pixel  " << setw(4) << i << ": Rel-time resolution could not be calculated." << endl;
                 (*fBadPixels)[i].SetUncalibrated(MBadPixelsPix::kDeviatingTimeResolution);
                 continue;
@@ -307,11 +314,8 @@
 
             // Now compare to a lower and upper limit
-            const Float_t lolim = TMath::Max(med-fRelTimeResolutionLimit*dev, 0.);
-            const Float_t hilim = TMath::Max(med+fRelTimeResolutionLimit*dev, 0.);
-
             if (res<=lolim || res>=hilim)
             {
-                *fLog << warn << "Pixel  " << setw(4) << i << ": Deviating time resolution: "
-                    << Form("%4.2f", res) << " out of range "
+                *fLog << warn << "Pixel  " << setw(4) << i << ": Deviating rel-time resolution: "
+                    << Form("%5.2f", res) << " out of range "
                     << Form("[%4.2f,%4.2f]", lolim, hilim) << endl;
 
Index: trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc	(revision 8477)
+++ trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc	(revision 8478)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -58,4 +58,9 @@
 //  - MDataChain *fError;     // Object from which the error is filled
 //
+// Class Version 3:
+// ----------------
+//  + Double_t fMinimum;      // User defined minimum
+//  + Double_t fMaximum;      // User defined maximum
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MHVsTime.h"
@@ -92,5 +97,5 @@
 MHVsTime::MHVsTime(const char *rule, const char *error)
     : fGraph(NULL), fData(NULL), fError(NULL), fScale(1), fMaxPts(-1),
-    fNumEvents(1), fUseEventNumber(0)
+    fNumEvents(1), fMinimum(-1111), fMaximum(-1111), fUseEventNumber(0)
 {
     fName  = gsDefName;
@@ -129,14 +134,4 @@
 // --------------------------------------------------------------------------
 //
-// Call SetMinimum of fGraph
-//
-void MHVsTime::SetMinimum(Double_t min)
-{
-    if (fGraph)
-        fGraph->SetMinimum(min);
-}
-
-// --------------------------------------------------------------------------
-//
 // Return the data members used by the data chain to be used in
 // MTask::AddBranchToList
@@ -178,4 +173,7 @@
     fMean = 0;
     fN    = 0;
+
+    fMin =  FLT_MAX;
+    fMax = -FLT_MAX;
 
     return kTRUE;
@@ -252,8 +250,13 @@
         }
 
-        fGraph->SetPoint(fGraph->GetN(), t, fMean/fN*fScale);
+        const Double_t val = fMean/fN*fScale;
+
+        fGraph->SetPoint(fGraph->GetN(), t, val);
 
         if (fError)
             static_cast<TGraphErrors*>(fGraph)->SetPointError(fGraph->GetN()-1, 0, fMeanErr/fN*fScale);
+
+        fMin = TMath::Min(fMin, val);
+        fMax = TMath::Max(fMax, val);
 
         fMean = 0;
@@ -265,15 +268,23 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Set Minimum and Maximum;
+Bool_t MHVsTime::Finalize()
+{
+    const Double_t add = (fMax-fMin)*0.15;
+
+    if (fMinimum==-1111)
+        fGraph->SetMinimum(fMin-add);
+    if (fMaximum==-1111)
+        fGraph->SetMaximum(fMax+add);
+
+    return kTRUE;
+}
+
 void MHVsTime::Paint(Option_t *opt)
 {
-    /*
-     *fLog << all << fGraph << " " << gPad->GetName() << " ----> Paint " << opt << endl;
-     TListIter Next(gPad->GetListOfPrimitives()); TObject *obj;
-     while ((obj=Next())) *fLog << obj << " " << obj->GetName() << " " << obj->ClassName() << " " << Next.GetOption() << endl;
-     */
     if (!fGraph)
         return;
-
-//    *fLog << all << fGraph->GetN() << " " << opt << endl;
 
     if (fGraph->GetN()==0)
@@ -318,12 +329,15 @@
         gPad->SetLogy();
 
+    // If this is set to early the plot remains empty in root 5.12/00
+    if (fMinimum!=-1111)
+        fGraph->SetMinimum(fMinimum);
+    if (fMaximum!=-1111)
+        fGraph->SetMaximum(fMaximum);
+
+
     // This is a workaround if the TGraph has only one point.
     // Otherwise MStatusDisplay::Update hangs.
-//    gPad->GetListOfPrimitives()->Remove(fGraph);
-//    fGraph->Draw(fGraph->GetN()<2 ? "A" : str.Data());
-    //gPad->GetListOfPrimitives()->Add(fGraph, fGraph->GetN()<2 ? "A" : opt);
-    //    AppendPad(str);
-    //    fGraph->Draw(str);
-
+    gPad->GetListOfPrimitives()->Remove(fGraph);
+    fGraph->Draw(fGraph->GetN()<2 ? "A" : str.Data());
 }
 
@@ -339,6 +353,4 @@
     pad->SetBorderMode(0);
     AppendPad(opt);
-
-    fGraph->Draw("A");
 }
 
Index: trunk/MagicSoft/Mars/mhvstime/MHVsTime.h
===================================================================
--- trunk/MagicSoft/Mars/mhvstime/MHVsTime.h	(revision 8477)
+++ trunk/MagicSoft/Mars/mhvstime/MHVsTime.h	(revision 8478)
@@ -34,4 +34,10 @@
     MTime       fLast;      //! For checks
 
+    Double_t fMinimum;      // User defined minimum
+    Double_t fMaximum;      // User defined maximum
+
+    Double_t fMin;          //! Calculation of minimum
+    Double_t fMax;          //! Calculation of maximum
+
     enum {
         kIsLogy = BIT(18)
@@ -40,4 +46,6 @@
     Bool_t fUseEventNumber;
 
+    Bool_t Finalize();
+
 public:
     MHVsTime(const char *rule=NULL, const char *ruleerr=NULL);
@@ -45,5 +53,7 @@
 
     void SetScale(Double_t scale) { fScale = scale; }
-    void SetMinimum(Double_t min=-1111);
+
+    void SetMinimum(Double_t min=-1111) { fMinimum = min; }
+    void SetMaximum(Double_t max=-1111) { fMaximum = max; }
 
     Int_t GetNbins() const;
@@ -78,5 +88,5 @@
     void SetMaxPts(Int_t n) { fMaxPts=n; }
 
-    ClassDef(MHVsTime, 2) // Generalized 1/2/3D-histogram for Mars variables
+    ClassDef(MHVsTime, 3) // Generalized 1/2/3D-histogram for Mars variables
 };
 
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8477)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8478)
@@ -829,5 +829,5 @@
 
       const Double_t min = 1;
-      const Double_t max = 12.;
+      const Double_t max = 10.;
       const Double_t f   = (numcol-1)/(max-min);
 
@@ -848,14 +848,14 @@
       DrawBadPixel(*pave, disp24,  1, f, "Signal smaller 4.5 Pedestal RMS:               ");
       DrawBadPixel(*pave, disp24,  2, f, "Low Gain Saturation:                                   ");
-      DrawBadPixel(*pave, disp24,  3, f, "Mean Arr. Time In First Extraction Bin:      ");
-      DrawBadPixel(*pave, disp24,  4, f, "Mean Arr. Time In Last 2 Extraction Bins:  ");
-      DrawBadPixel(*pave, disp24,  5, f, "High-Gain Histogram Overflow:                  ");
-      DrawBadPixel(*pave, disp24,  6, f, "Low-Gain Histogram Overflow:                   ");
-      DrawBadPixel(*pave, disp24,  7, f, "Presumably dead from Ped. Rms:              ");
-      DrawBadPixel(*pave, disp24,  8, f, "Fluctuating Pulse Arrival Times:                 ");
-      DrawBadPixel(*pave, disp24,  9, f, "Deviating Number of Photo-electrons:       ");
-      DrawBadPixel(*pave, disp24, 10, f, "Deviating Rel. Arrival Time RMS:                ");
-      DrawBadPixel(*pave, disp24, 11, f, "Too many Low-Gain Blackout Events:       ");
-      DrawBadPixel(*pave, disp24, 12, f, "Previously Excluded:                                   ");
+      // DrawBadPixel(*pave, disp24,  3, f, "Mean Arr. Time In First Extraction Bin:      ");
+      // DrawBadPixel(*pave, disp24,  4, f, "Mean Arr. Time In Last 2 Extraction Bins:  ");
+      DrawBadPixel(*pave, disp24,  3, f, "High-Gain Histogram Overflow:                  ");
+      DrawBadPixel(*pave, disp24,  4, f, "Low-Gain Histogram Overflow:                   ");
+      DrawBadPixel(*pave, disp24,  5, f, "Presumably dead from Ped. Rms:              ");
+      DrawBadPixel(*pave, disp24,  6, f, "Deviating Number of Photo-electrons:       ");
+      DrawBadPixel(*pave, disp24,  7, f, "Fluctuating Pulse Arrival Times:                 ");
+      DrawBadPixel(*pave, disp24,  8, f, "Deviating Rel. Arrival Time RMS:                ");
+      DrawBadPixel(*pave, disp24,  9, f, "Too many Low-Gain Blackout Events:       ");
+      DrawBadPixel(*pave, disp24, 10, f, "Previously Excluded:                                   ");
       pave->Draw();
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 8477)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 8478)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndChargeSpline.cc,v 1.67 2007-03-05 08:55:09 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndChargeSpline.cc,v 1.68 2007-05-09 12:15:53 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -20,5 +20,5 @@
 !   Author(s): Markus Gaug 09/2004 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2002-2006
+!   Copyright: MAGIC Software Development, 2002-2007
 !
 !
@@ -145,6 +145,4 @@
 #include "MExtractTimeAndChargeSpline.h"
 
-#include "MExtralgoSpline.h"
-
 #include "MPedestalPix.h"
 
@@ -181,5 +179,5 @@
 //
 MExtractTimeAndChargeSpline::MExtractTimeAndChargeSpline(const char *name, const char *title) 
-    : fExtractionType(kIntegral)
+    : fHeightTm(0.5), fExtractionType(MExtralgoSpline::kIntegralRel)
 {
 
@@ -220,5 +218,5 @@
 //               second derivative to zero, there.
 //
-void MExtractTimeAndChargeSpline::SetChargeType( ExtractionType_t typ )
+void MExtractTimeAndChargeSpline::SetChargeType(MExtralgoSpline::ExtractionType_t typ)
 {
   fExtractionType = typ;
@@ -228,10 +226,11 @@
   switch (fExtractionType)
   {
-  case kAmplitude:
+  case MExtralgoSpline::kAmplitude:
       SetResolutionPerPheHiGain(0.053);
       SetResolutionPerPheLoGain(0.016);
       return;
 
-  case kIntegral:
+  case MExtralgoSpline::kIntegralRel:
+  case MExtralgoSpline::kIntegralAbs:
       switch (fWindowSizeHiGain)
       {
@@ -305,5 +304,5 @@
     switch (fExtractionType)
     {
-    case kAmplitude:
+    case MExtralgoSpline::kAmplitude:
         fNumHiGainSamples  = 1.;
         fNumLoGainSamples  = fLoGainLast ? 1. : 0.;
@@ -315,5 +314,6 @@
         break;
 
-    case kIntegral:
+    case MExtralgoSpline::kIntegralAbs:
+    case MExtralgoSpline::kIntegralRel:
         fNumHiGainSamples  = fRiseTimeHiGain + fFallTimeHiGain;
         fNumLoGainSamples  = fLoGainLast ? fRiseTimeLoGain + fFallTimeLoGain : 0.;
@@ -336,4 +336,6 @@
     MExtralgoSpline s(ptr, num, fHiGainFirstDeriv.GetArray(), fHiGainSecondDeriv.GetArray());
 
+    s.SetExtractionType(fExtractionType);
+    s.SetHeightTm(fHeightTm);
     s.SetRiseFallTime(fRiseTimeHiGain, fFallTimeHiGain);
 
@@ -357,4 +359,6 @@
     MExtralgoSpline s(ptr, num, fLoGainFirstDeriv.GetArray(), fLoGainSecondDeriv.GetArray());
 
+    s.SetExtractionType(fExtractionType);
+    s.SetHeightTm(fHeightTm);
     s.SetRiseFallTime(fRiseTimeLoGain, fFallTimeLoGain);
 
@@ -404,5 +408,10 @@
       rc = kTRUE;
     }
-  
+  if (IsEnvDefined(env, prefix, "HeightTm", print))
+    {
+      fHeightTm = GetEnvValue(env, prefix, "HeightTm", fHeightTm);
+      rc = kTRUE;
+    }
+
   if (IsEnvDefined(env, prefix, "ExtractionType", print))
   {
@@ -411,7 +420,9 @@
       type = type.Strip(TString::kBoth);
       if (type==(TString)"amplitude")
-          SetChargeType(kAmplitude);
-      if (type==(TString)"integral")
-          SetChargeType(kIntegral);
+          SetChargeType(MExtralgoSpline::kAmplitude);
+      if (type==(TString)"integralabsolute")
+          SetChargeType(MExtralgoSpline::kIntegralAbs);
+      if (type==(TString)"integralrelative")
+          SetChargeType(MExtralgoSpline::kIntegralRel);
       rc=kTRUE;
   }
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h	(revision 8477)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h	(revision 8478)
@@ -4,4 +4,8 @@
 #ifndef MARS_MExtractTimeAndCharge
 #include "MExtractTimeAndCharge.h"
+#endif
+
+#ifndef MARS_MExtralgoSpline
+#include "MExtralgoSpline.h"
 #endif
 
@@ -41,4 +45,5 @@
 
     Float_t fLoGainStretch;                  // The stretch of the low-gain w.r.t. the high-gain pulse
+    Float_t fHeightTm;
 
 //    Int_t   fRandomIter;                     //! Counter used to randomize weights for noise calculation
@@ -47,13 +52,9 @@
     Bool_t  InitArrays(Int_t n);
 
-public:
-    enum ExtractionType_t { kAmplitude, kIntegral };    //! Possible time and charge extraction types
-
 private:
-    ExtractionType_t fExtractionType;
+    MExtralgoSpline::ExtractionType_t fExtractionType;
 
 public:
     MExtractTimeAndChargeSpline(const char *name=NULL, const char *title=NULL);
-    ~MExtractTimeAndChargeSpline() {}
 
     Float_t GetRiseTimeHiGain() const { return fRiseTimeHiGain; }
@@ -83,5 +84,5 @@
     void SetLoGainStretch(const Float_t f=fgLoGainStretch) { fLoGainStretch = f;   }
 
-    void SetChargeType(const ExtractionType_t typ=kIntegral);
+    void SetChargeType(const MExtralgoSpline::ExtractionType_t typ=MExtralgoSpline::kIntegralRel);
 /*
     void FindTimeAndChargeHiGain(Byte_t *first, Byte_t *logain, Float_t &sum, Float_t &dsum,
@@ -100,5 +101,5 @@
                                   Byte_t sat, Int_t maxpos) const;
 
-    ClassDef(MExtractTimeAndChargeSpline, 4)   // Task to Extract Arrival Times and Charges using a Cubic Spline
+    ClassDef(MExtractTimeAndChargeSpline, 5)   // Task to Extract Arrival Times and Charges using a Cubic Spline
 };
 
Index: trunk/MagicSoft/Mars/showplot.cc
===================================================================
--- trunk/MagicSoft/Mars/showplot.cc	(revision 8477)
+++ trunk/MagicSoft/Mars/showplot.cc	(revision 8478)
@@ -258,5 +258,5 @@
         d->SetCanvasWidth(kCanvasWidth);
 
-    d->Open(kInput);
+    const Int_t rc = d->Open(kInput);
 
     if (kPrint)
@@ -285,5 +285,5 @@
         d->SaveAsC(kTab,    kNameC);
 
-    if (kBatch || kQuit)
+    if (kBatch || kQuit || !rc)
     {
         delete d;
