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 | #include "MAvalanchePhotoDiode.h"
|
---|
43 |
|
---|
44 | #include <TRandom.h>
|
---|
45 |
|
---|
46 | #include "MMath.h"
|
---|
47 |
|
---|
48 | ClassImp(APD);
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 |
|
---|
52 | /*
|
---|
53 | class MyProfile : public TProfile2D
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | void AddBinEntry(Int_t cell) { fBinEntries.fArray[cell]++; }
|
---|
57 | };
|
---|
58 | */
|
---|
59 |
|
---|
60 | // --------------------------------------------------------------------------
|
---|
61 | //
|
---|
62 | // Default Constructor.
|
---|
63 | //
|
---|
64 | // n is the number od cells in x or y. The APD is assumed to
|
---|
65 | // be square.
|
---|
66 | // prob is the crosstalk probability, i.e., the probability that a
|
---|
67 | // photon which produced an avalanche will create another
|
---|
68 | // photon in a neighboring cell
|
---|
69 | // dt is the deadtime, i.e., the time in which the APD cell will show
|
---|
70 | // no response to a photon after a hit
|
---|
71 | // rt is the recovering tims, i.e. the exponential (e^(-dt/rt))
|
---|
72 | // with which the cell is recovering after being dead
|
---|
73 | //
|
---|
74 | // prob, dt and ar can be set to 0 to switch the effect off.
|
---|
75 | // 0 is also the dfeault for all three.
|
---|
76 | //
|
---|
77 | APD::APD(Int_t n, Float_t prob, Float_t dt, Float_t rt)
|
---|
78 | : fHist("APD", "", n, 0.5, n+0.5, n, 0.5, n+0.5),
|
---|
79 | fCrosstalkProb(prob), fDeadTime(dt), fRecoveryTime(rt)
|
---|
80 | {
|
---|
81 | fHist.SetDirectory(0);
|
---|
82 | }
|
---|
83 |
|
---|
84 | // --------------------------------------------------------------------------
|
---|
85 | //
|
---|
86 | // This is the recursive implementation of a hit. If a photon hits a cell
|
---|
87 | // at x and y (must be a valid cell!) at time t, at first we check if the
|
---|
88 | // cell is still dead. If it is not dead we calculate the signal height
|
---|
89 | // from the recovery time. Now we check with the crosstalk probability
|
---|
90 | // whether another photon is created. If another photon is created we
|
---|
91 | // calculate randomly which of the four neighbor cells are hit.
|
---|
92 | // If the cell is outside the APD the photon is ignored. As many
|
---|
93 | // new photons are created until our random number is below the crosstak-
|
---|
94 | // probability.
|
---|
95 | //
|
---|
96 | // The total height of the signal (in units of photons) is returned.
|
---|
97 | // Note, that this can be a fractional number.
|
---|
98 | //
|
---|
99 | // This function looks a bit fancy accessing the histogram and works around
|
---|
100 | // a few histogram functions. This is a speed optimization which works
|
---|
101 | // around a lot of sanity checks which are obsolete in our case.
|
---|
102 | //
|
---|
103 | // The default time is 0.
|
---|
104 | //
|
---|
105 | Float_t APD::HitCellImp(Int_t x, Int_t y, Float_t t)
|
---|
106 | {
|
---|
107 | // if (x<1 || x>fHist.GetNbinsX() ||
|
---|
108 | // y<1 || y>fHist.GetNbinsY())
|
---|
109 | // return 0;
|
---|
110 |
|
---|
111 | // const Int_t cell = fHist.GetBin(x, y);
|
---|
112 | const Int_t cell = x + (fHist.GetNbinsX()+2)*y;
|
---|
113 |
|
---|
114 | // This is the fastes way to access the bin-contents in fArray
|
---|
115 | Float_t &cont = fHist.GetArray()[cell];
|
---|
116 |
|
---|
117 | // const Double_t dt = t-fHist.GetBinContent(x, y)-fDeadTime; //
|
---|
118 | const Float_t dt = t-cont-fDeadTime;
|
---|
119 |
|
---|
120 | // Photons within the dead time are just ignored
|
---|
121 | if (/*hx.GetBinContent(x,y)>0 &&*/ dt<=0)
|
---|
122 | return 0;
|
---|
123 |
|
---|
124 | // Signal height (in units of one photon) produced after dead time
|
---|
125 | const Float_t weight = fRecoveryTime<=0 ? 1 : 1.-exp(-dt/fRecoveryTime);
|
---|
126 |
|
---|
127 | cont = t; // fHist.SetBinContent(x, y, t)
|
---|
128 |
|
---|
129 | // Counter for the numbers of produced photons
|
---|
130 | Float_t n = weight;
|
---|
131 |
|
---|
132 | /*
|
---|
133 | // Check if a photon in a neighboring cell is produced (crosstalk)
|
---|
134 | while (gRandom->Rndm()<fCrosstalkProb)
|
---|
135 | {
|
---|
136 | // Get a random neighbor which is hit.
|
---|
137 | switch (gRandom->Integer(4))
|
---|
138 | {
|
---|
139 | case 0: x++; if (x>fHist.GetNbinsX()) continue; break;
|
---|
140 | case 1: x--; if (x<1) continue; break;
|
---|
141 | case 2: y++; if (y>fHist.GetNbinsY()) continue; break;
|
---|
142 | case 3: y--; if (y<1) continue; break;
|
---|
143 | }
|
---|
144 |
|
---|
145 | n += HitCellImp(x, y, t);
|
---|
146 | }
|
---|
147 | */
|
---|
148 |
|
---|
149 | //for (int i=0; i<1; i++)
|
---|
150 | while (1)
|
---|
151 | {
|
---|
152 | const Double_t rndm = gRandom->Rndm();
|
---|
153 | if (rndm>=fCrosstalkProb)
|
---|
154 | break;
|
---|
155 |
|
---|
156 | // We can re-use the random number becuase it is uniformely
|
---|
157 | // distributed. This saves cpu power
|
---|
158 | const Int_t dir = TMath::FloorNint(4*rndm/fCrosstalkProb);
|
---|
159 |
|
---|
160 | // Get a random neighbor which is hit.
|
---|
161 | switch (dir)
|
---|
162 | {
|
---|
163 | case 0: if (x<fHist.GetNbinsX()) n += HitCellImp(x+1, y, t); break;
|
---|
164 | case 1: if (x>1) n += HitCellImp(x-1, y, t); break;
|
---|
165 | case 2: if (y<fHist.GetNbinsY()) n += HitCellImp(x, y+1, t); break;
|
---|
166 | case 3: if (y>1) n += HitCellImp(x, y-1, t); break;
|
---|
167 | /*
|
---|
168 | case 0: x++; if (x>fHist.GetNbinsX()) continue; break;
|
---|
169 | case 1: x--; if (x<1) continue; break;
|
---|
170 | case 2: y++; if (y>fHist.GetNbinsY()) continue; break;
|
---|
171 | case 3: y--; if (y<1) continue; break;*/
|
---|
172 | }
|
---|
173 |
|
---|
174 | // In the unlikely case the calculated direction is out-of-range,
|
---|
175 | // i.e. <0 or >3, we would just try to fill the same cell again which
|
---|
176 |
|
---|
177 | //n += HitCellImp(x, y, t);
|
---|
178 | }
|
---|
179 |
|
---|
180 | return n;
|
---|
181 | }
|
---|
182 |
|
---|
183 | // --------------------------------------------------------------------------
|
---|
184 | //
|
---|
185 | // Check if x and y is a valid cell. If not return 0, otherwise
|
---|
186 | // HitCelImp(x, y, t)
|
---|
187 | //
|
---|
188 | // The default time is 0.
|
---|
189 | //
|
---|
190 | Float_t APD::HitCell(Int_t x, Int_t y, Float_t t)
|
---|
191 | {
|
---|
192 | if (x<1 || x>fHist.GetNbinsX() ||
|
---|
193 | y<1 || y>fHist.GetNbinsY())
|
---|
194 | return 0;
|
---|
195 |
|
---|
196 | return HitCellImp(x, y, t);
|
---|
197 | }
|
---|
198 |
|
---|
199 | // --------------------------------------------------------------------------
|
---|
200 | //
|
---|
201 | // Determine randomly (uniformly) a cell which was hit. Return
|
---|
202 | // HitCellImp for this cell and the given time.
|
---|
203 | //
|
---|
204 | // The default time is 0.
|
---|
205 | //
|
---|
206 | Float_t APD::HitRandomCell(Float_t t)
|
---|
207 | {
|
---|
208 | const UInt_t nx = fHist.GetNbinsX();
|
---|
209 | const UInt_t ny = fHist.GetNbinsY();
|
---|
210 |
|
---|
211 | const UInt_t idx = gRandom->Integer(nx*ny);
|
---|
212 |
|
---|
213 | const UInt_t x = idx%nx;
|
---|
214 | const UInt_t y = idx/nx;
|
---|
215 |
|
---|
216 | return HitCellImp(x+1, y+1, t);
|
---|
217 | }
|
---|
218 |
|
---|
219 | // --------------------------------------------------------------------------
|
---|
220 | //
|
---|
221 | // Sets all cells with a contents whihc is well before the time t such that
|
---|
222 | // the chip is "virgin". Therefore all cells are set to a time which
|
---|
223 | // is twice the deadtime before the given time and 1000 times the recovery
|
---|
224 | // time.
|
---|
225 | //
|
---|
226 | // If deadtime and recovery time are 0 then t-1 is set.
|
---|
227 | //
|
---|
228 | // The default time is 0.
|
---|
229 | //
|
---|
230 | void APD::FillEmpty(Float_t t)
|
---|
231 | {
|
---|
232 | const Int_t n = (fHist.GetNbinsX()+2)*(fHist.GetNbinsY()+2);
|
---|
233 |
|
---|
234 | const Double_t tm = fDeadTime<=0 && fRecoveryTime<=0 ? t-1 : t-2*fDeadTime-1000*fRecoveryTime;
|
---|
235 |
|
---|
236 | for (int i=0; i<n; i++)
|
---|
237 | fHist.GetArray()[i] = tm;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // --------------------------------------------------------------------------
|
---|
241 | //
|
---|
242 | // First call FillEmpty for the given time t. Then fill each cell by
|
---|
243 | // by calling HitCellImp with time t-gRandom->Exp(n/rate) with n being
|
---|
244 | // the total number of cells.
|
---|
245 | // The default time is 0.
|
---|
246 | //
|
---|
247 | void APD::FillRandom(Float_t rate, Float_t t)
|
---|
248 | {
|
---|
249 | FillEmpty(t);
|
---|
250 |
|
---|
251 | const Int_t nx = fHist.GetNbinsX();
|
---|
252 | const Int_t ny = fHist.GetNbinsY();
|
---|
253 |
|
---|
254 | const Double_t f = (nx*ny)/rate;
|
---|
255 |
|
---|
256 | // FIXME: This is not perfect, is it? What about the dead time?
|
---|
257 |
|
---|
258 | for (int x=1; x<=nx; x++)
|
---|
259 | for (int y=1; y<=ny; y++)
|
---|
260 | {
|
---|
261 | HitCellImp(x, y, t-MMath::RndmExp(f));
|
---|
262 | }
|
---|
263 | }
|
---|
264 |
|
---|
265 | // --------------------------------------------------------------------------
|
---|
266 | //
|
---|
267 | // Retunrs the number of cells which have a time t<=fDeadTime, i.e. which are
|
---|
268 | // dead.
|
---|
269 | // The default time is 0.
|
---|
270 | //
|
---|
271 | Int_t APD::CountDeadCells(Float_t t) const
|
---|
272 | {
|
---|
273 | const Int_t nx = fHist.GetNbinsX();
|
---|
274 | const Int_t ny = fHist.GetNbinsY();
|
---|
275 |
|
---|
276 | Int_t n=0;
|
---|
277 | for (int x=1; x<=nx; x++)
|
---|
278 | for (int y=1; y<=ny; y++)
|
---|
279 | if ((t-fHist.GetBinContent(x, y))<=fDeadTime)
|
---|
280 | n++;
|
---|
281 |
|
---|
282 | return n;
|
---|
283 | }
|
---|
284 |
|
---|
285 | // --------------------------------------------------------------------------
|
---|
286 | //
|
---|
287 | // Returs the number of cells which have a time t<=fDeadTime+fRecoveryTime.
|
---|
288 | // The default time is 0.
|
---|
289 | //
|
---|
290 | Int_t APD::CountRecoveringCells(Float_t t) const
|
---|
291 | {
|
---|
292 | const Int_t nx = fHist.GetNbinsX();
|
---|
293 | const Int_t ny = fHist.GetNbinsY();
|
---|
294 |
|
---|
295 | Int_t n=0;
|
---|
296 | for (int x=1; x<=nx; x++)
|
---|
297 | for (int y=1; y<=ny; y++)
|
---|
298 | {
|
---|
299 | Float_t dt = t-fHist.GetBinContent(x, y);
|
---|
300 | if (dt>fDeadTime && dt<=fDeadTime+fRecoveryTime)
|
---|
301 | n++;
|
---|
302 | }
|
---|
303 | return n;
|
---|
304 | }
|
---|