source: trunk/MagicSoft/Mars/msimcamera/MSimRandomPhotons.cc@ 9301

Last change on this file since 9301 was 9272, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.6 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// 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
66ClassImp(MSimRandomPhotons);
67
68using namespace std;
69
70// --------------------------------------------------------------------------
71//
72// Default Constructor.
73//
74MSimRandomPhotons::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//
86Int_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->FindCreateObj(fNameGeomCam);
94 if (!fGeom)
95 return kFALSE;
96 }
97
98 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
99 if (!fEvt)
100 {
101 *fLog << err << "MPhotonEvent not found... aborting." << endl;
102 return kFALSE;
103 }
104
105 fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
106 if (!fStat)
107 {
108 *fLog << err << "MPhotonStatistics not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 /*
113 fEvtHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
114 if (!fEvtHeader)
115 {
116 *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
117 return kFALSE;
118 }*/
119
120 fRunHeader = 0;
121 if (fSimulateWavelength)
122 {
123 fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
124 if (!fRunHeader)
125 {
126 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
127 return kFALSE;
128 }
129 }
130
131 return kTRUE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Check for the necessary containers
137//
138Int_t MSimRandomPhotons::Process()
139{
140 // Get array from event container
141 // const Int_t num = fEvt->GetNumPhotons();
142 //
143 // Do not produce pure pedestal events!
144 // if (num==0)
145 // return kTRUE;
146
147 // Get array from event container
148 // FIXME: Use statistics container instead
149 const UInt_t npix = fGeom->GetNumPixels();
150
151 // This is the possible window in which the triggered digitization
152 // may take place.
153 const Double_t start = fStat->GetTimeFirst();
154 const Double_t end = fStat->GetTimeLast();
155
156 // Loop over all pixels
157 for (UInt_t idx=0; idx<npix; idx++)
158 {
159 // Scale the rate with the pixel size. The rate must
160 // always be given for the pixel with index 0.
161 const Double_t avglen = 1./(fFreqFixed+fFreqNSB*(*fGeom)[idx].GetA()/100.);
162
163 // Start producing photons at time "start"
164 Double_t t = start;
165 while (1)
166 {
167 // Get a random time for the photon.
168 // The differences are exponentially distributed.
169 t += MMath::RndmExp(avglen);
170
171 // Check if we reached the end of the useful time window
172 if (t>end)
173 break;
174
175 // Add a new photon
176 // FIXME: SLOW!
177 MPhotonData &ph = fEvt->Add();
178
179 // Set source to NightSky, time to t and tag to pixel index
180 ph.SetPrimary(MMcEvtBasic::kNightSky);
181 ph.SetWeight();
182 ph.SetTime(t);
183 ph.SetTag(idx);
184
185 // fProductionHeight, fPosX, fPosY, fCosU, fCosV (irrelevant) FIXME: Reset?
186
187 if (fRunHeader)
188 {
189 const Float_t wmin = fRunHeader->GetWavelengthMin();
190 const Float_t wmax = fRunHeader->GetWavelengthMax();
191
192 ph.SetWavelength(TMath::Nint(gRandom->Uniform(wmin, wmax)));
193 }
194 }
195 }
196
197 // Re-sort the photons by time!
198 fEvt->Sort(kTRUE);
199
200 // Update maximum index
201 fStat->SetMaxIndex(npix-1);
202
203 // Shrink
204 return kTRUE;
205}
206
207// --------------------------------------------------------------------------
208//
209// Read the parameters from the resource file.
210//
211// FrequencyFixed: 40
212// FrequencyNSB: 40
213//
214// The frequency is given in units fitting the units of the time.
215// Usually the time is given in nanoseconds thus, e.g., 40 means 40MHz
216//
217Int_t MSimRandomPhotons::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
218{
219 Bool_t rc = kFALSE;
220 if (IsEnvDefined(env, prefix, "FrequencyFixed", print))
221 {
222 rc = kTRUE;
223 fFreqFixed = GetEnvValue(env, prefix, "FrequencyFixed", fFreqFixed);
224 }
225
226 if (IsEnvDefined(env, prefix, "FrequencyNSB", print))
227 {
228 rc = kTRUE;
229 fFreqNSB = GetEnvValue(env, prefix, "FrequencyNSB", fFreqNSB);
230 }
231
232 return rc;
233}
Note: See TracBrowser for help on using the repository browser.