Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7068)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7069)
@@ -21,4 +21,51 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2005/05/20 Thomas Bretz
+   
+   * msignal/MExtractTimeAndChargeSlidingWindow.cc
+     - increased log-gain window from 6 to 8 according to an
+       UNDOCUMENTED change in the bcn cvs
+
+   * mhcalib/MHCalibrationChargePINDiode.cc:
+     - removed a check in fill according to an UDOCUMENTED change
+       in the bcn cvs
+
+   * mhcalib/MHCalibrationChargePINDiode.cc:
+     - use a dynamic_cast for the Fill-argument
+
+   * mjobs/MJCalibration.cc:
+     - shortened output line telling file name of hi-/lo-gain
+       calibration
+
+   * mjobs/MJPedestal.[h,cc]:
+     - moved code for PulsePosCheck into own function
+     - put also code for pixel check into this function
+     - added a sanity check for fExtractor at some places
+
+   * msignal/MExtractor.cc:
+     - added output of pedestal container - if available - in Print()
+
+
+
+ 2005/05/20 Markus Gaug (2005/05/19) 
+
+   * mjobs/MJPedestal.cc:
+    - fixed an important bug in the setting of the incoming pedestal 
+      pointer to the signal extractor. This bug caused the pedestals not
+      to be subtracted correctly in the calibration afterwards. The 
+      effect was about 10% too high conversion factors for the digital 
+      filter and the spline and more than 40% for the sliding window. 
+      The bug existed since end of February! (Markus G.)
+
+
+
+ 2005/05/20 Markus Gaug (2005/05/18) 
+
+   * mcalib/MCalibrationChargeCalc.cc
+     - issue a warning if no colour has been set until the PostProcess.
+       (happens to old MC files).
+
+
+
  2005/05/19 Markus Meyer
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 7068)
+++ trunk/MagicSoft/Mars/NEWS	(revision 7069)
@@ -127,4 +127,16 @@
      hilocalib_sp1.root, hilocalib_df46_mc.root, hilocalib_df4.root, 
      hilocalib_df6.root
+
+   - callisto: The default lo-gain extraction window for the
+     MExtractTimeAndChargeSlidingWindow extractor has been increased 
+     from 6 to 8 to take the stretch of the pusle into account
+
+   - callisto (!!!): fixed an important bug in the setting of the 
+     incoming pedestal pointer to the signal extractor extracting
+     pedestals. This bug caused the pedestals not to be subtracted 
+     correctly in the calibration afterwards. The effect was about 10% 
+     too high conversion factors for the digital filter and the spline
+     and more than 40% for the sliding window. 
+     The bug existed since end of February! (Markus G.)
 
    - star: added muon support to star. A new tab "MHMuonPar" is
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 7068)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 7069)
@@ -657,5 +657,8 @@
 
   if (fPulserColor == MCalibrationCam::kNONE)
-    return kTRUE;
+  {
+      *fLog << warn << "WARNING - No Pulse colour has been set or used at all..." << endl;
+      return kTRUE;
+  }
   
   if (fNumProcessed == 0)
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePINDiode.cc	(revision 7068)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePINDiode.cc	(revision 7069)
@@ -71,4 +71,5 @@
 const TString MHCalibrationChargePINDiode::gsAbsHistXTitle     = "Time [FADC slices]";
 const TString MHCalibrationChargePINDiode::gsAbsHistYTitle     = "Nr. events";
+
 // --------------------------------------------------------------------------
 //
@@ -235,6 +236,5 @@
 {
 
-  MExtractedSignalPINDiode *extractor = (MExtractedSignalPINDiode*)par;
-  
+  const MExtractedSignalPINDiode *extractor = dynamic_cast<const MExtractedSignalPINDiode*>(par);
   if (!extractor)
     {
@@ -243,17 +243,8 @@
     }
   
-  Float_t slices = (Float_t)extractor->GetNumFADCSamples();
-  
-  if (slices == 0.)
-    {
-      *fLog << err << "Number of used signal slices in MExtractedSignalPINDiode is zero  ... abort." 
-            << endl;
-      return kFALSE;
-    }
-  
   const Float_t signal = (float)extractor->GetExtractedSignal();
   const Float_t time   = extractor->GetExtractedTime();
-  const Float_t sigma    = extractor->GetExtractedSigma();
-  const Float_t chi2    = extractor->GetExtractedChi2();
+  const Float_t sigma  = extractor->GetExtractedSigma();
+  const Float_t chi2   = extractor->GetExtractedChi2();
 
   if (time < 3. || time > 24.)
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 7068)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 7069)
@@ -1485,8 +1485,4 @@
 
   MCalibrationHiLoCam hilocam;
