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

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