Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5531)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5532)
@@ -27,4 +27,8 @@
 
  2004/11/30: Markus Gaug
+
+   * macros/calibration.C
+     - new version incorporating the possibility to calculate the 
+       extractor resolution
 
    * msignal/cosmics_weights_logaintest.dat
Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 5531)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 5532)
@@ -55,18 +55,10 @@
 //
 //////////////////////////////////////////////////////////////////////////////////////////
+#include "getExtractor.C"
+
 #include "MJPedestal.h"
 #include "MJCalibration.h"
 #include "MJExtractSignal.h"
 #include "MJExtractCalibTest.h"
-#include "MExtractFixedWindowPeakSearch.h"
-#include "MExtractSlidingWindow.h"
-#include "MExtractFixedWindow.h"
-#include "MExtractFixedWindowSpline.h"
-#include "MExtractAmplitudeSpline.h"
-#include "MExtractTimeHighestIntegral.h"
-#include "MExtractTimeFastSpline.h"
-#include "MExtractTimeAndChargeDigitalFilter.h"
-#include "MExtractTimeAndChargeSlidingWindow.h"
-#include "MExtractTimeAndChargeSpline.h"
 #include "MRunIter.h"
 #include "MStatusDisplay.h"
@@ -76,5 +68,4 @@
 #include "MArgs.h"
 #include "MArray.h"
-#include "MLog.h"
 #include "MParContainer.h"
 
@@ -82,24 +73,23 @@
 #include "TObject.h"
 #include "TObjectTable.h"
-#include "TSystem.h"
-
-#include <fstream>
+#include "TCanvas.h"
+#include "TPad.h"
+#include "TH1.h"
+#include "TPaveStats.h"
 
 using namespace std;
 
 static TString outpath = "./";
-static TString inpath  = "/home/rootdata/Calib/2004_07_06";
-static TString badfile = "";
-//static TString badfile = "badpixels_only0_559_560.dat";
-static TString weightfile = "msignal/calibration_weights_UV.dat";
-//static TString weightfile = "msignal/cosmics_weights.dat";
+static TString inpath  = "/home/rootdata/Calib/2004_09_22";
+//static TString badfile = "";
+static TString badfile = "badpixels_only0_388_559.dat";
 //
 // the default pedestal run for the calibration
 //
-static const Int_t   pedrun  = 31756;
+static const Int_t   pedrun  = 38995;
 //
 // the default start calibration run 
 //
-static const Int_t   calrun1 = 31755;
+static const Int_t   calrun1 = 38997;
 //
 // the default last calibration run (if 0, only one run is taken, otherwise consecutive runs 
@@ -120,12 +110,4 @@
 static Bool_t pindiode = kTRUE;
 //
-// Tell if you want to calibrate times:
-//
-static Bool_t useTimes = kTRUE;
-//
-// Tell if you want to use a combined extractor:
-//
-static Bool_t useTimeAndCharge = kTRUE;
-//
 // Tell if you want to use the display:
 //
@@ -140,60 +122,35 @@
 static Bool_t useIntensity = kFALSE;
 //
-// Tell if you want to use MPedCalcFromLogain for the pedestal calculation
-//
-static Bool_t usedata      = kFALSE;
-//
 // Tell if you want to store and read the F0 and F1- files
 //
 static Bool_t usestorage   = kFALSE;
 //
