Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 5614)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 5683)
@@ -59,6 +59,6 @@
 #include "MJPedestal.h"
 #include "MJCalibration.h"
-#include "MJExtractSignal.h"
 #include "MJExtractCalibTest.h"
+#include "MJCalibrateSignalFromOutside.h"
 #include "MRunIter.h"
 #include "MStatusDisplay.h"
@@ -69,4 +69,5 @@
 #include "MArray.h"
 #include "MParContainer.h"
+#include "MGeomCamMagic.h"
 
 #include "TStyle.h"
@@ -98,4 +99,13 @@
 static  const Int_t calrun2 = 0;
 //
+// the default start data run 
+//
+static const Int_t   datrun1 = 39900;
+//
+// the default last calibration run (if 0, only one run is taken, otherwise consecutive runs 
+// between calrun1 and calrun2)
+//
+static  const Int_t datrun2 = 0;
+//
 // A switch to output debugging information about Objects use
 //
@@ -120,20 +130,21 @@
 // Tell if you want to test the intensity calibration
 //
-static Bool_t useIntensity = kFALSE;
+static Bool_t useIntensity  = kFALSE;
 //
 // Tell if you want to store and read the F0 and F1- files
 //
-static Bool_t usestorage   = kFALSE;
+static Bool_t usestorage   = kTRUE;
 //
 // Tell which extractor you want to use. The flags are counted according 
 // to the extractor-TDAS
 // 
-static Int_t extractorflag = 1;
+static Int_t extractorflag = 33;
 //
 Int_t calibration(const UInt_t extflag=extractorflag, const Int_t prun=pedrun, 
-                  const Int_t crun1=calrun1, const Int_t crun2=calrun2)
+                  const Int_t crun1=calrun1, const Int_t crun2=calrun2, 
+                  const Int_t drun1=datrun1, const Int_t drun2=datrun2)
 {
 
-  MExtractor *extractor = getExtractor(extflag);
+  MExtractor *extractor = getExtractor(extflag==33 ? 32 : extflag);
 
   if (!extractor)
@@ -164,4 +175,5 @@
     cruns.AddRuns(crun1,crun2,inpath);
 
+  
   MStatusDisplay *display = NULL;
 
@@ -179,6 +191,8 @@
   // Hand over to the jobs a QE Cam with Cornings initialized
   // 
+  MGeomCamMagic          geomcam;
   MCalibrationQECamMagic qecam;
   MBadPixelsCam          badcam;
+  badcam.InitSize(geomcam.GetNumPixels());
   //
   // If you want to exclude pixels from the beginning, read 
@@ -193,5 +207,5 @@
 
   MJPedestal pedloop1;
-  pedloop1.SetNoStorage(!usestorage);
+  pedloop1.SetNoStorage();
   pedloop1.SetEnvDebug(debug);
   pedloop1.SetExtractor(extractor);
@@ -218,9 +232,9 @@
     {
       /***********************************************************/
-      /* NEEDE FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
+      /* NEEDED FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
       /***********************************************************/
       
       pedloop2.SetUseData();
-      pedloop2.SetNoStorage(!usestorage);
+      pedloop2.SetNoStorage();
       pedloop2.SetEnvDebug(debug);
       pedloop2.SetExtractor(extractor);
@@ -239,5 +253,4 @@
         return 1;
       
-      extractor->SetNoiseCalculation(kFALSE);
       calloop.SetExtractorCam(pedloop2.GetPedestalCam());
     }
@@ -252,4 +265,5 @@
   //  calloop.SetHistsStorage();
   calloop.SetNoStorage(!usestorage);
+  calloop.SetRelTimeCalibration(kTRUE);
   //
   // If you want to set a colour explicitely from outside (not recommanded!)
@@ -277,9 +291,11 @@
   calloop.SetUsePINDiode(pindiode);
   calloop.SetQECam(qecam);
-  calloop.SetBadPixels(pedloop1.GetBadPixels());
+  calloop.SetBadPixels(badcam);
 
   if (!calloop.Process(pedcam))
     return 2;
 
+  //  return 0;
+
   //
   // The next lines are the use the Print() function and have 
@@ -288,7 +304,7 @@
   if (debug)
     {
-      MCalibrationChargeCam &chargecam   = calloop.GetCalibrationCam();
       MCalibrationQECam     &nqecam      = calloop.GetQECam();
       MBadPixelsCam         &badbad      = calloop.GetBadPixels();
+      MCalibrationChargeCam &chargecam   = calloop.GetCalibrationCam();
       chargecam.Print();
       nqecam.Print();
@@ -318,7 +334,16 @@
         return 3;
       
-      return 4;
-      
-    }
+   }
+
+  if (drun1 == 0)
+    return 4;
+
+  MRunIter druns;
+
+  if (drun2==0)
+    druns.AddRun(drun1,inpath);
+  else
+    druns.AddRuns(drun1,drun2,inpath);
+
 
   /********************************************************************/
