Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6317)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6318)
@@ -22,4 +22,10 @@
 
  2005/02/09 Abelardo Moralejo 
+
+   * manalysis/MMcCalibrationUpdate.cc
+     - Updated to make the MC calibration in phe- work
+
+   * macros/starmc.C
+     - same as above. Now default is calibration in phe-
 
    * mraw/MRawEvtHeader.h
Index: trunk/MagicSoft/Mars/macros/starmc.C
===================================================================
--- trunk/MagicSoft/Mars/macros/starmc.C	(revision 6317)
+++ trunk/MagicSoft/Mars/macros/starmc.C	(revision 6318)
@@ -52,8 +52,10 @@
   // differences in gain of outer pixels)
   //
-  CalibrationFilename = new TString("/data1/magic/mc_data/root/Period021_0.73_mirror/gammas_nonoise/Gamma_zbin0_*.root");
+  CalibrationFilename = new TString("/users/emc/moralejo/mcdata/Period021_0.73_mirror/gammas_nonoise/Gamma_zbin0_*.root");
+
   // File to be used in the calibration (must be a camera file without added noise)
 
-  Char_t* AnalysisFilename = "Gamma_zbin*.root";  // File to be analyzed
+  Char_t* AnalysisFilename = "Gamma_*w0.root";  // File to be analyzed
+  //  Char_t* AnalysisFilename = "Gamma_*1000to1009*w0.root";  // File to be analyzed
 
 
@@ -72,5 +74,7 @@
   Float_t accepted_fraction = 1.;
 
-  Float_t CleanLev[2] = {3., 2.}; // Tail cuts for image analysis
+  Float_t CleanLev[2] = {5.75, 3.84}; // Tail cuts for image analysis
+  MImgCleanStd  clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
+  //  clean.SetMethod(MImgCleanStd::kScaled);
 
   //  Int_t BinsHigh[2] = {5, 10}; // First and last FADC bin of the range to be integrated,
@@ -81,6 +85,11 @@
   //  sigextract.SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
 
-  MExtractFixedWindowPeakSearch sigextract;
-  sigextract.SetWindows(6, 6, 4);
+//     MExtractFixedWindowPeakSearch sigextract;
+//     sigextract.SetWindows(6, 6, 4);
+
+   MExtractTimeAndChargeDigitalFilter sigextract;
+   sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/MC_weights.dat");
+   sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/cosmics_weights.dat");
+   sigextract.SetRange(1, 14, 3, 14);
 
   MSrcPosCam src;
@@ -136,9 +145,8 @@
   MCalibrateData calib; // Transforms signals from ADC counts into photons.
   calib.SetCalibrationMode(MCalibrateData::kFfactor);
+  calib.SetSignalType(MCalibrateData::kPhe);
 
   //    MBlindPixelCalc   blind;
   //    blind.SetUseInterpolation();
-
-  MImgCleanStd      clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
 
   MHillasCalc       hcalc; // Calculates Hillas parameters not dependent on source position.
@@ -223,9 +231,9 @@
   //
 
-  MProgressBar bar;
-  bar.SetWindowName("Calibrating...");
+  //  MProgressBar bar;
+  //  bar.SetWindowName("Calibrating...");
 
   MEvtLoop evtloop;
-  evtloop.SetProgressBar(&bar);
+  //  evtloop.SetProgressBar(&bar);
   evtloop.SetParList(&plist);
 
@@ -261,5 +269,5 @@
   tlist.AddToListBefore(&skip, &sigextract);
 
-  bar.SetWindowName("Analyzing...");
+  //  bar.SetWindowName("Analyzing...");
 
   tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
Index: trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 6317)
+++ trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 6318)
@@ -30,9 +30,10 @@
 //  MMcFadcHeader and translates it to the pedestal mean and rms (in adc counts).
 //  If not already existing in the parameter list, an MCalibrationCam object
-//  is created, with the conversion factor between photons and ADC counts is 
-//  set to 1 to allow the analysis to proceed.
+//  is created, with the conversion factor between ADC counts and photons or 
+//  photoelectrons (depending on fSignalType) is set to 1 to allow the analysis 
+//  to proceed.
 //
 //  Then it creates and fills also the MPedPhotCam object containing the pedestal
