source: trunk/MagicSoft/Mars/msimcamera/MSimCalibrationSignal.cc@ 9342

Last change on this file since 9342 was 9317, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 8.0 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// MSimCalibrationSignal
28//
29// This task is a MRead task which produces events instead of reading them
30// from a file. To be more precise, calibration events are produced.
31// (Note, that pedestal events are also a kind of calibration events).
32//
33// Whether pedestal or calibration events are produced is defined by
34// the RunType stored in MRawRunheader. The number of pixels which are
35// "enlightened" are determined from a MGeomCam.
36//
37//
38// Input Containers:
39// fNameGeomCam [MGeomCam]
40// MRawRunHeader
41// IntendedPulsePos [MParameterD]
42//
43// Output Containers:
44// [MPhotonEvent]
45// [TriggerPos [MParameterD]]
46// MPhotonStatistics
47// MRawEvtHeader
48//
49//////////////////////////////////////////////////////////////////////////////
50#include "MSimCalibrationSignal.h"
51
52#include <TRandom.h>
53
54#include "MParList.h"
55#include "MTaskList.h"
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60#include "MParameters.h"
61
62#include "MGeomCam.h"
63#include "MPulseShape.h"
64#include "MTriggerPattern.h"
65
66#include "MRawRunHeader.h"
67#include "MRawEvtHeader.h"
68
69#include "MPhotonEvent.h"
70#include "MPhotonData.h"
71
72ClassImp(MSimCalibrationSignal);
73
74using namespace std;
75
76// --------------------------------------------------------------------------
77//
78// Default Constructor.
79//
80MSimCalibrationSignal::MSimCalibrationSignal(const char* name, const char *title)
81 : fParList(0), fGeom(0), fPulse(0), fPulsePos(0), fTrigger(0),
82 fRunHeader(0), fEvtHeader(0), fEvt(0), fStat(0),
83 fNumEvents(1000), fNumPhotons(5), fTimeJitter(1)
84{
85 fName = name ? name : "MRead";//"MSimCalibrationSignal";
86 fTitle = title ? title : "Task to create a fake signal (derives from MRead)";
87}
88
89// --------------------------------------------------------------------------
90//
91// Check for the needed parameter containers.
92//
93Int_t MSimCalibrationSignal::PreProcess(MParList *pList)
94{
95 fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
96 if (!fGeom)
97 {
98 *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
99
100 fGeom = (MGeomCam*)pList->FindCreateObj(fNameGeomCam);
101 if (!fGeom)
102 return kFALSE;
103 }
104
105 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
106 if (!fRunHeader)
107 {
108 *fLog << err << "MRawRunHeader not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 fEvt = (MPhotonEvent*)pList->FindCreateObj("MPhotonEvent");
113 if (!fEvt)
114 return kFALSE;
115
116 fTrigger = (MParameterD*)pList->FindCreateObj("MParameterD", "TriggerPos");
117 if (!fTrigger)
118 return kFALSE;
119
120 fStat = (MPhotonStatistics*)pList->FindCreateObj("MPhotonStatistics");
121 if (!fStat)
122 return kFALSE;
123
124 fEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
125 if (!fEvtHeader)
126 return kFALSE;
127
128 fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
129 if (!fPulsePos)
130 {
131 *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
132 return kFALSE;
133 }
134
135 fPulse = (MPulseShape*)pList->FindObject("MPulseShape");
136 if (!fPulse)
137 {
138 *fLog << err << "MPulsShape not found... aborting." << endl;
139 return kFALSE;
140 }
141
142 *fLog << all << "Number of Events: " << fNumEvents << endl;
143
144 //
145 // Search for MTaskList
146 //
147 fParList = pList;
148
149 //
150 // A new file has been opened and new headers have been read.
151 // --> ReInit tasklist
152 //
153 return kTRUE;
154}
155
156// --------------------------------------------------------------------------
157//
158// ReInit the task-list if this is the first "event from this fake file"
159//
160Bool_t MSimCalibrationSignal::CallReInit()
161{
162 if (GetNumExecutions()!=1)
163 return kTRUE;
164
165 MTask *tlist = (MTask*)fParList->FindObject("MTaskList");
166 if (!tlist)
167 {
168 *fLog << err << dbginf << "MTaskList not found... abort." << endl;
169 return kFALSE;
170 }
171
172 fRunHeader->SetReadyToSave();
173
174 return tlist->ReInit(fParList);
175}
176
177// --------------------------------------------------------------------------
178//
179// Produce the events.
180//
181Int_t MSimCalibrationSignal::Process()
182{
183 if (GetNumExecutions()>fNumEvents)
184 return kFALSE;
185
186 if (!CallReInit())
187 return kERROR;
188
189 Int_t cnt = 0;
190 if (fRunHeader->IsCalibrationRun())
191 {
192 for (UInt_t idx=0; idx<fGeom->GetNumPixels(); idx++)
193 {
194 const Int_t num = TMath::Nint(gRandom->Gaus(fNumPhotons, fNumPhotons/10));
195
196 // FIXME: How does the distribution look like? Poissonian?
197 for (Int_t i=0; i<num; i++)
198 {
199 MPhotonData &ph = fEvt->Add(cnt++);
200
201 // FIMXE: Is this the correct distribution
202 const Float_t tm = gRandom->Gaus(0, fTimeJitter);
203
204 ph.SetPrimary(MMcEvtBasic::kArtificial);
205 ph.SetTag(idx);
206 ph.SetWeight();
207 ph.SetTime(tm);
208 }
209 }
210 }
211
212 fEvt->Shrink(cnt);
213 fEvt->Sort(kTRUE);
214
215 // ------------ FIMXE: Move somewhere else? -------------
216 // -------------------- MSimGeomCam ---------------------
217
218 // =====> Move to MSimReadoutWindow ?
219
220 const Double_t freq = fRunHeader->GetFreqSampling()/1000.;
221
222 // We add an additional sample at the end to support a possible shift
223 // of the start time of the first event by 0 to 1 sample.
224 const Int_t ns = fRunHeader->GetNumSamplesHiGain()+1;
225
226 // Length (ns), Pulse position (Units ns)
227 const Float_t pp = fPulsePos->GetVal();
228 const Float_t pw = fPulse->GetPulseWidth();
229
230 const Float_t first = cnt>0 ? fEvt->GetFirst()->GetTime() : 0;
231 const Float_t last = cnt>0 ? fEvt->GetLast()->GetTime() : ns*freq;
232
233 fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
234 fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
235 fStat->SetReadyToSave();
236
237 // FIXME: Jitter! (Own class?)
238 fTrigger->SetVal((pp+pw)*freq);
239 fTrigger->SetReadyToSave();
240
241 // Set trigger pattern according to the trigger type
242 const UInt_t p = fRunHeader->IsCalibrationRun() ? MTriggerPattern::kCalibration : MTriggerPattern::kPedestal;
243 fEvtHeader->SetTriggerPattern(~(p | (p<<8)));
244 fEvtHeader->SetCalibrationPattern(0/*BIT(16)<<16*/); // CT1 Pulser, see MCalibrationPatternDecode
245 fEvtHeader->SetReadyToSave();
246
247 return kTRUE;
248}
249
250// --------------------------------------------------------------------------
251//
252// Read the parameters from the resource file.
253//
254// NumEvents: 1000
255// NumPhotons: 5
256// TimeJitter: 1
257//
258Int_t MSimCalibrationSignal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
259{
260 Bool_t rc = kFALSE;
261 if (IsEnvDefined(env, prefix, "NumEvents", print))
262 {
263 rc = kTRUE;
264 fNumEvents = GetEnvValue(env, prefix, "NumEvents", (Int_t)fNumEvents);
265 }
266
267 if (IsEnvDefined(env, prefix, "NumPhotons", print))
268 {
269 rc = kTRUE;
270 fNumPhotons = GetEnvValue(env, prefix, "NumPhotons", (Int_t)fNumPhotons);
271 }
272
273 if (IsEnvDefined(env, prefix, "TimeJitter", print))
274 {
275 rc = kTRUE;
276 fTimeJitter = GetEnvValue(env, prefix, "TimeJitter", fTimeJitter);
277 }
278
279 return rc;
280}
Note: See TracBrowser for help on using the repository browser.