Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1424)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1425)
@@ -1,3 +1,11 @@
                                                                   -*-*- END -*-*-
+
+ 2002/07/22: Abelardo Moralejo
+
+   * manalysis/MCerPhotCalc2.[h,cc]:
+     -added procedure SetWeights.
+
+   * macros/MagicHillas.C:
+     -added example on how to use MCerPhotCalc2
 
  2002/07/22: Thomas Bretz
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.cc	(revision 1424)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.cc	(revision 1425)
@@ -28,10 +28,12 @@
 //                                                                          //
 //   This is a task which calculates the number of photons from the FADC    //
-//   time slices. It weights the each slice according to the fraction       //
-//   of signal which, in average, falls within it. This average has been    //
-//   determined over a run (about 1000 triggers, 0 deg z.a. gammas).        // 
+//   time slices. It weights the each slice according to the numbers in     //
+//   the array fWeight. The default values (see end of this file) are       //
+//   the fraction of signal which, in average, falls within each slice.     //
+//   This averages have been determined over a run (about 1000 triggers,    //
+//   0 deg z.a. gammas).                                                    // 
 //                                                                          //
 //  Input Containers:                                                       //
-//   MRawEvtData, MPedestalCam                                             //
+//   MRawRunHeader, MRawEvtData, MPedestalCam                               //
 //                                                                          //
 //  Output Containers:                                                      //
@@ -65,5 +67,5 @@
 {
     fName  = name  ? name  : "MCerPhotCalc2";
-    fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
+    fTitle = title ? title : "Task to calculate pixel signal from raw data";
 
     AddToBranchList("MRawEvtData.fHiGainPixId");
@@ -71,13 +73,4 @@
     AddToBranchList("MRawEvtData.fHiGainFadcSamples");
     AddToBranchList("MRawEvtData.fLoGainFadcSamples");
-
-    fSumQuadWeights = fSumWeights = 0.;
-    for (Int_t i = 0; i < 15; i++)
-      {
-	fSumQuadWeights += fWeight[i]*fWeight[i];
-	fSumWeights += fWeight[i];
-      }
-    fSumQuadWeights = sqrt(fSumQuadWeights);
-
 }
 
@@ -120,4 +113,11 @@
         return kFALSE;
 
+    // Calculate quadratic sum of weights:
+    fSumQuadWeights = 0.;
+    for (Int_t i = 0; i < 15; i++)
+      fSumQuadWeights += fWeight[i]*fWeight[i];
+
+    fSumQuadWeights = sqrt(fSumQuadWeights);
+
     return kTRUE;
 }
@@ -138,4 +138,10 @@
     }
 
+    if (fRunHeader->GetNumSamplesHiGain() != 15)
+    {
+        *fLog << dbginf << "Number of FADC slices (" << fRunHeader->GetNumSamplesHiGain() <<") is different from expected (15)... aborting." << endl;
+        return kFALSE;
+    }
+
     if (runheader->GetRunType() != kRTMonteCarlo)
         return kTRUE;
@@ -165,5 +171,5 @@
     MRawEvtPixelIter pixel(fRawEvt);
 
-    Float_t ADCBins[15];
+    Float_t BinSignal[15];
 
     while (pixel.Next())
@@ -187,17 +193,10 @@
 
 	Float_t nphot = 0.;
-	for(Int_t i = 0; i<15;i++)
+
+	for(Int_t i = 0; i<15; i++)
 	  {
-	    ADCBins[i] = (Float_t) *(ptr+i);
-	    nphot += ADCBins[i] * fWeight[i];
+	    BinSignal[i] =  (Float_t) ptr[i] - mean;
+	    nphot       +=  BinSignal[i] * fWeight[i];
 	  }
-
-        //
-	// We check that the pixel is not empty, if it is empty
-	// we won't substract the pedestal. Empty means that it has
-        // 0 signal in all the slices.
-        //
-        if (nphot!=0)
-	  nphot -= mean*fSumWeights;
 
 	Float_t nphoterr = ped.GetSigma()* fSumQuadWeights;
@@ -213,3 +212,4 @@
 }
 
-Float_t MCerPhotCalc2::fWeight[15] = {0, 0.0809835, 0.289593, 0.366926, 0.211665, 0.0508328, 0., 0., 0., 0., 0., 0., 0., 0., 0.};
+// Default weights: 
+Float_t MCerPhotCalc2::fWeight[] = {0, 0.0809835, 0.289593, 0.366926, 0.211665, 0.0508328, 0., 0., 0., 0., 0., 0., 0., 0., 0.};
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.h	(revision 1424)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc2.h	(revision 1425)
@@ -25,10 +25,10 @@
     MRawEvtData    *fRawEvt;     // raw event data (time slices)
     MCerPhotEvt    *fCerPhotEvt; // Cerenkov Photon Event used for calculation
-    MRawRunHeader  *fRunHeader;  //  RunHeader information
+    MRawRunHeader  *fRunHeader;  // RunHeader information
  
     Bool_t          fEnableFix;  // fix for a bug in files from older camera versions (<=40)
 
-    Float_t         fSumQuadWeights, fSumWeights;
-    static Float_t  fWeight[15];
+    static Float_t  fWeight[15];  // Weights for adding up the ADC slices
+    Float_t         fSumQuadWeights;
 
 public:
@@ -37,10 +37,11 @@
     Bool_t PreProcess(MParList *pList);
     Bool_t Process();
+    Bool_t ReInit(MParList *pList);
 
-    Bool_t ReInit(MParList *pList);
+    void   SetWeights(Float_t *w) {memcpy(fWeight,w,15*sizeof(Float_t));}
 
     ClassDef(MCerPhotCalc2, 0)   // Task to calculate cerenkov photons from raw data
 };
-
+ 
 
 #endif