@@ -326,14 +351,21 @@
   /********************************************************************/
 
-  MJExtractSignal pedphotloop;
-
-  pedphotloop.SetExtractor(extractor);
-  pedphotloop.SetInput(&pruns);
-  pedphotloop.SetOutputPath(outpath);
+  if (extflag == 33)
+    {
+      delete extractor;
+      extractor = getExtractor(28);
+    }
+  
+  MJCalibrateSignalFromOutside calibloop;
+
+  calibloop.SetExtractor(extractor);
+  calibloop.SetInput(&druns);
+  //  calibloop.SetOutputPath(outpath);
   if (useDisplay)
-    pedphotloop.SetDisplay(display);
-  pedphotloop.SetBadPixels(calloop.GetBadPixels());
-  
-  if (!pedphotloop.ProcessP(pedloop1.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
+    calibloop.SetDisplay(display);
+  calibloop.SetBadPixels(calloop.GetBadPixels());
+  calibloop.SetNoStorage(!usestorage);
+  
+  if (!calibloop.ProcessFile(pedloop1.GetPedestalCam(),timeandcharge ? pedloop2.GetPedestalCam() : pedloop1.GetPedestalCam(), calloop.GetCalibrationCam(),calloop.GetQECam(), calloop.GetRelTimeCam()))
     return 5;
 
@@ -347,4 +379,5 @@
     gObjectTable->Print();
 
+
   return 0;
 }
@@ -355,15 +388,21 @@
     gLog << "Usage:" << endl;
     gLog << endl;
-    gLog << "   calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.]" << endl ;
+    gLog << "   calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.] [first dat.run nr.] [last dat.run nr.]" << endl ;
     gLog << endl;
     gLog << "   ped.run.nr:        Run number of the pedestal file." << endl;
     gLog << "   first cal.run nr.: Run number of the first calibration file." << endl;
     gLog << "   last  cal.run nr.: Run number of the last  calibration file." << endl;
-    gLog << endl;
-    gLog << "All calibration runs between (first cal.run nr.) and (last  cal.run nr.) will be used" << endl;
+    gLog << "   first dat.run nr.: Run number of the first data file to be calibrated." << endl;
+    gLog << "   last  dat.run nr.: Run number of the last  data file to be calibrated." << endl;
+    gLog << endl;
+    gLog << "All calibration runs between (first cal.run nr.) and (last cal.run nr.) will be used" << endl;
     gLog << "If last.cal.run.nr is 0 (default), only one calibration run is taken"                  << endl;
+    gLog << endl;
+    gLog << "All data runs between (first dat.run nr.) and (last dat.run nr.) will be used" << endl;
+    gLog << "If last.dat.run.nr is 0 (default), only one data run is taken"                  << endl;
     gLog << endl;
     gLog << "Additional Options: " << endl;
     gLog << "     --extractor=#    Choose one of the following possible extractors (integer)" << endl;
+    gLog << "                      (default: Nr. 33)                                        " << endl;
     gLog << endl;
     gLog << "    Nr.    Extractor   Parameters " << endl;
@@ -372,5 +411,5 @@
     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 << "     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;
@@ -415,8 +454,5 @@
     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 << "     33:          Use calibration weights for calibration events and cosmics weights for data events" << endl;
     gLog << endl;
     gLog << "     --inpath=#          Find the data in inpath"                      << endl;
