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

Last change on this file since 7256 was 7220, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.0 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 // Calculate absolute deviation
179 const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz);
180
181 // Sanity check... larger deviation are strange and ignored
182 if (dev*60>fMaxAbsDev)
183 {
184 fSkip[4]++;
185 return kTRUE;
186 }
187
188 fDeviation->SetDevZdAz(devzd, devaz);
189
190 // Linear starguider calibration taken from April/May data
191 // For calibration add MDriveReport::GetErrorZd/Az !
192 fDeviation->SetDevXY(-7.0, 16);
193 //devzd -= 2.686/60; // 1arcmin ~ 5mm
194 //devaz -= 2.840/60;
195
196 fSkip[0]++;
197
198 return kTRUE;
199}
200
201// --------------------------------------------------------------------------
202//
203// See class description.
204//
205Int_t MPointingDevCalc::Process()
206{
207 switch (fRunType)
208 {
209 case MRawRunHeader::kRTNone:
210 case MRawRunHeader::kRTData:
211 return fReport ? ProcessStarguiderReport() : kTRUE;
212
213 case MRawRunHeader::kRTMonteCarlo:
214 fSkip[0]++;
215 fDeviation->SetDevZdAz(0, 0);
216 return kTRUE;
217 }
218 return kTRUE;
219}
220
221// --------------------------------------------------------------------------
222//
223// Print execution statistics
224//
225Int_t MPointingDevCalc::PostProcess()
226{
227 if (GetNumExecutions()==0)
228 return kTRUE;
229
230 *fLog << inf << endl;
231 *fLog << GetDescriptor() << " execution statistics:" << endl;
232 PrintSkipped(fSkip[1], "Starguider deviation not set, is exactly 0/0");
233 PrintSkipped(fSkip[2], Form("NSB out of %.1f sigma range", fNsbLevel));
234 PrintSkipped(fSkip[3], Form("Number of identified stars < %d", fNumMinStars));
235 PrintSkipped(fSkip[4], Form("Absolute deviation > %.1farcmin", fMaxAbsDev));
236 *fLog << " " << (int)fSkip[0] << " (" << Form("%5.1f", 100.*fSkip[0]/GetNumExecutions()) << "%) Evts survived calculation!" << endl;
237 *fLog << endl;
238
239 return kTRUE;
240}
241
242// --------------------------------------------------------------------------
243//
244// MPointingDevCalc.NumMinStars: 8
245// MPointingDevCalc.NsbLevel: 3.0
246// MPointingDevCalc.NsbMin: 30
247// MPointingDevCalc.NsbMax: 60
248// MPointingDevCalc.MaxAbsDev: 15
249//
250Int_t MPointingDevCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
251{
252 Bool_t rc = kFALSE;
253 if (IsEnvDefined(env, prefix, "NumMinStars", print))
254 {
255 SetNumMinStars(GetEnvValue(env, prefix, "NumMinStars", (Int_t)fNumMinStars));
256 rc = kTRUE;
257 }
258 if (IsEnvDefined(env, prefix, "NsbLevel", print))
259 {
260 SetNsbLevel(GetEnvValue(env, prefix, "NsbLevel", fNsbLevel));
261 rc = kTRUE;
262 }
263 if (IsEnvDefined(env, prefix, "NsbMin", print))
264 {
265 SetNsbMin(GetEnvValue(env, prefix, "NsbMin", fNsbMin));
266 rc = kTRUE;
267 }
268 if (IsEnvDefined(env, prefix, "NsbMax", print))
269 {
270 SetNsbMax(GetEnvValue(env, prefix, "NsbMax", fNsbMax));
271 rc = kTRUE;
272 }
273 if (IsEnvDefined(env, prefix, "MaxAbsDev", print))
274 {
275 SetMaxAbsDev(GetEnvValue(env, prefix, "MaxAbsDev", fMaxAbsDev));
276 rc = kTRUE;
277 }
278
279 return rc;
280}
Note: See TracBrowser for help on using the repository browser.