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

Last change on this file since 9316 was 9306, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 7.8 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()>0)
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 return tlist->ReInit(fParList);
173}
174
175// --------------------------------------------------------------------------
176//
177// Produce the events.
178//
179Int_t MSimCalibrationSignal::Process()
180{
181 if (GetNumExecutions()>fNumEvents)
182 return kFALSE;
183
184 if (!CallReInit())
185 return kERROR;
186
187 Int_t cnt = 0;
188 if (fRunHeader->IsCalibrationRun())
189 {
190 for (UInt_t idx=0; idx<fGeom->GetNumPixels(); idx++)
191 {
192 // FIXME: How does the distribution look like? Poissonian?
193 for (UInt_t i=0; i<fNumPhotons; i++)
194 {
195 MPhotonData &ph = fEvt->Add(cnt++);
196
197 // FIMXE: Is this the correct distribution
198 const Float_t tm = gRandom->Gaus(0, fTimeJitter);
199
200 ph.SetPrimary(MMcEvtBasic::kArtificial);
201 ph.SetTag(idx);
202 ph.SetWeight();
203 ph.SetTime(tm);
204 }
205 }
206 }
207
208 fEvt->Shrink(cnt);
209 fEvt->Sort(kTRUE);
210
211 // ------------ FIMXE: Move somewhere else? -------------
212 // -------------------- MSimGeomCam ---------------------
213
214 const Double_t freq = fRunHeader->GetFreqSampling()/1000.;
215
216 // We add an additional sample at the end to support a possible shift
217 // of the start time of the first event by 0 to 1 sample.
218 const Int_t ns = fRunHeader->GetNumSamplesHiGain()+1;
219
220 // Length (ns), Pulse position (Units ns)
221 const Float_t pp = fPulsePos->GetVal();
222 const Float_t pw = fPulse->GetPulseWidth();
223
224 const Float_t first = cnt>0 ? fEvt->GetFirst()->GetTime() : 0;
225 const Float_t last = cnt>0 ? fEvt->GetLast()->GetTime() : ns*freq;
226
227 fStat->SetTime(first-pp-pw, last-pp+pw + ns*freq);
228 fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
229 fStat->SetReadyToSave();
230
231 // FIXME: Jitter! (Own class?)
232 fTrigger->SetVal(pp*freq);
233 fTrigger->SetReadyToSave();
234
235 // Set trigger pattern according to the trigger type
236 const UInt_t p = fRunHeader->IsCalibrationRun() ? MTriggerPattern::kCalibration : MTriggerPattern::kPedestal;
237 fEvtHeader->SetTriggerPattern(~(p | (p<<8)));
238 fEvtHeader->SetReadyToSave();
239
240 return kTRUE;
241}
242
243// --------------------------------------------------------------------------
244//
245// Read the parameters from the resource file.
246//
247// NumEvents: 1000
248// NumPhotons: 5
249// TimeJitter: 1
250//
251Int_t MSimCalibrationSignal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
252{
253 Bool_t rc = kFALSE;
254 if (IsEnvDefined(env, prefix, "NumEvents", print))
255 {
256 rc = kTRUE;
257 fNumEvents = GetEnvValue(env, prefix, "NumEvents", (Int_t)fNumEvents);
258 }
259
260 if (IsEnvDefined(env, prefix, "NumPhotons", print))
261 {
262 rc = kTRUE;
263 fNumPhotons = GetEnvValue(env, prefix, "NumPhotons", (Int_t)fNumPhotons);
264 }
265
266 if (IsEnvDefined(env, prefix, "TimeJitter", print))
267 {
268 rc = kTRUE;
269 fTimeJitter = GetEnvValue(env, prefix, "TimeJitter", fTimeJitter);
270 }
271
272 return rc;
273}
Note: See TracBrowser for help on using the repository browser.