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 |
|
---|
64 | #include "MRawRunHeader.h"
|
---|
65 | #include "MRawEvtHeader.h"
|
---|
66 |
|
---|
67 | #include "MPhotonEvent.h"
|
---|
68 | #include "MPhotonData.h"
|
---|
69 |
|
---|
70 | ClassImp(MSimCalibrationSignal);
|
---|
71 |
|
---|
72 | using namespace std;
|
---|
73 |
|
---|
74 | // --------------------------------------------------------------------------
|
---|
75 | //
|
---|
76 | // Default Constructor.
|
---|
77 | //
|
---|
78 | MSimCalibrationSignal::MSimCalibrationSignal(const char* name, const char *title)
|
---|
79 | : fParList(0), fGeom(0), fPulsePos(0), fTrigger(0), fRunHeader(0), fEvtHeader(0),
|
---|
80 | fEvt(0), fStat(0), fNumEntries(1000)
|
---|
81 | {
|
---|
82 | fName = name ? name : "MRead";//"MSimCalibrationSignal";
|
---|
83 | fTitle = title ? title : "Task to create a fake signal (derives from MRead)";
|
---|
84 | }
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // Check for the needed parameter containers.
|
---|
89 | //
|
---|
90 | Int_t MSimCalibrationSignal::PreProcess(MParList *pList)
|
---|
91 | {
|
---|
92 | fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
|
---|
93 | if (!fGeom)
|
---|
94 | {
|
---|
95 | *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
|
---|
96 |
|
---|
97 | fGeom = (MGeomCam*)pList->FindCreateObj(fNameGeomCam);
|
---|
98 | if (!fGeom)
|
---|
99 | return kFALSE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
103 | if (!fRunHeader)
|
---|
104 | {
|
---|
105 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
---|
106 | return kFALSE;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | fEvt = 0;
|
---|
111 | fTrigger = 0;
|
---|
112 |
|
---|
113 | if (fRunHeader->IsCalibrationRun())
|
---|
114 | {
|
---|
115 | fEvt = (MPhotonEvent*)pList->FindCreateObj("MPhotonEvent");
|
---|
116 | if (!fEvt)
|
---|
117 | return kFALSE;
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | fTrigger = (MParameterD*)pList->FindCreateObj("MParameterD", "TriggerPos");
|
---|
122 | if (!fTrigger)
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | fStat = (MPhotonStatistics*)pList->FindCreateObj("MPhotonStatistics");
|
---|
127 | if (!fStat)
|
---|
128 | return kFALSE;
|
---|
129 |
|
---|
130 | fEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
|
---|
131 | if (!fEvtHeader)
|
---|
132 | return kFALSE;
|
---|
133 |
|
---|
134 | fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
|
---|
135 | if (!fPulsePos)
|
---|
136 | {
|
---|
137 | *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
|
---|
138 | return kFALSE;
|
---|
139 | }
|
---|
140 |
|
---|
141 | //
|
---|
142 | // Search for MTaskList
|
---|
143 | //
|
---|
144 | fParList = pList;
|
---|
145 |
|
---|
146 | //
|
---|
147 | // A new file has been opened and new headers have been read.
|
---|
148 | // --> ReInit tasklist
|
---|
149 | //
|
---|
150 | return kTRUE;
|
---|
151 | }
|
---|
152 |
|
---|
153 | // --------------------------------------------------------------------------
|
---|
154 | //
|
---|
155 | // ReInit the task-list if this is the first "event from this fake file"
|
---|
156 | //
|
---|
157 | Bool_t MSimCalibrationSignal::ReInit(MParList *plist)
|
---|
158 | {
|
---|
159 | if (plist)
|
---|
160 | return kTRUE;
|
---|
161 |
|
---|
162 | if (GetNumExecutions()==0)
|
---|
163 | return kTRUE;
|
---|
164 |
|
---|
165 | MTask *fTaskList = (MTask*)fParList->FindObject("MTaskList");
|
---|
166 | if (!fTaskList)
|
---|
167 | {
|
---|
168 | *fLog << err << dbginf << "MTaskList not found... abort." << endl;
|
---|
169 | return kFALSE;
|
---|
170 | }
|
---|
171 |
|
---|
172 | if (!fTaskList->ReInit(fParList))
|
---|
173 | return kFALSE;
|
---|
174 |
|
---|
175 | return kTRUE;
|
---|
176 | }
|
---|
177 |
|
---|
178 | // --------------------------------------------------------------------------
|
---|
179 | //
|
---|
180 | // Produce the events.
|
---|
181 | //
|
---|
182 | Int_t MSimCalibrationSignal::Process()
|
---|
183 | {
|
---|
184 | if (GetNumExecutions()==fNumEntries)
|
---|
185 | return kFALSE;
|
---|
186 |
|
---|
187 | if (!ReInit())
|
---|
188 | return kERROR;
|
---|
189 |
|
---|
190 | Int_t cnt = 0;
|
---|
191 | if (fRunHeader->IsCalibrationRun())
|
---|
192 | {
|
---|
193 | for (UInt_t idx=0; idx<fGeom->GetNumPixels(); idx++)
|
---|
194 | {
|
---|
195 | // FIXME: Where to get this number from?
|
---|
196 | for (int i=0; i<50; i++)
|
---|
197 | {
|
---|
198 | MPhotonData &ph = fEvt->Add(cnt++);
|
---|
199 |
|
---|
200 | const Float_t tm = gRandom->Gaus(0, 1);
|
---|
201 |
|
---|
202 | ph.SetTag(idx);
|
---|
203 | ph.SetWeight();
|
---|
204 | ph.SetTime(tm);
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | fEvt->Shrink(cnt);
|
---|
210 | fEvt->Sort(kTRUE);
|
---|
211 |
|
---|
212 | // ------------ FIMXE: Move somewhere else? -------------
|
---|
213 | // -------------------- MSimGeomCam ---------------------
|
---|
214 |
|
---|
215 | const Double_t freq = fRunHeader->GetFreqSampling()/1000.;
|
---|
216 |
|
---|
217 | // Length (ns), Pulse position (Units ns)
|
---|
218 | const Float_t ns = fRunHeader->GetNumSamplesHiGain()*freq;
|
---|
219 | const Float_t pp = fPulsePos->GetVal();
|
---|
220 |
|
---|
221 | const Float_t first = cnt>0 ? fEvt->GetFirst()->GetTime() : 0;
|
---|
222 | const Float_t last = cnt>0 ? fEvt->GetLast()->GetTime() : ns;
|
---|
223 |
|
---|
224 | fStat->SetTime(first-pp, last+(ns-pp));
|
---|
225 | fStat->SetMaxIndex(fGeom->GetNumPixels()-1);
|
---|
226 | fStat->SetReadyToSave();
|
---|
227 |
|
---|
228 | // FIXME: Jitter! (Own class?)
|
---|
229 | fTrigger->SetVal(pp*freq);
|
---|
230 |
|
---|
231 | // FIXME: Set from somewhere else? (see also MSimTrigger)
|
---|
232 | fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
|
---|
233 | fEvtHeader->SetReadyToSave();
|
---|
234 |
|
---|
235 | return kTRUE;
|
---|
236 |
|
---|
237 | }
|
---|