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

Last change on this file since 8015 was 7744, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 9.2 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[5] 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[5]++;
153}
154
155Int_t MPointingDevCalc::ProcessStarguiderReport()
156{
157 Double_t devzd = fReport->GetDevZd(); // [deg]
158 Double_t devaz = fReport->GetDevAz(); // [deg]
159 if (devzd==0 && devaz==0)
160 {
161 fDeviation->SetDevZdAz(0, 0);
162 fDeviation->SetDevXY(0, 0); //?!?
163 fSkip[1]++;
164 fLastMjd = fReport->GetMjd();
165 return kTRUE;
166 }
167
168 devzd /= 60; // Convert from arcmin to deg
169 devaz /= 60; // Convert from arcmin to deg
170
171 const Double_t nsb = fReport->GetSkyBrightness();
172 if (nsb>0)
173 {
174 if (nsb>fNsbMin && nsb<fNsbMax)
175 {
176 fNsbSum += nsb;
177 fNsbSq += nsb*nsb;
178 fNsbCount++;
179 }
180
181 if (fNsbCount>0)
182 {
183 const Double_t sum = fNsbSum/fNsbCount;
184 const Double_t sq = fNsbSq /fNsbCount;
185
186 const Double_t rms = fNsbLevel*TMath::Sqrt(sq - sum*sum);
187
188 if (nsb<sum-rms || nsb>sum+rms)
189 {
190 Skip(2);
191 return kTRUE;
192 }
193 }
194
195 if (fReport->GetNumIdentifiedStars()<fNumMinStars)
196 {
197 Skip(3);
198 return kTRUE;
199 }
200 }
201
202 // Calculate absolute deviation
203 const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz);
204
205 // Sanity check... larger deviation are strange and ignored
206 if (dev*60>fMaxAbsDev)
207 {
208 Skip(4);
209 return kTRUE;
210 }
211
212 fDeviation->SetDevZdAz(devzd, devaz);
213
214 // Linear starguider calibration taken from April/May data
215 // For calibration add MDriveReport::GetErrorZd/Az !
216 fDeviation->SetDevXY(fDx, fDy);
217 //devzd -= 2.686/60; // 1arcmin ~ 5mm
218 //devaz -= 2.840/60;
219
220 fSkip[0]++;
221 fLastMjd = fReport->GetMjd();
222
223 return kTRUE;
224}
225
226// --------------------------------------------------------------------------
227//
228// See class description.
229//
230Int_t MPointingDevCalc::Process()
231{
232 switch (fRunType)
233 {
234 case MRawRunHeader::kRTNone:
235 case MRawRunHeader::kRTData:
236 return fReport ? ProcessStarguiderReport() : kTRUE;
237
238 case MRawRunHeader::kRTMonteCarlo:
239 fSkip[0]++;
240 fDeviation->SetDevZdAz(0, 0);
241 fDeviation->SetDevXY(0, 0);
242 return kTRUE;
243 }
244 return kTRUE;
245}
246
247// --------------------------------------------------------------------------
248//
249// Print execution statistics
250//
251Int_t MPointingDevCalc::PostProcess()
252{
253 if (GetNumExecutions()==0)
254 return kTRUE;
255
256 *fLog << inf << endl;
257 *fLog << GetDescriptor() << " execution statistics:" << endl;
258 PrintSkipped(fSkip[1], "Starguider deviation not set, is exactly 0/0");
259 PrintSkipped(fSkip[2], Form("NSB out of %.1f sigma range", fNsbLevel));
260 PrintSkipped(fSkip[3], Form("Number of identified stars < %d", fNumMinStars));
261 PrintSkipped(fSkip[4], Form("Absolute deviation > %.1farcmin", fMaxAbsDev));
262 PrintSkipped(fSkip[5], Form("Events set to 0 because older than %.1fmin", fMaxAge));
263 *fLog << " " << (int)fSkip[0] << " (" << Form("%5.1f", 100.*fSkip[0]/GetNumExecutions()) << "%) Evts survived calculation!" << endl;
264 *fLog << endl;
265
266 return kTRUE;
267}
268
269// --------------------------------------------------------------------------
270//
271// MPointingDevCalc.NumMinStars: 8
272// MPointingDevCalc.NsbLevel: 3.0
273// MPointingDevCalc.NsbMin: 30
274// MPointingDevCalc.NsbMax: 60
275// MPointingDevCalc.MaxAbsDev: 15
276// MPointingDevCalc.MaxAge: 1.0
277//
278Int_t MPointingDevCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
279{
280 Bool_t rc = kFALSE;
281 if (IsEnvDefined(env, prefix, "NumMinStars", print))
282 {
283 SetNumMinStars(GetEnvValue(env, prefix, "NumMinStars", (Int_t)fNumMinStars));
284 rc = kTRUE;
285 }
286 if (IsEnvDefined(env, prefix, "NsbLevel", print))
287 {
288 SetNsbLevel(GetEnvValue(env, prefix, "NsbLevel", fNsbLevel));
289 rc = kTRUE;
290 }
291 if (IsEnvDefined(env, prefix, "NsbMin", print))
292 {
293 SetNsbMin(GetEnvValue(env, prefix, "NsbMin", fNsbMin));
294 rc = kTRUE;
295 }
296 if (IsEnvDefined(env, prefix, "NsbMax", print))
297 {
298 SetNsbMax(GetEnvValue(env, prefix, "NsbMax", fNsbMax));
299 rc = kTRUE;
300 }
301 if (IsEnvDefined(env, prefix, "MaxAbsDev", print))
302 {
303 SetMaxAbsDev(GetEnvValue(env, prefix, "MaxAbsDev", fMaxAbsDev));
304 rc = kTRUE;
305 }
306 if (IsEnvDefined(env, prefix, "Dx", print))
307 {
308 fDx = GetEnvValue(env, prefix, "Dx", fDx);
309 rc = kTRUE;
310 }
311 if (IsEnvDefined(env, prefix, "Dy", print))
312 {
313 fDy = GetEnvValue(env, prefix, "Dy", fDy);
314 rc = kTRUE;
315 }
316 if (IsEnvDefined(env, prefix, "MaxAge", print))
317 {
318 fMaxAge = GetEnvValue(env, prefix, "MaxAge", fMaxAge);
319 rc = kTRUE;
320 }
321
322 return rc;
323}
Note: See TracBrowser for help on using the repository browser.