-Int_t calibration(const Int_t prun=pedrun, 
+// Tell which extractor you want to use. The flags are counted according 
+// to the extractor-TDAS
+// 
+static Int_t extractorflag = 1;
+//
+Int_t calibration(const UInt_t extflag=extractorflag, const Int_t prun=pedrun, 
                   const Int_t crun1=calrun1, const Int_t crun2=calrun2)
 {
 
+  MExtractor *extractor = getExtractor(extflag);
+
+  if (!extractor)
+    return 99;
+
+  extractor->SetName(Form("%s_Run_%05d",extractor->GetName(),prun));
+  const Bool_t timeandcharge = extractor->InheritsFrom("MExtractTimeAndCharge");
+
+  gStyle->SetOptStat(1111);
+  gStyle->SetOptFit();
+  gStyle->SetTitleSize(0.35,"u");
+  gStyle->SetTitleFontSize(0.9);
+  gStyle->SetTitleH(0.12);
+  gStyle->SetTitleW(0.95);
+  gStyle->SetLineWidth(1);
+
   if (debug)
     TObject::SetObjectStat(kTRUE);
-
-  //
-  // Choose the signal Extractor:
-  //
-  // PURE CHARGE EXTRACTORS:
-  //  MExtractFixedWindowPeakSearch  extractor;
-  //  MExtractSlidingWindow         extractor;   
-  //  MExtractFixedWindow           extractor;
-  //  MExtractFixedWindowSpline     extractor;
-  //  MExtractAmplitudeSpline       extractor;
-  //
-  // PURE TIME EXTRACTORS:
-  // ATTENTION: If an extractor deriving from MExtractTimeAndCharge is
-  //            used, you may want to use the timing calculated directly
-  //            from there. Use the flag: "useTimeAndCharge" in this case
-  //
-  //  MExtractTimeHighestIntegral timeext;
-  MExtractTimeFastSpline timeext;
-  //  MExtractTimeSpline timeext;
-  //
-  // COMBINED TIME AND CHARGE EXTRACTORS:
-  // (You have to set the variable "useTimeAndCharge" in order to use the 
-  //  time calculated by this extractor!)
-  MExtractTimeAndChargeDigitalFilter extractor;
-  //  MExtractTimeAndChargeSpline   extractor;
-  //  MExtractTimeAndChargeSlidingWindow extractor;
-  //
-  //  Set Ranges or Windows
-  //
-  //  extractor.SetRange(1,14,4,12);
-  //  extractor.SetWindowSize(6,6);
-  //  timeext.SetRange(1,14,4,12);
-  //  timeext.SetWindowSize(6,6);
-  //
-  // Set additional information for some extractors
-  //
-  // Digital Filter:
-  extractor.ReadWeightsFile(weightfile.Data());
-  //  extractor.ReadWeightsFile("");
-  // TimeAndChargeSpline:
-  //  extractor.SetChargeType(MExtractTimeAndChargeSpline::kIntegral);
-  //  extractor.SetTimeType(MExtractTimeAndChargeSpline::kHalfMaximum);
 
   MRunIter pruns;
@@ -207,9 +164,4 @@
     cruns.AddRuns(crun1,crun2,inpath);
 
-  gStyle->SetOptStat(1111);
-  gStyle->SetOptFit();
-  gStyle->SetTitleSize(0.1,"u");
-  gStyle->SetLineWidth(1);
-
   MStatusDisplay *display = NULL;
 
@@ -221,8 +173,7 @@
     }
   
-  /************************************/
-  /* FIRST LOOP: PEDESTAL COMPUTATION */
-  /************************************/
-
+  /*****************************************/
+  /* FIRST LOOP: PURE PEDESTAL COMPUTATION */
+  /*****************************************/
   //
   // Hand over to the jobs a QE Cam with Cornings initialized
@@ -241,20 +192,18 @@
     }
 
-  MJPedestal pedloop;
-  if (usedata)
-   pedloop.SetUseData();
-  pedloop.SetNoStorage(!usestorage);
-  pedloop.SetEnvDebug(debug);
-  pedloop.SetExtractor(&extractor);
-  pedloop.SetInput(&pruns);
-  pedloop.SetPathOut(outpath.Data());
+  MJPedestal pedloop1;
+  pedloop1.SetNoStorage(!usestorage);
+  pedloop1.SetEnvDebug(debug);
+  pedloop1.SetExtractor(extractor);
+  pedloop1.SetInput(&pruns);
+  pedloop1.SetPathOut(outpath.Data());
   if (useDisplay)
     {
-      pedloop.SetDisplay(display);
-      pedloop.SetDataCheckDisplay();
-    }
-  pedloop.SetBadPixels(badcam);
-
-  if (!pedloop.Process())
+      pedloop1.SetDisplay(display);
+      pedloop1.SetDataCheckDisplay();
+    }
+  pedloop1.SetBadPixels(badcam);
+  
+  if (!pedloop1.Process())
     return 1;
 
@@ -263,5 +212,36 @@
   /****************************************/
 
+  MJPedestal    pedloop2;
   MJCalibration calloop;
+
+  if (timeandcharge)
+    {
+      /***********************************************************/
+      /* NEEDE FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
+      /***********************************************************/
+      
+      pedloop2.SetUseData();
+      pedloop2.SetNoStorage(!usestorage);
+      pedloop2.SetEnvDebug(debug);
+      pedloop2.SetExtractor(extractor);
+      pedloop2.SetExtractorResolution();
+      pedloop2.SetPedestals(pedloop1.GetPedestalCam());  
+      pedloop2.SetInput(&pruns);
+      pedloop2.SetPathOut(outpath.Data());
+      if (useDisplay)
+        {
+          pedloop2.SetDisplay(display);
+          pedloop2.SetDataCheckDisplay();
+        }
+      pedloop2.SetBadPixels(badcam);
+      
+      if (!pedloop2.Process())
+        return 1;
+      
+      extractor->SetNoiseCalculation(kFALSE);
+      calloop.SetExtractorCam(pedloop2.GetPedestalCam());
+    }
+
+  MPedestalCam &pedcam = pedloop1.GetPedestalCam();
 
   if (debug)
@@ -289,8 +269,5 @@
   // If you want to calibrate the times as well, choose:
   //
