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

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