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

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