Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 7005)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 7188)
@@ -71,16 +71,14 @@
 using namespace std;
 
-MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
+// --------------------------------------------------------------------------
+//
+// Constructor. Default value for fMinSize is 1000 ADC counts. This must be
+// set in general by the user (SetMinSize), since it depends among other things
+// on the signal extractor used.
+//
+MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title): fMinSize(1000)
 {
     fName  = name  ? name  : "MMcCalibrationCalc";
     fTitle = title ? title : "Calculate and write conversion factors into MCalibrationChargeCam and MCalibrationQECam containers";
-
-    fHistADC2PhotEl = new TH1F(AddSerialNumber("ADC2PhotEl"), "log10(fPhotElfromShower/fSize)", 1500, -3., 3.);
-    fHistADC2PhotEl->SetXTitle("log_{10}(fPhotElfromShower / fSize) [photel/ADC count]");
-
-
-    fHistPhot2PhotEl = new TH1F(AddSerialNumber("Phot2PhotEl"), "Photon conversion efficiency", 1000, 0., 1.);
-    fHistPhot2PhotEl->SetXTitle("Overall photon conversion efficiency [photoelectron/photon]");
-
 }
 
@@ -93,9 +91,10 @@
 Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
 {
-    const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
     if (!run)
     {
-        *fLog << warn << "Warning - cannot check file type, MRawRunHeader not found." << endl;
-        return kTRUE;
+      *fLog << warn << "Warning - cannot check file type, " << AddSerialNumber("MRawRunHeader") 
+	    << " not found." << endl;
+      return kTRUE;
     }
 
@@ -105,11 +104,8 @@
 // --------------------------------------------------------------------------
 //
-// Make sure, that there is an MCalibrationCam Object in the Parameter List.
+// Look for all necessary containers and create histograms
 //
 Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
 {
-    fHistADC2PhotEl->Reset();
-    fHistPhot2PhotEl->Reset();
-
     fADC2PhotEl = 0;
     fPhot2PhotEl = 0;
@@ -156,4 +152,16 @@
         return kFALSE;
     }
+
+    //
+    // Create histograms:
+    //
+
+    fHistADC2PhotEl = new TH1F(AddSerialNumber("ADC2PhotEl"), "log10(fPhotElfromShower/fSize)", 1500, -3., 3.);
+    fHistADC2PhotEl->SetXTitle("log_{10}(fPhotElfromShower / fSize) [photel/ADC count]");
+
+
+    fHistPhot2PhotEl = new TH1F(AddSerialNumber("Phot2PhotEl"), "Photon conversion efficiency", 1000, 0., 1.);
+    fHistPhot2PhotEl->SetXTitle("Overall photon conversion efficiency [photoelectron/photon]");
+
 
     return kTRUE;
@@ -210,12 +218,8 @@
   // 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");
+  MMcConfigRunHeader* mcconfig = (MMcConfigRunHeader*) pList->FindObject(AddSerialNumber("MMcConfigRunHeader"));
   if (!mcconfig)
     {
-      *fLog << err << "MMcConfigRunHeader" << " not found... aborting." << endl;
+      *fLog << err << AddSerialNumber("MMcConfigRunHeader") << " not found... aborting." << endl;
       return kFALSE;
     }
@@ -253,9 +257,7 @@
     //
     // Exclude events with low Size (larger fluctuations)
-    // FIXME? The present cut (1000 "inner-pixel-counts") is somehow
-    // arbitrary. Might it be optimized?
     //   
 
-    if (size < 1000)
+    if (size < fMinSize)
         return kTRUE;
 
@@ -288,5 +290,12 @@
     }
 
-    fPhot2PhotEl = fHistPhot2PhotEl->GetMean();   // Average quantum efficiency
+    fPhot2PhotEl = fHistPhot2PhotEl->GetMean();   
+    // Average quantum efficiency. For now we will set this value for all pixels, although
+    // even in MC there may be differences from pixel to pixel, if the .dat file containing 
+    // QE vs lambda, input of the camera simulation, has different QE curves for different
+    // pixels. FIXME?
+
+    MCalibrationQEPix &avqepix = (MCalibrationQEPix&)(fQECam->GetAverageArea(0));
+    avqepix.SetAverageQE(fPhot2PhotEl); // Needed by MCalibrateData!
 
     //
@@ -335,5 +344,5 @@
 	// 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.
+        // only be like this in camera 0.7, but might change in future versions of camera.
 	//
 
@@ -347,4 +356,5 @@
     }
 
+
     return kTRUE;
 }
