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 | // MSimAPD
|
---|
28 | //
|
---|
29 | // This tasks simulates the individual APDs. Before starting the APD is
|
---|
30 | // initialized randomly according to the photon rate hitting the APD. Such
|
---|
31 | // it is assumed that the initial condition of the APD is similar to the real
|
---|
32 | // one. In this context it is assumed that the events are independent, so
|
---|
33 | // that the APD is always in the same condition.
|
---|
34 | //
|
---|
35 | // For every photon and event the behaviour of the APD is simulated. The
|
---|
36 | // output is set as weight to the MPhotonData containers.
|
---|
37 | //
|
---|
38 | // Remark:
|
---|
39 | // - The photons MUST be sorted increasing in time.
|
---|
40 | // - The photon rate used to initialize the APD must match the one used
|
---|
41 | // to "fill" the random photons. (FIXME: This should be stored somewhere)
|
---|
42 | //
|
---|
43 | // Input Containers:
|
---|
44 | // fNameGeomCam [MGeomCam]
|
---|
45 | // MPhotonEvent
|
---|
46 | // MPhotonStatistics
|
---|
47 | //
|
---|
48 | // Output Containers:
|
---|
49 | // MPhotonEvent
|
---|
50 | //
|
---|
51 | //////////////////////////////////////////////////////////////////////////////
|
---|
52 | #include "MSimAPD.h"
|
---|
53 |
|
---|
54 | #include <TH2.h>
|
---|
55 | #include <TRandom.h>
|
---|
56 |
|
---|
57 | #include "MLog.h"
|
---|
58 | #include "MLogManip.h"
|
---|
59 |
|
---|
60 | #include "MMath.h"
|
---|
61 | #include "MParList.h"
|
---|
62 |
|
---|
63 | #include "MGeomCam.h"
|
---|
64 |
|
---|
65 | #include "MPhotonEvent.h"
|
---|
66 | #include "MPhotonData.h"
|
---|
67 |
|
---|
68 | #include "MPedestalCam.h"
|
---|
69 | #include "MPedestalPix.h"
|
---|
70 |
|
---|
71 | #include "MAvalanchePhotoDiode.h"
|
---|
72 |
|
---|
73 | ClassImp(MSimAPD);
|
---|
74 |
|
---|
75 | using namespace std;
|
---|
76 |
|
---|
77 | // --------------------------------------------------------------------------
|
---|
78 | //
|
---|
79 | // Default Constructor.
|
---|
80 | //
|
---|
81 | MSimAPD::MSimAPD(const char* name, const char *title)
|
---|
82 | : fGeom(0), fEvt(0), fStat(0), fType(1)
|
---|
83 | {
|
---|
84 | fName = name ? name : "MSimAPD";
|
---|
85 | fTitle = title ? title : " Task to simulate the detection behaviour of APDs";
|
---|
86 | }
|
---|
87 |
|
---|
88 | // --------------------------------------------------------------------------
|
---|
89 | //
|
---|
90 | // Get the necessary parameter containers
|
---|
91 | //
|
---|
92 | Int_t MSimAPD::PreProcess(MParList *pList)
|
---|
93 | {
|
---|
94 | if (fNameGeomCam.IsNull())
|
---|
95 | {
|
---|
96 | *fLog << inf << "No geometry container... skipping." << endl;
|
---|
97 | return kSKIP;
|
---|
98 | }
|
---|
99 |
|
---|
100 | fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
|
---|
101 | if (!fGeom)
|
---|
102 | {
|
---|
103 | *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
|
---|
104 |
|
---|
105 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
106 | if (!fGeom)
|
---|
107 | {
|
---|
108 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
109 | return kFALSE;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
|
---|
114 | if (!fStat)
|
---|
115 | {
|
---|
116 | *fLog << err << "MPhotonStatistics not found... aborting." << endl;
|
---|
117 | return kFALSE;
|
---|
118 | }
|
---|
119 |
|
---|
120 | fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
|
---|
121 | if (!fEvt)
|
---|
122 | {
|
---|
123 | *fLog << err << "MPhotonEvent not found... aborting." << endl;
|
---|
124 | return kFALSE;
|
---|
125 | }
|
---|
126 |
|
---|
127 | fRates = (MPedestalCam*)pList->FindObject("AccidentalPhotonRates", "MPedestalCam");
|
---|
128 | if (!fRates)
|
---|
129 | {
|
---|
130 | *fLog << inf;
|
---|
131 | *fLog << "AccidentalPhotonRates [MPedestalCam] not found..." << endl;
|
---|
132 | *fLog << " using " << fFreq << " as default for all G-APDs." << endl;
|
---|
133 | }
|
---|
134 |
|
---|
135 | return kTRUE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Initialize as many APDs as we have pixels in the fGeomCam
|
---|
141 | //
|
---|
142 | Bool_t MSimAPD::ReInit(MParList *plist)
|
---|
143 | {
|
---|
144 | if (UInt_t(fAPDs.GetEntriesFast())==fGeom->GetNumPixels())
|
---|
145 | return kTRUE;
|
---|
146 |
|
---|
147 | fAPDs.Delete();
|
---|
148 |
|
---|
149 | // FIXME:
|
---|
150 | // * initialize an empty APD and read the APD setup from a file to
|
---|
151 | // allow different APDs.
|
---|
152 | // * Make the arguments a data member of MSimAPD
|
---|
153 |
|
---|
154 | Int_t ncells = 0;
|
---|
155 | Float_t crosstalk = 0;
|
---|
156 | Float_t deadtime = 0;
|
---|
157 | Float_t recovery = 0;
|
---|
158 |
|
---|
159 | switch (fType)
|
---|
160 | {
|
---|
161 | case 1:
|
---|
162 | ncells = 30;
|
---|
163 | crosstalk = 0.2;
|
---|
164 | deadtime = 3;
|
---|
165 | recovery = 8.75*4;
|
---|
166 | break;
|
---|
167 |
|
---|
168 | case 2:
|
---|
169 | ncells = 60;
|
---|
170 | crosstalk = 0.2;
|
---|
171 | deadtime = 3;
|
---|
172 | recovery = 8.75;
|
---|
173 | break;
|
---|
174 |
|
---|
175 | default:
|
---|
176 | *fLog << err << "ERROR - APD type " << fType << " undefined." << endl;
|
---|
177 | return kFALSE;
|
---|
178 | }
|
---|
179 |
|
---|
180 | for (UInt_t i=0; i<fGeom->GetNumPixels(); i++)
|
---|
181 | fAPDs.Add(new APD(ncells, crosstalk, deadtime, recovery));
|
---|
182 |
|
---|
183 | return kTRUE;
|
---|
184 | }
|
---|
185 |
|
---|
186 | // --------------------------------------------------------------------------
|
---|
187 | //
|
---|
188 | // Process all photons through the corresponding APD and set the output
|
---|
189 | // (weight) accordingly.
|
---|
190 | //
|
---|
191 | Int_t MSimAPD::Process()
|
---|
192 | {
|
---|
193 | //const Double_t rate = 40e9;
|
---|
194 | // FIXME: Where do we get this number from??
|
---|
195 | // const Double_t rate = 0.04;
|
---|
196 |
|
---|
197 | // Make all APDs look neutral for the first hit by a photon according to the
|
---|
198 | // average hit rate
|
---|
199 | const UInt_t npix = fAPDs.GetEntriesFast();
|
---|
200 |
|
---|
201 | // Check if we can safely proceed (this can fail if we either haven't been
|
---|
202 | // ReInit'ed or the max index in MPhotonStatistics is wrong)
|
---|
203 | if ((Int_t)npix<fStat->GetMaxIndex())
|
---|
204 | {
|
---|
205 | *fLog << err << "ERROR - MSimAPD::Process: Only " << npix << " APDs initialized. At least " << fStat->GetMaxIndex() << " needed... abort." << endl;
|
---|
206 | return kERROR;
|
---|
207 | }
|
---|
208 | /*
|
---|
209 | for (UInt_t idx=0; idx<npix; idx++)
|
---|
210 | {
|
---|
211 | const Double_t freq = fRates ? (*fRates)[idx].GetPedestal() : fFreq;
|
---|
212 | static_cast<APD*>(fAPDs.UncheckedAt(idx))->FillRandom(freq, fStat->GetTimeFirst());
|
---|
213 | }
|
---|
214 | */
|
---|
215 |
|
---|
216 | // This tries to initialize dead and relaxing cells properly. If
|
---|
217 | // the APD has not been initialized before the chip is randomsly
|
---|
218 | // filled, otherwise a time window of the default relaxing time
|
---|
219 | // is simulated, so that the previous influence is less than a permille.
|
---|
220 | for (UInt_t idx=0; idx<npix; idx++)
|
---|
221 | {
|
---|
222 | const Double_t freq = fRates ? (*fRates)[idx].GetPedestal() : fFreq;
|
---|
223 | static_cast<APD*>(fAPDs.UncheckedAt(idx))->Init(freq);
|
---|
224 | }
|
---|
225 |
|
---|
226 | // Get number of photons
|
---|
227 | const Int_t num = fEvt->GetNumPhotons();
|
---|
228 |
|
---|
229 | // Loop over all photons
|
---|
230 | for (Int_t i=0; i<num; i++)
|
---|
231 | {
|
---|
232 | // Get i-th photon
|
---|
233 | MPhotonData &ph = (*fEvt)[i];
|
---|
234 |
|
---|
235 | // Get arrival time of photon and idx
|
---|
236 | const Double_t t = ph.GetTime()-fStat->GetTimeFirst();
|
---|
237 | const Int_t idx = ph.GetTag();
|
---|
238 | if (idx<0)
|
---|
239 | {
|
---|
240 | *fLog << err << "ERROR - MSimAPD: Invalid index -1." << endl;
|
---|
241 | return kERROR;
|
---|
242 | }
|
---|
243 |
|
---|
244 | if (ph.GetWeight()!=1)
|
---|
245 | {
|
---|
246 | *fLog << err << "ERROR - MSimAPD: Weight of " << i << "-th photon not 1, but " << ph.GetWeight() << endl;
|
---|
247 | ph.Print();
|
---|
248 | return kERROR;
|
---|
249 | }
|
---|
250 | // Simulate hitting the APD (the signal height in effective
|
---|
251 | // "number of photons" is returned)
|
---|
252 | const Double_t hits = static_cast<APD*>(fAPDs.UncheckedAt(idx))->HitRandomCellRelative(t);
|
---|
253 |
|
---|
254 | // FIXME: Make a proper simulation of the excess noise!!!
|
---|
255 | //const Double_t signal = gRandom->Gaus(hits, 0.2*TMath::Sqrt(hits));
|
---|
256 |
|
---|
257 | // Set the weight to the input
|
---|
258 | ph.SetWeight(hits);
|
---|
259 | }
|
---|
260 |
|
---|
261 | // Now we have to shift the evolved time of all APDs to the end of our
|
---|
262 | // simulated time.
|
---|
263 | for (UInt_t idx=0; idx<npix; idx++)
|
---|
264 | static_cast<APD*>(fAPDs.UncheckedAt(idx))->IncreaseTime(fStat->GetTimeLast());
|
---|
265 |
|
---|
266 | return kTRUE;
|
---|
267 | }
|
---|
268 |
|
---|
269 | // --------------------------------------------------------------------------
|
---|
270 | //
|
---|
271 | // NameGeomCam
|
---|
272 | // Type: 1
|
---|
273 | //
|
---|
274 | Int_t MSimAPD::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
275 | {
|
---|
276 | Bool_t rc = kFALSE;
|
---|
277 | if (IsEnvDefined(env, prefix, "NameGeomCam", print))
|
---|
278 | {
|
---|
279 | rc = kTRUE;
|
---|
280 | fNameGeomCam = GetEnvValue(env, prefix, "NameGeomCam", fNameGeomCam);
|
---|
281 | }
|
---|
282 |
|
---|
283 | if (IsEnvDefined(env, prefix, "Type", print))
|
---|
284 | {
|
---|
285 | rc = kTRUE;
|
---|
286 | fType = GetEnvValue(env, prefix, "Type", fType);
|
---|
287 | }
|
---|
288 |
|
---|
289 | return rc;
|
---|
290 | }
|
---|