Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8890)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8891)
@@ -23,5 +23,18 @@
    * mfilter/MFMagicCuts.[h,cc]:
      - fixed a few typos in comments and in the output
-     - added an option kAreaLin with a linear cut in area for special studies
+     - added an option kAreaLin with a linear cut in area for special
+       studies
+
+   * mbase/MStatusDisplay.cc:
+     - if no MStatusArray is found, keys which store a TCanvas object
+       are displayed instead if available
+
+   * mhcalib/MHCalibrationPulseTimeCam.[h,cc]:
+     - the extraction range to get the maximum is now determined
+       automatically from the MExtractedSignalCam
+
+   * mpedestal/MPedestalSubtract.cc, msignal/MExtractTimeAndCharge.cc:
+     - raise an error if there is a mismatch in the number of samples
+
 
 
@@ -40,9 +53,10 @@
    * mjtrain/MJTrainEnergy.cc
      - write the dataset to the output file
-     - added new plots to show the resolution versus several different parameters
+     - added new plots to show the resolution versus several different
+       parameters
 
    * mpedestal/MPedestalSubtract.[h,cc]:
-     - added an additional check to compate the number of hi-/lo-gain slices
-       in the run- and event-header
+     - added an additional check to compate the number of hi-/lo-gain
+       slices in the run- and event-header
 
    * mpointing/MPointingDevCalc.cc:
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 8890)
+++ trunk/MagicSoft/Mars/NEWS	(revision 8891)
@@ -64,4 +64,12 @@
       Since pedestal and calibration constants are continously recalculated
       this only effected the very first events of every sequence.
+
+    * For the extraction of the position of the maximum sample now the
+      extraction range is set automatically to the extraction window,
+      before the whole accessible range was used.
+
+    * If the number of samples in the events and the number of samples
+      in the run-header disagrees now an error is raised (this can 
+      happen in not well simulated Monte Carlo files)
 
  ;star
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 8890)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 8891)
@@ -2157,16 +2157,47 @@
     if (n==0)
     {
-        *fLog << warn << "MStatusDisplay::Read: No objects read." << endl;
+        const Bool_t store = TH1::AddDirectoryStatus();
+        TH1::AddDirectory(kFALSE);
+
+        TIter Next(gFile->GetListOfKeys());
+        TObject *key = 0;
+        while ((key=Next()))
+        {
+            TCanvas *c=0;
+            gFile->GetObject(key->GetName(), c);
+            if (!c)
+                break;
+
+            if (list.GetEntries()==0)
+                list.Add(new TNamed(GetName(), GetTitle()));
+
+            list.Add(c);
+        }
+
+        TH1::AddDirectory(store);
+
+        if (list.GetEntries()==0)
+        {
+            *fLog << warn << "MStatusDisplay::Read: No objects read." << endl;
+            return 0;
+        }
+
+        *fLog << inf << "MStatusDisplay: " << list.GetEntries() << " canvases directly read from file." << endl;
+    }
+
+
+    if (!Display(list, tab))
+    {
+        *fLog << err << "MStatusDisplay::Display: No entries found." << endl;
         return 0;
     }
 
-    if (!Display(list, tab))
-    {
-        *fLog << err << "MStatusDisplay::Display: No entry in " << name << "." << endl;
-        return 0;
-    }
+
+    cout << "Display done." << endl;
+
+    if (n==0)
+        return list.GetEntries();
 
     *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
-
     return n;
 }
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 8890)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 8891)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCalibrationPulseTimeCam.cc,v 1.41 2007-06-19 09:25:38 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCalibrationPulseTimeCam.cc,v 1.42 2008-05-15 18:37:26 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -175,5 +175,5 @@
 //
 MHCalibrationPulseTimeCam::MHCalibrationPulseTimeCam(const char *name, const char *title)
