source: branches/Mars_use_drstimefiles/msimcamera/MSimCalibrationSignal.cc@ 18605

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