Index: trunk/Mars/melectronics/MAvalanchePhotoDiode.cc
===================================================================
--- trunk/Mars/melectronics/MAvalanchePhotoDiode.cc	(revision 19129)
+++ trunk/Mars/melectronics/MAvalanchePhotoDiode.cc	(revision 19130)
@@ -457,9 +457,9 @@
 // --------------------------------------------------------------------------
 //
-// Retunrs the number of cells which have a time t<=fDeadTime, i.e. which are
+// Returns the number of cells which have a time t<=fDeadTime, i.e. which are
 // dead.
 // The default time is 0.
 //
-// Note that if you want to get a correct measure of teh number of dead cells
+// Note that if you want to get a correct measure of the number of dead cells
 // at the time t, this function will only produce a valid count if the
 // afterpulses have been processed up to this time.
@@ -481,5 +481,5 @@
 // --------------------------------------------------------------------------
 //
-// Returs the number of cells which have a time t<=fDeadTime+fRecoveryTime.
+// Returns the number of cells which have a time t<=fDeadTime+fRecoveryTime.
 // The default time is 0.
 //
@@ -506,4 +506,43 @@
 // --------------------------------------------------------------------------
 //
+// Returns the fraction of charge, the sensor can still release.
+// The default time is 0.
+//
+// Note that if you want to get a correct measure at the time t,
+// this function will only produce a valid count if the
+// afterpulses have been processed up to this time.
+//
+Float_t APD::GetChargeState(Float_t t) const
+{
+    const Int_t nx = fHist.GetNbinsX();
+    const Int_t ny = fHist.GetNbinsY();
+
+    Double_t tot = 0;
+
+    for (int x=1; x<=nx; x++)
+        for (int y=1; y<=ny; y++)
+        {
+            // Number of the x/y cell in the one dimensional array
+            // const Int_t cell = fHist.GetBin(x, y);
+            const Int_t cell = x + (fHist.GetNbinsX()+2)*y;
+
+            // Getting a reference to the float is the fastes way to
+            // access the bin-contents in fArray
+            const Float_t &cont = fHist.GetArray()[cell];
+
+            // Calculate the time since the last breakdown
+            const Float_t dt = t-cont-fDeadTime;
+
+            // The signal height (in units of one photon) produced after dead time
+            // depends on the recovery of the cell - described by an exponential.
+            if (dt>0)
+                tot += fRecoveryTime<=0 ? 1. : 1-TMath::Exp(-dt/fRecoveryTime);
+        }
+
+    return tot / (nx*ny);
+}
+
+// --------------------------------------------------------------------------
+//
 // Generate an afterpulse originating from the given cell and a pulse with
 // charge. The afterpulse distribution to use is specified by
Index: trunk/Mars/melectronics/MAvalanchePhotoDiode.h
===================================================================
--- trunk/Mars/melectronics/MAvalanchePhotoDiode.h	(revision 19129)
+++ trunk/Mars/melectronics/MAvalanchePhotoDiode.h	(revision 19130)
@@ -65,4 +65,5 @@
     Int_t CountDeadCells(Float_t t=0) const;
     Int_t CountRecoveringCells(Float_t t=0) const;
+    Float_t GetChargeState(Float_t t=0) const;
 
     // --- Lower level user interface ---