-//  mean and rms in units of photons.
+//  mean and rms in units of photons or photoelectrons.
 //
 //  Input Containers:
@@ -71,4 +72,5 @@
 #include "MMcFadcHeader.hxx"
 #include "MMcConfigRunHeader.h"
+#include "MCalibrateData.h"
 
 ClassImp(MMcCalibrationUpdate);
@@ -85,4 +87,6 @@
     fAmplitudeOuter = -1.;
     fConversionHiLo = -1.;
+
+    fSignalType = MCalibrateData::kPhe;
 
     fFillCalibrationCam = kTRUE;
@@ -221,5 +225,5 @@
     // If MCalibrationChargeCam and MCalibrationQECam already existed 
     // in the parameter list before MMcCalibrationUpdate::PreProcess was 
-    // executed (from a previous calibration loop) we must not fill it, 
+    // executed (from a previous calibration loop) we must not fill them, 
     // hence nothing else has to be done in ReInit:
     //
@@ -233,5 +237,5 @@
     // perpendicular to the camera plane.
     //
-    // FIXME! We should look for AddSerialNumber("MMcConfigRunHeader") but
+    // FIXME! We look for AddSerialNumber("MMcConfigRunHeader") but
     // for the moment the stereo version of camera does not write one such
     // header per telescope (it should!)
@@ -254,13 +258,22 @@
     // (at angle = 90 deg)
 
-    // Set now the default conversion from ADC counts to "photoelectrons" 
+    // Set now the default conversion from ADC counts to photoelectrons 
     // (in case no previous calibration existed in the parameter list).
-    // As default we want 1 photon = 1 inner pixel ADC count
-    // (this will make Size to be in ADC counts, which is what we want for
-    // the MC calibration loop). To achieve this we set the ADC to 
-    // photoelectron conversion equal to the QE, which will later make the 
-    // ADC to photon conversion factor (= ADC2PhotEl/QE) to be = 1.
-    //
-    fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
+    //
+    // As default we want to have SIZE in ADC counts, or rather, in "inner pixel
+    // equivalent ADC counts".
+    //
+    // To achieve this:
+    // - In the case fSignalType==kPhot: we set the ADC to photoelectron conversion 
+    // equal to the QE, which will later make the ADC to photon conversion factor 
+    // (= ADC2PhotEl/QE) to be = 1, 
+    //
+    // - In the case fSignalType==kPhe: we set the ADC to photoelectron conversion 
+    // equal to 1, since this will be applied directly to the signals...
+
+    if (fSignalType == MCalibrateData::kPhot)
+      fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
+    else
+      fADC2PhElInner = 1.;
 
     //
@@ -281,5 +294,5 @@
 
     if (fOuterPixelsGainScaling)
-      fADC2PhElOuter =  MCalibrationQEPix::gkDefaultAverageQE 
+      fADC2PhElOuter = fADC2PhElInner
 	* (fAmplitude / fAmplitudeOuter);
     else
@@ -397,11 +410,16 @@
 
         Float_t qe       = qepix.GetAverageQE();
-	Float_t adc2phot = calpix.GetMeanConvFADC2Phe() / qe;
+
+
+	Float_t conv = (fSignalType == MCalibrateData::kPhot? 
+	  calpix.GetMeanConvFADC2Phe() / qe  :
+	  calpix.GetMeanConvFADC2Phe());
+
 	Float_t hi2lo    = calpix.GetConversionHiLo();
 
 	if (sigpix.IsLoGainUsed())
-            pedpix.Set(adc2phot*hi2lo*pedestmean, adc2phot*hi2lo*pedestrms);
+            pedpix.Set(conv*hi2lo*pedestmean, conv*hi2lo*pedestrms);
 	else
-            pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
+            pedpix.Set(conv*pedestmean, conv*pedestrms);
 
     }
@@ -409,2 +427,3 @@
     return kTRUE;
 }
+
