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

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