| 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-2007 | 
|---|
| 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 | // | 
|---|
| 34 | //  * MPointingDevCalc.NumMinStars: 8 | 
|---|
| 35 | //    Minimum number of identified stars required to accep the data | 
|---|
| 36 | // | 
|---|
| 37 | //  * MPointingDevCalc.NsbLevel:    3.0 | 
|---|
| 38 | //    Minimum deviation (in rms) from the the mean allowed for the | 
|---|
| 39 | //    measured NSB (noise in the ccd camera) | 
|---|
| 40 | // | 
|---|
| 41 | //  * MPointingDevCalc.NsbMin:      30 | 
|---|
| 42 | //    - minimum NSB to be used in mean/rms calculation | 
|---|
| 43 | // | 
|---|
| 44 | //  * MPointingDevCalc.NsbMax:      60 | 
|---|
| 45 | //    - maximum NSB to be used in mean/rms calculation | 
|---|
| 46 | // | 
|---|
| 47 | //  * MPointingDevCalc.MaxAbsDev:   15 | 
|---|
| 48 | //    - Maximum absolute deviation which is consideres as valid (arcmin) | 
|---|
| 49 | // | 
|---|
| 50 | // Starguider data which doens't fullfill this requirements is ignored. | 
|---|
| 51 | // If the measures NSB==0 (file too old, starguider didn't write down | 
|---|
| 52 | // these values) the checks based on NSB and NumMinStar are skipped. | 
|---|
| 53 | // | 
|---|
| 54 | // The calculation of NSB mean and rms is reset for each file (ReInit) | 
|---|
| 55 | // | 
|---|
| 56 | // If your starguider data doesn't fullfill this requirement the latest | 
|---|
| 57 | // value which could be correctly calculated is used instead. If the time | 
|---|
| 58 | // for which no valid value can be calculated exceeds one minute | 
|---|
| 59 | // the return value is reset to 0/0. The maximum time allowed without | 
|---|
| 60 | // a valid value can be setup using: | 
|---|
| 61 | // | 
|---|
| 62 | //  * MPointingDevCalc.MaxAge:   1 | 
|---|
| 63 | //    Maximum time before the starguider is reset to 0/0 in minutes | 
|---|
| 64 | // | 
|---|
| 65 | // Note, that the starguider itself is not well calibrated. Therefore | 
|---|
| 66 | // it is necessary to do a starguider calibration in our software. | 
|---|
| 67 | // | 
|---|
| 68 | // There are two options: | 
|---|
| 69 | // | 
|---|
| 70 | //  * Simple starguider calibration using offsets in the camera plane | 
|---|
| 71 | // | 
|---|
| 72 | //    The starguider is calibrated by taking its values (dZd/dAz) | 
|---|
| 73 | //    adding them to the source position, calculating the source position | 
|---|
| 74 | //    in the camera plane and adding the offsets. To switch off the | 
|---|
| 75 | //    full starguider calibration do: | 
|---|
| 76 | // | 
|---|
| 77 | //      * MPointingDevCalc.PointingModels: | 
|---|
| 78 | // | 
|---|
| 79 | //    To set the offsets (in units of degree) use | 
|---|
| 80 | // | 
|---|
| 81 | //      * MPointingDevCalc.Dx: -0.001 | 
|---|
| 82 | //      * MPointingDevCalc.Dy: -0.004 | 
|---|
| 83 | // | 
|---|
| 84 | //   * A starguider calibration using a pointing model calculated | 
|---|
| 85 | //     from calibration data, so called TPoints | 
|---|
| 86 | // | 
|---|
| 87 | //     Because the pointing model can change from time to time | 
|---|
| 88 | //     you can give the run-number from which on a new pointing | 
|---|
| 89 | //     model is valid. The run itself is included, e.g.: | 
|---|
| 90 | // | 
|---|
| 91 | //      * MPointingDevCalc.PointingModels: 85240 89180 | 
|---|
| 92 | //      * MPointingDevCalc.FilePrefix:     resources/starguider | 
|---|
| 93 | // | 
|---|
| 94 | //     mean that for all runs<85240 the simple offset correction is used. | 
|---|
| 95 | //     For runs >=85240 and <89180 the file resources/starguider0085240.txt | 
|---|
| 96 | //     and for runs >=89180 the file resources/starguider0089180.txt is | 
|---|
| 97 | //     used. To setup a default file for all runs before 85240 setup | 
|---|
| 98 | //     a low number (eg. 0 or 1) | 
|---|
| 99 | // | 
|---|
| 100 | //     In the case a pointing model is used additional offsets in | 
|---|
| 101 | //     the x/y-camera plane (in units of deg) can be set using the DX | 
|---|
| 102 | //     and DY parameters of the pointing model. The fDx and fDy data | 
|---|
| 103 | //     members of this class are ignored. To overwrite the starguider | 
|---|
| 104 | //     calibrated offset in either Az or Zd with a constant, you | 
|---|
| 105 | //     can use the PX/PY directive in the pointing model. (To enable | 
|---|
| 106 | //     the overwrite set the third column, the error, to a value | 
|---|
| 107 | //     greater than zero) | 
|---|
| 108 | // | 
|---|
| 109 | // | 
|---|
| 110 | // At the PostProcessing step a table with statistics is print if the | 
|---|
| 111 | // debug level is greater or equal 3 (in most applications it is switched | 
|---|
| 112 | // on by -v3) | 
|---|
| 113 | // | 
|---|
| 114 | // | 
|---|
| 115 | // Pointing Models: | 
|---|
| 116 | // ---------------- | 
|---|
| 117 | // | 
|---|
| 118 | //  What we know so far about (maybe) important changes in cosy: | 
|---|
| 119 | // | 
|---|
| 120 | //   18.03.2006: The camera holding has been repaired and the camera got | 
|---|
| 121 | //               shifted a little bit. | 
|---|
| 122 | // | 
|---|
| 123 | //   16.04.2006: Around this date a roque lamp focussing hass been done | 
|---|
| 124 | // | 
|---|
| 125 | //   25.04.2006: A missalignment intrduced with the roque adjust has been | 
|---|
| 126 | //               corrected | 
|---|
| 127 | // | 
|---|
| 128 | //   The starguider pointing model for the time before 18.3.2006 and after | 
|---|
| 129 | //   April 2006 (in fact there are no TPoints until 07/2006 to check it) | 
|---|
| 130 | //   and for the period 07/2006 to (at least) 06/2007 are very similar. | 
|---|
| 131 | // | 
|---|
| 132 | //   The pointing model for the time between 18.3.2006 and 04/2006 is | 
|---|
| 133 | //   clearly different, mainly giving different Azimuth values between | 
|---|
| 134 | //   Zenith and roughly ~25deg, and a slight offset on both axes. | 
|---|
| 135 | // | 
|---|
| 136 | //   10.5.2006:  pos1 -= pos0 commented  (What was the mentioned fix?) | 
|---|
| 137 | //   29.6.2006:  repaired | 
|---|
| 138 | // | 
|---|
| 139 | //   23.3.2006:  new starguider algorithm | 
|---|
| 140 | // | 
|---|
| 141 | //   17.3.2005:  Fixed units of "nompos" in MDriveCom | 
|---|
| 142 | // | 
|---|
| 143 | // | 
|---|
| 144 | // New pointing models have been installed (if the pointing model | 
|---|
| 145 | // is different, than the previous one it might mean, that also | 
|---|
| 146 | // the starguider calibration is different.) | 
|---|
| 147 | // | 
|---|
| 148 | //   29. Apr. 2004    ~25800 | 
|---|
| 149 | //    5. Aug. 2004    ~32000 | 
|---|
| 150 | //   19. Aug. 2004    ~33530 | 
|---|
| 151 | //    7. Jun. 2005    ~57650 | 
|---|
| 152 | //    8. Jun. 2005 | 
|---|
| 153 | //    9. Jun. 2005    ~57860 | 
|---|
| 154 | //   12. Sep. 2005    ~68338 | 
|---|
| 155 | //   24. Nov. 2005    ~75562 | 
|---|
| 156 | //   17. Oct. 2006   ~103130 | 
|---|
| 157 | //   17. Jun. 2007   ~248193 | 
|---|
| 158 | // | 
|---|
| 159 | // From 2.2.2006 beginnig of the night (21:05h, run >=81855) to 24.2.2006 | 
|---|
| 160 | // beginning of the the night (20:34h, run<83722) the LEDs did not work. | 
|---|
| 161 | // In the time after this incident the shift crew often forgot to switch on | 
|---|
| 162 | // the LEDs at the beginning of the night! | 
|---|
| 163 | // | 
|---|
| 164 | // [2006-03-07 00:10:58] In the daytime, we raised the position of the | 
|---|
| 165 | // 9 o'clock LED by one screw hole to make it visible when the TPoint | 
|---|
| 166 | // Lid is closed. (< run 84980) | 
|---|
| 167 | // | 
|---|
| 168 | // [2007-04-25 23:50:39] | 
|---|
| 169 | // Markus is performing AMC focussing. | 
|---|
| 170 | // | 
|---|
| 171 | // Mirror refocussing around 4.Aug.2007, from the Runbook: | 
|---|
| 172 | // | 
|---|
| 173 | // [2007-08-04 04:46:47] | 
|---|
| 174 | // We finished with the focussing with Polaris. The images need to be | 
|---|
| 175 | // analysed and new LUTs generated. | 
|---|
| 176 | // | 
|---|
| 177 | // [2007-08-04 23:47:30] | 
|---|
| 178 | // Actually we see that the mispointing is always large; probably since | 
|---|
| 179 | // the LUT tables have not yet been adjusted to the new focussing. | 
|---|
| 180 | // | 
|---|
| 181 | // [2007-08-03 23:07:58] | 
|---|
| 182 | // Data taking stopped. Mirror focussing. | 
|---|
| 183 | // | 
|---|
| 184 | // [2007-08-05 00:09:16] | 
|---|
| 185 | // We take some pictures on stars nearby Cyg X3 with the sbig camera; | 
|---|
| 186 | // actually the spot doesn't look very nice... The pictures have been | 
|---|
| 187 | // saved with name Deneb- and Sadr- Polaris seems a bit better. Should we | 
|---|
| 188 | // have new LUT tables after the focussing? | 
|---|
| 189 | // | 
|---|
| 190 | // [2007-08-10 20:18:48] | 
|---|
| 191 | // Tonight we take first images of Polaris with a new LUT file generated | 
|---|
| 192 | // based on the recent focussing. The image will be analysed tomorrow and | 
|---|
| 193 | // than new LUTs will be generated. For tonight the focussing is still not | 
|---|
| 194 | // changed. | 
|---|
| 195 | // | 
|---|
| 196 | // [2007-08-14 20:57:59] | 
|---|
| 197 | // The weather is fine. There is a group of hobby astronomers at the | 
|---|
| 198 | // helicopter parking. Before data taking, we tried to check the new LUTs. | 
|---|
| 199 | // However, because of technical problems with the new LUTs we had to | 
|---|
| 200 | // postpone the measurements. We lost some 10 min of data taking because | 
|---|
| 201 | // of this. | 
|---|
| 202 | // | 
|---|
| 203 | // [2007-08-14 22:29:37] | 
|---|
| 204 | // Before continuing the observation we perform a focussing test with the | 
|---|
| 205 | // new LUTs from recent Polaris focussing. Note: Data on Her X-1 was taken | 
|---|
| 206 | // with old focussing. We performed PSF measurements on Kornephorus (Zd | 
|---|
| 207 | // 31.77, Az 264,67) first with old LUTs and then with new LUTs. We took | 
|---|
| 208 | // T-points with both focussing. The first T-Point corresponds to the | 
|---|
| 209 | // previous focussing and the second with the improved. Please check both | 
|---|
| 210 | // T-points for eventual misspointing. We found big improvement of the PSF | 
|---|
| 211 | // with the new LUTs and will therefore continue from now on with the new | 
|---|
| 212 | // focussing. Having a first look at the SBIG pictures we see a slightly | 
|---|
| 213 | // misspointing of ~0.1 deg with the new LUTs. | 
|---|
| 214 | // | 
|---|
| 215 | // [2007-08-14 22:46:10] | 
|---|
| 216 | // Comparing the trigger rate with yesterday night we do not see an | 
|---|
| 217 | // improvement with the new focussing. | 
|---|
| 218 | // | 
|---|
| 219 | // | 
|---|
| 220 | // | 
|---|
| 221 | // ToDo: | 
|---|
| 222 | // ----- | 
|---|
| 223 | // | 
|---|
| 224 | //   * Is 0/0 the best assumption if the starguider partly fails? | 
|---|
| 225 | // | 
|---|
| 226 | // | 
|---|
| 227 | // Input Container: | 
|---|
| 228 | //   MRawRunHeader | 
|---|
| 229 | //   MReportStarguider | 
|---|
| 230 | // | 
|---|
| 231 | // Output Container: | 
|---|
| 232 | //   MPointingDev | 
|---|
| 233 | // | 
|---|
| 234 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 235 | #include "MPointingDevCalc.h" | 
|---|
| 236 |  | 
|---|
| 237 | #include "MLog.h" | 
|---|
| 238 | #include "MLogManip.h" | 
|---|
| 239 |  | 
|---|
| 240 | #include "MParList.h" | 
|---|
| 241 |  | 
|---|
| 242 | #include "MAstro.h" | 
|---|
| 243 | #include "MPointing.h" | 
|---|
| 244 | #include "MPointingDev.h" | 
|---|
| 245 | #include "MRawRunHeader.h" | 
|---|
| 246 | #include "MReportStarguider.h" | 
|---|
| 247 |  | 
|---|
| 248 | ClassImp(MPointingDevCalc); | 
|---|
| 249 |  | 
|---|
| 250 | using namespace std; | 
|---|
| 251 |  | 
|---|
| 252 | const TString MPointingDevCalc::fgFilePrefix="resources/starguider"; | 
|---|
| 253 |  | 
|---|
| 254 | // -------------------------------------------------------------------------- | 
|---|
| 255 | // | 
|---|
| 256 | // Destructor. Call Clear() and delete fPointingModels if any. | 
|---|
| 257 | // | 
|---|
| 258 | MPointingDevCalc::~MPointingDevCalc() | 
|---|
| 259 | { | 
|---|
| 260 | Clear(); | 
|---|
| 261 | } | 
|---|
| 262 |  | 
|---|
| 263 | // -------------------------------------------------------------------------- | 
|---|
| 264 | // | 
|---|
| 265 | // Delete fPointing and set pointing to NULL | 
|---|
| 266 | // | 
|---|
| 267 | void MPointingDevCalc::Clear(Option_t *o) | 
|---|
| 268 | { | 
|---|
| 269 | if (fPointing) | 
|---|
| 270 | delete fPointing; | 
|---|
| 271 |  | 
|---|
| 272 | fPointing = NULL; | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | // -------------------------------------------------------------------------- | 
|---|
| 276 | // | 
|---|
| 277 | // Sort the entries in fPoinitngModels | 
|---|
| 278 | // | 
|---|
| 279 | void MPointingDevCalc::SortPointingModels() | 
|---|
| 280 | { | 
|---|
| 281 | const int n = fPointingModels.GetSize(); | 
|---|
| 282 |  | 
|---|
| 283 | TArrayI idx(n); | 
|---|
| 284 |  | 
|---|
| 285 | TMath::Sort(n, fPointingModels.GetArray(), idx.GetArray(), kFALSE); | 
|---|
| 286 |  | 
|---|
| 287 | const TArrayI arr(fPointingModels); | 
|---|
| 288 |  | 
|---|
| 289 | for (int i=0; i<n; i++) | 
|---|
| 290 | fPointingModels[i] = arr[idx[i]]; | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | // -------------------------------------------------------------------------- | 
|---|
| 294 | // | 
|---|
| 295 | // Set new pointing models | 
|---|
| 296 | // | 
|---|
| 297 | void MPointingDevCalc::SetPointingModels(const TString &models) | 
|---|
| 298 | { | 
|---|
| 299 | fPointingModels.Set(0); | 
|---|
| 300 |  | 
|---|
| 301 | if (models.IsNull()) | 
|---|
| 302 | return; | 
|---|
| 303 |  | 
|---|
| 304 | TObjArray *arr = models.Tokenize(" "); | 
|---|
| 305 |  | 
|---|
| 306 | const int n = arr->GetEntries(); | 
|---|
| 307 | fPointingModels.Set(n); | 
|---|
| 308 |  | 
|---|
| 309 | for (int i=0; i<n; i++) | 
|---|
| 310 | fPointingModels[i] = atoi((*arr)[i]->GetName()); | 
|---|
| 311 |  | 
|---|
| 312 | delete arr; | 
|---|
| 313 |  | 
|---|
| 314 | SortPointingModels(); | 
|---|
| 315 | } | 
|---|
| 316 |  | 
|---|
| 317 | // -------------------------------------------------------------------------- | 
|---|
| 318 | // | 
|---|
| 319 | // Return a string with the pointing models, seperated by a space. | 
|---|
| 320 | // | 
|---|
| 321 | TString MPointingDevCalc::GetPointingModels() const | 
|---|
| 322 | { | 
|---|
| 323 | TString rc; | 
|---|
| 324 | for (int i=0; i<fPointingModels.GetSize(); i++) | 
|---|
| 325 | rc += Form ("%d ", fPointingModels[i]); | 
|---|
| 326 |  | 
|---|
| 327 | return rc; | 
|---|
| 328 | } | 
|---|
| 329 |  | 
|---|
| 330 | // -------------------------------------------------------------------------- | 
|---|
| 331 | // | 
|---|
| 332 | // Add a number to the pointing models | 
|---|
| 333 | // | 
|---|
| 334 | void MPointingDevCalc::AddPointingModel(UInt_t runnum) | 
|---|
| 335 | { | 
|---|
| 336 | const int n = fPointingModels.GetSize(); | 
|---|
| 337 | for (int i=0; i<n; i++) | 
|---|
| 338 | if ((UInt_t)fPointingModels[i]==runnum) | 
|---|
| 339 | { | 
|---|
| 340 | *fLog << warn << "WARNING - Pointing model " << runnum << " already in list... ignored." << endl; | 
|---|
| 341 | return; | 
|---|
| 342 | } | 
|---|
| 343 |  | 
|---|
| 344 | fPointingModels.Set(n+1); | 
|---|
| 345 | fPointingModels[n] = runnum; | 
|---|
| 346 |  | 
|---|
| 347 | SortPointingModels(); | 
|---|
| 348 | } | 
|---|
| 349 |  | 
|---|
| 350 | // -------------------------------------------------------------------------- | 
|---|
| 351 | // | 
|---|
| 352 | // Find the highest number in the array which is lower or equal num. | 
|---|
| 353 | // | 
|---|
| 354 | UInt_t MPointingDevCalc::FindPointingModel(UInt_t num) | 
|---|
| 355 | { | 
|---|
| 356 | const int n = fPointingModels.GetSize(); | 
|---|
| 357 | if (n==0) | 
|---|
| 358 | return (UInt_t)-1; | 
|---|
| 359 |  | 
|---|
| 360 | // Loop over all pointing models | 
|---|
| 361 | for (int i=0; i<n; i++) | 
|---|
| 362 | { | 
|---|
| 363 | // The number stored in the array did not yet overtake the runnumber | 
|---|
| 364 | if ((UInt_t)fPointingModels[i]<num) | 
|---|
| 365 | continue; | 
|---|
| 366 |  | 
|---|
| 367 | // The first pointing model is later than this run: use a default | 
|---|
| 368 | if (i==0) | 
|---|
| 369 | return (UInt_t)-1; | 
|---|
| 370 |  | 
|---|
| 371 | // The last entry in the array is the right one. | 
|---|
| 372 | return fPointingModels[i-1]; | 
|---|
| 373 | } | 
|---|
| 374 |  | 
|---|
| 375 | // Runnumber is after last entry of pointing models. Use the last one. | 
|---|
| 376 | return fPointingModels[n-1]; | 
|---|
| 377 | } | 
|---|
| 378 |  | 
|---|
| 379 | // -------------------------------------------------------------------------- | 
|---|
| 380 | // | 
|---|
| 381 | // Clear the pointing model. If run-number >= 87751 read the new | 
|---|
| 382 | // pointing model with fFilePrefix | 
|---|
| 383 | // | 
|---|
| 384 | Bool_t MPointingDevCalc::ReadPointingModel(const MRawRunHeader &run) | 
|---|
| 385 | { | 
|---|
| 386 | const UInt_t num = FindPointingModel(run.GetRunNumber()); | 
|---|
| 387 |  | 
|---|
| 388 | // No poinitng models are defined. Use simple dx/dy-calibration | 
|---|
| 389 | if (num==(UInt_t)-1) | 
|---|
| 390 | { | 
|---|
| 391 | Clear(); | 
|---|
| 392 | return kTRUE; | 
|---|
| 393 | } | 
|---|
| 394 |  | 
|---|
| 395 | // compile the name for the starguider files | 
|---|
| 396 | // The file with the number 00000000 is the default file | 
|---|
| 397 | TString fname = Form("%s%08d.txt", fFilePrefix.Data(), num); | 
|---|
| 398 |  | 
|---|
| 399 | if (!fPointing) | 
|---|
| 400 | fPointing = new MPointing; | 
|---|
| 401 |  | 
|---|
| 402 | if (fname==fPointing->GetName()) | 
|---|
| 403 | { | 
|---|
| 404 | *fLog << inf << fname << " already loaded." << endl; | 
|---|
| 405 | return kTRUE; | 
|---|
| 406 | } | 
|---|
| 407 |  | 
|---|
| 408 | return fPointing->Load(fname); | 
|---|
| 409 | } | 
|---|
| 410 |  | 
|---|
| 411 | // -------------------------------------------------------------------------- | 
|---|
| 412 | // | 
|---|
| 413 | // Check the file/run type from the run-header and if it is a data file | 
|---|
| 414 | // load starguider calibration. | 
|---|
| 415 | // | 
|---|
| 416 | Bool_t MPointingDevCalc::ReInit(MParList *plist) | 
|---|
| 417 | { | 
|---|
| 418 | MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader"); | 
|---|
| 419 | if (!run) | 
|---|
| 420 | { | 
|---|
| 421 | *fLog << err << "MRawRunHeader not found... aborting." << endl; | 
|---|
| 422 | return kFALSE; | 
|---|
| 423 | } | 
|---|
| 424 |  | 
|---|
| 425 | fNsbSum   =  0; | 
|---|
| 426 | fNsbSq    =  0; | 
|---|
| 427 | fNsbCount =  0; | 
|---|
| 428 |  | 
|---|
| 429 | fRunType = run->GetRunType(); | 
|---|
| 430 |  | 
|---|
| 431 | switch (fRunType) | 
|---|
| 432 | { | 
|---|
| 433 | case MRawRunHeader::kRTData: | 
|---|
| 434 | if (!fReport) | 
|---|
| 435 | *fLog << warn << "MReportStarguider not found... skipped." << endl; | 
|---|
| 436 | return ReadPointingModel(*run); | 
|---|
| 437 |  | 
|---|
| 438 | case MRawRunHeader::kRTMonteCarlo: | 
|---|
| 439 | return kTRUE; | 
|---|
| 440 |  | 
|---|
| 441 | case MRawRunHeader::kRTPedestal: | 
|---|
| 442 | *fLog << err << "Cannot work in a pedestal Run!... aborting." << endl; | 
|---|
| 443 | return kFALSE; | 
|---|
| 444 |  | 
|---|
| 445 | case MRawRunHeader::kRTCalibration: | 
|---|
| 446 | *fLog << err << "Cannot work in a calibration Run!... aborting." << endl; | 
|---|
| 447 | return kFALSE; | 
|---|
| 448 |  | 
|---|
| 449 | default: | 
|---|
| 450 | *fLog << err << "Run Type " << fRunType << " unknown!... aborting." << endl; | 
|---|
| 451 | return kFALSE; | 
|---|
| 452 | } | 
|---|
| 453 |  | 
|---|
| 454 | return kTRUE; | 
|---|
| 455 | } | 
|---|
| 456 |  | 
|---|
| 457 | // -------------------------------------------------------------------------- | 
|---|
| 458 | // | 
|---|
| 459 | //  Search for 'MPointingPos'. Create if not found. | 
|---|
| 460 | // | 
|---|
| 461 | Int_t MPointingDevCalc::PreProcess(MParList *plist) | 
|---|
| 462 | { | 
|---|
| 463 | fDeviation = (MPointingDev*)plist->FindCreateObj("MPointingDev"); | 
|---|
| 464 | fReport    = (MReportStarguider*)plist->FindObject("MReportStarguider"); | 
|---|
| 465 |  | 
|---|
| 466 | // We use kRTNone here as a placeholder for data runs. | 
|---|
| 467 | fRunType  = MRawRunHeader::kRTNone; | 
|---|
| 468 | fLastMjd  = -1; | 
|---|
| 469 |  | 
|---|
| 470 | fSkip.Reset(); | 
|---|
| 471 |  | 
|---|
| 472 | return fDeviation ? kTRUE : kFALSE; | 
|---|
| 473 | } | 
|---|
| 474 |  | 
|---|
| 475 | // -------------------------------------------------------------------------- | 
|---|
| 476 | // | 
|---|
| 477 | // Increase fSkip[i] by one. If the data in fDeviation is outdated (older | 
|---|
| 478 | // than fMaxAge) and the current report should be skipped reset DevZdAz and | 
|---|
| 479 | // DevXY and fSkip[6] is increased by one. | 
|---|
| 480 | // | 
|---|
| 481 | void MPointingDevCalc::Skip(Int_t i) | 
|---|
| 482 | { | 
|---|
| 483 | fSkip[i]++; | 
|---|
| 484 |  | 
|---|
| 485 | const Double_t diff = (fReport->GetMjd()-fLastMjd)*1440; // [min] 1440=24*60 | 
|---|
| 486 | if (diff<fMaxAge && fLastMjd>0) | 
|---|
| 487 | return; | 
|---|
| 488 |  | 
|---|
| 489 | fDeviation->SetDevZdAz(0, 0); | 
|---|
| 490 | fDeviation->SetDevXY(0, 0); | 
|---|
| 491 | fSkip[6]++; | 
|---|
| 492 | } | 
|---|
| 493 |  | 
|---|
| 494 | // -------------------------------------------------------------------------- | 
|---|
| 495 | // | 
|---|
| 496 | // Do a full starguider calibration using a pointing model for the starguider. | 
|---|
| 497 | // | 
|---|
| 498 | void MPointingDevCalc::DoCalibration(Double_t devzd, Double_t devaz) const | 
|---|
| 499 | { | 
|---|
| 500 | if (!fPointing) | 
|---|
| 501 | { | 
|---|
| 502 | // Do a simple starguider calibration using a simple offset in x and y | 
|---|
| 503 | fDeviation->SetDevZdAz(devzd, devaz); | 
|---|
| 504 |  | 
|---|
| 505 | // Linear starguider calibration taken from April/May data | 
|---|
| 506 | // For calibration add MDriveReport::GetErrorZd/Az ! | 
|---|
| 507 | fDeviation->SetDevXY(fDx, fDy); // 1arcmin ~ 5mm | 
|---|
| 508 |  | 
|---|
| 509 | return; | 
|---|
| 510 | } | 
|---|
| 511 |  | 
|---|
| 512 | // Get the nominal position the star is at the sky | 
|---|
| 513 | // Unit: deg | 
|---|
| 514 | ZdAz nom(fReport->GetNominalZd(), fReport->GetNominalAz()); | 
|---|
| 515 | nom *= TMath::DegToRad(); | 
|---|
| 516 |  | 
|---|
| 517 | // Get the mispointing measured by the telescope. It is | 
|---|
| 518 | // calculate as follows: | 
|---|
| 519 | // | 
|---|
| 520 | // The mispointing measured by the starguider: | 
|---|
| 521 | //    ZdAz mis(devzd, devaz); | 
|---|
| 522 | //    mis *= TMath::DegToRad(); | 
|---|
| 523 |  | 
|---|
| 524 | // The pointing model is the conversion from the real pointing | 
|---|
| 525 | // position of the telescope into the pointing position measured | 
|---|
| 526 | // by the starguider. | 
|---|
| 527 | // | 
|---|
| 528 | // To keep as close to the fitted model we use the forward correction. | 
|---|
| 529 |  | 
|---|
| 530 | // Position at which the starguider camera is pointing in real: | 
|---|
| 531 | //       pointing position = nominal position - dev | 
|---|
| 532 | // | 
|---|
| 533 | // The position measured as the starguider's pointing position | 
|---|
| 534 | ZdAz pos(nom);        // cpos = sao - dev | 
|---|
| 535 | pos -= ZdAz(devzd, devaz)*TMath::DegToRad(); | 
|---|
| 536 |  | 
|---|
| 537 | // Now we convert the starguider's pointing position into the | 
|---|
| 538 | // telescope pointing position (the pointing model converts | 
|---|
| 539 | // the telescope pointing position into the starguider pointing | 
|---|
| 540 | // position) | 
|---|
| 541 | ZdAz point = fPointing->CorrectBack(pos);  //FWD!!! | 
|---|
| 542 |  | 
|---|
| 543 | // MSrcPosCalc uses the following condition to calculate the | 
|---|
| 544 | // source position in the camera: | 
|---|
| 545 | //    real pointing pos = nominal pointing pos - dev | 
|---|
| 546 | //      --> dev = nominal - real | 
|---|
| 547 | // Therefor we calculate dev as follows: | 
|---|
| 548 | ZdAz dev(nom); | 
|---|
| 549 | dev -= point; | 
|---|
| 550 | dev *= TMath::RadToDeg(); | 
|---|
| 551 |  | 
|---|
| 552 | /* | 
|---|
| 553 | // We chose the other way. It is less accurate because is is the | 
|---|
| 554 | // other was than the poinitng model was fittet, but it is more | 
|---|
| 555 | // accurate because the nominal (i.e. real) pointing position | 
|---|
| 556 | // is less accurately known than the position returned by the | 
|---|
| 557 | // starguider. | 
|---|
| 558 | // | 
|---|
| 559 | // Calculate the deviation which would be measured by the starguider | 
|---|
| 560 | // if applied to a perfectly pointing telescope. | 
|---|
| 561 | ZdAz dev = fPointing->Correct(nom); | 
|---|
| 562 | dev -= nom; | 
|---|
| 563 |  | 
|---|
| 564 | // Now add these offsets and the starguider measured offsets to | 
|---|
| 565 | // the real pointing deviation of the telescope (note, that | 
|---|
| 566 | // signs here are just conventions) | 
|---|
| 567 | dev += ZdAz(devzd, devaz)*TMath::DegToRad(); // --> nom-mis | 
|---|
| 568 | dev *= TMath::RadToDeg(); | 
|---|
| 569 | */ | 
|---|
| 570 |  | 
|---|
| 571 | // Check if the starguider pointing model requests overwriting | 
|---|
| 572 | // of the values with constants (e.g. 0) | 
|---|
| 573 | devaz = fPointing->IsPxValid() ? fPointing->GetPx() : dev.Az(); | 
|---|
| 574 | devzd = fPointing->IsPyValid() ? fPointing->GetPy() : dev.Zd(); | 
|---|
| 575 |  | 
|---|
| 576 | fDeviation->SetDevZdAz(devzd, devaz); | 
|---|
| 577 | fDeviation->SetDevXY(fPointing->GetDxy()); | 
|---|
| 578 | } | 
|---|
| 579 |  | 
|---|
| 580 | Int_t MPointingDevCalc::ProcessStarguiderReport() | 
|---|
| 581 | { | 
|---|
| 582 | Double_t devzd = fReport->GetDevZd(); // [arcmin] | 
|---|
| 583 | Double_t devaz = fReport->GetDevAz(); // [arcmin] | 
|---|
| 584 | if (devzd==0 && devaz==0) | 
|---|
| 585 | { | 
|---|
| 586 | Skip(1); | 
|---|
| 587 | return kTRUE; | 
|---|
| 588 | } | 
|---|
| 589 |  | 
|---|
| 590 | if (!fReport->IsMonitoring()) | 
|---|
| 591 | { | 
|---|
| 592 | Skip(2); | 
|---|
| 593 | return kTRUE; | 
|---|
| 594 | } | 
|---|
| 595 |  | 
|---|
| 596 | devzd /= 60; // Convert from arcmin to deg | 
|---|
| 597 | devaz /= 60; // Convert from arcmin to deg | 
|---|
| 598 |  | 
|---|
| 599 | const Double_t nsb = fReport->GetSkyBrightness(); | 
|---|
| 600 | if (nsb>0) | 
|---|
| 601 | { | 
|---|
| 602 | if (nsb>fNsbMin && nsb<fNsbMax) | 
|---|
| 603 | { | 
|---|
| 604 | fNsbSum += nsb; | 
|---|
| 605 | fNsbSq  += nsb*nsb; | 
|---|
| 606 | fNsbCount++; | 
|---|
| 607 | } | 
|---|
| 608 |  | 
|---|
| 609 | if (fNsbCount>0) | 
|---|
| 610 | { | 
|---|
| 611 | const Double_t sum = fNsbSum/fNsbCount; | 
|---|
| 612 | const Double_t sq  = fNsbSq /fNsbCount; | 
|---|
| 613 |  | 
|---|
| 614 | const Double_t rms = fNsbLevel*TMath::Sqrt(sq - sum*sum); | 
|---|
| 615 |  | 
|---|
| 616 | if (nsb<sum-rms || nsb>sum+rms) | 
|---|
| 617 | { | 
|---|
| 618 | Skip(3); | 
|---|
| 619 | return kTRUE; | 
|---|
| 620 | } | 
|---|
| 621 | } | 
|---|
| 622 |  | 
|---|
| 623 | if (fReport->GetNumIdentifiedStars()<fNumMinStars) | 
|---|
| 624 | { | 
|---|
| 625 | Skip(4); | 
|---|
| 626 | return kTRUE; | 
|---|
| 627 | } | 
|---|
| 628 | } | 
|---|
| 629 |  | 
|---|
| 630 | // >= 87751 (31.3.06 12:00) | 
|---|
| 631 |  | 
|---|
| 632 | // Calculate absolute deviation | 
|---|
| 633 | const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz); | 
|---|
| 634 |  | 
|---|
| 635 | // Sanity check... larger deviation are strange and ignored | 
|---|
| 636 | if (dev*60>fMaxAbsDev) | 
|---|
| 637 | { | 
|---|
| 638 | Skip(5); | 
|---|
| 639 | return kTRUE; | 
|---|
| 640 | } | 
|---|
| 641 |  | 
|---|
| 642 | DoCalibration(devzd, devaz); | 
|---|
| 643 |  | 
|---|
| 644 | fSkip[0]++; | 
|---|
| 645 | fLastMjd = fReport->GetMjd(); | 
|---|
| 646 |  | 
|---|
| 647 | return kTRUE; | 
|---|
| 648 | } | 
|---|
| 649 |  | 
|---|
| 650 | // -------------------------------------------------------------------------- | 
|---|
| 651 | // | 
|---|
| 652 | //  See class description. | 
|---|
| 653 | // | 
|---|
| 654 | Int_t MPointingDevCalc::Process() | 
|---|
| 655 | { | 
|---|
| 656 | switch (fRunType) | 
|---|
| 657 | { | 
|---|
| 658 | case MRawRunHeader::kRTNone: | 
|---|
| 659 | case MRawRunHeader::kRTData: | 
|---|
| 660 | return fReport ? ProcessStarguiderReport() : kTRUE; | 
|---|
| 661 |  | 
|---|
| 662 | case MRawRunHeader::kRTMonteCarlo: | 
|---|
| 663 | fSkip[0]++; | 
|---|
| 664 | fDeviation->SetDevZdAz(0, 0); | 
|---|
| 665 | fDeviation->SetDevXY(0, 0); | 
|---|
| 666 | return kTRUE; | 
|---|
| 667 | } | 
|---|
| 668 | return kTRUE; | 
|---|
| 669 | } | 
|---|
| 670 |  | 
|---|
| 671 | // -------------------------------------------------------------------------- | 
|---|
| 672 | // | 
|---|
| 673 | // Print execution statistics | 
|---|
| 674 | // | 
|---|
| 675 | Int_t MPointingDevCalc::PostProcess() | 
|---|
| 676 | { | 
|---|
| 677 | if (GetNumExecutions()==0) | 
|---|
| 678 | return kTRUE; | 
|---|
| 679 |  | 
|---|
| 680 | *fLog << inf << endl; | 
|---|
| 681 | *fLog << GetDescriptor() << " execution statistics:" << endl; | 
|---|
| 682 | PrintSkipped(fSkip[1], "Starguider deviation not set, is exactly 0/0"); | 
|---|
| 683 | PrintSkipped(fSkip[2], "Starguider was not monitoring (eg. LEDs off)"); | 
|---|
| 684 | PrintSkipped(fSkip[3], Form("NSB out of %.1f sigma range", fNsbLevel)); | 
|---|
| 685 | PrintSkipped(fSkip[4], Form("Number of identified stars < %d", fNumMinStars)); | 
|---|
| 686 | PrintSkipped(fSkip[5], Form("Absolute deviation > %.1farcmin", fMaxAbsDev)); | 
|---|
| 687 | PrintSkipped(fSkip[6], Form("Events set to 0 because older than %.1fmin", fMaxAge)); | 
|---|
| 688 | *fLog << " " << (int)fSkip[0] << " (" << Form("%5.1f", 100.*fSkip[0]/GetNumExecutions()) << "%) Evts survived calculation!" << endl; | 
|---|
| 689 | *fLog << endl; | 
|---|
| 690 |  | 
|---|
| 691 | return kTRUE; | 
|---|
| 692 | } | 
|---|
| 693 |  | 
|---|
| 694 | // -------------------------------------------------------------------------- | 
|---|
| 695 | // | 
|---|
| 696 | // MPointingDevCalc.NumMinStars: 8 | 
|---|
| 697 | // MPointingDevCalc.NsbLevel:    3.0 | 
|---|
| 698 | // MPointingDevCalc.NsbMin:      30 | 
|---|
| 699 | // MPointingDevCalc.NsbMax:      60 | 
|---|
| 700 | // MPointingDevCalc.MaxAbsDev:   15 | 
|---|
| 701 | // MPointingDevCalc.MaxAge:      1.0 | 
|---|
| 702 | // MPointingDevCalc.Dx:         -0.001 | 
|---|
| 703 | // MPointingDevCalc.Dy:         -0.004 | 
|---|
| 704 | // | 
|---|
| 705 | // For a detailed description see the class reference. | 
|---|
| 706 | // | 
|---|
| 707 | Int_t MPointingDevCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print) | 
|---|
| 708 | { | 
|---|
| 709 | Bool_t rc = kFALSE; | 
|---|
| 710 | if (IsEnvDefined(env, prefix, "NumMinStars", print)) | 
|---|
| 711 | { | 
|---|
| 712 | SetNumMinStars(GetEnvValue(env, prefix, "NumMinStars", (Int_t)fNumMinStars)); | 
|---|
| 713 | rc = kTRUE; | 
|---|
| 714 | } | 
|---|
| 715 | if (IsEnvDefined(env, prefix, "NsbLevel", print)) | 
|---|
| 716 | { | 
|---|
| 717 | SetNsbLevel(GetEnvValue(env, prefix, "NsbLevel", fNsbLevel)); | 
|---|
| 718 | rc = kTRUE; | 
|---|
| 719 | } | 
|---|
| 720 | if (IsEnvDefined(env, prefix, "NsbMin", print)) | 
|---|
| 721 | { | 
|---|
| 722 | SetNsbMin(GetEnvValue(env, prefix, "NsbMin", fNsbMin)); | 
|---|
| 723 | rc = kTRUE; | 
|---|
| 724 | } | 
|---|
| 725 | if (IsEnvDefined(env, prefix, "NsbMax", print)) | 
|---|
| 726 | { | 
|---|
| 727 | SetNsbMax(GetEnvValue(env, prefix, "NsbMax", fNsbMax)); | 
|---|
| 728 | rc = kTRUE; | 
|---|
| 729 | } | 
|---|
| 730 | if (IsEnvDefined(env, prefix, "MaxAbsDev", print)) | 
|---|
| 731 | { | 
|---|
| 732 | SetMaxAbsDev(GetEnvValue(env, prefix, "MaxAbsDev", fMaxAbsDev)); | 
|---|
| 733 | rc = kTRUE; | 
|---|
| 734 | } | 
|---|
| 735 | if (IsEnvDefined(env, prefix, "Dx", print)) | 
|---|
| 736 | { | 
|---|
| 737 | fDx = GetEnvValue(env, prefix, "Dx", fDx); | 
|---|
| 738 | rc = kTRUE; | 
|---|
| 739 | } | 
|---|
| 740 | if (IsEnvDefined(env, prefix, "Dy", print)) | 
|---|
| 741 | { | 
|---|
| 742 | fDy = GetEnvValue(env, prefix, "Dy", fDy); | 
|---|
| 743 | rc = kTRUE; | 
|---|
| 744 | } | 
|---|
| 745 | if (IsEnvDefined(env, prefix, "MaxAge", print)) | 
|---|
| 746 | { | 
|---|
| 747 | fMaxAge = GetEnvValue(env, prefix, "MaxAge", fMaxAge); | 
|---|
| 748 | rc = kTRUE; | 
|---|
| 749 | } | 
|---|
| 750 | if (IsEnvDefined(env, prefix, "FilePrefix", print)) | 
|---|
| 751 | { | 
|---|
| 752 | fFilePrefix = GetEnvValue(env, prefix, "FilePrefix", fFilePrefix); | 
|---|
| 753 | rc = kTRUE; | 
|---|
| 754 | } | 
|---|
| 755 | if (IsEnvDefined(env, prefix, "PointingModels", print)) | 
|---|
| 756 | { | 
|---|
| 757 | SetPointingModels(GetEnvValue(env, prefix, "PointingModels", GetPointingModels())); | 
|---|
| 758 | rc = kTRUE; | 
|---|
| 759 | } | 
|---|
| 760 |  | 
|---|
| 761 | return rc; | 
|---|
| 762 | } | 
|---|