1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC 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 appear 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 4/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2007
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MMoviePrepare
|
---|
28 | //
|
---|
29 | // Prepare the splines for displaying of a movie. The data is shifted by
|
---|
30 | // the calculated time offset from MCalibrationRelTimeCam. It is
|
---|
31 | // flat-fielded by multiplication with the calibration factor from
|
---|
32 | // MCalibrateData divided by the median of the calibration factors of the
|
---|
33 | // pixels with area index 0 (for MAGIC: inner pixels).
|
---|
34 | //
|
---|
35 | // The splines are initialized for the first slice given to the last
|
---|
36 | // slice given (included).
|
---|
37 | //
|
---|
38 | // By default (MJCalibrateSignal.cc) the same slices than for the hi-gain
|
---|
39 | // extraction range are used. To overwrite this behaviour use
|
---|
40 | //
|
---|
41 | // MMoviewPrepare.FirstSlice: 10
|
---|
42 | // MMoviewPrepare.LastSlice: 50
|
---|
43 | //
|
---|
44 | // The maximum y-value set as knot is stored together with the splines
|
---|
45 | // in MMovieData
|
---|
46 | //
|
---|
47 | // Input:
|
---|
48 | // MGeomCam
|
---|
49 | // MPedestalSubtractedEvt
|
---|
50 | // MPedestalFundamental [MPedestalCam]
|
---|
51 | // MCalibrateData
|
---|
52 | // MCalibrationRelTimeCam
|
---|
53 | // MRawRunHeader
|
---|
54 | //
|
---|
55 | // Output:
|
---|
56 | // MMovieData
|
---|
57 | //
|
---|
58 | /////////////////////////////////////////////////////////////////////////////
|
---|
59 | #include "MMoviePrepare.h"
|
---|
60 |
|
---|
61 | #include <TGraph.h>
|
---|
62 |
|
---|
63 | #include "MLog.h"
|
---|
64 | #include "MLogManip.h"
|
---|
65 |
|
---|
66 | #include "MString.h"
|
---|
67 |
|
---|
68 | #include "MParList.h"
|
---|
69 | #include "MTaskList.h"
|
---|
70 |
|
---|
71 | #include "MGeomCam.h"
|
---|
72 | #include "MGeomPix.h"
|
---|
73 |
|
---|
74 | #include "MPedestalCam.h"
|
---|
75 | #include "MPedestalPix.h"
|
---|
76 |
|
---|
77 |
|
---|
78 | #include "MCalibrationRelTimeCam.h"
|
---|
79 | #include "MCalibrationRelTimePix.h"
|
---|
80 |
|
---|
81 | #include "MExtractor.h"
|
---|
82 | #include "MMovieData.h"
|
---|
83 | #include "MRawRunHeader.h"
|
---|
84 | #include "MCalibrateData.h"
|
---|
85 | #include "MPedestalSubtractedEvt.h"
|
---|
86 |
|
---|
87 | ClassImp(MMoviePrepare);
|
---|
88 |
|
---|
89 | using namespace std;
|
---|
90 |
|
---|
91 | // --------------------------------------------------------------------------
|
---|
92 | //
|
---|
93 | // Default constructor. Initialize fData with default rule "MMcEvt.fEnergy"
|
---|
94 | //
|
---|
95 | MMoviePrepare::MMoviePrepare(const char *name, const char *title)
|
---|
96 | : fFirstSlice(2), fLastSlice(12)
|
---|
97 | {
|
---|
98 | fName = name ? name : "MMoviePrepare";
|
---|
99 | fTitle = title ? title : "Task to calculate a MParameterD";
|
---|
100 | }
|
---|
101 |
|
---|
102 | // --------------------------------------------------------------------------
|
---|
103 | //
|
---|
104 | // Set moview range from extractor
|
---|
105 | //
|
---|
106 | void MMoviePrepare::SetRangeFromExtractor(const MExtractor &ext)
|
---|
107 | {
|
---|
108 | fFirstSlice = ext.GetHiGainFirst();
|
---|
109 | fLastSlice = ext.GetHiGainLast();
|
---|
110 | }
|
---|
111 |
|
---|
112 | // --------------------------------------------------------------------------
|
---|
113 | //
|
---|
114 | // Input:
|
---|
115 | // MGeomCam
|
---|
116 | // MPedestalSubtractedEvt
|
---|
117 | // MPedestalFundamental [MPedestalCam]
|
---|
118 | // MCalibrateData
|
---|
119 | // MCalibrationRelTimeCam
|
---|
120 | // MRawRunHeader
|
---|
121 | //
|
---|
122 | // Output:
|
---|
123 | // MMovieData
|
---|
124 | //
|
---|
125 | Int_t MMoviePrepare::PreProcess(MParList *plist)
|
---|
126 | {
|
---|
127 | fCam = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
128 | if (!fCam)
|
---|
129 | {
|
---|
130 | *fLog << err << "MGeomCam not found ... aborting." << endl;
|
---|
131 | return kFALSE;
|
---|
132 | }
|
---|
133 | fEvt = (MPedestalSubtractedEvt*)plist->FindObject("MPedestalSubtractedEvt");
|
---|
134 | if (!fEvt)
|
---|
135 | {
|
---|
136 | *fLog << err << "MPedestalSubtractedEvt not found ... aborting." << endl;
|
---|
137 | return kFALSE;
|
---|
138 | }
|
---|
139 | fPed = (MPedestalCam*)plist->FindObject("MPedestalFundamental", "MPedestalCam");
|
---|
140 | if (!fPed)
|
---|
141 | {
|
---|
142 | *fLog << err << "MPedestalFundamental [MPedestalCam] not found ... aborting." << endl;
|
---|
143 | return kFALSE;
|
---|
144 | }
|
---|
145 | fCal = (MCalibrateData*)plist->FindTaskListWithTask("MCalibrateData")->FindTask("MCalibrateData");
|
---|
146 | if (!fCal)
|
---|
147 | {
|
---|
148 | *fLog << err << "MCalibrateData not found ... aborting." << endl;
|
---|
149 | return kFALSE;
|
---|
150 | }
|
---|
151 | fRel = (MCalibrationRelTimeCam*)plist->FindObject("MCalibrationRelTimeCam");
|
---|
152 | if (!fRel)
|
---|
153 | {
|
---|
154 | *fLog << err << "MCalibrationRelTimeCam not found ... aborting." << endl;
|
---|
155 | return kFALSE;
|
---|
156 | }
|
---|
157 | fRun = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
|
---|
158 | if (!fRun)
|
---|
159 | {
|
---|
160 | *fLog << err << "MRawRunHeader not found ... aborting." << endl;
|
---|
161 | return kFALSE;
|
---|
162 | }
|
---|
163 |
|
---|
164 | fOut = (MMovieData*)plist->FindCreateObj("MMovieData");
|
---|
165 | if (!fOut)
|
---|
166 | return kFALSE;
|
---|
167 |
|
---|
168 | return kTRUE;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*
|
---|
172 | Bool_t MMoviePrepare::ReInit(MParList *plist)
|
---|
173 | {
|
---|
174 | MExtractedSignalCam *cam = (MExtractedSignalCam*)plist->FindObject("MExtractedSignalCam");
|
---|
175 | if (!cam)
|
---|
176 | {
|
---|
177 | *fLog << err << "MExtractedSignalCam not found ... aborting." << endl;
|
---|
178 | return kFALSE;
|
---|
179 | }
|
---|
180 | fSlope = cam->GetNumUsedHiGainFADCSlices();
|
---|
181 |
|
---|
182 | cout << "---> " << fSlope << " <---" << endl;
|
---|
183 |
|
---|
184 | return kTRUE;
|
---|
185 | }
|
---|
186 | */
|
---|
187 |
|
---|
188 | // --------------------------------------------------------------------------
|
---|
189 | //
|
---|
190 | // Return the median of the calibration constants of all pixels
|
---|
191 | // with area index 0
|
---|
192 | //
|
---|
193 | Double_t MMoviePrepare::GetMedianCalibConst() const
|
---|
194 | {
|
---|
195 | const MArrayF &calco = fCal->GetCalibConsts();
|
---|
196 |
|
---|
197 | Int_t n = fCam->GetNumPixWithAidx(0);
|
---|
198 |
|
---|
199 | MArrayF arr(n);
|
---|
200 |
|
---|
201 | for (UInt_t i=0; i<fCam->GetNumPixels(); i++)
|
---|
202 | if ((*fCam)[i].GetAidx()==0)
|
---|
203 | arr[--n] = calco[i];
|
---|
204 |
|
---|
205 | return TMath::Median(arr.GetSize(), arr.GetArray());
|
---|
206 | }
|
---|
207 |
|
---|
208 | // --------------------------------------------------------------------------
|
---|
209 | //
|
---|
210 | // Return the median of the pedestal rms of all pixels with area index 0
|
---|
211 | //
|
---|
212 | Double_t MMoviePrepare::GetMedianPedestalRms() const
|
---|
213 | {
|
---|
214 | Int_t n = fCam->GetNumPixWithAidx(0);
|
---|
215 |
|
---|
216 | MArrayF rms(n);
|
---|
217 |
|
---|
218 | for (UInt_t i=0; i<fCam->GetNumPixels(); i++)
|
---|
219 | if ((*fCam)[i].GetAidx()==0)
|
---|
220 | rms[--n] = (*fPed)[i].GetPedestalRms();
|
---|
221 |
|
---|
222 | return TMath::Median(rms.GetSize(), rms.GetArray());
|
---|
223 | }
|
---|
224 |
|
---|
225 | // --------------------------------------------------------------------------
|
---|
226 | //
|
---|
227 | // Get value from fData and set it to fEnergy. SetReadyToSave for fEnergy.
|
---|
228 | // Return kCONTINUE if value is NaN (Not a Number)
|
---|
229 | //
|
---|
230 | Int_t MMoviePrepare::Process()
|
---|
231 | {
|
---|
232 | if (fLastSlice>=fEvt->GetNumSamples())
|
---|
233 | {
|
---|
234 | fLastSlice = fEvt->GetNumSamples()-1;
|
---|
235 | *fLog << inf << "Cannot go beyond last slice... set last=" << fLastSlice << "." << endl;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // ---------------- Setup ------------------
|
---|
239 | const UInt_t width = fLastSlice-fFirstSlice+1; // [slices] width of window shown
|
---|
240 | const Float_t freq = fRun->GetFreqSampling()/1000.; // [GHz] Sampling frequency
|
---|
241 | const Float_t len = width/freq; // [ns] length of data stream in data-time
|
---|
242 |
|
---|
243 | // ---------------- Prepare data ------------------
|
---|
244 |
|
---|
245 | fOut->Reset();
|
---|
246 |
|
---|
247 | // For invalid calib constants we can use the sector average
|
---|
248 | const MArrayF &calco = fCal->GetCalibConsts();
|
---|
249 | const UShort_t npix = fEvt->GetNumPixels();
|
---|
250 | const Double_t slope = 1./GetMedianCalibConst();
|
---|
251 |
|
---|
252 | TGraph g(width);
|
---|
253 |
|
---|
254 | Float_t max = 0;
|
---|
255 | for (UShort_t p=0; p<npix; p++)
|
---|
256 | {
|
---|
257 | const MCalibrationRelTimePix &tpix = (MCalibrationRelTimePix&)(*fRel)[p];
|
---|
258 |
|
---|
259 | const Float_t offset = tpix.GetTimeOffset();
|
---|
260 | const Float_t cal = calco[p];
|
---|
261 | const Float_t *ptr = fEvt->GetSamples(p)+fFirstSlice;
|
---|
262 | const Float_t scale = cal*slope*fCam->GetPixRatio(p);
|
---|
263 |
|
---|
264 | for (UInt_t s=0; s<width; s++)
|
---|
265 | {
|
---|
266 | const Double_t x = (s-offset)/freq;
|
---|
267 | const Double_t y = ptr[s]*scale;
|
---|
268 |
|
---|
269 | g.SetPoint(s, x, y);
|
---|
270 |
|
---|
271 | // Check for maximum in the visible time range only
|
---|
272 | if (x>0 && x<len && y>max)
|
---|
273 | max=y;
|
---|
274 | }
|
---|
275 |
|
---|
276 | g.SetName(MString::Format("%d", p));
|
---|
277 | fOut->Add(g);
|
---|
278 | }
|
---|
279 |
|
---|
280 | fOut->SetMax(max);
|
---|
281 | fOut->SetNumSlices(width);
|
---|
282 | fOut->SetMedianPedestalRms(GetMedianPedestalRms());
|
---|
283 |
|
---|
284 | return kTRUE;
|
---|
285 | }
|
---|
286 |
|
---|
287 | // --------------------------------------------------------------------------
|
---|
288 | //
|
---|
289 | // Check for corresponding entries in resource file and setup
|
---|
290 | //
|
---|
291 | // Example:
|
---|
292 | // MMoviewPrepare.FirstSlice: 10
|
---|
293 | // MMoviewPrepare.LastSlice: 50
|
---|
294 | //
|
---|
295 | Int_t MMoviePrepare::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
296 | {
|
---|
297 | Bool_t rc = kFALSE;
|
---|
298 | if (IsEnvDefined(env, prefix, "FirstSlice", print))
|
---|
299 | {
|
---|
300 | rc = kTRUE;
|
---|
301 | fFirstSlice = GetEnvValue(env, prefix, "FirstSlice", (Int_t)fFirstSlice);
|
---|
302 | }
|
---|
303 | if (IsEnvDefined(env, prefix, "LastSlice", print))
|
---|
304 | {
|
---|
305 | rc = kTRUE;
|
---|
306 | fLastSlice = GetEnvValue(env, prefix, "LastSlice", (Int_t)fLastSlice);
|
---|
307 | }
|
---|
308 |
|
---|
309 | return rc;
|
---|
310 | }
|
---|