source: trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc@ 8709

Last change on this file since 8709 was 8641, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 12.5 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, 07/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MPointingDevCalc
28//
29// Calculates the pointing deviation from the starguider information.
30//
31// There are some quality parameters to steer which are the valid
32// starguider data points:
33// * MPointingDevCalc.NumMinStars: 8
34// Minimum number of identified stars required to accep the data
35// * MPointingDevCalc.NsbLevel: 3.0
36// Minimum deviation (in rms) from the the mean allowed for the measured
37// NSB (noise in the ccd camera)
38// * MPointingDevCalc.NsbMin: 30
39// - minimum NSB to be used in mean/rms calculation
40// * MPointingDevCalc.NsbMax: 60
41// - maximum NSB to be used in mean/rms calculation
42// * MPointingDevCalc.MaxAbsDev: 15
43// - Maximum absolute deviation which is consideres as valid (arcmin)
44//
45// Starguider data which doens't fullfill this requirements is ignored.
46// If the measures NSB==0 (file too old, starguider didn't write down
47// these values) the checks based on NSB and NumMinStar are skipped.
48//
49// The calculation of NSB mean and rms is reset for each file (ReInit)
50//
51//
52// Input Container:
53// MReportStarguider
54//
55// Output Container:
56// MPointingDev
57//
58/////////////////////////////////////////////////////////////////////////////
59#include "MPointingDevCalc.h"
60
61#include "MLog.h"
62#include "MLogManip.h"
63
64#include "MParList.h"
65
66#include "MAstro.h"
67#include "MPointing.h"
68#include "MPointingDev.h"
69#include "MRawRunHeader.h"
70#include "MReportStarguider.h"
71
72ClassImp(MPointingDevCalc);
73
74using namespace std;
75
76const TString MPointingDevCalc::fgFileName="resources/starguider.txt";
77
78// --------------------------------------------------------------------------
79//
80// Delete fPointing and set pointing to NULL
81//
82void MPointingDevCalc::Clear(Option_t *o)
83{
84 if (fPointing)
85 delete fPointing;
86
87 fPointing = NULL;
88}
89
90// --------------------------------------------------------------------------
91//
92// Clear the pointing model. If run-number >= 87751 read the new
93// pointing model with fFileName
94//
95Bool_t MPointingDevCalc::ReadPointingModel(const MRawRunHeader &run)
96{
97 if (run.GetRunNumber()<85240)
98 {
99 Clear();
100 return kTRUE;
101 }
102
103 if (!fPointing)
104 fPointing = new MPointing;
105
106 if (fFileName==fPointing->GetName())
107 {
108 *fLog << inf << fFileName << " already loaded." << endl;
109 return kTRUE;
110 }
111
112 return fPointing->Load(fFileName);
113}
114
115// --------------------------------------------------------------------------
116//
117// Check the file/run type from the run-header and if it is a data file
118// load starguider calibration.
119//
120Bool_t MPointingDevCalc::ReInit(MParList *plist)
121{
122 MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
123 if (!run)
124 {
125 *fLog << err << "MRawRunHeader not found... aborting." << endl;
126 return kFALSE;
127 }
128
129 fNsbSum = 0;
130 fNsbSq = 0;
131 fNsbCount = 0;
132
133 fRunType = run->GetRunType();
134
135 switch (fRunType)
136 {
137 case MRawRunHeader::kRTData:
138 if (!fReport)
139 *fLog << warn << "MReportStarguider not found... skipped." << endl;
140 return ReadPointingModel(*run);
141
142 case MRawRunHeader::kRTMonteCarlo:
143 return kTRUE;
144
145 case MRawRunHeader::kRTPedestal:
146 *fLog << err << "Cannot work in a pedestal Run!... aborting." << endl;
147 return kFALSE;
148
149 case MRawRunHeader::kRTCalibration:
150 *fLog << err << "Cannot work in a calibration Run!... aborting." << endl;
151 return kFALSE;
152
153 default:
154 *fLog << err << "Run Type " << fRunType << " unknown!... aborting." << endl;
155 return kFALSE;
156 }
157
158 return kTRUE;
159}
160
161// --------------------------------------------------------------------------
162//
163// Search for 'MPointingPos'. Create if not found.
164//
165Int_t MPointingDevCalc::PreProcess(MParList *plist)
166{
167 fDeviation = (MPointingDev*)plist->FindCreateObj("MPointingDev");
168 fReport = (MReportStarguider*)plist->FindObject("MReportStarguider");
169
170 // We use kRTNone here as a placeholder for data runs.
171 fRunType = MRawRunHeader::kRTNone;
172 fLastMjd = -1;
173
174 fSkip.Reset();
175
176 return fDeviation ? kTRUE : kFALSE;
177}
178
179// --------------------------------------------------------------------------
180//
181// Increase fSkip[i] by one. If the data in fDeviation is outdated (older
182// than fMaxAge) and the current report should be skipped reset DevZdAz and
183// DevXY and fSkip[6] is increased by one.
184//
185void MPointingDevCalc::Skip(Int_t i)
186{
187 fSkip[i]++;
188
189 const Double_t diff = (fReport->GetMjd()-fLastMjd)*1440; // [min] 1440=24*60
190 if (diff<fMaxAge && fLastMjd>0)
191 return;
192
193 fDeviation->SetDevZdAz(0, 0);
194 fDeviation->SetDevXY(0, 0);
195 fSkip[6]++;
196}
197
198// --------------------------------------------------------------------------
199//
200// Do a full starguider calibration using a pointing model for the starguider.
201//
202void MPointingDevCalc::DoCalibration(Double_t devzd, Double_t devaz) const
203{
204 if (!fPointing)
205 {
206 // Do a simple starguider calibration using a simple offset in x and y
207 fDeviation->SetDevZdAz(devzd, devaz);
208
209 // Linear starguider calibration taken from April/May data
210 // For calibration add MDriveReport::GetErrorZd/Az !
211 fDeviation->SetDevXY(fDx, fDy); // 1arcmin ~ 5mm
212 //devzd -= 2.686/60;
213 //devaz -= 2.840/60;
214
215 return;
216 }
217
218 // def?: 20.105, 773
219 // 0/0 : 20.119, 763
220 // -/- : 19.417 726
221 // +mis: 19.80, 756
222
223 // Get the nominal position the star is at the sky
224 // Unit: deg
225 ZdAz nom(fReport->GetNominalZd(), fReport->GetNominalAz());
226 nom *= TMath::DegToRad();
227
228 // Get the mispointing measured by the telescope. It is
229 // calculate as follows:
230 //
231 // Position at which the starguider camera is pointing in real:
232 // pointing position = nominal position - mis
233 ZdAz mis(devzd, devaz);
234 mis *= TMath::DegToRad();
235
236 // The pointing mode is the conversion from the real pointing
237 // position of the telescope into the pointing position measured
238 // by the starguider.
239 //
240 // --> To get the real poiting position of the telescope we have
241 // to convert the measured position back;
242 //
243
244 // Position at which the starguider camera is pointing in real:
245 // pointing position = nominal position - dev
246 //
247 // The position measured as the starguider's pointing position
248 ZdAz pos(nom); // cpos = sao - dev
249 pos -= mis;
250
251 // Now we convert the starguider's pointing position into the
252 // telescope pointing position (the pointing model converts
253 // the telescope pointing position into the starguider pointing
254 // position)
255 ZdAz point = fPointing->CorrectBack(pos);
256
257 // MSrcPosCalc uses the following condition to calculate the
258 // source position in the camera:
259 // real pointing pos = nominal pointing pos - dev
260 //
261 // Therefor we calculate dev as follows:
262 ZdAz dev(nom);
263 dev -= point;
264 dev *= TMath::RadToDeg();
265
266 // Set Measured mispointing and additional offset
267 fDeviation->SetDevZdAz(dev.Zd(), dev.Az());
268 fDeviation->SetDevXY(0, 0);
269}
270
271Int_t MPointingDevCalc::ProcessStarguiderReport()
272{
273 /************* CHECK STATUS!!! ******************/
274
275 Double_t devzd = fReport->GetDevZd(); // [arcmin]
276 Double_t devaz = fReport->GetDevAz(); // [arcmin]
277 if (devzd==0 && devaz==0)
278 {
279 Skip(1);
280 return kTRUE;
281 }
282
283 if (!fReport->IsMonitoring())
284 {
285 Skip(2);
286 return kTRUE;
287 }
288
289 devzd /= 60; // Convert from arcmin to deg
290 devaz /= 60; // Convert from arcmin to deg
291
292 const Double_t nsb = fReport->GetSkyBrightness();
293 if (nsb>0)
294 {
295 if (nsb>fNsbMin && nsb<fNsbMax)
296 {
297 fNsbSum += nsb;
298 fNsbSq += nsb*nsb;
299 fNsbCount++;
300 }
301
302 if (fNsbCount>0)
303 {
304 const Double_t sum = fNsbSum/fNsbCount;
305 const Double_t sq = fNsbSq /fNsbCount;
306
307 const Double_t rms = fNsbLevel*TMath::Sqrt(sq - sum*sum);
308
309 if (nsb<sum-rms || nsb>sum+rms)
310 {
311 Skip(3);
312 return kTRUE;
313 }
314 }
315
316 if (fReport->GetNumIdentifiedStars()<fNumMinStars)
317 {
318 Skip(4);
319 return kTRUE;
320 }
321 }
322
323 // >= 87751 (31.3.06 12:00)
324
325 // Calculate absolute deviation
326 const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz);
327
328 // Sanity check... larger deviation are strange and ignored
329 if (dev*60>fMaxAbsDev)
330 {
331 Skip(5);
332 return kTRUE;
333 }
334
335 DoCalibration(devzd, devaz);
336
337 fSkip[0]++;
338 fLastMjd = fReport->GetMjd();
339
340 return kTRUE;
341}
342
343// --------------------------------------------------------------------------
344//
345// See class description.
346//
347Int_t MPointingDevCalc::Process()
348{
349 switch (fRunType)
350 {
351 case MRawRunHeader::kRTNone:
352 case MRawRunHeader::kRTData:
353 return fReport ? ProcessStarguiderReport() : kTRUE;
354
355 case MRawRunHeader::kRTMonteCarlo:
356 fSkip[0]++;
357 fDeviation->SetDevZdAz(0, 0);
358 fDeviation->SetDevXY(0, 0);
359 return kTRUE;
360 }
361 return kTRUE;
362}
363
364// --------------------------------------------------------------------------
365//
366// Print execution statistics
367//
368Int_t MPointingDevCalc::PostProcess()
369{
370 if (GetNumExecutions()==0)
371 return kTRUE;
372
373 *fLog << inf << endl;
374 *fLog << GetDescriptor() << " execution statistics:" << endl;
375 PrintSkipped(fSkip[1], "Starguider deviation not set, is exactly 0/0");
376 PrintSkipped(fSkip[2], "Starguider was not monitoring (eg. LEDs off)");
377 PrintSkipped(fSkip[3], Form("NSB out of %.1f sigma range", fNsbLevel));
378 PrintSkipped(fSkip[4], Form("Number of identified stars < %d", fNumMinStars));
379 PrintSkipped(fSkip[5], Form("Absolute deviation > %.1farcmin", fMaxAbsDev));
380 PrintSkipped(fSkip[6], Form("Events set to 0 because older than %.1fmin", fMaxAge));
381 *fLog << " " << (int)fSkip[0] << " (" << Form("%5.1f", 100.*fSkip[0]/GetNumExecutions()) << "%) Evts survived calculation!" << endl;
382 *fLog << endl;
383
384 return kTRUE;
385}
386
387// --------------------------------------------------------------------------
388//
389// MPointingDevCalc.NumMinStars: 8
390// MPointingDevCalc.NsbLevel: 3.0
391// MPointingDevCalc.NsbMin: 30
392// MPointingDevCalc.NsbMax: 60
393// MPointingDevCalc.MaxAbsDev: 15
394// MPointingDevCalc.MaxAge: 1.0
395//
396Int_t MPointingDevCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
397{
398 Bool_t rc = kFALSE;
399 if (IsEnvDefined(env, prefix, "NumMinStars", print))
400 {
401 SetNumMinStars(GetEnvValue(env, prefix, "NumMinStars", (Int_t)fNumMinStars));
402 rc = kTRUE;
403 }
404 if (IsEnvDefined(env, prefix, "NsbLevel", print))
405 {
406 SetNsbLevel(GetEnvValue(env, prefix, "NsbLevel", fNsbLevel));
407 rc = kTRUE;
408 }
409 if (IsEnvDefined(env, prefix, "NsbMin", print))
410 {
411 SetNsbMin(GetEnvValue(env, prefix, "NsbMin", fNsbMin));
412 rc = kTRUE;
413 }
414 if (IsEnvDefined(env, prefix, "NsbMax", print))
415 {
416 SetNsbMax(GetEnvValue(env, prefix, "NsbMax", fNsbMax));
417 rc = kTRUE;
418 }
419 if (IsEnvDefined(env, prefix, "MaxAbsDev", print))
420 {
421 SetMaxAbsDev(GetEnvValue(env, prefix, "MaxAbsDev", fMaxAbsDev));
422 rc = kTRUE;
423 }
424 if (IsEnvDefined(env, prefix, "Dx", print))
425 {
426 fDx = GetEnvValue(env, prefix, "Dx", fDx);
427 rc = kTRUE;
428 }
429 if (IsEnvDefined(env, prefix, "Dy", print))
430 {
431 fDy = GetEnvValue(env, prefix, "Dy", fDy);
432 rc = kTRUE;
433 }
434 if (IsEnvDefined(env, prefix, "MaxAge", print))
435 {
436 fMaxAge = GetEnvValue(env, prefix, "MaxAge", fMaxAge);
437 rc = kTRUE;
438 }
439
440 return rc;
441}
Note: See TracBrowser for help on using the repository browser.