Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6819)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6820)
@@ -21,11 +21,58 @@
 
                                                  -*-*- END OF LINE -*-*-
- 2005/03/14 Toni Coarasa
-   Please use the new CVS
-
  2005/03/14 Thomas Bretz
 
    * mbase/MGMenu.h:
      - added a fix for root 4.02.00
+
+
+ 2005/03/14 Markus Gaug
+
+   * mcalib/MCalibrateData.cc
+     - catch the case that now high-gain low-gian intercalibration const.
+       is available.
+
+   * mjobs/MJPedestal.cc
+     - modify option for pedy*.root: from UPDATE to RECREATE
+
+
+
+ 2005/03/11 Markus Gaug
+
+   * callisto.rc
+     - changed default weights for DF to cosmics_weights4.dat. (This has 
+       turned out to be the most stable set of weights). 
+
+   * mjobs/MJCalibration.cc
+     - some cosmetic changes in the output
+     - in case of WriteHists(), do not overwrite existing signal*.root 
+       file, but append histograms (bugfix!)
+
+
+
+ 2005/03/10 Toni Coarasa (With Nadia's and Alessandro's inside)
+
+   * mjobs/MJCut.cc
+     - inclusion of (TString) to avoid compiler error under 2.95.3
+
+   * sinope.cc
+     - inclusion of <errno.h> to avoid compiler error under 2.95.3
+
+
+
+ 2005/03/10 Markus Gaug
+
+   * msignal/MExtractTimeAndCharge.cc
+     - set fgLoGainStartShift to -4.0
+     - put a check to avoid a dynamic low-gain range < 0 (should not 
+       occur with current extractors, but one never knows...)
+
+   * msignal/MExtractor.[h,cc]
+     - introduced Clear()-function, used in SetRange()
+
+   * mjobs/MJCalibrateSignal.cc
+     - changed order of initialization of the 2 MWriteRootFiles whereupon
+       the crash goes away. Have to revise the /dev/null work-around 
+       in MWriteRootFile!
 
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 6820)
@@ -669,6 +669,14 @@
             if (sig.IsLoGainUsed())
             {
-                signal    = sig.GetExtractedSignalLoGain()*fHiLoConv   [pixidx];
-                signalErr = sig.GetExtractedSignalLoGain()*fHiLoConvErr[pixidx];
+              if (fHiLoConv[pixidx] < 0.5)
+                {
+                  signal    = sig.GetExtractedSignalHiGain()*1.5;
+                  signalErr = sig.GetExtractedSignalHiGain()*2.;
+                }
+              else
+                {
+                  signal    = sig.GetExtractedSignalLoGain()*fHiLoConv   [pixidx];
+                  signalErr = sig.GetExtractedSignalLoGain()*fHiLoConvErr[pixidx];
+                }
             }
             else
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 6820)
@@ -159,6 +159,9 @@
 Bool_t MJCalibrateSignal::WriteResult(TObjArray &cont)
 {
-    const TString name(Form("signal%08d.root", fSequence.GetSequence()));
-    return WriteContainer(cont, name);
+  if (IsNoStorage())
+    return kTRUE;
+
+  const TString name(Form("signal%08d.root", fSequence.GetSequence()));
+  return WriteContainer(cont, name);
 }
 
@@ -367,24 +370,4 @@
 
     *fLog << all;
-    if (extractor1)
-    {
-        *fLog << underline << "Signal Extractor found in calibration file" << endl;
-        extractor1->Print();
-        *fLog << endl;
-	extractor3 = (MExtractor*)extractor1->Clone();
-        
-    }
-    else
-        *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
-
-    if (extractor2)
-    {
-        *fLog << underline << "Time Extractor found in calibration file" << endl;
-        extractor2->Print();
-        *fLog << endl;
-    }
-    else
-        *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
-
     if (!geom.IsNull())
         *fLog << inf << "Camera geometry found in file: " << geom << endl;
@@ -395,4 +378,23 @@
       if (!ReadExtractorCosmics(extractor1))
         *fLog << warn << "No extraction window update for signal extractor found" << endl;