-  
-  *fLog << all << "Initializing High gain vs. Low gain intercalibration from " << fHiLoCalibFile << endl;
-  *fLog << all << endl;
-
   if (hilocam.Read()<=0)
   {
@@ -1500,4 +1496,6 @@
       return kFALSE;
   }
+
+  *fLog << all << "Hi-/Lo-Gain intercalibration constants read from " << fHiLoCalibFile << endl << endl;
 
   if (fCalibrationCam.GetSize() < 1)
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 7068)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 7069)
@@ -822,4 +822,147 @@
 }
 
+Bool_t MJPedestal::PulsePosCheck(const MParList &plist) const
+{
+    if (fIsPixelCheck)
+    {
+        MHPedestalCam *hcam = (MHPedestalCam*)plist.FindObject("MHPedestalCam");
+        if (hcam)
+        {
+            MHPedestalPix &pix1 = (MHPedestalPix&)(*hcam)[fCheckedPixId];
+            pix1.DrawClone("");
+        }
+    }
+
+    if (!fIsPulsePosCheck)
+        return kTRUE;
+
+    Int_t numhigainsamples = 0;
+    Int_t numlogainsamples = 0;
+
+    Float_t meanpulsetime  = 0.;
+    Float_t rmspulsetime   = 0.;
+
+    if (IsUseMC())
+    {
+        //
+        // FIXME:
+        // The MC cannot run over the first 2000 pedestal events since almost all
+        // events are empty, therefore a pulse pos. check is not possible, either.
+        // For the moment, have to fix the problem hardcoded...
+        //
+        //            MMcEvt *evt = (MMcEvt*)plist.FindObject("MMcEvt");
+        //            const Float_t meanpulsetime = evt->GetFadcTimeJitter();
+        meanpulsetime = 4.5;
+        rmspulsetime  = 1.0;
+
+        numhigainsamples = 15;
+        numlogainsamples = 15;
+
+    }
+    else
+    {
+        if (fIsPixelCheck)
+        {
+            MHCalibrationPulseTimeCam *hcam = (MHCalibrationPulseTimeCam*)plist.FindObject("MHCalibrationPulseTimeCam");
+            if (!hcam)
+            {
+                *fLog << err << "MHCalibrationPulseTimeCam not found... abort." << endl;
+                return kFALSE;
+            }
+            hcam->DrawClone();
+            gPad->SaveAs(Form("%s/PulsePosTest_all.root",fPathOut.Data()));
+
+            MHCalibrationPix &pix = (*hcam)[fCheckedPixId];
+            pix.DrawClone();
+            gPad->SaveAs(Form("%s/PulsePosTest_Pixel%04d.root",fPathOut.Data(),fCheckedPixId));
+        }
+
+        MCalibrationPulseTimeCam *cam = (MCalibrationPulseTimeCam*)plist.FindObject("MCalibrationPulseTimeCam");
+        if (!cam)
+        {
+            *fLog << err << "MCalibrationPulseTimeCam not found... abort." << endl;
+            return kFALSE;
+        }
+
+        meanpulsetime = cam->GetAverageArea(0).GetHiGainMean();
+        rmspulsetime  = cam->GetAverageArea(0).GetHiGainRms();
+
+        MRawEvtData *data = (MRawEvtData*)plist.FindObject("MRawEvtData");
+        if (!data)
+        {
+            *fLog << err << "MRawEvtData not found... abort." << endl;
+            return kFALSE;
+        }
+
+        numhigainsamples = data->GetNumHiGainSamples();
+        numlogainsamples = data->GetNumLoGainSamples();
+    }
+
+    *fLog << all << "Mean pulse time (" << (IsUseMC()?"MC":"cosmics") << "): ";
+    *fLog << meanpulsetime << "+-" << rmspulsetime << endl;
+
+    const MExtractTimeAndCharge *ext = dynamic_cast<MExtractTimeAndCharge*>(fExtractor);
+
+    //
+    // Get the ranges for the new extractor setting
+    //
+    const Int_t newfirst = TMath::Nint(meanpulsetime-fExtractWinLeft);
+
+    Int_t wshigain = ext ? ext->GetWindowSizeHiGain() : 6;
+    if (wshigain > 6)
+        wshigain = 6;
+
+    Int_t wslogain = ext ? ext->GetWindowSizeLoGain() : 4;
+    if (wslogain > 4)
+        wslogain = 4;
+
+    const Int_t newlast  = TMath::Nint(meanpulsetime+fExtractWinRight);
+
+    *fLog << underline;
+    *fLog << "Try to set new range limits: (" << newfirst << "," << newlast;
+    *fLog << "+" << wshigain << "," << newfirst-1 << "," << newlast << "+";
+    *fLog << wslogain << ")" << endl;
+
+    //
+    // Check the ranges for the new extractor setting
+    //
+    if (newfirst < 0)
+    {
+        *fLog << err << "Pulse is too much to the left, cannot go below 0!" << endl;
+        return kFALSE;
+
+    }
+    if (newlast+wshigain > numhigainsamples+numlogainsamples-1)
+    {
+        *fLog << err << "Pulse is too much to the right, cannot go beyond limits: ";
+        *fLog << numhigainsamples << "+" << numlogainsamples << "-1" << endl;
+        *fLog << " Cannot extract at all!" << endl;
+        return kFALSE;
+    }
+    if (newlast+wslogain > numlogainsamples)
+    {
+        *fLog << err << "Pulse is too much to the right, cannot go beyond logain limits!" << endl;
+        *fLog << endl;
+        *fLog << "Try to use a different extractor (e.g. with a window size of only 4 sl.) or:" << endl;
+        *fLog << "Set the limit to a lower value (callisto.rc):" << endl;
+        *fLog << "    MJPedestalY2:ExtractWinRight: 4.5" << endl;
+        *fLog << "(ATTENTION, you will lose late cosmics pulses!)" << endl;
+        *fLog << endl;
+        return kFALSE;
+    }
+
+    //
+    // Set and store the new ranges
+    //
+    const Int_t hi0 = newfirst;
+    const Int_t hi1 = newlast+wshigain;
+
+    const Int_t lo0 = newfirst>0 ? newfirst-1 : newfirst;
+    const Int_t lo1 = numlogainsamples-1;
+
+    fExtractor->SetRange(hi0, hi1, lo0, lo1);
+    return kTRUE;
+}
+
 Bool_t MJPedestal::Process()
 {
@@ -989,5 +1132,5 @@
     }
     
