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

Last change on this file since 8359 was 8307, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.3 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 "MPointingDev.h"
68#include "MRawRunHeader.h"
69#include "MReportStarguider.h"
70
71ClassImp(MPointingDevCalc);
72
73using namespace std;
74
75// --------------------------------------------------------------------------
76//
77Bool_t MPointingDevCalc::ReInit(MParList *plist)
78{
79 MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
80 if (!run)
81 {
82 *fLog << err << "MRawRunHeader not found... aborting." << endl;
83 return kFALSE;
84 }
85
86 fNsbSum = 0;
87 fNsbSq = 0;
88 fNsbCount = 0;
89
90 fRunType = run->GetRunType();
91
92 switch (fRunType)
93 {
94 case MRawRunHeader::kRTData:
95 if (!fReport)
96 *fLog << warn << "MReportStarguider not found... skipped." << endl;
97 return kTRUE;
98
99 case MRawRunHeader::kRTMonteCarlo:
100 return kTRUE;
101
102 case MRawRunHeader::kRTPedestal:
103 *fLog << err << "Cannot work in a pedestal Run!... aborting." << endl;
104 return kFALSE;
105
106 case MRawRunHeader::kRTCalibration:
107 *fLog << err << "Cannot work in a calibration Run!... aborting." << endl;
108 return kFALSE;
109
110 default:
111 *fLog << err << "Run Type " << fRunType << " unknown!... aborting." << endl;
112 return kFALSE;
113 }
114
115 return kTRUE;
116}
117
118// --------------------------------------------------------------------------
119//
120// Search for 'MPointingPos'. Create if not found.
121//
122Int_t MPointingDevCalc::PreProcess(MParList *plist)
123{
124 fDeviation = (MPointingDev*)plist->FindCreateObj("MPointingDev");
125 fReport = (MReportStarguider*)plist->FindObject("MReportStarguider");
126
127 // We use kRTNone here as a placeholder for data runs.
128 fRunType = MRawRunHeader::kRTNone;
129 fLastMjd = -1;
130
131 fSkip.Reset();
132
133 return fDeviation ? kTRUE : kFALSE;
134}
135
136// --------------------------------------------------------------------------
137//
138// Increase fSkip[i] by one. If the data in fDeviation is outdated (older
139// than fMaxAge) and the current report should be skipped reset DevZdAz and
140// DevXY and fSkip[6] is increased by one.
141//
142void MPointingDevCalc::Skip(Int_t i)
143{
144 fSkip[i]++;
145
146 const Double_t diff = (fReport->GetMjd()-fLastMjd)*1440; // [min] 1440=24*60
147 if (diff<fMaxAge && fLastMjd>0)
148 return;
149
150 fDeviation->SetDevZdAz(0, 0);
151 fDeviation->SetDevXY(0, 0);
152 fSkip[6]++;
153}
154
155Int_t MPointingDevCalc::ProcessStarguiderReport()
156{
157 /************* CHECK STATUS!!! ******************/
158
159 Double_t devzd = fReport->GetDevZd(); // [deg]
160 Double_t devaz = fReport->GetDevAz(); // [deg]
161 if (devzd==0 && devaz==0)
162 {
163 Skip(1);
164 return kTRUE;
165 }
166
167 if (!fReport->IsMonitoring())
168 {
169 Skip(2);
170 return kTRUE;
171 }
172
173 devzd /= 60; // Convert from arcmin to deg
174 devaz /= 60; // Convert from arcmin to deg
175
176 const Double_t nsb = fReport->GetSkyBrightness();
177 if (nsb>0)
178 {
179 if (nsb>fNsbMin && nsb<fNsbMax)
180 {
181 fNsbSum += nsb;
182 fNsbSq += nsb*nsb;
183 fNsbCount++;
184 }
185
186 if (fNsbCount>0)
187 {
188 const Double_t sum = fNsbSum/fNsbCount;
189 const Double_t sq = fNsbSq /fNsbCount;
190
191 const Double_t rms = fNsbLevel*TMath::Sqrt(sq - sum*sum);
192
193 if (nsb<sum-rms || nsb>sum+rms)
194 {
195 Skip(3);
196 return kTRUE;
197 }
198 }
199
200 if (fReport->GetNumIdentifiedStars()<fNumMinStars)
201 {
202 Skip(4);
203 return kTRUE;
204 }
205 }
206
207 // Calculate absolute deviation
208 const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz);
209
210 // Sanity check... larger deviation are strange and ignored
211 if (dev*60>fMaxAbsDev)
212 {
213 Skip(5);
214 return kTRUE;
215 }
216
217 fDeviation->SetDevZdAz(devzd, devaz);
218
219 // Linear starguider calibration taken from April/May data
220 // For calibration add MDriveReport::GetErrorZd/Az !
221 fDeviation->SetDevXY(fDx, fDy);
222 //devzd -= 2.686/60; // 1arcmin ~ 5mm
223 //devaz -= 2.840/60;
224
225 fSkip[0]++;
226 fLastMjd = fReport->GetMjd();
227
228 return kTRUE;
229}
230
231// --------------------------------------------------------------------------
232//
233// See class description.
234//
235Int_t MPointingDevCalc::Process()
236{
237 switch (fRunType)
238 {
239 case MRawRunHeader::kRTNone:
240 case MRawRunHeader::kRTData:
241 return fReport ? ProcessStarguiderReport() : kTRUE;
242
243 case MRawRunHeader::kRTMonteCarlo:
244 fSkip[0]++;
245 fDeviation->SetDevZdAz(0, 0);
246 fDeviation->SetDevXY(0, 0);
247 return kTRUE;
248 }
249 return kTRUE;
250}
251
252// --------------------------------------------------------------------------
253//
254// Print execution statistics
255//
256Int_t MPointingDevCalc::PostProcess()
257{
258 if (GetNumExecutions()==0)
259 return kTRUE;
260
261 *fLog << inf << endl;
262 *fLog << GetDescriptor() << " execution statistics:" << endl;
263 PrintSkipped(fSkip[1], "Starguider deviation not set, is exactly 0/0");
264 PrintSkipped(fSkip[2], "Starguider was not monitoring (eg. LEDs off)");
265 PrintSkipped(fSkip[3], Form("NSB out of %.1f sigma range", fNsbLevel));
266 PrintSkipped(fSkip[4], Form("Number of identified stars < %d", fNumMinStars));
267 PrintSkipped(fSkip[5], Form("Absolute deviation > %.1farcmin", fMaxAbsDev));
268 PrintSkipped(fSkip[6], Form("Events set to 0 because older than %.1fmin", fMaxAge));
269 *fLog << " " << (int)fSkip[0] << " (" << Form("%5.1f", 100.*fSkip[0]/GetNumExecutions()) << "%) Evts survived calculation!" << endl;
270 *fLog << endl;
271
272 return kTRUE;
273}
274
275// --------------------------------------------------------------------------
276//
277// MPointingDevCalc.NumMinStars: 8
278// MPointingDevCalc.NsbLevel: 3.0
279// MPointingDevCalc.NsbMin: 30
280// MPointingDevCalc.NsbMax: 60
281// MPointingDevCalc.MaxAbsDev: 15
282// MPointingDevCalc.MaxAge: 1.0
283//
284Int_t MPointingDevCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
285{
286 Bool_t rc = kFALSE;
287 if (IsEnvDefined(env, prefix, "NumMinStars", print))
288 {
289 SetNumMinStars(GetEnvValue(env, prefix, "NumMinStars", (Int_t)fNumMinStars));
290 rc = kTRUE;
291 }
292 if (IsEnvDefined(env, prefix, "NsbLevel", print))
293 {
294 SetNsbLevel(GetEnvValue(env, prefix, "NsbLevel", fNsbLevel));
295 rc = kTRUE;
296 }
297 if (IsEnvDefined(env, prefix, "NsbMin", print))
298 {
299 SetNsbMin(GetEnvValue(env, prefix, "NsbMin", fNsbMin));
300 rc = kTRUE;
301 }
302 if (IsEnvDefined(env, prefix, "NsbMax", print))
303 {
304 SetNsbMax(GetEnvValue(env, prefix, "NsbMax", fNsbMax));
305 rc = kTRUE;
306 }
307 if (IsEnvDefined(env, prefix, "MaxAbsDev", print))
308 {
309 SetMaxAbsDev(GetEnvValue(env, prefix, "MaxAbsDev", fMaxAbsDev));
310 rc = kTRUE;
311 }
312 if (IsEnvDefined(env, prefix, "Dx", print))
313 {
314 fDx = GetEnvValue(env, prefix, "Dx", fDx);
315 rc = kTRUE;
316 }
317 if (IsEnvDefined(env, prefix, "Dy", print))
318 {
319 fDy = GetEnvValue(env, prefix, "Dy", fDy);
320 rc = kTRUE;
321 }
322 if (IsEnvDefined(env, prefix, "MaxAge", print))
323 {
324 fMaxAge = GetEnvValue(env, prefix, "MaxAge", fMaxAge);
325 rc = kTRUE;
326 }
327
328 return rc;
329}
Note: See TracBrowser for help on using the repository browser.