+
+    if (extractor1)
+    {
+      *fLog << underline << "Signal Extractor found in calibration file" << endl;
+      extractor1->Print();
+      *fLog << endl;
+      extractor3 = (MExtractor*)extractor1->Clone();
+    }
+    else
+      *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
+
+    if (extractor2)
+    {
+        *fLog << underline << "Time Extractor found in calibration file" << endl;
+        extractor2->Print();
+        *fLog << endl;
+    }
+    else
+        *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
 
     // This is necessary for the case in which it is not in the files
@@ -436,9 +438,5 @@
     const TString fname(Form("%s{s/_D_/_Y_}{s/.raw$/.root}", fPathOut.Data()));
 
-    // Write the special MC tree
-    MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
-    writemc.SetName("WriteMC");
-    writemc.AddContainer("MMcEvtBasic", "OriginalMC");
-
+    
     // Skips empty MC events (Not necessary, but faster!)
     MContinue contmc("MRawEvtData.GetNumPixels<0.5", "ContEmptyMC");
@@ -689,4 +687,9 @@
     write.AddContainer("MTimeCC",                   "CC",         kFALSE);
 
+    // Write the special MC tree
+    MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
+    writemc.SetName("WriteMC");
+    writemc.AddContainer("MMcEvtBasic", "OriginalMC");
+
     // Now setup tasklist for events
     MTaskList tlist2;
@@ -836,13 +839,13 @@
       interlacedcont.Add(&hilcam);
 
+    if (IsHistsStorage())
+      {
+        interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
+        interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
+      }
+    
     if (!WriteResult(interlacedcont))
       return kFALSE;
 
-    //    if (IsHistsStorage())
-    //      {
-    //        addcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
-    //        addcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
-    //      }
-    
     // return if job went ok
     *fLog << all << GetDescriptor() << ": Done." << endl;
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 6820)
@@ -177,5 +177,5 @@
 const Int_t MJCalibration::gkThirdBlindPixelInstallation   = 43308;
 const TString MJCalibration::fgReferenceFile = "mjobs/calibrationref.rc";
-const TString MJCalibration::fgHiLoCalibFile = "mjobs/hilocalib_df6.root";
+const TString MJCalibration::fgHiLoCalibFile = "mjobs/hilocalib_df4.root";
 // --------------------------------------------------------------------------
 //
@@ -1482,4 +1482,7 @@
   MCalibrationHiLoCam hilocam;
   
+  *fLog << all << "Initializing High gain vs. Low gain intercalibration from " << fHiLoCalibFile << endl;
+  *fLog << all << endl;
+
   if (hilocam.Read()<=0)
   {
@@ -1712,10 +1715,4 @@
     }
 
-    //if (!CheckEnv())
-    //    return kFALSE;
-
-    if (!CheckEnv())
-      return kFALSE;
-
     // --------------------------------------------------------------------------------
 
@@ -1732,4 +1729,9 @@
     // --------------------------------------------------------------------------------
     
+    if (!CheckEnv())
+      return kFALSE;
+
+    // --------------------------------------------------------------------------------
+
     // Setup Tasklist
     MParList plist;
@@ -1975,33 +1977,35 @@
     tlist.PrintStatistics();
 