-    : fBadPixels(NULL)
+    : fSignalCam(NULL), fBadPixels(NULL)
 {
 
@@ -277,8 +277,6 @@
 Bool_t MHCalibrationPulseTimeCam::ReInitHists(MParList *pList)
 {
-
-  MExtractedSignalCam *signal = 
-    (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
-  if (!signal)
+  fSignalCam = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
+  if (!fSignalCam)
   {
       *fLog << err << "MExtractedSignalCam not found... abort." << endl;
@@ -397,7 +395,8 @@
             continue;
 
-        // Get position of maximum (FIXME: Extraction range?)
+        // Get position of maximum
         Float_t max;
-        const Int_t pos = evt->GetMaxPos(idx, max);
+        const Int_t pos = evt->GetMax(idx, fSignalCam->GetFirstUsedSliceHiGain(),
+                                      fSignalCam->GetLastUsedSliceHiGain(), max);
 
         // check if maximum is high enough
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.h	(revision 8890)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.h	(revision 8891)
@@ -8,4 +8,5 @@
 class TH1F;
 class MRawEvtData;
+class MExtractedSignalCam;
 class MHCalibrationChargePix;
 
@@ -39,5 +40,6 @@
   Float_t fOuterRefTime;                       // The reference mean arrival time outer pixels
 
-  MBadPixelsCam *fBadPixels;                   //!  Bad Pixels
+  MExtractedSignalCam *fSignalCam;             //! Signal cam for extraction range
+  MBadPixelsCam *fBadPixels;                   //! Bad Pixels
   
   void   InitHiGainArrays( const Int_t npix, const Int_t nareas, const Int_t nsectors );
Index: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc	(revision 8890)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc	(revision 8891)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.10 2008-05-14 11:03:24 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.11 2008-05-15 18:37:26 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -158,4 +158,10 @@
 Int_t MPedestalSubtract::Process()
 {
+    // Please note:
+    //   - for data with only hi-gain samples numl is 0
+    //   - for data with hi- and lo-gain samples
+    //     numl is 0 if read from a raw-data file or a new MC root-file(?)
+    //     numl is not 0 if read from an old MC root-file
+
     // Total number of samples
     const Int_t numh = fRawEvt->GetNumHiGainSamples();
@@ -167,13 +173,13 @@
 
     // Check for consistency (our simulation can do weird things!)
-    if (numh!=fRunHeader->GetNumSamplesHiGain())
-    {
-        *fLog << warn << "WARNING - Number of hi-gain samples (" << numh << ") ";
-        *fLog << " doesn't match run-header (" << fRunHeader->GetNumSamplesHiGain() << ")." << endl;
-    }
-    if (numl!=fRunHeader->GetNumSamplesLoGain())
-    {
-        *fLog << warn << "WARNING - Number of lo-gain samples (" << numl << ") ";
-        *fLog << " doesn't match run-header (" << fRunHeader->GetNumSamplesLoGain() << ")." << endl;
+    if (numh+numl!=fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain())
+    {
+        *fLog << err << "MPedestalSubtract::Process: ERROR - Number of samples in event ";
+        *fLog << "(hi+lo=" << numh+numl << ")" << endl << " doesn't match number in run-header ";
+        *fLog << "(" << fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain() << ")" << endl;
+        *fLog << " In case you are processing real data you have just found a bug." << endl;
+        *fLog << " If you process Monte Carlo data, it means probably that the length" << endl;
+        *fLog << " of the arrays in MRawEvtData are inconsistent with the run-header." << endl;
+        return kERROR;
     }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 8890)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 8891)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.68 2007-08-10 11:21:21 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.69 2008-05-15 18:37:27 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -219,7 +219,22 @@
 Int_t MExtractTimeAndCharge::Process()
 {
+    const Int_t nums = fSignal->GetNumSamples();
+
     const Int_t numh = fRunHeader->GetNumSamplesHiGain();
     const Int_t numl = fRunHeader->GetNumSamplesLoGain();
 
+    // Some sanity checks to get rid of some weird behaviour of the simulation
+    if (nums!=numh+numl)
+    {
+        *fLog << err << "MExtractTimeAndCharge::Process: ERROR - Number of samples in event ";
+        *fLog << "(" << nums << ")" << endl << " doesn't match number in run-header ";
+        *fLog << "(" << numh+numl << ")" << endl;
+        *fLog << " In case you are processing real data you have just found a bug." << endl;
+        *fLog << " If you process Monte Carlo data, it means probably that the length" << endl;
+        *fLog << " of the arrays in MRawEvtData are inconsistent with the run-header." << endl;
+        return kERROR;
+    }
+
+    // Start extraction
     const UInt_t satlim = fSaturationLimit*fRunHeader->GetScale();
 
