Index: /trunk/Mars/melectronics/MAvalanchePhotoDiode.cc
===================================================================
--- /trunk/Mars/melectronics/MAvalanchePhotoDiode.cc	(revision 18447)
+++ /trunk/Mars/melectronics/MAvalanchePhotoDiode.cc	(revision 18448)
@@ -352,15 +352,22 @@
     FillEmpty(t);
 
-    const Int_t nx = fHist.GetNbinsX();
-    const Int_t ny = fHist.GetNbinsY();
-
-    const Double_t f = (nx*ny)/rate;
-
-    // FIXME: Dead time is not taken into account,
-    //        possible earlier afterpulses are not produced.
-
-    for (int x=1; x<=nx; x++)
-        for (int y=1; y<=ny; y++)
-            HitCellImp(x, y, t-MMath::RndmExp(f));
+    // If the rate is 0, we don't need to initiatize the cells, because there
+    // won't be any hitted cells.
+    if (rate > 0.)
+    {
+
+        const Int_t nx = fHist.GetNbinsX();
+        const Int_t ny = fHist.GetNbinsY();
+
+        const Double_t f = (nx*ny)/rate;
+
+        // FIXME: Dead time is not taken into account,
+        //        possible earlier afterpulses are not produced.
+
+        for (int x=1; x<=nx; x++)
+            for (int y=1; y<=ny; y++)
+                HitCellImp(x, y, t-MMath::RndmExp(f));
+
+    }
 
     // Deleting of the afterpulses before fHist.GetMinimum() won't
