Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3851)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3852)
@@ -18,4 +18,20 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2004/04/27: Abelardo Moralejo
+
+   * mcalib/MMcCalibrationCalc.[h,cc]
+     - added histogram which stores the conversion of photons before 
+       the plexiglas to photoelectrons hitting first dynode.
+
+   * macros/mccalibrate.C
+     - added MPointingPosCalc to the tasklist to create and fill an 
+       MPointingPos object, and later write it to the Events tree of 
+       the calibrated MC files. Added some comments and simplified
+       some lines. One more histogram from MMcCalibrationCalc (see
+       above) is now written to the output.
+
+   * macros/starmc2.C
+     - added the writing of MPointingPos to output star file.
+
 
  2004/04/27: Markus Gaug
@@ -33,5 +49,5 @@
 
 
- 2004/04/26: Abelardo Moralejo
+ 2004/04/27: Abelardo Moralejo
 
    * mhistmc/MHMcCollectionArea.[h,cc]
Index: trunk/MagicSoft/Mars/macros/mccalibrate.C
===================================================================
--- trunk/MagicSoft/Mars/macros/mccalibrate.C	(revision 3851)
+++ trunk/MagicSoft/Mars/macros/mccalibrate.C	(revision 3852)
@@ -28,6 +28,5 @@
 //  MMCALIBRATE - Calibration of MC data
 //
-//  This macro is a version of the standard procedure to convert raw MC data 
-//  into calibrated data (photons per pixel) 
+//  This macro converts raw MC data into calibrated data (photons per pixel) 
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -43,20 +42,23 @@
   //
 
-
   // ------------- user change -----------------
   TString* CalibrationFilename;
-  CalibrationFilename = new TString("../../gammas_nonoise/Gamma_zbin0_0*.root");
-  // File to be used for the calibration (must be a camera file without added noise)
-
-  Char_t* AnalysisFilename = "Gamma_zbin0*.root";  // File to be analyzed
-
-  Char_t* OutFilename      = "calibrated_data.root";       // Output file name
-
-
-  Int_t BinsHigh[2] = {5, 10}; // First and last FADC bin of the range to be integrated,
-  Int_t BinsLow[2]  = {5, 10}; // for high and low gain respectively.
-
-  // -------------------------------------------
-
+  CalibrationFilename = new TString("../../gammas_nonoise/Gamma_zbin0_0*.root");  // File to be used for the calibration (must be a camera file without added noise)
+
+  Char_t* AnalysisFilename = "Proton_zbin0_0*.root";  // File to be analyzed
+
+  Char_t* OutFilename      = "calibrated_data.root";  // Output file name
+
+
+  MExtractSignal    sigextract;  
+  // (other extraction methods can be used)
+
+  sigextract.SetSaturationLimit(240);
+  // Defines when to switch to low gain
+
+  // Define FADC slices to be integrated in high and low gain:
+  sigextract.SetRange(5, 10, 5, 10);
+
+  // ---------------------------------------------------------------------
   //
   // Create a empty Parameter List and an empty Task List
@@ -74,7 +76,6 @@
 
   MBadPixelsCam badpix;
-  plist.AddToList(&badpix);
-  
-
+  plist.AddToList(&badpix);  // Not used for now.
+ 
   //
   // Now setup the tasks and tasklist:
@@ -88,24 +89,28 @@
   read.DisableAutoScheme();
 
-  MGeomApply geom; // Reads in geometry from MC file and sets the right sizes for
+  MGeomApply geom; 
+  // Reads in geometry from MC file and sets the right sizes for
   // several parameter containers.
 
   MMcPedestalCopy   pcopy; 
-  // Copies pedestal data from the MC file run fadc header to the MPedestalCam container.
-
-  MExtractSignal    sigextract;
-  sigextract.SetSaturationLimit(240);
-
-  // Define ADC slices to be integrated in high and low gain:
-  sigextract.SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
+  // Copies pedestal data from the MC file run fadc header to the 
+  // MPedestalCam container.
+
+  MPointingPosCalc pointcalc;
+  // Creates MPointingPos object and fill it with the telescope orientation
+  // information taken from MMcEvt.
 
   MMcCalibrationUpdate  mccalibupdate;
 
