1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of CheObs, the Modular Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appears in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: CheObs Software Development, 2000-2009
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // APD
|
---|
28 | //
|
---|
29 | // All times in this class are relative times. Therefor the unit for the
|
---|
30 | // time is not intrinsically fixed. In fact the dead-time and recovery-
|
---|
31 | // time given in the constructor must have the same units. This is what
|
---|
32 | // defines the unit of the times given in the function and the unit of
|
---|
33 | // rates given.
|
---|
34 | // For example, if recovery and dead time are given in nanoseconds the
|
---|
35 | // all times must be in nanoseconds and rates are given per nanosecond,
|
---|
36 | // i.e. GHz.
|
---|
37 | //
|
---|
38 | // Hamamatsu 30x30 cells: APD(30, 0.2, 3, 35)
|
---|
39 | // Hamamatsu 60x60 cells: APD(60, 0.2, 3, 8.75)
|
---|
40 | //
|
---|
41 | //
|
---|
42 | // The implementation of afterpulsing is based on
|
---|
43 | // A.Du, F.Retiere
|
---|
44 | // After-pulsing and cross-talk in multi-pixel photon counters
|
---|
45 | // NIM A, Volume 596, Issue 3, p. 396-401
|
---|
46 | //
|
---|
47 | //
|
---|
48 | // Example:
|
---|
49 | //
|
---|
50 | // APD apd(ncells, crosstalk, deadtime, recovery);
|
---|
51 | // apd.SetAfterpulseProb(0.14, 0.11);
|
---|
52 | //
|
---|
53 | // while (1)
|
---|
54 | // {
|
---|
55 | // // Make the chip "empty" from the influence of external photons
|
---|
56 | // // It also sets fTime to 0.
|
---|
57 | // apd.Init(freq); // freq of external noise (eg. nsb)
|
---|
58 | //
|
---|
59 | // // Now call this function for each external photon you have. The
|
---|
60 | // // times are relative to the the time you get by apd.GetTime()
|
---|
61 | // // set automatically after the call to apd.Init().
|
---|
62 | // for (int i=0; i<nphot; i++)
|
---|
63 | // apd.HitRandomCellRelative(dt);
|
---|
64 | //
|
---|
65 | // [...]
|
---|
66 | //
|
---|
67 | // // Process and produce afterpulses until a time, wrt to GetTime(),
|
---|
68 | // // given by the end of your simulated window. Note that this
|
---|
69 | // // does not produce noise. This must have been properly simulated
|
---|
70 | // // up to this time already.
|
---|
71 | // apd.IncreaseTime(dtend);
|
---|
72 | //
|
---|
73 | // // Now you can access the afterpulses by
|
---|
74 | // TIter Next(&a->GetListOfAfterpulses());
|
---|
75 | // Afterpulse *ap = 0;
|
---|
76 | // while ((ap=static_cast<Afterpulse*>(Next())))
|
---|
77 | // {
|
---|
78 | // if (apd.GetTime()>=dtend)
|
---|
79 | // continue;
|
---|
80 | //
|
---|
81 | // cout << "Amplitude: " << ap->GetAmplitude() << endl;
|
---|
82 | // cout << "Arrival Time: " << ap->GetTime() << endl;
|
---|
83 | // }
|
---|
84 | // }
|
---|
85 | //
|
---|
86 | //
|
---|
87 | //////////////////////////////////////////////////////////////////////////////
|
---|
88 | #include "MAvalanchePhotoDiode.h"
|
---|
89 |
|
---|
90 | #include <TRandom.h>
|
---|
91 |
|
---|
92 | #include "MMath.h"
|
---|
93 |
|
---|
94 | #include "MLog.h"
|
---|
95 | #include "MLogManip.h"
|
---|
96 | #include "Afterpulse.h"
|
---|
97 |
|
---|
98 | ClassImp(APD);
|
---|
99 |
|
---|
100 | using namespace std;
|
---|
101 |
|
---|
102 | /*
|
---|
103 | class MyProfile : public TProfile2D
|
---|
104 | {
|
---|
105 | public:
|
---|
106 | void AddBinEntry(Int_t cell) { fBinEntries.fArray[cell]++; }
|
---|
107 | };
|
---|
108 | */
|
---|
109 |
|
---|
110 | // --------------------------------------------------------------------------
|
---|
111 | //
|
---|
112 | // Default Constructor.
|
---|
113 | //
|
---|
114 | // n is the number od cells in x or y. The APD is assumed to
|
---|
115 | // be square.
|
---|
116 | // prob is the crosstalk probability, i.e., the probability that a
|
---|
117 | // photon which produced an avalanche will create another
|
---|
118 | // photon in a neighboring cell
|
---|
119 | // dt is the deadtime, i.e., the time in which the APD cell will show
|
---|
120 | // no response to a photon after a hit
|
---|
121 | // rt is the recovering tims, i.e. the exponential (e^(-dt/rt))
|
---|
122 | // with which the cell is recovering after being dead
|
---|
123 | //
|
---|
124 | // prob, dt and ar can be set to 0 to switch the effect off.
|
---|
125 | // 0 is also the dfeault for all three.
|
---|
126 | //
|
---|
127 | APD::APD(Int_t n, Float_t prob, Float_t dt, Float_t rt)
|
---|
128 | : fHist("APD", "", n, 0.5, n+0.5, n, 0.5, n+0.5),
|
---|
129 | fCrosstalkProb(prob), fDeadTime(dt), fRecoveryTime(rt),
|
---|
130 | fTime(-1)
|
---|
131 | {
|
---|
132 | fHist.SetDirectory(0);
|
---|
133 |
|
---|
134 | fAfterpulses.SetOwner();
|
---|
135 |
|
---|
136 | fAfterpulseProb[0] = 0;
|
---|
137 | fAfterpulseProb[1] = 0;
|
---|
138 |
|
---|
139 | fAfterpulseTau[0] = 15;
|
---|
140 | fAfterpulseTau[1] = 85;
|
---|
141 | }
|
---|
142 |
|
---|
143 | // --------------------------------------------------------------------------
|
---|
144 | //
|
---|
145 | // This is the time a chips needs after an external signal to relax to
|
---|
146 | // a "virgin" state, i.e. without no influence of the external pulse
|
---|
147 | // above the given threshold.
|
---|
148 | //
|
---|
149 | // It takes into account the dead time of the cell, the relaxation time
|
---|
150 | // and the two afterpulse distributions. However, in most cases the
|
---|
151 | // afterpulse distribution will dominate (except they are switched off by
|
---|
152 | // a zero probability).
|
---|
153 | //
|
---|
154 | // FIXME: Maybe the calculation of the relaxation time could be optimized?
|
---|
155 | //
|
---|
156 | Float_t APD::GetRelaxationTime(Float_t threshold) const
|
---|
157 | {
|
---|
158 | // Calculate time until the probability of one of these
|
---|
159 | // events falls below the threshold probability.
|
---|
160 | const Double_t rt0 = - TMath::Log(threshold)*fRecoveryTime;
|
---|
161 | const Double_t rt1 = fAfterpulseProb[0]>0 ? -TMath::Log(threshold/fAfterpulseProb[0])*fAfterpulseTau[0] : 0;
|
---|
162 | const Double_t rt2 = fAfterpulseProb[1]>0 ? -TMath::Log(threshold/fAfterpulseProb[1])*fAfterpulseTau[1] : 0;
|
---|
163 |
|
---|
164 | // Probability not between t and inf, but between t and t+dt
|
---|
165 | // -tau * log ( p / ( 1 - exp(- dt/tau) ) ) = t
|
---|
166 |
|
---|
167 | return fDeadTime + TMath::Max(rt0, TMath::Max(rt1, rt2));
|
---|
168 | }
|
---|
169 |
|
---|
170 | // --------------------------------------------------------------------------
|
---|
171 | //
|
---|
172 | // This is the recursive implementation of a hit. If a photon hits a cell
|
---|
173 | // at x and y (must be a valid cell!) at time t, at first we check if the
|
---|
174 | // cell is still dead. If it is not dead we calculate the signal height
|
---|
175 | // from the recovery time. Now we check with the crosstalk probability
|
---|
176 | // whether another photon is created. If another photon is created we
|
---|
177 | // calculate randomly which of the four neighbor cells are hit.
|
---|
178 | // If the cell is outside the APD the photon is ignored. As many
|
---|
179 | // new photons are created until our random number is below the crosstak-
|
---|
180 | // probability.
|
---|
181 | //
|
---|
182 | // For each photon the possible afterpulses of two distributions are
|
---|
183 | // created and added to the list of afterpulses. This is done by calling
|
---|
184 | // GenerateAfterpulse for the two afterpulse-distributions.
|
---|
185 | //
|
---|
186 | // The total height of the signal (in units of photons) is returned.
|
---|
187 | // Note, that this can be a fractional number.
|
---|
188 | //
|
---|
189 | // This function looks a bit fancy accessing the histogram and works around
|
---|
190 | // a few histogram functions. This is a speed optimization which works
|
---|
191 | // around a lot of sanity checks which are obsolete in our case.
|
---|
192 | //
|
---|
193 | // The default time is 0.
|
---|
194 | //
|
---|
195 | Float_t APD::HitCellImp(Int_t x, Int_t y, Float_t t)
|
---|
196 | {
|
---|
197 | // if (x<1 || x>fHist.GetNbinsX() ||
|
---|
198 | // y<1 || y>fHist.GetNbinsY())
|
---|
199 | // return 0;
|
---|
200 | #ifdef DEBUG
|
---|
201 | cout << "Hit: " << t << endl;
|
---|
202 | #endif
|
---|
203 |
|
---|
204 | // Number of the x/y cell in the one dimensional array
|
---|
205 | // const Int_t cell = fHist.GetBin(x, y);
|
---|
206 | const Int_t cell = x + (fHist.GetNbinsX()+2)*y;
|
---|
207 |
|
---|
208 | // Getting a reference to the float is the fastes way to
|
---|
209 | // access the bin-contents in fArray
|
---|
210 | Float_t &cont = fHist.GetArray()[cell];
|
---|
211 |
|
---|
212 | // Calculate the time since the last breakdown
|
---|
213 | // const Double_t dt = t-fHist.GetBinContent(x, y)-fDeadTime; //
|
---|
214 | const Float_t dt = t-cont-fDeadTime;
|
---|
215 |
|
---|
216 | // Photons within the dead time are just ignored
|
---|
217 | if (/*hx.GetBinContent(x,y)>0 &&*/ dt<=0)
|
---|
218 | {
|
---|
219 | #ifdef DEBUG
|
---|
220 | cout << "Dead: " << t << " " << cont << " " << dt << endl;
|
---|
221 | #endif
|
---|
222 | return 0;
|
---|
223 | }
|
---|
224 | // The signal height (in units of one photon) produced after dead time
|
---|
225 | // depends on the recovery of the cell - described by an exponential.
|
---|
226 | const Float_t weight = fRecoveryTime<=0 ? 1. : 1-TMath::Exp(-dt/fRecoveryTime);
|
---|
227 |
|
---|
228 | // Now we know the charge in the cell and we can generate
|
---|
229 | // the afterpulses with both time-constants
|
---|
230 | GenerateAfterpulse(cell, 0, weight, t);
|
---|
231 | GenerateAfterpulse(cell, 1, weight, t);
|
---|
232 |
|
---|
233 | // The probability that the cell emits a photon causing crosstalk
|
---|
234 | // scales as the signal height.
|
---|
235 | const Float_t prob = weight*fCrosstalkProb;
|
---|
236 |
|
---|
237 | // Set the contents to the time of the last breakdown (now)
|
---|
238 | cont = t; // fHist.SetBinContent(x, y, t)
|
---|
239 |
|
---|
240 | // Counter for the numbers of produced photons
|
---|
241 | Float_t n = weight;
|
---|
242 |
|
---|
243 | /*
|
---|
244 | // Check if a photon in a neighboring cell is produced (crosstalk)
|
---|
245 | while (gRandom->Rndm()<fCrosstalkProb)
|
---|
246 | {
|
---|
247 | // Get a random neighbor which is hit.
|
---|
248 | switch (gRandom->Integer(4))
|
---|
249 | {
|
---|
250 | case 0: x++; if (x>fHist.GetNbinsX()) continue; break;
|
---|
251 | case 1: x--; if (x<1) continue; break;
|
---|
252 | case 2: y++; if (y>fHist.GetNbinsY()) continue; break;
|
---|
253 | case 3: y--; if (y<1) continue; break;
|
---|
254 | }
|
---|
255 |
|
---|
256 | n += HitCellImp(x, y, t);
|
---|
257 | }
|
---|
258 | */
|
---|
259 |
|
---|
260 |
|
---|
261 | //for (int i=0; i<1; i++)
|
---|
262 | while (1)
|
---|
263 | {
|
---|
264 | const Double_t rndm = gRandom->Rndm();
|
---|
265 | if (rndm>=prob/*fCrosstalkProb*/)
|
---|
266 | break;
|
---|
267 |
|
---|
268 | // We can re-use the random number because it is uniformely
|
---|
269 | // distributed. This saves cpu power
|
---|
270 | const Int_t dir = TMath::FloorNint(4*rndm/prob/*fCrosstalkProb*/);
|
---|
271 |
|
---|
272 | // Get a random neighbor which is hit.
|
---|
273 | switch (dir)
|
---|
274 | {
|
---|
275 | case 0: if (x<fHist.GetNbinsX()) n += HitCellImp(x+1, y, t); break;
|
---|
276 | case 1: if (x>1) n += HitCellImp(x-1, y, t); break;
|
---|
277 | case 2: if (y<fHist.GetNbinsY()) n += HitCellImp(x, y+1, t); break;
|
---|
278 | case 3: if (y>1) n += HitCellImp(x, y-1, t); break;
|
---|
279 | }
|
---|
280 |
|
---|
281 | // In the unlikely case the calculated direction is out-of-range,
|
---|
282 | // i.e. <0 or >3, we would just try to fill the same cell again which
|
---|
283 | }
|
---|
284 |
|
---|
285 | return n;
|
---|
286 | }
|
---|
287 |
|
---|
288 | // --------------------------------------------------------------------------
|
---|
289 | //
|
---|
290 | // Check if x and y is a valid cell. If not return 0, otherwise
|
---|
291 | // HitCelImp(x, y, t). HitCellImp generates Crosstalk and Afterpulses.
|
---|
292 | //
|
---|
293 | // The default time is 0.
|
---|
294 | //
|
---|
295 | Float_t APD::HitCell(Int_t x, Int_t y, Float_t t)
|
---|
296 | {
|
---|
297 | if (x<1 || x>fHist.GetNbinsX() ||
|
---|
298 | y<1 || y>fHist.GetNbinsY())
|
---|
299 | return 0;
|
---|
300 |
|
---|
301 | return HitCellImp(x, y, t);
|
---|
302 | }
|
---|
303 |
|
---|
304 | // --------------------------------------------------------------------------
|
---|
305 | //
|
---|
306 | // Determine randomly (uniformly) a cell which was hit. Return
|
---|
307 | // HitCellImp for this cell and the given time. HitCellImp
|
---|
308 | // generates Crosstalk and Afterpulses
|
---|
309 | //
|
---|
310 | // The default time is 0.
|
---|
311 | //
|
---|
312 | // If you want t w.r.t. fTime use HitRandomCellRelative istead.
|
---|
313 | //
|
---|
314 | Float_t APD::HitRandomCell(Float_t t)
|
---|
315 | {
|
---|
316 | const UInt_t nx = fHist.GetNbinsX();
|
---|
317 | const UInt_t ny = fHist.GetNbinsY();
|
---|
318 |
|
---|
319 | const UInt_t idx = gRandom->Integer(nx*ny);
|
---|
320 |
|
---|
321 | const UInt_t x = idx%nx;
|
---|
322 | const UInt_t y = idx/nx;
|
---|
323 |
|
---|
324 | return HitCellImp(x+1, y+1, t);
|
---|
325 | }
|
---|
326 |
|
---|
327 | // --------------------------------------------------------------------------
|
---|
328 | //
|
---|
329 | // Sets all cells with a contents which is well before the time t such that
|
---|
330 | // the chip is "virgin". Therefore all cells are set to a time which
|
---|
331 | // is twice the deadtime before the given time and 1000 times the recovery
|
---|
332 | // time.
|
---|
333 | //
|
---|
334 | // The afterpulse list is deleted.
|
---|
335 | //
|
---|
336 | // If deadtime and recovery time are 0 then t-1 is set.
|
---|
337 | //
|
---|
338 | // Sets fTime to t
|
---|
339 | //
|
---|
340 | // The default time is 0.
|
---|
341 | //
|
---|
342 | void APD::FillEmpty(Float_t t)
|
---|
343 | {
|
---|
344 | const Int_t n = (fHist.GetNbinsX()+2)*(fHist.GetNbinsY()+2);
|
---|
345 |
|
---|
346 | const Double_t tm = fDeadTime<=0 && fRecoveryTime<=0 ? t-1 : t-2*fDeadTime-1000*fRecoveryTime;
|
---|
347 |
|
---|
348 | for (int i=0; i<n; i++)
|
---|
349 | fHist.GetArray()[i] = tm;
|
---|
350 |
|
---|
351 | fHist.SetEntries(1);
|
---|
352 |
|
---|
353 | fAfterpulses.Delete();
|
---|
354 |
|
---|
355 | fTime = t;
|
---|
356 | }
|
---|
357 |
|
---|
358 | // --------------------------------------------------------------------------
|
---|
359 | //
|
---|
360 | // First call FillEmpty for the given time t. Then fill each cell by
|
---|
361 | // by calling HitCellImp with time t-gRandom->Exp(n/rate) with n being
|
---|
362 | // the total number of cells. This the time at which the cell was last hit.
|
---|
363 | //
|
---|
364 | // Sets fTime to t
|
---|
365 | //
|
---|
366 | // If the argument t is omitted it defaults to 0.
|
---|
367 | //
|
---|
368 | // Since after calling this function the chip should reflect the
|
---|
369 | // status at the new time fTime=t, all afterpulses are processed
|
---|
370 | // until this time. However, the produced random pulses might have produced
|
---|
371 | // new new afterpulses.
|
---|
372 | //
|
---|
373 | // All afterpulses before the new timestamp are deleted.
|
---|
374 | //
|
---|
375 | // WARNING: Note that this might not correctly reproduce afterpulses
|
---|
376 | // produced by earlier pulese.
|
---|
377 | //
|
---|
378 | void APD::FillRandom(Float_t rate, Float_t t)
|
---|
379 | {
|
---|
380 | FillEmpty(t);
|
---|
381 |
|
---|
382 | const Int_t nx = fHist.GetNbinsX();
|
---|
383 | const Int_t ny = fHist.GetNbinsY();
|
---|
384 |
|
---|
385 | const Double_t f = (nx*ny)/rate;
|
---|
386 |
|
---|
387 | // FIXME: Dead time is not taken into account,
|
---|
388 | // possible earlier afterpulses are not produced.
|
---|
389 |
|
---|
390 | for (int x=1; x<=nx; x++)
|
---|
391 | for (int y=1; y<=ny; y++)
|
---|
392 | HitCellImp(x, y, t-MMath::RndmExp(f));
|
---|
393 |
|
---|
394 | // Deleting of the afterpulses before fHist.GetMinimum() won't
|
---|
395 | // speed things because we have to loop over them once in any case
|
---|
396 |
|
---|
397 | ProcessAfterpulses(fHist.GetMinimum(), t);
|
---|
398 | DeleteAfterpulses(t);
|
---|
399 |
|
---|
400 | fTime = t;
|
---|
401 | }
|
---|
402 |
|
---|
403 | // --------------------------------------------------------------------------
|
---|
404 | //
|
---|
405 | // Shift all times including fTime to dt (ie. add -dt to all times)
|
---|
406 | // This allows to set a user-defined T0 or shift T0 to fTime=0.
|
---|
407 | //
|
---|
408 | // However, T0<0 is not allowed (dt cannot be greater than fTime)
|
---|
409 | //
|
---|
410 | void APD::ShiftTime(Double_t dt)
|
---|
411 | {
|
---|
412 | if (dt>fTime)
|
---|
413 | {
|
---|
414 | gLog << warn << "APD::ShiftTime: WARNING - requested time shift results in fTime<0... ignored." << endl;
|
---|
415 | return;
|
---|
416 | }
|
---|
417 |
|
---|
418 | // If reset was requested shift all times by end backwards
|
---|
419 | // so that fTime is now 0
|
---|
420 | const Int_t n = (fHist.GetNbinsX()+2)*(fHist.GetNbinsY()+2);
|
---|
421 | for (int i=0; i<n; i++)
|
---|
422 | fHist.GetArray()[i] -= dt;
|
---|
423 |
|
---|
424 | fTime -= dt;
|
---|
425 | }
|
---|
426 |
|
---|
427 | // --------------------------------------------------------------------------
|
---|
428 | //
|
---|
429 | // Evolve the chip from fTime to fTime+dt if it with a given frequency
|
---|
430 | // freq. Returns the total signal "recorded".
|
---|
431 | //
|
---|
432 | // fTime is set to the fTime+dt.
|
---|
433 | //
|
---|
434 | // If you want to evolve over a default relaxation time (relax the chip
|
---|
435 | // from a signal) use Relax instead.
|
---|
436 | //
|
---|
437 | // Since after calling this function the chip should reflect the
|
---|
438 | // status at the new time fTime=fTime+dt, all afterpulses are processed
|
---|
439 | // until this time. However, evolving the chip until this time might
|
---|
440 | // have produced new afterpulses.
|
---|
441 | //
|
---|
442 | // All afterpulses before the new timestamp are deleted.
|
---|
443 | //
|
---|
444 | Float_t APD::Evolve(Double_t freq, Double_t dt)
|
---|
445 | {
|
---|
446 | const Double_t end = fTime+dt;
|
---|
447 |
|
---|
448 | Float_t hits = 0;
|
---|
449 |
|
---|
450 | if (freq>0)
|
---|
451 | {
|
---|
452 | const Double_t avglen = 1./freq;
|
---|
453 |
|
---|
454 | Double_t time = fTime;
|
---|
455 | while (1)
|
---|
456 | {
|
---|
457 | const Double_t deltat = MMath::RndmExp(avglen);
|
---|
458 | if (time+deltat>end)
|
---|
459 | break;
|
---|
460 |
|
---|
461 | time += deltat;
|
---|
462 |
|
---|
463 | hits += HitRandomCell(time);
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | // Deleting of the afterpulses before fTime won't speed things
|
---|
468 | // because we have to loop over them once in any case
|
---|
469 |
|
---|
470 | ProcessAfterpulses(fTime, dt);
|
---|
471 | DeleteAfterpulses(end);
|
---|
472 |
|
---|
473 | fTime = end;
|
---|
474 |
|
---|
475 | return hits;
|
---|
476 | }
|
---|
477 |
|
---|
478 | // --------------------------------------------------------------------------
|
---|
479 | //
|
---|
480 | // Retunrs the number of cells which have a time t<=fDeadTime, i.e. which are
|
---|
481 | // dead.
|
---|
482 | // The default time is 0.
|
---|
483 | //
|
---|
484 | // Note that if you want to get a correct measure of teh number of dead cells
|
---|
485 | // at the time t, this function will only produce a valid count if the
|
---|
486 | // afterpulses have been processed up to this time.
|
---|
487 | //
|
---|
488 | Int_t APD::CountDeadCells(Float_t t) const
|
---|
489 | {
|
---|
490 | const Int_t nx = fHist.GetNbinsX();
|
---|
491 | const Int_t ny = fHist.GetNbinsY();
|
---|
492 |
|
---|
493 | Int_t n=0;
|
---|
494 | for (int x=1; x<=nx; x++)
|
---|
495 | for (int y=1; y<=ny; y++)
|
---|
496 | if ((t-fHist.GetBinContent(x, y))<=fDeadTime)
|
---|
497 | n++;
|
---|
498 |
|
---|
499 | return n;
|
---|
500 | }
|
---|
501 |
|
---|
502 | // --------------------------------------------------------------------------
|
---|
503 | //
|
---|
504 | // Returs the number of cells which have a time t<=fDeadTime+fRecoveryTime.
|
---|
505 | // The default time is 0.
|
---|
506 | //
|
---|
507 | // Note that if you want to get a correct measure of teh number of dead cells
|
---|
508 | // at the time t, this function will only produce a valid count if the
|
---|
509 | // afterpulses have been processed up to this time.
|
---|
510 | //
|
---|
511 | Int_t APD::CountRecoveringCells(Float_t t) const
|
---|
512 | {
|
---|
513 | const Int_t nx = fHist.GetNbinsX();
|
---|
514 | const Int_t ny = fHist.GetNbinsY();
|
---|
515 |
|
---|
516 | Int_t n=0;
|
---|
517 | for (int x=1; x<=nx; x++)
|
---|
518 | for (int y=1; y<=ny; y++)
|
---|
519 | {
|
---|
520 | Float_t dt = t-fHist.GetBinContent(x, y);
|
---|
521 | if (dt>fDeadTime && dt<=fDeadTime+fRecoveryTime)
|
---|
522 | n++;
|
---|
523 | }
|
---|
524 | return n;
|
---|
525 | }
|
---|
526 |
|
---|
527 | // --------------------------------------------------------------------------
|
---|
528 | //
|
---|
529 | // Generate an afterpulse originating from the given cell and a pulse with
|
---|
530 | // charge. The afterpulse distribution to use is specified by
|
---|
531 | // the index. The "current" time to which the afterpulse delay refers must
|
---|
532 | // be given by t.
|
---|
533 | //
|
---|
534 | // A generated Afterpulse is added to the list of afterpulses
|
---|
535 | //
|
---|
536 | void APD::GenerateAfterpulse(UInt_t cell, Int_t idx, Double_t charge, Double_t t)
|
---|
537 | {
|
---|
538 | // The cell had a single avalanche with signal height weight.
|
---|
539 | // This cell now can produce an afterpulse photon/avalanche.
|
---|
540 | const Double_t p = gRandom->Uniform();
|
---|
541 |
|
---|
542 | // It's probability scales with the charge of the pulse
|
---|
543 | if (p>charge*fAfterpulseProb[idx])
|
---|
544 | return;
|
---|
545 |
|
---|
546 | // Afterpulses come with a well defined time-constant
|
---|
547 | // after the normal pulse
|
---|
548 | const Double_t dt = MMath::RndmExp(fAfterpulseTau[idx]);
|
---|
549 |
|
---|
550 | fAfterpulses.Add(new Afterpulse(cell, t+dt));
|
---|
551 |
|
---|
552 | #ifdef DEBUG
|
---|
553 | cout << "Add : " << t << " + " << dt << " = " << t+dt << endl;
|
---|
554 | #endif
|
---|
555 | }
|
---|
556 |
|
---|
557 | // --------------------------------------------------------------------------
|
---|
558 | //
|
---|
559 | // Process afterpulses between time and time+dt. All afterpulses in the list
|
---|
560 | // before t=time are ignored. All afterpulses between t=time and
|
---|
561 | // t=time+dt are processed through HitCellImp. Afterpulses after and
|
---|
562 | // equal t=time+dt are skipped.
|
---|
563 | //
|
---|
564 | // Since the afterpulse list is a sorted list newly generated afterpulses
|
---|
565 | // are always inserted into the list behind the current entry. Consequently,
|
---|
566 | // afterpulses generated by afterpulses will also be processed correctly.
|
---|
567 | //
|
---|
568 | // Afterpulses with zero amplitude are deleted from the list. All other after
|
---|
569 | // pulses remain in the list for later evaluation.
|
---|
570 | //
|
---|
571 | void APD::ProcessAfterpulses(Float_t time, Float_t dt)
|
---|
572 | {
|
---|
573 | #ifdef DEBUG
|
---|
574 | cout << "Process afterpulses from " << time << " to " << time+dt << endl;
|
---|
575 | #endif
|
---|
576 |
|
---|
577 | const Float_t end = time+dt;
|
---|
578 |
|
---|
579 | TObjLink *lnk = fAfterpulses.FirstLink();
|
---|
580 | while (lnk)
|
---|
581 | {
|
---|
582 | Afterpulse &ap = *static_cast<Afterpulse*>(lnk->GetObject());
|
---|
583 |
|
---|
584 | // Skip afterpulses which have been processed already
|
---|
585 | // or which we do not have to process anymore
|
---|
586 | if (ap.GetTime()<time || ap.GetAmplitude()>0)
|
---|
587 | {
|
---|
588 | lnk = lnk->Next();
|
---|
589 | continue;
|
---|
590 | }
|
---|
591 |
|
---|
592 | // No afterpulses left in correct time window
|
---|
593 | if (ap.GetTime()>=end)
|
---|
594 | break;
|
---|
595 |
|
---|
596 | // Process afterpulse through HitCellImp
|
---|
597 | const Float_t ampl = ap.Process(*this);
|
---|
598 |
|
---|
599 | // Step to the next entry already, the current one might get deleted
|
---|
600 | lnk = lnk->Next();
|
---|
601 |
|
---|
602 | if (ampl!=0)
|
---|
603 | continue;
|
---|
604 |
|
---|
605 | #ifdef DEBUG
|
---|
606 | cout << "Del : " << ap.GetTime() << " (" << ampl << ")" << endl;
|
---|
607 | #endif
|
---|
608 |
|
---|
609 | // The afterpulse "took place" within the dead time of the
|
---|
610 | // pixel ==> No afterpulse, no crosstalk.
|
---|
611 | delete fAfterpulses.Remove(&ap);
|
---|
612 | }
|
---|
613 | }
|
---|
614 |
|
---|
615 | // --------------------------------------------------------------------------
|
---|
616 | //
|
---|
617 | // Delete all afterpulses before and equal to t=time from the list
|
---|
618 | //
|
---|
619 | void APD::DeleteAfterpulses(Float_t time)
|
---|
620 | {
|
---|
621 | TIter Next(&fAfterpulses);
|
---|
622 |
|
---|
623 | Afterpulse *ap = 0;
|
---|
624 |
|
---|
625 | while ((ap = static_cast<Afterpulse*>(Next())))
|
---|
626 | {
|
---|
627 | if (ap->GetTime()>=time)
|
---|
628 | break;
|
---|
629 |
|
---|
630 | delete fAfterpulses.Remove(ap);
|
---|
631 | }
|
---|
632 | }
|
---|