Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 4295)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 4296)
@@ -18,4 +18,12 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/06/12: Abelardo Moralejo
+
+  * manalysis/MMcCalibrationUpdate.cc
+  * mcalib/MMcCalibrationCalc.[h,cc]
+    - Fixed mistake in the calibration which occurred only when 
+      different light collection efficiency was simulated for outer 
+      pixels.
 
  2004/06/12: Abelardo Moralejo
Index: /trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 4295)
+++ /trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 4296)
@@ -253,29 +253,33 @@
     // (at angle = 90 deg)
 
-    // Set now the conversion from ADC counts to photoelectrons (in case
-    // no previous calibration existed in the parameter list).
+    // 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 
+    // (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.
+    // ADC to photon conversion factor (= ADC2PhotEl/QE) to be = 1.
     //
     fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
 
     //
-    // Set the ADC to photons conversion factor for outer pixels.
-    // One can choose not to apply the known (in MC) gain factor between
-    // inner and outer pixels, (fOuterPixelsGainScaling = kFALSE),
+    // Set the default ADC to "photoelectrons" conversion factor for outer 
+    // pixels. One can choose not to apply the known (in MC) gain factor 
+    // between inner and outer pixels, (in case 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 on the contrary we apply the factor, we must take into account the 
+    // different gains photoelectrons->ADC counts, given in MC by fAmplitude
+    // and fAmplitudeOuter. This "default" calibration is such that a shower
+    // completely contained in the inner part would have Size in ADC counts, 
+    // whereas one partially in the outer part would have Size in "equivalent 
+    // inner ADC counts" : the "same" shower (light density distribution) would
+    // have the same Size no matter where in the camera it lies. For this we have 
+    // also to set later (see below) the right QE for outer pixels, which may 
+    // be different from that of inner pixels.
     //
 
     if (fOuterPixelsGainScaling)
       fADC2PhElOuter =  MCalibrationQEPix::gkDefaultAverageQE 
-	  * fOuterPixelsLightCollection
-	  * (fAmplitude / fAmplitudeOuter);
+	* (fAmplitude / fAmplitudeOuter);
     else
       fADC2PhElOuter = fADC2PhElInner;
@@ -306,4 +310,5 @@
 	  fADC2PhElOuter : fADC2PhElInner;
 
+
 	calpix.SetMeanConvFADC2Phe(adc2photel);
         calpix.SetMeanConvFADC2PheVar(0.);
@@ -314,5 +319,5 @@
     //
     // Now set the average QE for each type of pixels. Correct outer pixels
-    // by different light collection efficiency.
+    // for different light collection efficiency.
     //
     num = fQECam->GetSize();
@@ -320,8 +325,10 @@
     {
         MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
-	Float_t avqe = 
-  	    (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
-  	    MCalibrationQEPix::gkDefaultAverageQE*fOuterPixelsLightCollection:
-  	    MCalibrationQEPix::gkDefaultAverageQE;
+
+	Float_t avqe = MCalibrationQEPix::gkDefaultAverageQE;
+
+	if (fOuterPixelsGainScaling)
+	  if (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))
+	    avqe = MCalibrationQEPix::gkDefaultAverageQE*fOuterPixelsLightCollection;
 
 	qepix.SetAverageQE(avqe);
Index: /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 4295)
+++ /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 4296)
@@ -28,4 +28,5 @@
 //
 //  Input Containers:
+//   MMcConfigRunHeader
 //   MRawRunHeader
 //   MMcFadcHeader
@@ -57,4 +58,5 @@
 #include "MGeomCam.h"
 #include "MRawRunHeader.h"
+#include "MMcConfigRunHeader.h"
 
 #include "MHillas.h"
@@ -194,4 +196,31 @@
   }
 
+  // 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)
+
+
   return kTRUE;
 }
@@ -210,4 +239,8 @@
         return kTRUE;
 
+    const Float_t size = fHillas->GetSize(); 
+    const Float_t innersize = fNew->GetInnerSize();
+
+    // Size will at this point be in ADC counts (still uncalibrated)
     //
     // Exclude events with low Size (larger fluctuations)
@@ -216,13 +249,23 @@
     //   
 
-    const Float_t size = fHillas->GetSize(); 
-    // Size will at this point be in ADC counts (still uncalibrated)
-
     if (size < 1000)
         return kTRUE;
 
-    fHistADC2PhotEl->Fill(TMath::Log10(fMcEvt->GetPhotElfromShower()/size));
-    fHistPhot2PhotEl->Fill( (Float_t) fMcEvt->GetPhotElfromShower() /
-			(Float_t) fMcEvt->GetPassPhotCone() );
+    //
+    // PATCH: Convert number of photoelectrons in camera to the approximate number 
+    // of photoelectrons that would have been registered if all pixels had the same
+    // light collection efficiency as inner ones (called here "corrected_photel").
+    //
+ 
+    const Float_t inner_photel = (Float_t) fMcEvt->GetPhotElfromShower() * innersize / size;
+    const Float_t outer_photel = (Float_t) fMcEvt->GetPhotElfromShower() - inner_photel;
+
+    const Float_t corrected_photel = inner_photel + outer_photel / fOuterPixelsLightCollection;
+
+
+    //    fHistADC2PhotEl->Fill(TMath::Log10(fMcEvt->GetPhotElfromShower()/size));
+
+    fHistADC2PhotEl->Fill(TMath::Log10(corrected_photel/size));
+    fHistPhot2PhotEl->Fill( corrected_photel / (Float_t) fMcEvt->GetPassPhotCone() );
 
     return kTRUE;
@@ -270,5 +313,8 @@
 	MCalibrationQEPix     &qepix  = (MCalibrationQEPix&)    (*fQECam) [i];
 
-	qepix.SetAverageQE(fPhot2PhotEl);
+	Float_t qe = fPhot2PhotEl;
+	if (fGeom->GetPixRatio(i) < 1.)
+	  qe *= fOuterPixelsLightCollection;
+	qepix.SetAverageQE(qe);
 
 	qepix.SetAvNormFFactor(1.);
@@ -284,5 +330,9 @@
 	//
 	// We take into account the (possibly) different gain of outer pixels:
+	// FIXME: we are now assuming that all inner pixels have the same gain, and all 
+	// outer pixels have the same gain (different from inner ones though). This can 
+        // only be like this in camera 0.7, but may change in future versions of camera.
 	//
+
 	if (fGeom->GetPixRatio(i) < 1.)
 	  factor *= fHeaderFadc->GetAmplitud()/fHeaderFadc->GetAmplitudOuter();
Index: /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 4295)
+++ /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 4296)
@@ -27,7 +27,9 @@
     MMcFadcHeader             *fHeaderFadc;
 
-    Float_t fADC2PhotEl;   // Conversion factor (photel / ADC count)
-    Float_t fPhot2PhotEl;  // Conversion factor (photons / photoelectron) = average QE
+    Float_t fADC2PhotEl;   // Conversion factor (photel / ADC count). FOR INER PIXELS
+    Float_t fPhot2PhotEl;  // Conversion factor (photons / photoelectron) = average QE. FOR INER PIXELS
     Long_t  fEvents;
+    Float_t fOuterPixelsLightCollection; // Light collection efficiency (plexiglas, light guide) of 
+                                         // outer pixels w.r.t inner ones
 
     TH1F*   fHistADC2PhotEl;