-  MCalibrate calib; // Transforms signals from ADC counts into photons.
+  MCalibrate calib; 
+  // MCalibrate transforms signals from ADC counts into photons. In the first
+  // loop it applies a "dummy" calibration supplied by MMcCalibrationUpdate, just 
+  // to equalize inner and outer pixels. At the end of the first loop, in the
+  // PostProcess of MMcCalibrationCalc (see below) the true calibration constants
+  // are calculated.
+
   calib.SetCalibrationMode(MCalibrate::kFfactor);
 
-  //    MBlindPixelCalc   blind;
-  //    blind.SetUseInterpolation();
-
+  MImgCleanStd clean;
   //
   // Applies tail cuts to image. Since the calibration is performed on 
@@ -114,20 +119,19 @@
   // be rejected).
   //
-  MImgCleanStd      clean;
-
-
-  MHillasCalc       hcalc; // Calculates Hillas parameters not dependent on source position.
-
-  MMcCalibrationCalc mccalibcalc;
+
+  MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
+
+  MMcCalibrationCalc mccalibcalc; 
+  // Calculates calibration constants to convert from ADC counts to photons.
+  
 
   tlist.AddToList(&read);
   tlist.AddToList(&geom);
   tlist.AddToList(&pcopy);
-
+  tlist.AddToList(&pointcalc);
   tlist.AddToList(&sigextract);
   tlist.AddToList(&mccalibupdate);
   tlist.AddToList(&calib);
   tlist.AddToList(&clean);
-  //    tlist.AddToList(&blind);
   tlist.AddToList(&hcalc);
 
@@ -150,4 +154,5 @@
   write.AddContainer("MMcEvt",        "Events");
   write.AddContainer("MMcTrig",       "Events");
+  write.AddContainer("MPointingPos",  "Events");
   write.AddContainer("MRawEvtHeader", "Events");
   write.AddContainer("MCerPhotEvt",   "Events");
@@ -169,9 +174,12 @@
       if (!evtloop.Eventloop())
 	return;
-      mccalibcalc->GetHist()->Write();
+      mccalibcalc->GetHistADC2PhotEl()->Write();
+      mccalibcalc->GetHistPhot2PhotEl()->Write();
+      // Writes out the histograms used for calibration.
     }
 
   //
-  // Second loop: analysis loop
+  // Second loop: apply calibration factors to MC events in the 
+  // file to be anlyzed:
   //
 
Index: trunk/MagicSoft/Mars/macros/starmc2.C
===================================================================
--- trunk/MagicSoft/Mars/macros/starmc2.C	(revision 3851)
+++ trunk/MagicSoft/Mars/macros/starmc2.C	(revision 3852)
@@ -38,5 +38,5 @@
 void starmc2()
 {
-  Char_t* AnalysisFilename = "Calibrated_run.root"; // File to be analyzed
+  Char_t* AnalysisFilename = "calibrated_data.root"; // File to be analyzed
   Char_t* OutFilename      = "star.root";        // Output file name
 
@@ -77,5 +77,4 @@
   tlist.AddToList(&read);
   tlist.AddToList(&clean);
-  //    tlist.AddToList(&blind);
   tlist.AddToList(&hcalc);
   tlist.AddToList(&scalc); // Calculates Source-dependent Hillas parameters
@@ -89,4 +88,5 @@
   write.AddContainer("MSrcPosCam",    "RunHeaders");
   write.AddContainer("MMcEvt",        "Events", kFALSE);
+  write.AddContainer("MPointingPos",  "Events");
   write.AddContainer("MHillas",       "Events");
   write.AddContainer("MHillasExt",    "Events");
Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 3851)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 3852)
@@ -73,6 +73,11 @@
     fTitle = title ? title : "Calculate and write conversion factors into MCalibrationChargeCam and MCalibrationQECam containers";
 
