Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4290)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4291)
@@ -19,4 +19,11 @@
                                                  -*-*- END OF LINE -*-*-
 
+ 2004/06/12: Abelardo Moralejo
+
+  * manalysis/MMcCalibrationUpdate.[h,cc]
+    - Adapted to the possibility of having different light collection
+      efficiencies in inner and outer pixels. For now we assume that the
+      dependence with incidence angle on the camera plane is the same
+      for both types of pixels.
 
  2004/06/12: Markus Gaug
Index: trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 4290)
+++ trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 4291)
@@ -70,4 +70,5 @@
 #include "MMcRunHeader.hxx"
 #include "MMcFadcHeader.hxx"
+#include "MMcConfigRunHeader.h"
 
 ClassImp(MMcCalibrationUpdate);
@@ -80,11 +81,4 @@
     fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
 
-    //
-    // As default we set 1 photon = 1 ADC count.
-    // (this will make Size to be in ADC counts if no previous calibration has been made)
-    // Hence:
-    //
-    fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
-    fADC2PhElOuter = MCalibrationQEPix::gkDefaultAverageQE;
 
     fAmplitude = -1.;
@@ -224,14 +218,48 @@
     }
 
-
-
-    //
-    // If MCalibrationCam already existed in the parameter list before
-    // MMcCalibrationUpdate::PreProcess was executed (from a 
-    // previous calibration loop) we must not fill it, hence nothing
-    // else has to be done in ReInit:
+    //
+    // 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, 
+    // hence nothing else has to be done in ReInit:
     //
     if (!fFillCalibrationCam)
         return kTRUE;
+
+    // Now check the light collection for inner and outer pixels to
+    // calculate the ratio between the two. FIXME! Light collection
+    // depends on the incidence angle of the light w.r.t. the camera
+    // plane. For the moment we take the ratio for light impinging
+    // perpendicular to the camera plane.
+    //
+    // FIXME! We should look for AddSerialNumber("MMcConfigRunHeader") but
+    // for the moment the stereo version of camera does not write one such
+    // header per telescope (it should!)
+    //
+    MMcConfigRunHeader* mcconfig = (MMcConfigRunHeader*) pList->FindObject("MMcConfigRunHeader");
+    if (!mcconfig)
+    {
+        *fLog << err << "MMcConfigRunHeader" << " not found... aborting." << endl;
+        return kFALSE;
+    }
+    TArrayF innerlightcoll = mcconfig->GetLightCollectionFactor();
+    TArrayF outerlightcoll = mcconfig->GetLightCollectionFactorOuter();
+
+    // In principle outer pixels seem to have a different average light 
+    // collection efficiency than outer ones. We set here the factor between
+    // the two.
+
+    fOuterPixelsLightCollection = outerlightcoll[90] / innerlightcoll[90]; 
+    // (at angle = 90 deg)
+
+    // Set now the 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 to be = 1.
+    //
+    fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
 
     //
@@ -240,13 +268,19 @@
     // inner and outer pixels, (fOuterPixelsGainScaling = kFALSE),
     // which may be useful for display purposes.
+    // If we apply the factor, we must take into account the different
+    // gain photoelectrons->ADC counts, and also apply the correct QE
+    // (see comment above) for the outer pixels through the factor
+    // fOuterPixelsLightCollection.
     //
 
     if (fOuterPixelsGainScaling)
-      fADC2PhElOuter = fADC2PhElInner * (fAmplitude / fAmplitudeOuter);
+      fADC2PhElOuter =  MCalibrationQEPix::gkDefaultAverageQE 
+	  * fOuterPixelsLightCollection
+	  * (fAmplitude / fAmplitudeOuter);
     else
       fADC2PhElOuter = fADC2PhElInner;
 
 
-    const int num = fCalCam->GetSize();
+    Int_t num = fCalCam->GetSize();
 
     fCalCam->SetFFactorMethodValid   ( kTRUE );
@@ -256,5 +290,5 @@
     fQECam->SetPINDiodeMethodValid   ( kTRUE );  
     
-    for (int i=0; i<num; i++)
+    for (Int_t i=0; i<num; i++)
     {
         MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
@@ -274,8 +308,23 @@
 	calpix.SetMeanConvFADC2Phe(adc2photel);
         calpix.SetMeanConvFADC2PheVar(0.);
-        calpix.SetMeanFFactorFADC2Phot(0.);
-
-    }
-
+        calpix.SetMeanFFactorFADC2Phot(0.); // Not used for now.
+
+    }
+
+    //
+    // Now set the average QE for each type of pixels. Correct outer pixels
+    // by different light collection efficiency.
+    //
+    num = fQECam->GetSize();
+    for (Int_t i=0; i<num; i++)
+    {
+        MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
+	Float_t avqe = 
+  	    (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
+  	    MCalibrationQEPix::gkDefaultAverageQE*fOuterPixelsLightCollection:
+  	    MCalibrationQEPix::gkDefaultAverageQE;
+
+	qepix.SetAverageQE(avqe);
+    }
 
     return kTRUE;
@@ -289,7 +338,7 @@
 Int_t MMcCalibrationUpdate::Process()
 {
-    const int num = fCalCam->GetSize();
-
-    for (int i=0; i<num; i++)
+    const Int_t num = fCalCam->GetSize();
+
+    for (Int_t i=0; i<num; i++)
     {
 	MExtractedSignalPix &sigpix = (*fSignalCam)[i];
@@ -330,6 +379,8 @@
 
 	qepix.SetAvNormFFactor(1.);
-	// This factor should convert the default average QE to average QE for a spectrum
-	// like that of Cherenkov light. See the documentration of MCalibrationQEPix.
+	// This factor should convert the default average QE to average QE 
+	// for a spectrum like that of Cherenkov light. See the documentation 
+	// of MCalibrationQEPix. Here it is 1 because we calibrate using 
+	// Cherenkov light.
 
         Float_t qe       = qepix.GetAverageQE();
Index: trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.h	(revision 4290)
+++ trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.h	(revision 4291)
@@ -38,4 +38,7 @@
     Float_t fConversionHiLo; // Ratio of high to low gain.
 
+    Float_t fOuterPixelsLightCollection; 
+    // Photon collection efficiency of outer pixels w.r.t. inner ones.
+
 public:
     MMcCalibrationUpdate(const char *name=NULL, const char *title=NULL);