-    if (fIsUseHists)
+    if (fIsUseHists && fExtractor)
       {
         if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
@@ -1021,4 +1164,5 @@
     if (fExtractor)
     {
+      fExtractor->SetPedestals(&fPedestalCamIn);
 
       if (fExtractionType!=kFundamental)
@@ -1065,51 +1209,4 @@
         *fLog << "windows." << endl;
     }
-    
-    /*
-    switch (fExtractType)
-    {
-    case kUseData:
-        *fLog << all << "TYPE: USEDATA " << fExtractor << endl;
-        taskenv.SetDefault(&pedlogain);
-        tlist.AddToList(&taskenv);
-
-        if (!SetupExtractor(plist, pedlogain))
-        {
-            *fLog << all <<  "SETTING TO: " << fExtractor << " " << fExtractor->GetNumHiGainSamples() << endl;
-            fExtractor->Print();
-            pedlogain.SetExtractWindow(15, (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
-        }
-        break;
-
-    case kUsePedRun:
-        *fLog << all <<  "TYPE: USEPEDRUN " << fExtractor << endl;
-        taskenv.SetDefault(&pedcalc);
-        tlist.AddToList(&taskenv);
-
-        if (!SetupExtractor(plist, pedcalc))
-            pedcalc.SetExtractWindow(fExtractor->GetHiGainFirst(), TMath::Nint(fExtractor->GetNumHiGainSamples()));
-        break;
-
-    case kUseHists:
-        if (!fExtractor)
-        {
-            *fLog << err << GetDescriptor() << " - ERROR: ";
-            *fLog << "Extraction Type is kUseHists, but no extractor was set" << endl;
-            return kFALSE;
-        }
-
-        tlist.AddToList(fExtractor);
-        tlist.AddToList(&fillped);
-        break;
-    } */
-
-    /*
-    if (!fPathIn.IsNull())
-    {
-        delete fExtractor;
-        fExtractor = 0;
-    }
-    */
-
 
     //
@@ -1135,14 +1232,4 @@
     tlist.PrintStatistics();
 
-    if (fIsPixelCheck)
-      {
-        MHPedestalCam *hcam = (MHPedestalCam*)plist.FindObject("MHPedestalCam");
-        if (hcam)
-          {
-            MHPedestalPix &pix1 = (MHPedestalPix&)(*hcam)[fCheckedPixId];
-            pix1.DrawClone("");
-          }
-      }
-    
     if (fDisplayType!=kDisplayNone)
         DisplayResult(plist);
@@ -1151,116 +1238,6 @@
         return kFALSE;
 
-    if (fIsPulsePosCheck)
-      {
-        
-        Int_t numhigainsamples = 0;
-        Int_t numlogainsamples = 0;
-        Float_t meanpulsetime  = 0.;
-        Float_t rmspulsetime   = 0.;
-
-        if (IsUseMC())
-          {
-            //
-            // FIXME:
-            // The MC cannot run over the first 2000 pedestal events since almost all
-            // events are empty, therefore a pulse pos. check is not possible, either. 
-            // For the moment, have to fix the problem hardcoded...
-            //
-            //            MMcEvt *evt = (MMcEvt*)plist.FindObject("MMcEvt");
-            //            const Float_t meanpulsetime = evt->GetFadcTimeJitter();
-            meanpulsetime = 4.5;
-            rmspulsetime  = 1.0;
-
-            *fLog << all << "Mean pulse time (MC): " << meanpulsetime << "+-" << rmspulsetime << endl;
-
-            numhigainsamples = 15;
-            numlogainsamples = 15;
-
-          }
-        else
-          {
-            MHCalibrationPulseTimeCam *hcam = (MHCalibrationPulseTimeCam*)plist.FindObject("MHCalibrationPulseTimeCam");
-            if (fIsPixelCheck)
-              {
-                hcam->DrawClone();
-                gPad->SaveAs(Form("%s/PulsePosTest_all.root",fPathOut.Data()));
-                MHCalibrationPix &pix = (*hcam)[fCheckedPixId];
-                pix.DrawClone();
-                gPad->SaveAs(Form("%s/PulsePosTest_Pixel%04d.root",fPathOut.Data(),fCheckedPixId));
-              }
-            
-            MCalibrationPulseTimeCam *cam = (MCalibrationPulseTimeCam*)plist.FindObject("MCalibrationPulseTimeCam");
-            if (!cam)
-              {
-                *fLog << err << "Could not determine mean pulse position, abort... " << endl;
-                return kFALSE;
-              }
-            
-            meanpulsetime = cam->GetAverageArea(0).GetHiGainMean();
-            rmspulsetime  = cam->GetAverageArea(0).GetHiGainRms();
-
-            *fLog << all << "Mean pulse time (cosmics): " << meanpulsetime << "+-" << rmspulsetime << endl;
-
-            MRawEvtData *data = (MRawEvtData*)plist.FindObject("MRawEvtData");
-
-            numhigainsamples = data->GetNumHiGainSamples();
-            numlogainsamples = data->GetNumLoGainSamples();
-          }
-        
-        //
-        // Get the ranges for the new extractor setting
-        //
-        const Int_t newfirst = TMath::Nint(meanpulsetime-fExtractWinLeft);
-        Int_t wshigain = fExtractor->InheritsFrom("MExtractTimeAndCharge") 
-          ?  ((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeHiGain()
-          : 6;
-
-        if (wshigain > 6)
-          wshigain = 6;
-
-        Int_t wslogain = fExtractor->InheritsFrom("MExtractTimeAndCharge") 
-          ? ((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeLoGain()
-          : 6;
-        if (wslogain > 4)
-          wslogain = 4;
-
-        const Int_t newlast  = TMath::Nint(meanpulsetime+fExtractWinRight);
-
-        *fLog << all << underline 
-              << "Try to set new range limits: ("<<newfirst<<","<<newlast<<"+"<<wshigain
-              <<","<<newfirst-1<<","<<newlast<<"+"<<wslogain<<")"<<endl;
-        //
-        // Check the ranges for the new extractor setting
-        //
-        if (newfirst < 0)
-          {
-            *fLog << err << "Pulse is too much to the left, cannot go below 0! " << endl;
-            return kFALSE;
-          }
-        if (newlast+wshigain > numhigainsamples+numlogainsamples-1)
-          {
-            *fLog << err << "Pulse is too much to the right, cannot go beyond limits: " 
-                  << numhigainsamples << "+" << numlogainsamples << "-1" << endl;
-            *fLog << " Cannot extract at all! ... " << endl;
-            return kFALSE;
-          }
-        if (newlast+wslogain > numlogainsamples)
-          {
-            *fLog << err << "Pulse is too much to the right, cannot go beyond logain limits! " << endl;
-            *fLog << endl;
-            *fLog << "Try to use a different extractor (e.g. with a window size of only 4 sl.) or:" << endl;
-            *fLog << "Set the limit to a lower value (callisto.rc: line 329): " << endl;
-            *fLog << "    MJPedestalY2:ExtractWinRight: 4.5           " << endl;
-            *fLog << "(ATTENTION, you will lose late cosmics pulses!)" << endl;
-            *fLog << endl;
-            return kFALSE;
-          }
-        //
-        // Set and store the new ranges 
-        //
-        fExtractor->SetRange(newfirst,newlast+wshigain,
-                             newfirst>0?newfirst-1:newfirst,numlogainsamples-1);
-      }
-    
+    if (!PulsePosCheck(plist))
+        return kFALSE;
 
     *fLog << all << GetDescriptor() << ": Done." << endl;
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 7068)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 7069)
@@ -26,5 +26,4 @@
 {
 private:
-
     static const TString  fgReferenceFile;    //! default for fReferenceFile ("pedestalref.rc")
     static const TString  fgBadPixelsFile;    //! default for fBadPixelsFile ("badpixels_0_559.rc")
@@ -83,4 +82,5 @@
     void   DisplayOutliers(TH1D *hist) const;
     void   FixDataCheckHist(TH1D *hist) const;
+    Bool_t PulsePosCheck(const MParList &plist) const;
 
     Bool_t CheckEnvLocal();
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 7068)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 7069)
@@ -75,5 +75,5 @@
 const Byte_t  MExtractTimeAndChargeSlidingWindow::fgLoGainLast   = 14;
 const Byte_t  MExtractTimeAndChargeSlidingWindow::fgHiGainWindowSize = 6;
-const Byte_t  MExtractTimeAndChargeSlidingWindow::fgLoGainWindowSize = 6;
+const Byte_t  MExtractTimeAndChargeSlidingWindow::fgLoGainWindowSize = 8;
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 7068)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 7069)
@@ -434,3 +434,5 @@
     *fLog << " Saturation Lim:     " << (int)fSaturationLimit << endl;
     *fLog << " Num Samples HiGain: " << fNumHiGainSamples << "  LoGain: " << fNumLoGainSamples << endl;
-}
+    if (fPedestals)
+        *fLog << " Pedestals:          " << fPedestals->GetName() << ", " << fPedestals << endl;
+}