-    fHistRatio = new TH1F(AddSerialNumber("HistRatio"), "log10(fPhotElfromShower/fSize)", 1500, -3., 3.);
-    fHistRatio->SetXTitle("log_{10}(fPhotElfromShower / fSize) [photel/ADC count]");
+    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]");
+
 }
 
@@ -101,5 +106,7 @@
 Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
 {
-    fHistRatio->Reset();
+    fHistADC2PhotEl->Reset();
+    fHistPhot2PhotEl->Reset();
+
     fADC2PhotEl = 0;
     fPhot2PhotEl = 0;
@@ -215,8 +222,7 @@
         return kTRUE;
 
-    fPhot2PhotEl += (Float_t) fMcEvt->GetPhotElfromShower() /
-      (Float_t) fMcEvt->GetPassPhotCone();
-
-    fHistRatio->Fill(TMath::Log10(fMcEvt->GetPhotElfromShower()/size));
+    fHistADC2PhotEl->Fill(TMath::Log10(fMcEvt->GetPhotElfromShower()/size));
+    fHistPhot2PhotEl->Fill( (Float_t) fMcEvt->GetPhotElfromShower() /
+			(Float_t) fMcEvt->GetPassPhotCone() );
 
     return kTRUE;
@@ -229,5 +235,5 @@
 Int_t MMcCalibrationCalc::PostProcess()
 {
-    const Stat_t n = fHistRatio->GetEntries();
+    const Stat_t n = fHistADC2PhotEl->GetEntries();
     if (n<1)
     {
@@ -236,5 +242,5 @@
     }
 
-    fPhot2PhotEl /= n;   // Average quantum efficiency
+    fPhot2PhotEl = fHistPhot2PhotEl->GetMean();   // Average quantum efficiency
 
     //
@@ -244,7 +250,7 @@
     Stat_t summax = 0;
     Int_t  mode   = 0;
-    for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
-    {
-        const Stat_t sum = fHistRatio->Integral(ibin-reach, ibin+reach);
+    for (Int_t ibin = 1+reach; ibin <= fHistADC2PhotEl->GetNbinsX()-reach; ibin++)
+    {
+        const Stat_t sum = fHistADC2PhotEl->Integral(ibin-reach, ibin+reach);
 
         if (sum <= summax)
@@ -255,5 +261,5 @@
     }
 
-    fADC2PhotEl = TMath::Power(10, fHistRatio->GetBinCenter(mode));
+    fADC2PhotEl = TMath::Power(10, fHistADC2PhotEl->GetBinCenter(mode));
 
     const Int_t num = fCalCam->GetSize();
@@ -270,5 +276,5 @@
         // average QE for a spectrum like that of Cherenkov light (see the documentration 
 	// of MCalibrationQEPix). 
-	// Here we obtain average QE using already a Cherenkov spectrum so AvNormFFacto 
+	// Here we obtain average QE using already a Cherenkov spectrum so AvNormFFactor
 	// must be 1.
 
Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 3851)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 3852)
@@ -31,5 +31,6 @@
     Long_t  fEvents;
 
-    TH1F*   fHistRatio; // Histogram for monitoring the calibration.
+    TH1F*   fHistADC2PhotEl;
+    TH1F*   fHistPhot2PhotEl; // Histograms for monitoring the calibration.
 
     Bool_t CheckRunType(MParList *pList) const;
@@ -42,5 +43,6 @@
     MMcCalibrationCalc(const char *name=NULL, const char *title=NULL);
 
-    TH1F*   GetHist() { return fHistRatio; }
+    TH1F*   GetHistADC2PhotEl() { return fHistADC2PhotEl; }
+    TH1F*   GetHistPhot2PhotEl() { return fHistPhot2PhotEl; }
 
     ClassDef(MMcCalibrationCalc, 0)   // Task which obtains, for MC files, the calibration factor from ADC counts to photons. 
