Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2683)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2684)
@@ -4,4 +4,11 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2003/12/16: Javi Lopez
+
+   * manalysis/MCalibrate.[h,cc]
+     - new classe that takes the integrated charge from MExtractedSignal container
+       and apply the calibration constants stored in MCalibrationCam container
+       storing the number of photons in MCerPhotEvt.
+
  2003/12/16: Thomas Bretz
 
@@ -9,5 +16,4 @@
      mhist/MSimulatedAnnealing.[h,cc]:
      - fixed includes
-
 
 
Index: /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2683)
+++ /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2684)
@@ -10,4 +10,6 @@
 #pragma link C++ class MCerPhotAnal2+;
 #pragma link C++ class MCerPhotCalc+;
+
+#pragma link C++ class MCalibrate+;
 
 #pragma link C++ class MCameraData+;
Index: /trunk/MagicSoft/Mars/manalysis/MCalibrate.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrate.cc	(revision 2684)
+++ /trunk/MagicSoft/Mars/manalysis/MCalibrate.cc	(revision 2684)
@@ -0,0 +1,163 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug  09/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//   MCalibrate
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MCalibrate.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MH.h"
+
+#include "MRawRunHeader.h"
+#include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
+#include "MRawEvtPixelIter.h"
+
+#include "MCalibrationCam.h"
+#include "MCalibrationPix.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+
+#include "MCerPhotEvt.h"
+
+#include "MTime.h"
+#include "TMath.h"
+
+ClassImp(MCalibrate);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default constructor. b is the number of slices before the maximum slice,
+// a the number of slices behind the maximum slice which is taken as signal.
+//
+MCalibrate::MCalibrate(const char *name, const char *title)
+{
+
+    fName  = name  ? name  : "MCalibrate";
+    fTitle = title ? title : "Task to calculate the number of photons in one event";
+
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess searches for the following input containers:
+//  - MCalibrationCam
+//  - MExtractedSignalCam
+//
+// The following output containers are also searched and created if
+// they were not found:
+//
+//  - MCerPhotEvt
+//  - MPedPhotCam
+//
+Int_t MCalibrate::PreProcess(MParList *pList)
+{
+
+    fCalibrations = (MCalibrationCam*)pList->FindObject("MCalibrationCam");
+    if (!fCalibrations)
+      {
+        *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;        
+        return kFALSE;
+      }
+
+    fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
+    if (!fSignals)
+      {
+        *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
+        return kFALSE;
+      }
+
+    fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
+    if (!fCerPhotEvt)
+      {
+        *fLog << err << dbginf << "Cannot find  MCerPhotEvt ... aborting" << endl;
+        return kFALSE;
+      }
+    
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+//
+Int_t MCalibrate::Process()
+{
+
+  for (UInt_t pixid = 0; pixid<577; pixid++)
+    {
+
+      MExtractedSignalPix &sig =  (*fSignals)[pixid];
+
+      Bool_t logain = sig.IsLoGainUsed();
+
+      Float_t signal;
+      if (logain)
+	signal = sig.GetExtractedSignalLoGain();
+      else
+	signal = sig.GetExtractedSignalHiGain();
+
+      MCalibrationPix &pix = (*fCalibrations)[pixid];
+
+      //      Float_t fCalibraitonConvertionFactor = pix.GetMeanConversionFFactorMethod();
+      Float_t fCalibrationConvertionFactor = pix.GetMeanConversionBlindPixelMethod();
+      
+
+      Float_t nphot = signal*fCalibrationConvertionFactor;
+      Float_t nphoterr = 0;
+      
+      cout << "DBG MCalibrate::Process logain " << logain << " signal " << signal << " fCalibrationConvertionFactor " << fCalibrationConvertionFactor << " nphot " << nphot << endl;
+ 
+      cout << "Blind " << pix.GetMeanConversionBlindPixelMethod() << " " 
+	 <<  pix.GetErrorConversionBlindPixelMethod()   << " " 
+	 <<  pix.GetSigmaConversionBlindPixelMethod()   << " "
+	
+	   <<  "FFactor " << pix.GetMeanConversionFFactorMethod()       << " " 
+   <<  pix.GetErrorConversionFFactorMethod()      << " " 
+   <<  pix.GetSigmaConversionFFactorMethod()      << " " 
+   <<  pix.GetPheFFactorMethod()                  << " " 
+ 
+	   <<  "PIN " << pix.GetMeanConversionPINDiodeMethod()      << " " 
+   <<  pix.GetErrorConversionPINDiodeMethod()     << " " 
+	   <<  pix.GetSigmaConversionPINDiodeMethod()     << endl;
+
+ 
+      fCerPhotEvt->AddPixel(pixid, nphot, nphoterr);
+
+    }
+
+    fCerPhotEvt->FixSize();
+    fCerPhotEvt->SetReadyToSave();
+
+    return kTRUE;
+}
+
Index: /trunk/MagicSoft/Mars/manalysis/MCalibrate.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrate.h	(revision 2684)
+++ /trunk/MagicSoft/Mars/manalysis/MCalibrate.h	(revision 2684)
@@ -0,0 +1,42 @@
+#ifndef MARS_MCalibrate
+#define MARS_MCalibrate
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrate                                                            //
+//                                                                         //
+// Integrates the desired ADC time slices of one pixel and apply           //
+// calibration constants                                                   //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MCalibrationCam;
+class MExtractedSignalCam;
+class MCerPhotEvt;
+
+class MCalibrate : public MTask
+{
+
+  MCalibrationCam     *fCalibrations;
+  MExtractedSignalCam *fSignals;
+  MCerPhotEvt         *fCerPhotEvt; // Cerenkov Photon Event used for calculation
+ 
+  Int_t PreProcess(MParList *pList);
+  Int_t Process();
+
+public:
+
+    MCalibrate(const char *name=NULL, const char *title=NULL);
+
+    ClassDef(MCalibrate, 0)   // Task to calculate cerenkov photons from raw data
+};
+ 
+
+#endif
Index: /trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2683)
+++ /trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2684)
@@ -53,4 +53,5 @@
            MCerPhotAnal2.cc \
 	   MCerPhotCalc.cc \
+	   MCalibrate.cc \
            MBlindPixels.cc \
            MBlindPixelCalc.cc \
