source: trunk/Mars/mmovie/MMoviePrepare.cc@ 18878

Last change on this file since 18878 was 8411, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.7 KB
Line 
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// MCalibConstCam
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#include "MCalibConstCam.h"
78#include "MCalibConstPix.h"
79
80#include "MCalibrationRelTimeCam.h"
81#include "MCalibrationRelTimePix.h"
82
83#include "MExtractor.h"
84#include "MMovieData.h"
85#include "MRawRunHeader.h"
86#include "MPedestalSubtractedEvt.h"
87
88ClassImp(MMoviePrepare);
89
90using namespace std;
91
92// --------------------------------------------------------------------------
93//
94// Default constructor. Initialize fData with default rule "MMcEvt.fEnergy"
95//
96MMoviePrepare::MMoviePrepare(const char *name, const char *title)
97 : fFirstSlice(2), fLastSlice(12)
98{
99 fName = name ? name : "MMoviePrepare";
100 fTitle = title ? title : "Task to calculate a MParameterD";
101}
102
103// --------------------------------------------------------------------------
104//
105// Set moview range from extractor
106//
107void MMoviePrepare::SetRangeFromExtractor(const MExtractor &ext)
108{
109 fFirstSlice = ext.GetHiGainFirst();
110 fLastSlice = ext.GetHiGainLast();
111}
112
113// --------------------------------------------------------------------------
114//
115// Input:
116// MGeomCam
117// MPedestalSubtractedEvt
118// MPedestalFundamental [MPedestalCam]
119// MCalibrateData
120// MCalibrationRelTimeCam
121// MRawRunHeader
122//
123// Output:
124// MMovieData
125//
126Int_t MMoviePrepare::PreProcess(MParList *plist)
127{
128 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
129 if (!fCam)
130 {
131 *fLog << err << "MGeomCam not found ... aborting." << endl;
132 return kFALSE;
133 }
134 fEvt = (MPedestalSubtractedEvt*)plist->FindObject("MPedestalSubtractedEvt");
135 if (!fEvt)
136 {
137 *fLog << err << "MPedestalSubtractedEvt not found ... aborting." << endl;
138 return kFALSE;
139 }
140 fPed = (MPedestalCam*)plist->FindObject("MPedestalFundamental", "MPedestalCam");
141 if (!fPed)
142 {
143 *fLog << err << "MPedestalFundamental [MPedestalCam] not found ... aborting." << endl;
144 return kFALSE;
145 }
146 fCal = (MCalibConstCam*)plist->FindObject("MCalibConstCam");
147 if (!fCal)
148 {
149 *fLog << err << "MCalibConstCam not found ... aborting." << endl;
150 return kFALSE;
151 }
152 fRel = (MCalibrationRelTimeCam*)plist->FindObject("MCalibrationRelTimeCam");
153 if (!fRel)
154 {
155 *fLog << err << "MCalibrationRelTimeCam not found ... aborting." << endl;
156 return kFALSE;
157 }
158 fRun = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
159 if (!fRun)
160 {
161 *fLog << err << "MRawRunHeader not found ... aborting." << endl;
162 return kFALSE;
163 }
164
165 fOut = (MMovieData*)plist->FindCreateObj("MMovieData");
166 if (!fOut)
167 return kFALSE;
168
169 return kTRUE;
170}
171
172/*
173Bool_t MMoviePrepare::ReInit(MParList *plist)
174{
175 MExtractedSignalCam *cam = (MExtractedSignalCam*)plist->FindObject("MExtractedSignalCam");
176 if (!cam)
177 {
178 *fLog << err << "MExtractedSignalCam not found ... aborting." << endl;
179 return kFALSE;
180 }
181 fSlope = cam->GetNumUsedHiGainFADCSlices();
182
183 cout << "---> " << fSlope << " <---" << endl;
184
185 return kTRUE;
186}
187*/
188
189// --------------------------------------------------------------------------
190//
191// Return the median of the calibration constants of all pixels
192// with area index 0
193//
194Double_t MMoviePrepare::GetMedianCalibConst() const
195{
196 Int_t n = fCam->GetNumPixWithAidx(0);
197
198 MArrayF arr(n);
199
200 for (UInt_t i=0; i<fCam->GetNumPixels(); i++)
201 if ((*fCam)[i].GetAidx()==0)
202 arr[--n] = (*fCal)[i].GetCalibConst();
203
204 return TMath::Median(arr.GetSize(), arr.GetArray());
205}
206
207// --------------------------------------------------------------------------
208//
209// Return the median of the pedestal rms of all pixels with area index 0
210//
211Double_t MMoviePrepare::GetMedianPedestalRms() const
212{
213 Int_t n = fCam->GetNumPixWithAidx(0);
214
215 MArrayF rms(n);
216
217 for (UInt_t i=0; i<fCam->GetNumPixels(); i++)
218 if ((*fCam)[i].GetAidx()==0)
219 rms[--n] = (*fPed)[i].GetPedestalRms();
220
221 return TMath::Median(rms.GetSize(), rms.GetArray());
222}
223
224// --------------------------------------------------------------------------
225//
226// Get value from fData and set it to fEnergy. SetReadyToSave for fEnergy.
227// Return kCONTINUE if value is NaN (Not a Number)
228//
229Int_t MMoviePrepare::Process()
230{
231 if (fLastSlice>=fEvt->GetNumSamples())
232 {
233 fLastSlice = fEvt->GetNumSamples()-1;
234 *fLog << inf << "Cannot go beyond last slice... set last=" << fLastSlice << "." << endl;
235 }
236
237 // ---------------- Setup ------------------
238 const UInt_t width = fLastSlice-fFirstSlice+1; // [slices] width of window shown
239 const Float_t freq = fRun->GetFreqSampling()/1000.; // [GHz] Sampling frequency
240 const Float_t len = width/freq; // [ns] length of data stream in data-time
241
242 // ---------------- Prepare data ------------------
243
244 fOut->Reset();
245
246 // For invalid calib constants we can use the sector average
247 const UShort_t npix = fEvt->GetNumPixels();
248 const Double_t slope = 1./GetMedianCalibConst();
249
250 TGraph g(width);
251
252 Float_t max = 0;
253 for (UShort_t p=0; p<npix; p++)
254 {
255 const MCalibrationRelTimePix &tpix = (MCalibrationRelTimePix&)(*fRel)[p];
256
257 const Float_t offset = tpix.GetTimeOffset();
258 const Float_t cal = (*fCal)[p].GetCalibConst();
259 const Float_t *ptr = fEvt->GetSamples(p)+fFirstSlice;
260 const Float_t scale = cal*slope*fCam->GetPixRatio(p);
261
262 for (UInt_t s=0; s<width; s++)
263 {
264 const Double_t x = (s-offset)/freq;
265 const Double_t y = ptr[s]*scale;
266
267 g.SetPoint(s, x, y);
268
269 // Check for maximum in the visible time range only
270 if (x>0 && x<len && y>max)
271 max=y;
272 }
273
274 g.SetName(MString::Format("%d", p));
275 fOut->Add(g);
276 }
277
278 fOut->SetMax(max);
279 fOut->SetNumSlices(width);
280 fOut->SetMedianPedestalRms(GetMedianPedestalRms());
281
282 return kTRUE;
283}
284
285// --------------------------------------------------------------------------
286//
287// Check for corresponding entries in resource file and setup
288//
289// Example:
290// MMoviePrepare.FirstSlice: 10
291// MMoviePrepare.LastSlice: 50
292//
293Int_t MMoviePrepare::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
294{
295 Bool_t rc = kFALSE;
296 if (IsEnvDefined(env, prefix, "FirstSlice", print))
297 {
298 rc = kTRUE;
299 fFirstSlice = GetEnvValue(env, prefix, "FirstSlice", (Int_t)fFirstSlice);
300 }
301 if (IsEnvDefined(env, prefix, "LastSlice", print))
302 {
303 rc = kTRUE;
304 fLastSlice = GetEnvValue(env, prefix, "LastSlice", (Int_t)fLastSlice);
305 }
306
307 return rc;
308}
Note: See TracBrowser for help on using the repository browser.