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

Last change on this file since 9294 was 9243, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.7 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 fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
92 if (!fGeom)
93 {
94 *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
95
96 fGeom = (MGeomCam*)pList->FindCreateObj(fNameGeomCam);
97 if (!fGeom)
98 return kFALSE;
99 }
100
101 fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
102 if (!fStat)
103 {
104 *fLog << err << "MPhotonStatistics not found... aborting." << endl;
105 return kFALSE;
106 }
107
108 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
109 if (!fEvt)
110 {
111 *fLog << err << "MPhotonEvent not found... aborting." << endl;
112 return kFALSE;
113 }
114
115 return kTRUE;
116}
117
118// --------------------------------------------------------------------------
119//
120// Initialize as many APDs as we have pixels in the fGeomCam
121//
122Bool_t MSimAPD::ReInit(MParList *plist)
123{
124 if (UInt_t(fAPDs.GetEntriesFast())!=fGeom->GetNumPixels())
125 {
126 fAPDs.Delete();
127
128 // FIXME:
129 // * initialize an empty APD and read the APD setup from a file to
130 // allow different APDs.
131 // * Make the arguments a data member of MSimAPD
132
133 for (UInt_t i=0; i<fGeom->GetNumPixels(); i++)
134 //fAPDs.Add(new APD(60, 0.2, 3, 8.75));
135 //fAPDs.Add(new APD(60/2, 0.2, 3e-9, 8.75e-9*4));
136 fAPDs.Add(new APD(60/2, 0.2, 3, 8.75*4));
137 }
138
139 return kTRUE;
140}
141
142// --------------------------------------------------------------------------
143//
144// Process all photons through the corresponding APD and set the output
145// (weight) accordingly.
146//
147Int_t MSimAPD::Process()
148{
149 //const Double_t rate = 40e9;
150 // FIXME: Where do we get this number from??
151 // const Double_t rate = 0.04;
152
153 // Make all APDs look neutral for the first hit by a photon according to the
154 // average hit rate
155 const UInt_t npix = fAPDs.GetEntriesFast();
156 for (UInt_t idx=0; idx<npix; idx++)
157 static_cast<APD*>(fAPDs.UncheckedAt(idx))->FillRandom(fFreq, fStat->GetTimeFirst());
158
159 // Get number of photons
160 const Int_t num = fEvt->GetNumPhotons();
161
162 // Loop over all photons
163 for (Int_t i=0; i<num; i++)
164 {
165 // Get i-th photon
166 MPhotonData &ph = (*fEvt)[i];
167
168 // Get arrival time of photon and idx
169 const Double_t t = ph.GetTime();
170 const UInt_t idx = ph.GetTag();
171
172 if (ph.GetWeight()!=1)
173 {
174 *fLog << err << "ERROR - MSimAPD: Weight of " << i << "-th photon not 1, but " << ph.GetWeight() << endl;
175 ph.Print();
176 return kERROR;
177 }
178
179 // Simulate hitting the APD (the signal height in effective
180 // "number of photons" is returned)
181 const Double_t hits = static_cast<APD*>(fAPDs.UncheckedAt(idx))->HitRandomCell(t);
182
183 // FIXME: Make a proper simulation of the excess noise!!!
184 //const Double_t signal = gRandom->Gaus(hits, 0.2*TMath::Sqrt(hits));
185
186 // Set the weight to the input
187 ph.SetWeight(hits);
188 }
189
190 return kTRUE;
191}
Note: See TracBrowser for help on using the repository browser.