source: trunk/MagicSoft/Mars/msimcamera/MSimAPD.cc@ 9328

Last change on this file since 9328 was 9328, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.5 KB
Line 
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 "MAvalanchePhotoDiode.h"
69
70ClassImp(MSimAPD);
71
72using namespace std;
73
74// --------------------------------------------------------------------------
75//
76// Default Constructor.
77//
78MSimAPD::MSimAPD(const char* name, const char *title)
79: fGeom(0), fEvt(0), fStat(0)
80{
81 fName = name ? name : "MSimAPD";
82 fTitle = title ? title : " Task to simulate the detection behaviour of APDs";
83}
84
85// --------------------------------------------------------------------------
86//
87// Get the necessary parameter containers
88//
89Int_t MSimAPD::PreProcess(MParList *pList)
90{
91 if (fNameGeomCam.IsNull())
92 {
93 *fLog << inf << "No geometry container... skipping." << endl;
94 return kSKIP;
95 }
96
97 fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
98 if (!fGeom)
99 {
100 *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
101
102 fGeom = (MGeomCam*)pList->FindCreateObj(fNameGeomCam);
103 if (!fGeom)
104 return kFALSE;
105 }
106
107 fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
108 if (!fStat)
109 {
110 *fLog << err << "MPhotonStatistics not found... aborting." << endl;
111 return kFALSE;
112 }
113
114 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
115 if (!fEvt)
116 {
117 *fLog << err << "MPhotonEvent not found... aborting." << endl;
118 return kFALSE;
119 }
120
121 return kTRUE;
122}
123
124// --------------------------------------------------------------------------
125//
126// Initialize as many APDs as we have pixels in the fGeomCam
127//
128Bool_t MSimAPD::ReInit(MParList *plist)
129{
130 if (UInt_t(fAPDs.GetEntriesFast())!=fGeom->GetNumPixels())
131 {
132 fAPDs.Delete();
133
134 // FIXME:
135 // * initialize an empty APD and read the APD setup from a file to
136 // allow different APDs.
137 // * Make the arguments a data member of MSimAPD
138
139 for (UInt_t i=0; i<fGeom->GetNumPixels(); i++)
140 //fAPDs.Add(new APD(60, 0.2, 3, 8.75));
141 //fAPDs.Add(new APD(60/2, 0.2, 3e-9, 8.75e-9*4));
142 fAPDs.Add(new APD(60/2, 0.2, 3, 8.75*4));
143 }
144
145 return kTRUE;
146}
147
148// --------------------------------------------------------------------------
149//
150// Process all photons through the corresponding APD and set the output
151// (weight) accordingly.
152//
153Int_t MSimAPD::Process()
154{
155 //const Double_t rate = 40e9;
156 // FIXME: Where do we get this number from??
157 // const Double_t rate = 0.04;
158
159 // Make all APDs look neutral for the first hit by a photon according to the
160 // average hit rate
161 const UInt_t npix = fAPDs.GetEntriesFast();
162
163 // Check if we can safely proceed (this can fail if we either haven't been
164 // ReInit'ed or the max index in MPhotonStatistics is wrong)
165 if ((Int_t)npix<fStat->GetMaxIndex())
166 {
167 *fLog << err << "ERROR - MSimAPD::Process: Only " << npix << " APDs initialized. At least " << fStat->GetMaxIndex() << " needed... abort." << endl;
168 return kERROR;
169 }
170
171 for (UInt_t idx=0; idx<npix; idx++)
172 static_cast<APD*>(fAPDs.UncheckedAt(idx))->FillRandom(fFreq, fStat->GetTimeFirst());
173
174 // Get number of photons
175 const Int_t num = fEvt->GetNumPhotons();
176
177 // Loop over all photons
178 for (Int_t i=0; i<num; i++)
179 {
180 // Get i-th photon
181 MPhotonData &ph = (*fEvt)[i];
182
183 // Get arrival time of photon and idx
184 const Double_t t = ph.GetTime();
185 const UInt_t idx = ph.GetTag();
186
187 if (ph.GetWeight()!=1)
188 {
189 *fLog << err << "ERROR - MSimAPD: Weight of " << i << "-th photon not 1, but " << ph.GetWeight() << endl;
190 ph.Print();
191 return kERROR;
192 }
193
194 // Simulate hitting the APD (the signal height in effective
195 // "number of photons" is returned)
196 const Double_t hits = static_cast<APD*>(fAPDs.UncheckedAt(idx))->HitRandomCell(t);
197
198 // FIXME: Make a proper simulation of the excess noise!!!
199 //const Double_t signal = gRandom->Gaus(hits, 0.2*TMath::Sqrt(hits));
200
201 // Set the weight to the input
202 ph.SetWeight(hits);
203 }
204
205 return kTRUE;
206}
207
208// --------------------------------------------------------------------------
209//
210// NameGeomCam
211//
212Int_t MSimAPD::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
213{
214 Bool_t rc = kFALSE;
215 if (IsEnvDefined(env, prefix, "NameGeomCam", print))
216 {
217 rc = kTRUE;
218 fNameGeomCam = GetEnvValue(env, prefix, "NameGeomCam", fNameGeomCam);
219 }
220
221 return rc;
222}
Note: See TracBrowser for help on using the repository browser.