Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3540)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3541)
@@ -50,4 +50,8 @@
    * mimage/ImageIncl.h:
      - added TVector2
+
+   * manalysis/MCerPhotEvt.[h,cc]:
+     - fixed a bug in AddPixels which - in some special circumstances -
+       cutted pixels with high pixel indices
 
 
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 3540)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 3541)
@@ -97,4 +97,5 @@
 {
     fNumPixels = 0;
+    fMaxIndex  = 0;
     fLut.Set(0);
     // fPixels->Delete();
@@ -103,5 +104,5 @@
 void MCerPhotEvt::FixSize()
 {
-    fLut.Set(fNumPixels);
+    fLut.Set(fMaxIndex);
 
     if (fPixels->GetEntriesFast() == (Int_t)fNumPixels)
@@ -372,5 +373,4 @@
         if (idx>=fLut.GetSize())
             return 0;
-
         return fLut[idx]<0 ? 0 : (MCerPhotPix*)(fPixels->UncheckedAt(fLut[idx]));
     }
@@ -385,4 +385,25 @@
     return NULL;
 }
+
+MCerPhotPix *MCerPhotEvt::AddPixel(Int_t idx, Float_t nph, Float_t er)
+    {
+        //
+        // If this is too slow or takes to much space we might use
+        // MGeomApply and an InitSize member function instead.
+        //
+        if (idx>=fLut.GetSize())
+        {
+            const Int_t n = fLut.GetSize();
+            fLut.Set(idx*2+1); //idx+1 is slower than idx*2+1
+            for (int i=n; i<idx*2+1; i++)
+                fLut[i] = -1;
+        }
+
+        fLut[idx] = fNumPixels;
+        if ((UInt_t)idx>fMaxIndex)
+            fMaxIndex=(UInt_t)idx;
+
+        return new ((*fPixels)[fNumPixels++]) MCerPhotPix(idx, nph, er);
+    }
 
 // --------------------------------------------------------------------------
@@ -399,4 +420,5 @@
 {
     MCerPhotPix *pix = GetPixById(idx);
+
     if (!pix || !pix->IsPixelUsed())
         return kFALSE;
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 3540)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 3541)
@@ -24,4 +24,5 @@
 private:
     UInt_t        fNumPixels;
+    UInt_t        fMaxIndex;
     TArrayI       fLut;        // Lookup tabel to lookup pixel by index
     TClonesArray *fPixels;     //-> FIXME: Change TClonesArray away from a pointer?
@@ -34,21 +35,5 @@
     //void   InitSize(UInt_t num) { fPixels->Expand(num); }
 
-    MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0)
-    {
-        //
-        // If this is too slow or takes to much space we might use
-        // MGeomApply and an InitSize member function instead.
-        //
-        if (idx>=fLut.GetSize())
-        {
-            const Int_t n = fLut.GetSize();
-            fLut.Set(idx*2+1); //idx+1 is slower than idx*2+1
-            for (int i=n; i<idx*2+1; i++)
-                fLut[i] = -1;
-        }
-
-        fLut[idx] = fNumPixels;
-        return new ((*fPixels)[fNumPixels++]) MCerPhotPix(idx, nph, er);
-    }
+    MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0);
 
     void FixSize();