-  calloop.SetRelTimeCalibration(useTimes);
-  calloop.SetExtractor(&extractor);
-  calloop.SetTimeAndCharge(useTimeAndCharge);
-  calloop.SetTimeExtractor(&timeext);
+  calloop.SetExtractor(extractor);
   calloop.SetInput(&cruns);
   calloop.SetPathOut(outpath.Data());
@@ -300,7 +277,7 @@
   calloop.SetUsePINDiode(pindiode);
   calloop.SetQECam(qecam);
-  calloop.SetBadPixels(pedloop.GetBadPixels());
-
-  if (!calloop.Process(pedloop.GetPedestalCam()))
+  calloop.SetBadPixels(pedloop1.GetBadPixels());
+
+  if (!calloop.Process(pedcam))
     return 2;
 
@@ -331,6 +308,5 @@
       testloop.SetDataCheckDisplay();
 
-      testloop.SetExtractor(&extractor);
-      testloop.SetTimeExtractor(&timeext);
+      testloop.SetExtractor(extractor);
       testloop.SetInput(&cruns);
       testloop.SetPathOut(outpath);
@@ -339,9 +315,7 @@
       testloop.SetBadPixels(calloop.GetBadPixels());
       
-      if (!testloop.ProcessD(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
+      if (!testloop.ProcessD(pedloop1.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
         return 3;
       
-      if (useTimes)
-        if (!testloop.ProcessT(pedloop.GetPedestalCam(),calloop.GetRelTimeCam()))
       return 4;
       
@@ -354,6 +328,5 @@
   MJExtractSignal pedphotloop;
 
-  pedphotloop.SetExtractor(&extractor);
-  pedphotloop.SetTimeExtractor(&timeext);
+  pedphotloop.SetExtractor(extractor);
   pedphotloop.SetInput(&pruns);
   pedphotloop.SetOutputPath(outpath);
@@ -362,5 +335,5 @@
   pedphotloop.SetBadPixels(calloop.GetBadPixels());
   
-  if (!pedphotloop.ProcessP(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
+  if (!pedphotloop.ProcessP(pedloop1.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
     return 5;
 
@@ -375,5 +348,4 @@
 
   return 0;
-
 }
 
@@ -393,4 +365,59 @@
     gLog << endl;
     gLog << "Additional Options: " << endl;
+    gLog << "     --extractor=#    Choose one of the following possible extractors (integer)" << endl;
+    gLog << endl;
+    gLog << "    Nr.    Extractor   Parameters " << endl;
+    gLog << endl;    
+    gLog << "       MExtractFixedWindow: " << endl;
+    gLog << "           with the following parameters, if 'maxbin' defines the mean position" << endl;
+    gLog << "           of the High-Gain FADC slice carrying the pulse maximum: " << endl;
+    gLog << "     1:           SetRange('maxbin}}-1,'maxbin}}+2,'maxbin}}+0.5,'maxbin}}+3.5) " << endl;
+    gLog << "     2:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'-0.5,'maxbin'+4.5)" << endl;
+    gLog << "     3:           SetRange('maxbin'-2,'maxbin'+3,'maxbin'-0.5,'maxbin'+4.5)" << endl;
+    gLog << "     4:           SetRange('maxbin'-3,'maxbin'+4,'maxbin'-1.5,'maxbin'+5.5)" << endl;
+    gLog << "     5:           SetRange('maxbin'-5,'maxbin'+8,'maxbin'-1.5,'maxbin'+7.5)" << endl;
+    gLog << "       MExtractFixedWindowSpline: " << endl;
+    gLog << "     6:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'+0.5,'maxbin'+3.5)" << endl;
+    gLog << "     7:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'-0.5,'maxbin'+4.5)" << endl;
+    gLog << "     8:           SetRange('maxbin'-2,'maxbin'+3,'maxbin'-0.5,'maxbin'+4.5)" << endl;
+    gLog << "     9:           SetRange('maxbin'-3,'maxbin'+4,'maxbin'-1.5,'maxbin'+5.5)" << endl;
+    gLog << "     10:          SetRange('maxbin'-5,'maxbin'+8,'maxbin'-1.5,'maxbin'+7.5)" << endl;
+    gLog << "       MExtractFixedWindowPeakSearch: " << endl;
+    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl;
+    gLog << "     11:          SetWindows(2,2,2)" << endl;
+    gLog << "     12:          SetWindows(4,4,2)" << endl;
+    gLog << "     13:          SetWindows(6,6,4)" << endl;
+    gLog << "     14:          SetWindows(4,6,4)" << endl;
+    gLog << "     15:          SetWindows(8,8,4)" << endl;
+    gLog << "     16:          SetWindows(14,10,4)" << endl;
+    gLog << "      MExtractTimeAndChargeSlidingWindow:" << endl;
+    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl;
+    gLog << "     17:          SetWindowSize(2,2)" << endl;
+    gLog << "     18:          SetWindowSize(4,4)" << endl;
+    gLog << "     19:          SetWindowSize(6,6)" << endl;
+    gLog << "     20:          SetWindowSize(4,6)" << endl;
+    gLog << "     21:          SetWindowSize(8,8)" << endl;
+    gLog << "     22:          SetWindowSize(14,10)" << endl;
+    gLog << "      MExtractTimeAndChargeSpline: " << endl; 
+    gLog << "                  SetChargeType(MExtractTimeAndChargeSpline::kIntegral) and:" << endl;
+    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl; 
+    gLog << "     23:          SetRiseTime(1.5); SetFallTime(4.5)" << endl;
+    gLog << "     24:          SetRiseTime(0.5); SetFallTime(2.5)" << endl;
+    gLog << "     25:          SetRiseTime(0.5); SetFallTime(1.5)" << endl;
+    gLog << "     26:          SetRiseTime(0.5); SetFallTime(0.5)" << endl;
+    gLog << "     27:          SetChargeType(MExtractTimeAndChargeSpline::kAmplitude" << endl;
+    gLog << "                  SetRange(0,10,4,11)" << endl; 
+    gLog << "      MExtractTimeAndChargeDigitalFilter" << endl;
+    gLog << "                  SetRange(0,18,2,14) and the following parameters:" << endl; 
+    gLog << "     28:          SetNameWeightsFile('msignal/cosmics_weights.dat')" << endl;
+    gLog << "     29:          SetNameWeightsFile('msignal/cosmics_weights4.dat')" << endl;
+    gLog << "     30:          SetNameWeightsFile('msignal/cosmics_weights_logain6.dat')" << endl;
+    gLog << "     31:          SetNameWeightsFile('msignal/cosmics_weights_logain4.dat')" << endl;
+    gLog << "     32:          SetNameWeightsFile('msignal/calibration_weights_UV.dat')" << endl;
+    gLog << "     33:          SetNameWeightsFile('msignal/calibration_weights_UV4.dat')" << endl;
+    gLog << "     34:          SetNameWeightsFile('msignal/calibration_weights_UV_logain6.dat')" << endl;
+    gLog << "     35:          SetNameWeightsFile('msignal/calibration_weights_UV_logain4.dat')" << endl;
+    gLog << "     36:  Real Fit: (not yet implemented)" << endl;
+    gLog << endl;
     gLog << "     --inpath=#          Find the data in inpath"                      << endl;
     gLog << "     --outpath=#         Write the output containers to outpath"       << endl;
@@ -398,5 +425,4 @@
     gLog << "     --debug             Use the TObjectTable for debugging    "       << endl;
     gLog << "                             and write out the pixels as ascii tables" << endl;
-    gLog << "     --useTimes          Calibrate the relative arrival times"         << endl;
     gLog << "     --useTest           Use the class MJExtractCalibTest to test the calibration on itself" << endl;
     gLog << "     --skipBlindPix      Skip the blind pixel calibration"             << endl;
@@ -419,8 +445,10 @@
   
   debug    = arg.HasOnlyAndRemove("--debug")    || arg.HasOnlyAndRemove("-d");
-  useTimes = arg.HasOnlyAndRemove("--useTimes") || arg.HasOnlyAndRemove("-t");
   useTest  = arg.HasOnlyAndRemove("--useTest")  || arg.HasOnlyAndRemove("-e");
   blindpix = !(arg.HasOnlyAndRemove("--skipBlindPix"));
   pindiode = !(arg.HasOnlyAndRemove("--skipPINDiode"));
+
+  if (arg.HasOption("--extractor="))
+    extractorflag = arg.GetIntAndRemove("--extractor=");
 
   if (arg.HasOption("--inpath="))
@@ -455,7 +483,5 @@
   // Switch off the display
   //
-  useDisplay = kFALSE;
-
-
+  useDisplay = kTRUE;
   //
   // check for the arguments
@@ -479,5 +505,8 @@
       pedr = arg.GetArgumentInt(0);
       calr1 = arg.GetArgumentInt(1);
-      return calibration(pedr,calr1);
+      gLog << "PEDR: " << pedr << " CALR1: " << calr1 << " CALR2 " << calr2 << endl;
+      gLog << "inpath: " << inpath << endl;
+      gLog << "extractor: " << extractorflag << endl;
+      return calibration();
     }
 
@@ -485,8 +514,8 @@
     {
       pedr = arg.GetArgumentInt(0);
-      gLog << "PEDR: " << pedr << endl;
-      return calibration(pedr);
-    }
-
-  return calibration();
+      return calibration(pedr,calr1,calr2);
+    }
+
+  return calibration(pedr,calr1,calr2);
 }
+
