Index: trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.cc	(revision 860)
+++ trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.cc	(revision 861)
@@ -24,14 +24,14 @@
 \* ======================================================================== */
 
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-//  MMcThresholdCalc                                                       //
-//                                                                         //
-//  Input Containers:                                                      //
-//   MMcEvt                                                                //
-//                                                                         //
-//  Output Containers:                                                     //
-//   MMcTrig;*, MHMcEnergy;*                                               //
-//                                                                         //
+///////////////////////////////////////////////////////////////////////////
+//
+//  MMcThresholdCalc
+//                                                                         
+//  Input Containers:
+//   MMcEvt, MMcTrig;*
+//
+//  Output Containers:
+//   MHMcEnergies
+//
 /////////////////////////////////////////////////////////////////////////////
 
@@ -52,4 +52,8 @@
 ClassImp(MMcThresholdCalc)
 
+// --------------------------------------------------------------------------
+//
+// Default Constructor.
+//
 MMcThresholdCalc::MMcThresholdCalc(const UInt_t dim, const char* name,
                                    const char* title) : fDimension(dim)
@@ -58,4 +62,6 @@
     *fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
 
+    // Arrays of MMcTrig* and MHMcEnergy* are created in order to be 
+    // able to work with root files with several trigger conditions.
     fMcTrig     = new MMcTrig*[fDimension];
     fHMcEnergy  = new MHMcEnergy*[fDimension];
@@ -66,4 +72,8 @@
 }
 
+// -------------------------------------------------------------------------
+//
+// Default Destructor.
+//
 MMcThresholdCalc::~MMcThresholdCalc()
 {
@@ -81,4 +91,7 @@
     // connect Monte Carlo data with this task
 
+    // This task has into accout if the root file has one trigger
+    // condition (MMcTrig) or severl of them (MMcTrig;#.)
+
     fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
     if (!fMcEvt)
@@ -93,5 +106,5 @@
     {
         if (fDimension>1)
-            sprintf(auxname+7, ";%i", i+1);
+            sprintf(auxname+7, ";%i.", i+1);
 
         fMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
@@ -110,6 +123,6 @@
     for (unsigned int i=0; i<fDimension; i++)
     {
-        if (fDimension>1)
-            sprintf(auxname+10, ";%i", i+1);
+        if (fDimension>1&&i!=0)
+            sprintf(auxname+10, ";%i", i);
 
         fHMcEnergy[i] = (MHMcEnergy*)pList->FindObject(auxname);
@@ -119,5 +132,5 @@
         *fLog << dbginf << "'" << auxname << "' not found in list... creating." << endl;
 
-        fHMcEnergy[i] = new MHMcEnergy(fDimension>1 ? i+1 : 0);
+        fHMcEnergy[i] = new MHMcEnergy(fDimension>1&&i!=0 ? i : 0);
         fMustDelete[i] = kTRUE;
         pList->AddToList(fHMcEnergy[i]);
@@ -129,4 +142,9 @@
 Bool_t MMcThresholdCalc::Process()
 {
+
+    // The histograms are filled with log10 of the energy for triggered
+    // events and weighted with 1/E because it is needed the dN/dE vs. logE
+    // distribution to get the energy threshold.
+
     const Float_t energy   = fMcEvt->GetEnergy();
     const Float_t lg10     = log10(energy);
@@ -147,4 +165,5 @@
 {
     // fit the energy distribution to get the threshold
+    // Some iterations are done to be sure the fit parameters converge.
 
     const Float_t sqrt2 = sqrt(2);
@@ -152,12 +171,16 @@
     for (unsigned int i=0; i<fDimension; i++)
     {
-        MHMcEnergy &h = *fHMcEnergy[i];
+      Float_t peak;
+      Float_t sigma;
 
-        const Float_t peak  = h.GetGaussPeak();
-        const Float_t sigma = h.GetGaussSigma();
-
-        h.Fit(1, 3);
-        h.Fit(peak - 2.   *sigma, peak + 2.   *sigma);
-        h.Fit(peak - sqrt2*sigma, peak + sqrt2*sigma);
+      fHMcEnergy[i]->Fit(1, 3);
+      
+      peak  = fHMcEnergy[i]->GetGaussPeak();
+      sigma = fHMcEnergy[i]->GetGaussSigma();
+      fHMcEnergy[i]->Fit(peak - 2.   *sigma, peak + 2.   *sigma);
+	
+      peak  = fHMcEnergy[i]->GetGaussPeak();
+      sigma = fHMcEnergy[i]->GetGaussSigma();
+      fHMcEnergy[i]->Fit(peak - sqrt2*sigma, peak + sqrt2*sigma);
     }
     return kTRUE;
Index: trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.h	(revision 860)
+++ trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.h	(revision 861)
@@ -39,5 +39,5 @@
     Bool_t PostProcess();
 
-    ClassDef(MMcThresholdCalc, 0) // Task to fill the energy threshold information
+    ClassDef(MMcThresholdCalc, 0) // Task to compute the energy threshold
 };
 
