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 | // MSimRandomPhotons
|
---|
28 | //
|
---|
29 | // Simulate poissonian photons. Since the distribution of the arrival time
|
---|
30 | // differences of these photons is an exonential we can simulate them
|
---|
31 | // using exponentially distributed time differences between two consecutive
|
---|
32 | // photons.
|
---|
33 | //
|
---|
34 | // FIXME: We should add the wavelength distribution.
|
---|
35 | //
|
---|
36 | // Input Containers:
|
---|
37 | // fNameGeomCam [MGeomCam]
|
---|
38 | // MPhotonEvent
|
---|
39 | // MPhotonStatistics
|
---|
40 | // MCorsikaEvtHeader
|
---|
41 | // [MCorsikaRunHeader]
|
---|
42 | //
|
---|
43 | // Output Containers:
|
---|
44 | // MPhotonEvent
|
---|
45 | //
|
---|
46 | //////////////////////////////////////////////////////////////////////////////
|
---|
47 | #include "MSimRandomPhotons.h"
|
---|
48 |
|
---|
49 | #include <TRandom.h>
|
---|
50 |
|
---|
51 | #include "MMath.h" // RndmExp
|
---|
52 |
|
---|
53 | #include "MLog.h"
|
---|
54 | #include "MLogManip.h"
|
---|
55 |
|
---|
56 | #include "MParList.h"
|
---|
57 |
|
---|
58 | #include "MGeomCam.h"
|
---|
59 | #include "MGeomPix.h"
|
---|
60 |
|
---|
61 | #include "MPhotonEvent.h"
|
---|
62 | #include "MPhotonData.h"
|
---|
63 |
|
---|
64 | #include "MCorsikaRunHeader.h"
|
---|
65 |
|
---|
66 | ClassImp(MSimRandomPhotons);
|
---|
67 |
|
---|
68 | using namespace std;
|
---|
69 |
|
---|
70 | // --------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // Default Constructor.
|
---|
73 | //
|
---|
74 | MSimRandomPhotons::MSimRandomPhotons(const char* name, const char *title)
|
---|
75 | : fGeom(0), fEvt(0), fStat(0), /*fEvtHeader(0),*/ fRunHeader(0),
|
---|
76 | fSimulateWavelength(kFALSE), fNameGeomCam("MGeomCam")
|
---|
77 | {
|
---|
78 | fName = name ? name : "MSimRandomPhotons";
|
---|
79 | fTitle = title ? title : "Simulate possonian photons (like NSB or dark current)";
|
---|
80 | }
|
---|
81 |
|
---|
82 | // --------------------------------------------------------------------------
|
---|
83 | //
|
---|
84 | // Check for the necessary containers
|
---|
85 | //
|
---|
86 | Int_t MSimRandomPhotons::PreProcess(MParList *pList)
|
---|
87 | {
|
---|
88 | fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
|
---|
89 | if (!fGeom)
|
---|
90 | {
|
---|
91 | *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
|
---|
92 |
|
---|
93 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
94 | if (!fGeom)
|
---|
95 | {
|
---|
96 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
97 | return kFALSE;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
|
---|
102 | if (!fEvt)
|
---|
103 | {
|
---|
104 | *fLog << err << "MPhotonEvent not found... aborting." << endl;
|
---|
105 | return kFALSE;
|
---|
106 | }
|
---|
107 |
|
---|
108 | fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
|
---|
109 | if (!fStat)
|
---|
110 | {
|
---|
111 | *fLog << err << "MPhotonStatistics not found... aborting." << endl;
|
---|
112 | return kFALSE;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*
|
---|
116 | fEvtHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
|
---|
117 | if (!fEvtHeader)
|
---|
118 | {
|
---|
119 | *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
|
---|
120 | return kFALSE;
|
---|
121 | }*/
|
---|
122 |
|
---|
123 | fRunHeader = 0;
|
---|
124 | if (fSimulateWavelength)
|
---|
125 | {
|
---|
126 | fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
|
---|
127 | if (!fRunHeader)
|
---|
128 | {
|
---|
129 | *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | return kTRUE;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Check for the necessary containers
|
---|
140 | //
|
---|
141 | Int_t MSimRandomPhotons::Process()
|
---|
142 | {
|
---|
143 | // Get array from event container
|
---|
144 | // const Int_t num = fEvt->GetNumPhotons();
|
---|
145 | //
|
---|
146 | // Do not produce pure pedestal events!
|
---|
147 | // if (num==0)
|
---|
148 | // return kTRUE;
|
---|
149 |
|
---|
150 | // Get array from event container
|
---|
151 | // FIXME: Use statistics container instead
|
---|
152 | const UInt_t npix = fGeom->GetNumPixels();
|
---|
153 |
|
---|
154 | // This is the possible window in which the triggered digitization
|
---|
155 | // may take place.
|
---|
156 | const Double_t start = fStat->GetTimeFirst();
|
---|
157 | const Double_t end = fStat->GetTimeLast();
|
---|
158 |
|
---|
159 | // Loop over all pixels
|
---|
160 | for (UInt_t idx=0; idx<npix; idx++)
|
---|
161 | {
|
---|
162 | // Scale the rate with the pixel size. The rate must
|
---|
163 | // always be given for the pixel with index 0.
|
---|
164 | const Double_t avglen = 1./(fFreqFixed+fFreqNSB*(*fGeom)[idx].GetA()/100.);
|
---|
165 |
|
---|
166 | // Start producing photons at time "start"
|
---|
167 | Double_t t = start;
|
---|
168 | while (1)
|
---|
169 | {
|
---|
170 | // Get a random time for the photon.
|
---|
171 | // The differences are exponentially distributed.
|
---|
172 | t += MMath::RndmExp(avglen);
|
---|
173 |
|
---|
174 | // Check if we reached the end of the useful time window
|
---|
175 | if (t>end)
|
---|
176 | break;
|
---|
177 |
|
---|
178 | // Add a new photon
|
---|
179 | // FIXME: SLOW!
|
---|
180 | MPhotonData &ph = fEvt->Add();
|
---|
181 |
|
---|
182 | // Set source to NightSky, time to t and tag to pixel index
|
---|
183 | ph.SetPrimary(MMcEvtBasic::kNightSky);
|
---|
184 | ph.SetWeight();
|
---|
185 | ph.SetTime(t);
|
---|
186 | ph.SetTag(idx);
|
---|
187 |
|
---|
188 | // fProductionHeight, fPosX, fPosY, fCosU, fCosV (irrelevant) FIXME: Reset?
|
---|
189 |
|
---|
190 | if (fRunHeader)
|
---|
191 | {
|
---|
192 | const Float_t wmin = fRunHeader->GetWavelengthMin();
|
---|
193 | const Float_t wmax = fRunHeader->GetWavelengthMax();
|
---|
194 |
|
---|
195 | ph.SetWavelength(TMath::Nint(gRandom->Uniform(wmin, wmax)));
|
---|
196 | }
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | // Re-sort the photons by time!
|
---|
201 | fEvt->Sort(kTRUE);
|
---|
202 |
|
---|
203 | // Update maximum index
|
---|
204 | fStat->SetMaxIndex(npix-1);
|
---|
205 |
|
---|
206 | // Shrink
|
---|
207 | return kTRUE;
|
---|
208 | }
|
---|
209 |
|
---|
210 | // --------------------------------------------------------------------------
|
---|
211 | //
|
---|
212 | // Read the parameters from the resource file.
|
---|
213 | //
|
---|
214 | // FrequencyFixed: 40
|
---|
215 | // FrequencyNSB: 40
|
---|
216 | //
|
---|
217 | // The frequency is given in units fitting the units of the time.
|
---|
218 | // Usually the time is given in nanoseconds thus, e.g., 40 means 40MHz
|
---|
219 | //
|
---|
220 | Int_t MSimRandomPhotons::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
221 | {
|
---|
222 | Bool_t rc = kFALSE;
|
---|
223 | if (IsEnvDefined(env, prefix, "FrequencyFixed", print))
|
---|
224 | {
|
---|
225 | rc = kTRUE;
|
---|
226 | fFreqFixed = GetEnvValue(env, prefix, "FrequencyFixed", fFreqFixed);
|
---|
227 | }
|
---|
228 |
|
---|
229 | if (IsEnvDefined(env, prefix, "FrequencyNSB", print))
|
---|
230 | {
|
---|
231 | rc = kTRUE;
|
---|
232 | fFreqNSB = GetEnvValue(env, prefix, "FrequencyNSB", fFreqNSB);
|
---|
233 | }
|
---|
234 |
|
---|
235 | return rc;
|
---|
236 | }
|
---|