-  if (fIsPixelCheck)
-    {
-      MHCalibrationChargeCam *hcam = (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
-      MHCalibrationChargePix &pix1 = (MHCalibrationChargePix&)(*hcam)[fCheckedPixId];
-      pix1.DrawClone("");
-      
-      MHCalibrationChargePix &pix2 = (MHCalibrationChargePix&)(*hcam)(fCheckedPixId);
-      pix2.DrawClone("");
-      
-      if (IsRelTimes())
-	{
-	  MHCalibrationRelTimeCam *hccam = (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
-	  MHCalibrationPix &pix11 = (*hccam)[fCheckedPixId];
-	  pix11.DrawClone("");
-	  MHCalibrationPix &pix12 = (*hccam)(fCheckedPixId);
-	  pix12.DrawClone("");
-	}
-    }
-
+    // --------------------------------------------------------------------------------
+
+    if (fIsPixelCheck)
+      {
+        MHCalibrationChargeCam *hcam = (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
+        MHCalibrationChargePix &pix1 = (MHCalibrationChargePix&)(*hcam)[fCheckedPixId];
+        pix1.DrawClone("");
+        
+        MHCalibrationChargePix &pix2 = (MHCalibrationChargePix&)(*hcam)(fCheckedPixId);
+        pix2.DrawClone("");
+        
+        if (IsRelTimes())
+          {
+            MHCalibrationRelTimeCam *hccam = (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
+            MHCalibrationPix &pix11 = (*hccam)[fCheckedPixId];
+            pix11.DrawClone("");
+            MHCalibrationPix &pix12 = (*hccam)(fCheckedPixId);
+            pix12.DrawClone("");
+          }
+      }
+    
     if (!fCalibrationPINDiode.IsValid())
-        SetUsePINDiode(kFALSE);
-
+      SetUsePINDiode(kFALSE);
+    
     DisplayResult(plist);
-
+    
     if (!WriteResult(plist))
-        return kFALSE;
-
+      return kFALSE;
+    
     *fLog << all << GetDescriptor() << ": Done." << endl;
-
+    
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 6820)
@@ -347,6 +347,6 @@
     TString fname0(path);
     TString fname1(path);
-    fname0 += fNameSummary.IsNull() ? Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
-    fname1 += fNameResult.IsNull()  ? Form("ganymed%08d-result.root",  set.GetNumAnalysis()) : fNameResult;
+    fname0 += fNameSummary.IsNull() ?  (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
+    fname1 += fNameResult.IsNull()  ?  (TString) Form("ganymed%08d-result.root",  set.GetNumAnalysis()) : fNameResult;
 
     MWriteRootFile write0(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW");
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 6820)
@@ -179,4 +179,11 @@
     const TString fname = GetOutputFile();
 
+    const Bool_t fileexist = !gSystem->AccessPathName(fname, kFileExists);
+    if (!fileexist)
+      {
+        *fLog << inf << "Input file " << fname << " not found, will create pedestals" << endl;
+        return kFALSE;
+      }
+
     *fLog << inf << "Reading pedestals from file: " << fname << endl;
 
@@ -242,8 +249,9 @@
   *fLog << inf << "Updating extractor in file: " << fname << endl;
 
-  TFile file(fname, "UPDATE");
+  TFile file(fname, fOverwrite?"RECREATE":"NEW");
   if (!file.IsOpen())
     {
       *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
+      *fLog << err << dbginf << "Maybe, file " << fname << " already exists, call callisto with option -f then." << endl;
       return kFALSE;
     }
@@ -252,5 +260,5 @@
   cont.Add(fExtractor);
 
-  return WriteContainer(cont,name, fOverwrite?"RECREATE":"NEW");
+  return WriteContainer(cont);
 }
 
@@ -914,5 +922,6 @@
         if (fRuns && fRuns->GetNumRuns() != fRuns->GetNumEntries())
         {
-            *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
+            *fLog << err << "Number of files found doesn't match number of runs... abort."
+                << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
             return kFALSE;
         }
@@ -1007,7 +1016,9 @@
     
     MHPedestalCam hpedcam;
-    hpedcam.SetRenorm(kTRUE);
+    if (fExtractionType != kFundamental)
+      hpedcam.SetRenorm(kTRUE);
     //    fPedestalHist.SetRenorm(kTRUE);
     //    fPedestalHist.SetPedestalsOut(&fPedestalCamOut);
+    hpedcam.SetPedestalsOut(&fPedestalCamOut);
 
     MPedestalCam pedinter;
@@ -1038,5 +1049,5 @@
     sel.SetNumSelectEvts(0);
      
-    if (fExtractionType!=kFundamental && fExtractor)
+    if (fExtractor)
       {
         fExtractor->SetFilter(&sel);
@@ -1077,5 +1088,8 @@
     
     if (fIsUseHists)
-    {
+      {
+        if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
+          hpedcam.SetFitStart(-10.*((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeHiGain());
+        
         pedcalc.SetIntermediateStorage();
         pedlogain.SetIntermediateStorage();
@@ -1248,5 +1262,5 @@
             const Float_t meanpulsetime = cam->GetAverageArea(0).GetHiGainMean();
             const Float_t rmspulsetime = cam->GetAverageArea(0).GetHiGainRms();
-            *fLog << inf << "Mean pulse time (cosmics): " << meanpulsetime << "+-" << rmspulsetime << endl;
+            *fLog << all << "Mean pulse time (cosmics): " << meanpulsetime << "+-" << rmspulsetime << endl;
             const Int_t newfirst = (Int_t)(meanpulsetime-fExtractWinLeft);
             Int_t wshigain = fExtractor->InheritsFrom("MExtractTimeAndCharge") 
@@ -1255,10 +1269,13 @@
             if (wshigain > 6)
               wshigain = 6;
-            const Int_t wslogain = fExtractor->InheritsFrom("MExtractTimeAndCharge") 
+            Int_t wslogain = fExtractor->InheritsFrom("MExtractTimeAndCharge") 
               ? ((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeLoGain()
               : 6;
+            if (wslogain > 6)
+              wslogain = 6;
             const Int_t newlast  = (Int_t)(meanpulsetime+fExtractWinRight);
-            *fLog << inf << "Try to set new range limits: ("<<newfirst<<","<<newlast<<"+"<<wshigain
-                  <<","<<newfirst<<","<<newlast<<"+"<<wslogain<<")"<<endl;
+            *fLog << all << underline 
+                  << "Try to set new range limits: ("<<newfirst<<","<<newlast<<"+"<<wshigain
+                  <<","<<newfirst-1<<","<<newlast<<"+"<<wslogain<<")"<<endl;
             if (newfirst < 0)
               {
@@ -1274,9 +1291,15 @@
             if (newlast+wslogain > data->GetNumLoGainSamples())
               {
-                *fLog << err << "Pulse is too much to the right, cannot go beyond logain limits! " 
-                      << " Try to use a different extractor ... " << endl;
+                *fLog << err << "Pulse is too much to the right, cannot go beyond logaie 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 310): " << endl;
+                *fLog << "    MJPedestalY2:ExtractWinRight: 5.0           " << endl;
+                *fLog << "(ATTENTION, you will lose late cosmics pulses!)" << endl;
+                *fLog << endl;
                 return kFALSE;
               }
-            fExtractor->SetRange(newfirst,newlast+wshigain,newfirst,data->GetNumLoGainSamples()-1);
+            fExtractor->SetRange(newfirst,newlast+wshigain,
+                                 newfirst>0?newfirst-1:newfirst,data->GetNumLoGainSamples()-1);
             if (!WriteExtractor())
               {
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 6820)
@@ -85,5 +85,5 @@
 using namespace std;
 
-const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -2.8; 
+const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -4.0; 
 const Byte_t  MExtractTimeAndCharge::fgLoGainSwitch = 120; 
 // --------------------------------------------------------------------------
@@ -217,6 +217,6 @@
           fLoGainFirstSave = fLoGainFirst;
           const Byte_t logainstart = sathi 
-            ? (sathi > (Int_t)fLoGainStartShift ? sathi + (Int_t)fLoGainStartShift : fLoGainFirst)
-            : (Byte_t)(timehi + fLoGainStartShift);
+            ? (sathi > (Int_t)(-fLoGainStartShift) ? sathi + (Int_t)fLoGainStartShift : fLoGainFirst)
+            : (timehi+fLoGainStartShift > 0. ? (Byte_t)(timehi + fLoGainStartShift) : fLoGainFirst);
           fLoGainFirst = logainstart > fLoGainFirstSave ? logainstart : fLoGainFirstSave;
 
Index: trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 6820)
@@ -133,9 +133,12 @@
 void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
 {
-    fHiGainFirst = hifirst;
-    fHiGainLast  = hilast;
-
-    fLoGainFirst = lofirst;
-    fLoGainLast  = lolast;
+ 
+  Clear();
+
+  fHiGainFirst = hifirst;
+  fHiGainLast  = hilast;
+  
+  fLoGainFirst = lofirst;
+  fLoGainLast  = lolast;
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractor.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 6819)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 6820)
@@ -72,4 +72,9 @@
   MExtractor(const char *name=NULL, const char *title=NULL);
   
+  void Clear(Option_t *o="") 
+    {
+      fHiGainFirst = fHiGainLast = fLoGainFirst = fLoGainLast = fHiLoLast = 0;
+    }
+
   Byte_t  GetHiGainFirst()      const { return fHiGainFirst;      }
   Byte_t  GetHiGainLast ()      const { return fHiGainLast ;      }
Index: trunk/MagicSoft/Mars/sinope.cc
===================================================================
--- trunk/MagicSoft/Mars/sinope.cc	(revision 6819)
+++ trunk/MagicSoft/Mars/sinope.cc	(revision 6820)
@@ -1,2 +1,3 @@
+#include <errno.h>
 #include <fstream>
 
