source: trunk/MagicSoft/Cosy/main/MStarguider.cc@ 8821

Last change on this file since 8821 was 8821, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 65.1 KB
Line 
1#undef EXPERT
2#undef EXPERT
3
4#include "MStarguider.h"
5
6#include <fstream> // ifstream
7#include <iostream> // cout
8#include <iomanip> // cout
9
10#include <TH2F.h>
11#include <TGraph.h>
12#include <TTimer.h>
13#include <TSystem.h>
14#include <TFile.h> // temp writeout of histos
15#include <TSocket.h>
16
17#include "MAstro.h"
18#include "MString.h"
19
20#include <TGMenu.h>
21#include <TGLabel.h>
22#include <TGButton.h>
23#include <TGSplitter.h> // TGHorizontal3DLine
24#include <TGTextEntry.h>
25#include <TGLayout.h>
26#include "MString.h"
27
28#include "MCosy.h"
29#include "MCaos.h"
30// #include "MStargLeds.h"
31#include "MStargHistograms.h"
32#include "MDriveCom.h"
33
34#include "MGStarg.h"
35#include "MGNumStars.h"
36
37#include "MGImage.h"
38#include "MGCoordinates.h"
39
40#include "coord.h"
41
42#include "Camera.h"
43#include "PngReader.h"
44
45#include "Led.h"
46#include "Writer.h"
47#include "FilterLed.h"
48#include "MStarList.h"
49#include "CaosFilter.h"
50#include "StarCatalog.h"
51#include "MGeomCamMagic.h"
52#include "MAstroCamera.h"
53
54#include "MGCosy.h"
55
56ClassImp(MStarguider);
57
58using namespace std;
59
60enum {
61 IDM_kFilter,
62 IDM_kFindStar,
63 IDM_kCaosFilter,
64 IDM_kCatalog,
65 IDM_kStarguider,
66 IDM_kStart,
67 IDM_kStop,
68 IDM_kFileType,
69 IDM_kPPM,
70 IDM_kPNG,
71 IDM_kOnce,
72 IDM_kStretch,
73 IDM_kInput,
74 IDM_kChannel1,
75 IDM_kChannel2,
76 IDM_kChannel3,
77 IDM_kContinous,
78 IDM_kRate25ps,
79 IDM_kRate5ps,
80 IDM_kRate1s,
81 IDM_kRate5s,
82 IDM_kRate30s,
83 IDM_kRate1m,
84 IDM_kRate5m,
85 IDM_kSetup,
86 IDM_kLimMag3,
87 IDM_kLimMag4,
88 IDM_kLimMag5,
89 IDM_kLimMag6,
90 IDM_kLimMag7,
91 IDM_kLimMag8,
92 IDM_kLimMag9,
93 IDM_kPixSize,
94 IDM_kAngle,
95 IDM_kCut,
96 IDM_kInterpol250,
97 IDM_kInterpol125,
98 IDM_kInterpol50,
99 IDM_kInterpol25,
100 IDM_kInterpol10,
101 IDM_kInterpol5,
102 IDM_kInterpol2,
103 IDM_kInterpol1,
104 IDM_kCaosPrintRings,
105 IDM_kCaosPrintLeds,
106 IDM_kCaosAnalStart,
107 IDM_kCaosAnalStop,
108 IDM_kCaosWriteStart,
109 IDM_kCaosWriteStop,
110 IDM_kResetHistograms,
111 IDM_kStargAnalysis,
112 IDM_kStargCaosFilter,
113 IDM_kStargFindStar,
114 IDM_kRoqueLampAna,
115 IDM_kStarguiderMode,
116 IDM_kTpointMode
117
118};
119
120Bool_t MStarguider::HandleTimer(TTimer *t)
121{
122 if (IsMapped())
123 {
124 fImage->DoRedraw();
125 fZoomImage->DoRedraw();
126 }
127
128 if (fCosy && fCosy->GetWin()->IsMapped())
129 fCosy->GetWin()->GetImage()->DoRedraw();
130
131 fGStarg->Update(fPos, fD);
132 if (fDisplay->IsEntryChecked(IDM_kStarguider))
133 fGNumStars->Update(fNumStarsDetected, fNumStarsCorrelated);
134
135 return kTRUE;
136}
137
138#define kZOOM 96
139
140XY MStarguider::GetCoordinates() const
141{
142 return fPZdAz->GetCoordinates();
143}
144
145void MStarguider::InitGui(Int_t channel)
146{
147 fList = new MGList;
148 fList->SetOwner();
149
150 const TGWindow *p=gClient->GetRoot();
151
152 fChannel = new TGPopupMenu(p);
153 fChannel->AddEntry("Starfield Camera", IDM_kChannel1);
154 fChannel->AddEntry("TPoint Camera", IDM_kChannel2);
155 fChannel->AddEntry("Read from File", IDM_kChannel3);
156 if (channel<0)
157 fChannel->CheckEntry(IDM_kChannel3);
158 else
159 fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
160 fChannel->Associate(this);
161 fList->Add(fChannel);
162
163 fFileType = new TGPopupMenu(p);
164 fFileType->AddEntry("PP&M", IDM_kPPM);
165 fFileType->AddEntry("&PNG", IDM_kPNG);
166 fFileType->CheckEntry(IDM_kPNG);
167 fFileType->Associate(this);
168 fList->Add(fFileType);
169
170 fWriteType = new TGPopupMenu(p);
171 fWriteType->AddEntry("&Once", IDM_kOnce);
172 fWriteType->AddEntry("&Continous", IDM_kContinous);
173 fWriteType->CheckEntry(IDM_kOnce);
174 fWriteType->Associate(this);
175 fList->Add(fWriteType);
176
177 fWriteRate = new TGPopupMenu(p);
178 fWriteRate->AddEntry("25/s", IDM_kRate25ps);
179 fWriteRate->AddEntry("5/s", IDM_kRate5ps);
180 fWriteRate->AddEntry("1s", IDM_kRate1s);
181 fWriteRate->AddEntry("5s", IDM_kRate5s);
182 fWriteRate->AddEntry("30s", IDM_kRate30s);
183 fWriteRate->AddEntry("1min", IDM_kRate1m);
184 fWriteRate->AddEntry("5min", IDM_kRate5m);
185 fWriteRate->CheckEntry(IDM_kRate1m);
186 fWriteRate->Associate(this);
187 fList->Add(fWriteRate);
188
189 fWrtRate = 25*60;
190
191 fLimMag = new TGPopupMenu(p);
192 fLimMag->AddEntry("3", IDM_kLimMag3);
193 fLimMag->AddEntry("4", IDM_kLimMag4);
194 fLimMag->AddEntry("5", IDM_kLimMag5);
195 fLimMag->AddEntry("6", IDM_kLimMag6);
196 fLimMag->AddEntry("7", IDM_kLimMag7);
197 fLimMag->AddEntry("8", IDM_kLimMag8);
198 fLimMag->AddEntry("9", IDM_kLimMag9);
199 fLimMag->CheckEntry(IDM_kLimMag9);
200 fLimMag->Associate(this);
201 fList->Add(fLimMag);
202
203 fSao->SetLimitMag(9.0);
204
205 fInterpol = new TGPopupMenu(p);
206 fInterpol->AddEntry("250", IDM_kInterpol250);
207 fInterpol->AddEntry("125", IDM_kInterpol125);
208 fInterpol->AddEntry("50", IDM_kInterpol50);
209 fInterpol->AddEntry("25", IDM_kInterpol25);
210 fInterpol->AddEntry("10", IDM_kInterpol10);
211 fInterpol->AddEntry("5", IDM_kInterpol5);
212 fInterpol->AddEntry("2", IDM_kInterpol2);
213 fInterpol->AddEntry("Off", IDM_kInterpol1);
214 fInterpol->Associate(this);
215 fList->Add(fInterpol);
216
217 TString disp=gVirtualX->DisplayName();
218 cout << "Display: " << disp << endl;
219 if (disp.First(':')>=0)
220 disp=disp(0, disp.First(':'));
221
222 if (disp.IsNull() || disp==(TString)"localhost")
223 {
224 fInterpol->CheckEntry(IDM_kInterpol5);
225 fIntRate = 50;
226 }
227 else
228 {
229 fInterpol->CheckEntry(IDM_kInterpol125);
230 fIntRate = 125;
231 }
232
233 fCaosPrint = new TGPopupMenu(p);
234 fCaosPrint->AddEntry("&Leds", IDM_kCaosPrintLeds);
235 fCaosPrint->AddEntry("&Rings", IDM_kCaosPrintRings);
236 fCaosPrint->Associate(this);
237 fList->Add(fCaosPrint);
238
239 fCaosWrite = new TGPopupMenu(p);
240 fCaosWrite->AddEntry("&Start", IDM_kCaosWriteStart);
241 fCaosWrite->AddEntry("Sto&p", IDM_kCaosWriteStop);
242 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
243 fCaosWrite->Associate(this);
244 fList->Add(fCaosWrite);
245
246 fCaosAnalyse = new TGPopupMenu(p);
247 fCaosAnalyse->AddEntry("S&tart Analysis", IDM_kCaosAnalStart);
248 fCaosAnalyse->AddEntry("St&op Analysis", IDM_kCaosAnalStop);
249 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
250 // fCaosAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
251 // fCaosAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
252 fCaosAnalyse->Associate(this);
253 fList->Add(fCaosAnalyse);
254
255 fMenu = new TGMenuBar(this, 0, 0, kHorizontalFrame);
256 //fMenu->SetCleanup();
257 //fMenu->AddPopup("&Display", fDisplay, NULL);
258 //fMenu->AddPopup("&Mode", fMode, NULL);
259 //fMenu->AddPopup("&WritePics", fWritePictures, NULL);
260 //fMenu->AddPopup("&Setup", fSetup, NULL);
261 //fMenu->AddPopup("&Operations", fOperations, NULL);
262 fDisplay = fMenu->AddPopup("&Display");
263 fMode = fMenu->AddPopup("&Mode");
264 fWritePictures = fMenu->AddPopup("&WritePics");
265 fSetup = fMenu->AddPopup("&Setup");
266 fOperations = fMenu->AddPopup("&Operations");
267 fMenu->Resize(fMenu->GetDefaultSize());
268 //fMenu->BindKeys(this);
269 AddFrame(fMenu);
270 //fList->Add(fMenu);
271
272 //
273 // Create Menu for MStarguider Display
274 //
275 //fDisplay = new MMGPopupMenu(p);
276 fDisplay->AddEntry("&Filter", IDM_kFilter);
277 fDisplay->AddEntry("Stretch", IDM_kStretch);
278 fDisplay->AddSeparator();
279 fDisplay->AddEntry("Find &Star", IDM_kFindStar);
280 fDisplay->AddEntry("C&aos Filter", IDM_kCaosFilter);
281 fDisplay->AddSeparator();
282 fDisplay->AddEntry("SAO &Catalog", IDM_kCatalog);
283 fDisplay->AddEntry("Starguider", IDM_kStarguider);
284 fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter);
285 fDisplay->AddEntry("Starguider Find Star", IDM_kStargFindStar);
286 fDisplay->AddSeparator();
287 if (channel>=0)
288 fDisplay->AddPopup("&Input", fChannel);
289 fDisplay->DisableEntry(IDM_kStargFindStar);
290 fDisplay->CheckEntry(IDM_kStretch);
291 fDisplay->Associate(this);
292 //fList->Add(fDisplay);
293
294 //fMode = new MGPopupMenu(p);
295 fMode->AddEntry("Starguider", IDM_kStarguiderMode);
296 fMode->AddEntry("Tpoint", IDM_kTpointMode);
297 fMode->Associate(this);
298 //fList->Add(fMode);
299
300 //fWritePictures = new MGPopupMenu(p);
301 fWritePictures->AddEntry("&Start", IDM_kStart);
302 fWritePictures->AddEntry("Sto&p", IDM_kStop);
303 fWritePictures->AddSeparator();
304 fWritePictures->AddPopup("File &Type", fFileType);
305 fWritePictures->AddPopup("&Write Type", fWriteType);
306 fWritePictures->AddPopup("Write &Rate", fWriteRate);
307 fWritePictures->DisableEntry(IDM_kStop);
308 fWritePictures->Associate(this);
309 //fList->Add(fWritePictures);
310
311 //fSetup = new MGPopupMenu(p);
312 fSetup->AddPopup("Lim. &Magnitude", fLimMag);
313 fSetup->AddPopup("Disp. &Interpolation", fInterpol);
314 //fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
315 fSetup->Associate(this);
316 //fList->Add(fSetup);
317
318 //fOperations = new MGPopupMenu(p);
319 fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
320 fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis);
321 fOperations->DisableEntry(IDM_kStargAnalysis);
322 fOperations->Associate(this);
323 //fList->Add(fOperations);
324
325 fCaOs = new TGPopupMenu(p);
326 fCaOs->AddPopup("&Write", fCaosWrite);
327 fCaOs->AddPopup("&Print", fCaosPrint);
328 fCaOs->AddPopup("&Analyse", fCaosAnalyse);
329 fCaOs->Associate(this);
330 //fCaOs->BindKeys(fMenu, this);
331 fList->Add(fCaOs);
332/*
333 TGLayoutHints *hints2a =
334 new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|
335 kLHintsExpandX|kLHintsExpandY,1,1);
336 fList->Add(hints2a);
337 */
338 fGStarg = new MGStarg(this, 235);
339 fGStarg->DrawText("0.75'", "1.50'", "3.00'", "Mispointing [min]");
340 fGStarg->DrawHexagon();
341 fGStarg->Move(530,596+5);
342 fList->Add(fGStarg);
343
344 //RA,Dec for catalog
345 fCRaDec = new MGCoordinates(this, kETypeRaDec);
346 fCRaDec->Move(4, fMenu->GetDefaultHeight()+584);
347 AddFrame(fCRaDec);
348 //fList->Add(fCRaDec);
349
350 //telescope position
351 fCZdAz = new MGCoordinates(this, kETypeZdAz, 2);
352 fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+597);
353 AddFrame(fCZdAz);
354 //fList->Add(fCZdAz);
355
356 //starguider position
357 fPZdAz = new MGCoordinates(this, kETypeZdAz, 2);
358 fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+640);
359 AddFrame(fPZdAz);
360 //fList->Add(fPZdAz);
361
362 //mispointing
363 fDZdAz = new MGCoordinates(this, kETypeZdAz, 2);
364 fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+683);
365 AddFrame(fDZdAz);
366 //fList->Add(fDZdAz);
367
368 fSZdAz = new MGCoordinates(this, kETypeZdAz, 2);
369 fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+795);
370 AddFrame(fSZdAz);
371 //fList->Add(fSZdAz);
372
373 fGNumStars = new MGNumStars(this, 235);
374 fGNumStars->DrawText("Number of stars");
375 fGNumStars->Move(278, fMenu->GetDefaultHeight()+713);
376 fList->Add(fGNumStars);
377
378 fTPoint = new TGTextButton(this, "TPoint");
379 fTPoint->Move(4, fMenu->GetDefaultHeight()+785);
380 fTPoint->AllowStayDown(kTRUE);
381 AddFrame(fTPoint);
382 //fList->Add(fTPoint);
383
384 fStargTPoint = new TGTextButton(this, "StargTPoint");
385 fStargTPoint->Move(170, fMenu->GetDefaultHeight()+785);
386 fStargTPoint->AllowStayDown(kTRUE);
387 AddFrame(fStargTPoint);
388 //fList->Add(fStargTPoint);
389
390 fFps = new TGLabel(this, "---fps");
391 fFps->SetTextJustify(kTextRight);
392 fFps->Move(650-495, fMenu->GetDefaultHeight()+714+23);
393 AddFrame(fFps);
394 //fList->Add(fFps);
395
396 fPosZoom = new TGLabel(this, "(----, ----) ----.--d/----.--d");
397 fPosZoom->SetTextJustify(kTextLeft);
398 fPosZoom->Move(4, fMenu->GetDefaultHeight()+765);
399 AddFrame(fPosZoom);
400 //fList->Add(fPosZoom);
401
402 fSkyBright = new TGLabel(this, "Sky Brightness: --- ");
403 fSkyBright->SetTextJustify(kTextLeft);
404 fSkyBright->Move(4, fMenu->GetDefaultHeight()+785);
405 AddFrame(fSkyBright);
406 //fList->Add(fSkyBright);
407
408 TGLabel *l = new TGLabel(this, "deg");
409 l->SetTextJustify(kTextLeft);
410 l->Move(606-412, fMenu->GetDefaultHeight()+669);
411 AddFrame(l);
412 //fList->Add(l);
413
414 l = new TGLabel(this, "arcsec/pix");
415 l->SetTextJustify(kTextLeft);
416 l->Move(606-412, fMenu->GetDefaultHeight()+692);
417 AddFrame(l);
418 //fList->Add(l);
419
420 l = new TGLabel(this, "sigma");
421 l->SetTextJustify(kTextLeft);
422 l->Move(606-412, fMenu->GetDefaultHeight()+715);
423 AddFrame(l);
424 //fList->Add(l);
425
426 fCZdAzText = new TGLabel(this, "Zd/Az telescope pointing at");
427 fCZdAzText->SetTextJustify(kTextLeft);
428 fCZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+584-5);
429 AddFrame(fCZdAzText);
430 //fList->Add(fCZdAzText);
431
432 fPZdAzText = new TGLabel(this, "Zd/Az starguider pointing at");
433 fPZdAzText->SetTextJustify(kTextLeft);
434 fPZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+630+20-5-23);
435 AddFrame(fPZdAzText);
436 //fList->Add(fPZdAzText);
437
438 fDZdAzText = new TGLabel(this, "Zd/Az mispointing");
439 fDZdAzText->SetTextJustify(kTextLeft);
440 fDZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5-46);
441 AddFrame(fDZdAzText);
442 //fList->Add(fDZdAzText);
443
444#ifdef EXPERT
445 l = new TGLabel(this, "Mispointing/FindStar (Experts Only!)");
446 l->SetTextJustify(kTextLeft);
447 l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*20-5);
448 AddFrame(l);
449 //fList->Add(l);
450#endif
451
452 // Set input box for rotation angle
453 const Double_t angle = -0.2;
454 fSao->SetRotationAngle(angle);
455
456 TString txt;
457 txt += angle;
458
459 fAngle = new TGTextEntry(this, txt, IDM_kAngle);
460 fAngle->SetAlignment(kTextCenterX);
461 fAngle->Move(547-410, fMenu->GetDefaultHeight()+667);
462 AddFrame(fAngle);
463 //fList->Add(fAngle);
464
465 // Set input box for pixel size
466 const Double_t pixsize = 48.9; // used to be 23.4
467
468 fSao->SetPixSize(pixsize);
469
470 txt = "";
471 txt += pixsize;
472
473 fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
474 fPixSize->SetAlignment(kTextCenterX);
475 fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690);
476 AddFrame(fPixSize);
477 //fList->Add(fPixSize);
478
479 // Set input box for cleaning cut
480 const Double_t cut = 3.0;
481
482 txt = "";
483 txt += cut;
484
485 fCut = new TGTextEntry(this, txt, IDM_kCut);
486 fCut->SetAlignment(kTextCenterX);
487 fCut->Move(547-410, fMenu->GetDefaultHeight()+713);
488 AddFrame(fCut);
489 //fList->Add(fCut);
490
491 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
492 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
493 // fList->Add(fLineSep);
494
495 //
496 // Create Image Display
497 //
498 fZoomImage = new MGImage(this, kZOOM, kZOOM);
499 // fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
500 fZoomImage->Move(4, 700-kZOOM-2+85);
501 AddFrame(fZoomImage);
502 //fList->Add(fZoomImage);
503
504 fImage = new MGImage(this, 768, 576);
505 fImage->Move(0, fMenu->GetDefaultHeight());
506 AddFrame(fImage);
507 //fList->Add(fImage);
508
509 const Int_t w = 768;
510 const Int_t h = 840;
511 SetWMSizeHints(w, h, w, h, 1, 1); // set the smallest and biggest size of the Main frame
512
513 //
514 // Make everything visible
515 //
516 SetWindowName("MStarguider Main Window");
517 SetIconName("MStarguider");
518
519 MapSubwindows();
520 fTPoint->UnmapWindow();
521 fStargTPoint->UnmapWindow();
522 fGStarg->UnmapWindow();
523 fGNumStars->UnmapWindow();
524 fCRaDec->UnmapWindow();
525 fCZdAz->UnmapWindow();
526 fCZdAzText->UnmapWindow();
527 fPZdAz->UnmapWindow();
528 fPZdAzText->UnmapWindow();
529 fDZdAz->UnmapWindow();
530 fDZdAzText->UnmapWindow();
531 fSZdAz->UnmapWindow();
532 fSkyBright->UnmapWindow();
533 MapWindow();
534
535
536 //IconifyWindow();
537
538 //------------------------------------------------------------
539 // XY xy(3.819444, 24.05333);
540 // fCRaDec->SetCoordinates(xy);
541 // fRaDec->Set(xy.X()*360/24, xy.Y());
542 //------------------------------------------------------------
543}
544
545MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
546 : TGMainFrame(gClient->GetRoot(), 768, 840),
547 fNumStarsDetected(0),
548 fNumStarsCorrelated(0),
549 fCosy(NULL),
550 fOutTp(0),
551 fOutStargTp(0),
552 fOutRq(0),
553 fDx((768-kZOOM)/2),
554 fDy((512-kZOOM)/2),
555 fStatus(MDriveCom::kStandby)
556{
557 cout << " #### FIXME: Make MCaos Thread safe!" << endl;
558
559 // This means that all objects added with AddFrame are deleted
560 // automatically, including all LayoutHints.
561 SetCleanup();
562
563 fAmcSocket = new TSocket("amc", 7307);
564
565 fSao = new StarCatalog(obs);
566 fRaDec = new RaDec(180, 40);
567
568 // fStargLeds = new MStargLeds;
569 // fStargLeds->ReadResources();
570
571 fCaos = new MCaos;
572 fCaos->ReadResources();
573
574 fStargCaos = new MCaos;
575 fStargCaos->ReadResources("stargleds.txt");
576 fStargCaos->SetMinNumberRings(3);
577 fStargCaos->SetRadii(158,164);
578
579 fStargHistograms = new MStargHistograms();
580
581 InitGui(channel);
582
583 fTimer=new TTimer(this, 1000/25); // 40ms
584 fTimer->TurnOn();
585
586 fTime.Now();
587
588 fTimeFromTp.Set(1970,1,1);
589 fAltAzOffsetFromTp = AltAz(-1000,-1000);
590
591 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
592
593 if (channel<0)
594 fGetter=new PngReader(*this);
595 else
596 {
597 fGetter = new Camera(*this, channel);
598 ((Camera*)fGetter)->Loop(0);
599 }
600}
601
602MStarguider::~MStarguider()
603{
604 fGetter->ExitLoop();
605 delete fGetter;
606
607 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
608
609 fTimer->TurnOff();
610 delete fTimer;
611
612 delete fList;
613
614 delete fCaos;
615 delete fStargCaos;
616 // delete fStargLeds;
617 delete fStargHistograms;
618 delete fSao;
619 delete fRaDec;
620
621 if (fOutTp)
622 delete fOutTp;
623
624 if (fOutStargTp)
625 delete fOutStargTp;
626
627 if (fOutRq)
628 delete fOutRq;
629
630 delete fAmcSocket;
631
632 cout << "Camera Display destroyed." << endl;
633}
634
635bool MStarguider::SendAmcTrigger(const char *msg)
636{
637 if (!fAmcSocket->IsValid())
638 return false;
639
640 TString txt("TRIGGER ");
641 txt += msg;
642
643 const Int_t len = fAmcSocket->SendRaw(txt.Data(), txt.Length());
644 if (len<0)
645 {
646 cout << "ERROR - Sending Trigger to Amc" << endl;
647 return false;
648 }
649 if (len!=txt.Length())
650 {
651 cout << "Send wrong number (" << len << ") of Bytes to Amc." << endl;
652 return false;
653 }
654
655 return true;
656}
657
658void MStarguider::Layout()
659{
660 // Resize(GetDefaultSize());
661}
662
663void MStarguider::CloseWindow()
664{
665 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
666
667 //fClient.ExitLoop();
668 // cout << "FIXME: ExitLoop not called!!!!!!" << endl;
669 gSystem->ExitLoop();
670}
671
672void MStarguider::SwitchOff(TGPopupMenu *p, UInt_t id)
673{
674 p->UnCheckEntry(id);
675 p->DisableEntry(id);
676}
677
678void MStarguider::SetChannel()
679{
680 if (fChannel->IsEntryChecked(IDM_kChannel3))
681 {
682 if (dynamic_cast<PngReader*>(fGetter)==0)
683 {
684 delete fGetter;
685 fGetter=new PngReader(*this);
686 }
687 }
688 else
689 {
690 const Int_t ch = fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
691 if (dynamic_cast<Camera*>(fGetter)==0)
692 {
693 delete fGetter;
694 fGetter = new Camera(*this, ch);
695 }
696 else
697 fGetter->SetChannel(ch);
698 }
699}
700
701void MStarguider::Toggle(TGPopupMenu *p, UInt_t id)
702{
703 if (p->IsEntryChecked(id))
704 p->UnCheckEntry(id);
705 else
706 p->CheckEntry(id);
707}
708
709void MStarguider::ToggleStargAnalysis()
710{
711 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
712 fStargHistograms->OpenFile();
713 else
714 fStargHistograms->CloseFile();
715}
716
717void MStarguider::ToggleFindStar()
718{
719 if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
720 fTPoint->MapWindow();
721 else
722 {
723 fTPoint->UnmapWindow();
724 fTPoint->SetDown(kFALSE);
725 }
726}
727
728void MStarguider::ToggleStarguider()
729{
730 if (fDisplay->IsEntryChecked(IDM_kStarguider))
731 {
732 fLastBright = 0xff;
733
734 fChannel->EnableEntry(IDM_kChannel1);
735 fDisplay->DisableEntry(IDM_kFindStar);
736 fDisplay->DisableEntry(IDM_kCaosFilter);
737 fOperations->EnableEntry(IDM_kStargAnalysis);
738
739 fStargTPoint->MapWindow();
740
741 fPZdAz->MapWindow();
742 fDZdAz->MapWindow();
743 fSkyBright->MapWindow();
744
745 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
746 fLimMag->UnCheckEntry(i);
747 fLimMag->CheckEntry(IDM_kLimMag9);
748 fSao->SetLimitMag(9.0);
749
750 for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++)
751 fInterpol->UnCheckEntry(i);
752 fInterpol->CheckEntry(IDM_kInterpol125);
753 fIntRate = 125;
754
755 //catalog
756 fDisplay->CheckEntry(IDM_kCatalog);
757 fCRaDec->MapWindow();
758 fCZdAz->MapWindow();
759 fCZdAzText->MapWindow();
760
761 fPZdAz->MapWindow();
762 fPZdAzText->MapWindow();
763 fDZdAz->MapWindow();
764 fDZdAzText->MapWindow();
765
766 fGStarg->MapWindow();
767 fGNumStars->MapWindow();
768
769 SwitchOff(fChannel, IDM_kChannel2);
770 fChannel->CheckEntry(IDM_kChannel1);
771
772 }
773 else
774 {
775 fStatus = MDriveCom::kStandby;
776
777 fStargTPoint->UnmapWindow();
778 fStargTPoint->SetDown(kFALSE);
779
780 fPZdAz->UnmapWindow();
781 fPZdAzText->UnmapWindow();
782 fDZdAz->UnmapWindow();
783 fDZdAzText->UnmapWindow();
784 fSkyBright->UnmapWindow();
785 //catalog
786 fCRaDec->UnmapWindow();
787 fCZdAz->UnmapWindow();
788 fCZdAzText->UnmapWindow();
789 fDisplay->UnCheckEntry(IDM_kCatalog);
790
791 fGStarg->UnmapWindow();
792 fGNumStars->UnmapWindow();
793
794 fChannel->EnableEntry(IDM_kChannel2);
795 fDisplay->EnableEntry(IDM_kFindStar);
796 fDisplay->EnableEntry(IDM_kCaosFilter);
797 fOperations->DisableEntry(IDM_kStargAnalysis);
798 }
799
800 SetChannel();
801 //gSystem->Unlink("tracking_error.txt");
802}
803
804void MStarguider::ToggleCaosFilter()
805{
806 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
807 {
808 if (!fMode->IsEntryChecked(IDM_kStarguiderMode)
809 && !fMode->IsEntryChecked(IDM_kTpointMode))
810 fMenu->AddPopup("&CaOs", fCaOs, NULL);
811
812 SwitchOff(fDisplay, IDM_kStarguider);
813 SwitchOff(fDisplay, IDM_kStargCaosFilter);
814 fDisplay->DisableEntry(IDM_kStargFindStar);
815 }
816 else
817 {
818 fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
819 fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
820
821 if (fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
822 {
823 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
824 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
825 fCaos->DeleteHistograms();
826 }
827 if (fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
828 {
829 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
830 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
831 fCaos->CloseFile();
832 }
833 fMenu->RemovePopup("CaOs");
834
835 fDisplay->EnableEntry(IDM_kStargCaosFilter);
836 fDisplay->EnableEntry(IDM_kStarguider);
837 }
838 fMenu->Resize(fMenu->GetDefaultSize());
839 MapSubwindows(); // maps everything, but we don't want that
840 fTPoint->UnmapWindow();
841 fStargTPoint->UnmapWindow();
842 fGStarg->UnmapWindow();
843 fGNumStars->UnmapWindow();
844 fCRaDec->UnmapWindow();
845 fCZdAz->UnmapWindow();
846 fCZdAzText->UnmapWindow();
847 fPZdAz->UnmapWindow();
848 fPZdAzText->UnmapWindow();
849 fDZdAz->UnmapWindow();
850 fDZdAzText->UnmapWindow();
851 fSZdAz->UnmapWindow();
852 fSkyBright->UnmapWindow();
853 MapWindow();
854}
855
856Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
857{
858 switch (GET_MSG(msg))
859 {
860 case kC_TEXTENTRY:
861 if (GET_SUBMSG(msg)==kTE_ENTER)
862 switch (mp1)
863 {
864 case IDM_kPixSize:
865 {
866 const Float_t pixsize = atof(fPixSize->GetText());
867 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
868 fSao->SetPixSize(pixsize);
869 return kTRUE;
870 }
871 case IDM_kAngle:
872 {
873 const Float_t angle = atof(fAngle->GetText());
874 cout << "Rotation Angle changed to " << angle << "deg" << endl;
875 fSao->SetRotationAngle(angle);
876 return kTRUE;
877 }
878 case IDM_kCut:
879 {
880 const Float_t cut = atof(fCut->GetText());
881 cout << "Starguider cleaning level changed to " << cut << " sigma." << endl;
882 return kTRUE;
883 }
884 }
885 return kTRUE;
886
887 case kC_COMMAND:
888 switch (GET_SUBMSG(msg))
889 {
890 case kCM_MENU:
891 switch (mp1)
892 {
893 case IDM_kCatalog:
894 Toggle(fDisplay, IDM_kCatalog);
895 if (fDisplay->IsEntryChecked(IDM_kCatalog))
896 {
897 fCRaDec->MapWindow();
898 fCZdAz->MapWindow();
899 fCZdAzText->MapWindow();
900 }
901 else
902 {
903 fCRaDec->UnmapWindow();
904 fCZdAz->UnmapWindow();
905 fCZdAzText->UnmapWindow();
906 }
907 return kTRUE;
908
909 case IDM_kRoqueLampAna:
910 Toggle(fOperations, IDM_kRoqueLampAna);
911 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
912 fDisplay->CheckEntry(IDM_kStargCaosFilter);
913 else
914 fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
915
916 return kTRUE;
917
918 case IDM_kStargFindStar:
919 Toggle(fDisplay, IDM_kStargFindStar);
920 if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
921 fSZdAz->MapWindow();
922 else
923 fSZdAz->UnmapWindow();
924 return kTRUE;
925
926 case IDM_kStarguider:
927 Toggle(fDisplay, IDM_kStarguider);
928 ToggleStarguider();
929 return kTRUE;
930
931 case IDM_kStargAnalysis:
932 Toggle(fOperations, IDM_kStargAnalysis);
933 ToggleStargAnalysis();
934 return kTRUE;
935
936 case IDM_kStarguiderMode:
937 Toggle(fMode, IDM_kStarguiderMode);
938
939 if (fMode->IsEntryChecked(IDM_kStarguiderMode))
940 {
941 //uncheck not needed items
942 //general
943 fDisplay->UnCheckEntry(IDM_kStargFindStar);
944 SwitchOff(fDisplay, IDM_kFilter);
945 SwitchOff(fChannel, IDM_kChannel3);
946 SwitchOff(fOperations, IDM_kRoqueLampAna);
947 SwitchOff(fOperations, IDM_kStargAnalysis);
948
949 //tpoint
950 SwitchOff(fDisplay, IDM_kFindStar);
951 ToggleFindStar();
952 SwitchOff(fDisplay, IDM_kCaosFilter);
953 ToggleCaosFilter();
954 fMode->UnCheckEntry(IDM_kTpointMode);
955
956 //enable starguider items
957 fDisplay->EnableEntry(IDM_kStargCaosFilter);
958 fDisplay->EnableEntry(IDM_kStarguider);
959 fDisplay->EnableEntry(IDM_kCatalog);
960
961 //check needed items
962 fDisplay->CheckEntry(IDM_kStretch);
963 fDisplay->CheckEntry(IDM_kStargCaosFilter);
964 fDisplay->CheckEntry(IDM_kStarguider);
965 ToggleStarguider();
966 }
967 else
968 {
969 //uncheck
970 //starguider items
971 fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
972 fDisplay->UnCheckEntry(IDM_kStarguider);
973 ToggleStarguider();
974
975 //general
976 fDisplay->UnCheckEntry(IDM_kCatalog);
977 fDisplay->EnableEntry(IDM_kFilter);
978 fDisplay->EnableEntry(IDM_kCaosFilter);
979 fDisplay->EnableEntry(IDM_kFindStar);
980 fChannel->EnableEntry(IDM_kChannel3);
981 fOperations->EnableEntry(IDM_kRoqueLampAna);
982 }
983 return kTRUE;
984
985 case IDM_kTpointMode:
986 Toggle(fMode, IDM_kTpointMode);
987
988 if (fMode->IsEntryChecked(IDM_kTpointMode))
989 {
990 //unchecking not needed items
991 //general
992 fDisplay->UnCheckEntry(IDM_kStargFindStar);
993 SwitchOff(fDisplay, IDM_kFilter);
994 SwitchOff(fChannel, IDM_kChannel3);
995 SwitchOff(fOperations, IDM_kRoqueLampAna);
996
997 //from starguider
998 SwitchOff(fDisplay, IDM_kStargCaosFilter);
999 SwitchOff(fDisplay, IDM_kCatalog);
1000 SwitchOff(fDisplay, IDM_kStarguider);
1001 ToggleStarguider();
1002 fMode->UnCheckEntry(IDM_kStarguiderMode);
1003 SwitchOff(fOperations, IDM_kStargAnalysis);
1004 ToggleStargAnalysis();
1005
1006 //switch camera
1007 SwitchOff(fChannel, IDM_kChannel1);
1008 fChannel->CheckEntry(IDM_kChannel2);
1009
1010 SetChannel();
1011
1012 //checking needed items
1013 fDisplay->CheckEntry(IDM_kStretch);
1014 fDisplay->CheckEntry(IDM_kCaosFilter);
1015 ToggleCaosFilter();
1016 fDisplay->CheckEntry(IDM_kFindStar);
1017 ToggleFindStar();
1018 }
1019 else
1020 {
1021 //enable
1022 //starguider items
1023 fDisplay->EnableEntry(IDM_kStargCaosFilter);
1024 fDisplay->EnableEntry(IDM_kCatalog);
1025 fDisplay->EnableEntry(IDM_kStarguider);
1026 fOperations->EnableEntry(IDM_kStargAnalysis);
1027
1028 //general
1029 fDisplay->EnableEntry(IDM_kFilter);
1030 fChannel->EnableEntry(IDM_kChannel1);
1031 fChannel->EnableEntry(IDM_kChannel3);
1032 fOperations->EnableEntry(IDM_kRoqueLampAna);
1033
1034 //tpoint
1035 fDisplay->UnCheckEntry(IDM_kCaosFilter);
1036 ToggleCaosFilter();
1037 fDisplay->UnCheckEntry(IDM_kFindStar);
1038 ToggleFindStar();
1039 }
1040 return kTRUE;
1041
1042 case IDM_kFilter:
1043 Toggle(fDisplay, IDM_kFilter);
1044 return kTRUE;
1045
1046 case IDM_kFindStar:
1047 Toggle(fDisplay, IDM_kFindStar);
1048 ToggleFindStar();
1049 return kTRUE;
1050
1051 case IDM_kStretch:
1052 Toggle(fDisplay, IDM_kStretch);
1053 return kTRUE;
1054
1055 case IDM_kCaosFilter:
1056 Toggle(fDisplay, IDM_kCaosFilter);
1057 ToggleCaosFilter();
1058 return kTRUE;
1059
1060 case IDM_kStargCaosFilter:
1061 Toggle(fDisplay, IDM_kStargCaosFilter);
1062 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
1063 {
1064 fDisplay->EnableEntry(IDM_kStargFindStar);
1065 SwitchOff(fDisplay, IDM_kCaosFilter);
1066 SwitchOff(fDisplay, IDM_kFindStar);
1067 SwitchOff(fDisplay, IDM_kFilter);
1068 }
1069 else
1070 {
1071 fDisplay->EnableEntry(IDM_kFilter);
1072 fDisplay->EnableEntry(IDM_kFindStar);
1073 fDisplay->EnableEntry(IDM_kCaosFilter);
1074 fDisplay->DisableEntry(IDM_kStargFindStar);
1075 }
1076 return kTRUE;
1077
1078 case IDM_kCaosPrintLeds:
1079 case IDM_kCaosPrintRings:
1080 Toggle(fCaosPrint, mp1);
1081 return kTRUE;
1082
1083 case IDM_kCaosAnalStart:
1084 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStart);
1085 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStop);
1086 fCaos->InitHistograms();
1087 return kTRUE;
1088
1089 case IDM_kCaosAnalStop:
1090 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
1091 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
1092 fCaos->ShowHistograms();
1093 fCaos->DeleteHistograms();
1094 return kTRUE;
1095
1096 case IDM_kCaosWriteStart:
1097 fCaosWrite->DisableEntry(IDM_kCaosWriteStart);
1098 fCaosWrite->EnableEntry(IDM_kCaosWriteStop);
1099 fCaos->OpenFile();
1100 return kTRUE;
1101
1102 case IDM_kCaosWriteStop:
1103 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
1104 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
1105 fCaos->CloseFile();
1106 return kTRUE;
1107
1108 case IDM_kStart:
1109 fWritePictures->DisableEntry(IDM_kStart);
1110 fWritePictures->EnableEntry(IDM_kStop);
1111 return kTRUE;
1112
1113 case IDM_kStop:
1114 fWritePictures->DisableEntry(IDM_kStop);
1115 fWritePictures->EnableEntry(IDM_kStart);
1116 return kTRUE;
1117
1118 case IDM_kPNG:
1119 fFileType->CheckEntry(IDM_kPNG);
1120 fFileType->UnCheckEntry(IDM_kPPM);
1121 return kTRUE;
1122
1123 case IDM_kPPM:
1124 fFileType->CheckEntry(IDM_kPPM);
1125 fFileType->UnCheckEntry(IDM_kPNG);
1126 return kTRUE;
1127
1128 case IDM_kOnce:
1129 fWriteType->CheckEntry(IDM_kOnce);
1130 fWriteType->UnCheckEntry(IDM_kContinous);
1131 return kTRUE;
1132
1133 case IDM_kContinous:
1134 fWriteType->CheckEntry(IDM_kContinous);
1135 fWriteType->UnCheckEntry(IDM_kOnce);
1136 return kTRUE;
1137
1138 case IDM_kRate25ps:
1139 case IDM_kRate5ps:
1140 case IDM_kRate1s:
1141 case IDM_kRate5s:
1142 case IDM_kRate30s:
1143 case IDM_kRate1m:
1144 case IDM_kRate5m:
1145 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
1146 if (mp1==i)
1147 fWriteRate->CheckEntry(i);
1148 else
1149 fWriteRate->UnCheckEntry(i);
1150 switch (mp1)
1151 {
1152 case IDM_kRate25ps:
1153 fWrtRate = 1;
1154 return kTRUE;
1155 case IDM_kRate5ps:
1156 fWrtRate = 5;
1157 return kTRUE;
1158 case IDM_kRate1s:
1159 fWrtRate = 25;
1160 return kTRUE;
1161 case IDM_kRate5s:
1162 fWrtRate = 5*25;
1163 return kTRUE;
1164 case IDM_kRate30s:
1165 fWrtRate = 30*25;
1166 return kTRUE;
1167 case IDM_kRate1m:
1168 fWrtRate = 60*25;
1169 return kTRUE;
1170 case IDM_kRate5m:
1171 fWrtRate = 5*60*25;
1172 return kTRUE;
1173 }
1174 return kTRUE;
1175
1176 case IDM_kChannel1:
1177 case IDM_kChannel2:
1178 {
1179 const Int_t ch0 = fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
1180 const Int_t ch1 = mp1==IDM_kChannel1 ? 0 : 1;
1181
1182 if (ch0==ch1)
1183 return kTRUE;
1184
1185 fChannel->CheckEntry (ch1==0?IDM_kChannel1:IDM_kChannel2);
1186 fChannel->UnCheckEntry(ch1==1?IDM_kChannel1:IDM_kChannel2);
1187
1188 SetChannel();
1189 }
1190 return kTRUE;
1191
1192 case IDM_kInterpol250:
1193 case IDM_kInterpol125:
1194 case IDM_kInterpol50:
1195 case IDM_kInterpol25:
1196 case IDM_kInterpol10:
1197 case IDM_kInterpol5:
1198 case IDM_kInterpol2:
1199 case IDM_kInterpol1:
1200 for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++)
1201 if (mp1==i)
1202 fInterpol->CheckEntry(i);
1203 else
1204 fInterpol->UnCheckEntry(i);
1205 switch (mp1)
1206 {
1207 case IDM_kInterpol1:
1208 fIntRate = 1;
1209 return kTRUE;
1210 case IDM_kInterpol2:
1211 fIntRate = 2;
1212 return kTRUE;
1213 case IDM_kInterpol5:
1214 fIntRate = 5;
1215 return kTRUE;
1216 case IDM_kInterpol10:
1217 fIntRate = 10;
1218 return kTRUE;
1219 case IDM_kInterpol25:
1220 fIntRate = 25;
1221 return kTRUE;
1222 case IDM_kInterpol50:
1223 fIntRate = 50;
1224 return kTRUE;
1225 case IDM_kInterpol125:
1226 fIntRate = 125;
1227 return kTRUE;
1228 case IDM_kInterpol250:
1229 fIntRate = 250;
1230 return kTRUE;
1231 }
1232 return kTRUE;
1233
1234 case IDM_kLimMag3:
1235 case IDM_kLimMag4:
1236 case IDM_kLimMag5:
1237 case IDM_kLimMag6:
1238 case IDM_kLimMag7:
1239 case IDM_kLimMag8:
1240 case IDM_kLimMag9:
1241 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
1242 if (mp1==i)
1243 fLimMag->CheckEntry(i);
1244 else
1245 fLimMag->UnCheckEntry(i);
1246
1247 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
1248 return kTRUE;
1249 }
1250 break;
1251 }
1252 break;
1253 }
1254
1255 return kTRUE;
1256}
1257
1258void MStarguider::SetPointingPosition(RaDec rd)
1259{
1260 rd.Ra(rd.Ra()*24/360);
1261 fCRaDec->SetCoordinates(rd);
1262}
1263
1264ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag,
1265 Int_t &num) const
1266{
1267 num = -1;
1268
1269 // Width of the final 2D gaussian
1270 const Double_t width = 0.8;
1271
1272 // The binning is made 1.7 sigma (which, in the 1D case, gives the
1273 // highest significance of a gaussian signal) (1bin equiv 3x3 sigma)
1274 const Double_t max = 50;
1275 const Int_t n = TMath::Nint(2*max/(1.77*1.7*width));
1276 //1.77=sqrt(pi) comes from pir=bin
1277
1278 // Fill a histogram with the dx/dy values from the file
1279 TH2F hist("Hist", "dX/dY", n, -max, max, n, -max, max);
1280// hist.SetDirectory(0);
1281
1282 //
1283 // Search for matching Magnitudes
1284 //
1285 //for (int i=0; i<mag.GetSize(); i++)
1286 //{
1287 // if (mag[i]>48-15 && mag[i]<48+15)
1288 // h.Fill(x[i], y[i]);
1289 //}
1290
1291 // fill dx and dy into histogram
1292 for (int i=0; i<mag.GetSize(); i++)
1293 hist.Fill(x[i], y[i]);
1294
1295 // Remove all bins which have content of only a single event
1296 // including under- and overflow bins
1297 for (int i=0; i<hist.GetSize(); i++)
1298 if (hist.GetBinContent(i)<1.5)
1299 hist.SetBinContent(i, 0);
1300
1301 // Find the bin containing the maximum
1302 Int_t bx, by, bz;
1303 hist.GetMaximumBin(bx, by, bz);
1304
1305 // In the worst case the events are spread through the
1306 // bins which are the neighbors of the maximum
1307 // Normally neighbors which do not belong to the signal are empty!
1308 hist.GetXaxis()->SetRange(bx-1, bx+1); // 3x3bins ~8x8pix ~9x9sigma
1309 hist.GetYaxis()->SetRange(by-1, by+1); // 3x3bins ~8x8pix ~9x9sigma
1310
1311 // Check whether this region contains events
1312 num = TMath::Nint(hist.Integral());
1313 if (num<1)
1314 return ZdAz();
1315
1316 // Get Mean for the given axis range
1317 Double_t mx = hist.GetMean(1);
1318 Double_t my = hist.GetMean(2);
1319
1320 const Int_t max1 = TMath::Nint(hist.GetBinContent(bx, by));
1321
1322 // Check if the maximum is unique
1323 Int_t bx2, by2, bz2;
1324 hist.GetXaxis()->SetRange(-1, 9999);
1325 hist.GetYaxis()->SetRange(-1, 9999);
1326 hist.SetBinContent(bx, by, 0);
1327 hist.GetMaximumBin(bx2, by2, bz2);
1328
1329 const Int_t max2 = TMath::Nint(hist.GetBinContent(bx2, by2));
1330 if (max1==max2 && TMath::Abs(bx2-bx)+TMath::Abs(by2-by)>1)
1331 return ZdAz();
1332
1333 // loop again over the file and fill the histogram again.
1334 // to get closer to the correct value
1335 Double_t sumx = 0;
1336 Double_t sumy = 0;
1337 num = 0;
1338 for (int i=0; i<mag.GetSize(); i++)
1339 {
1340 // only fill values into the histogram which
1341 // are inside 2*1.7=3.4 sigma (99.7%)
1342 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*3.4)
1343 continue;
1344
1345 sumx += x[i];
1346 sumy += y[i];
1347 num++;
1348 }
1349
1350 if (num<1)
1351 return ZdAz();
1352
1353 // calc MeanX and MeanY
1354 mx = sumx/num;
1355 my = sumy/num;
1356
1357 // loop again to fill the mispointing corrected histograms
1358 // and fill another histogram to check the quality of the calculated
1359 // mispointing.
1360 sumx = 0;
1361 sumy = 0;
1362 num = 0;
1363 for (int i=0; i<mag.GetSize(); i++)
1364 {
1365 // only fill values into the histogram which
1366 // are inside 1.7=3.4 sigma (92%)
1367 // Cut at 1.7 sigma which gives the best background supression
1368 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*1.7)
1369 continue;
1370
1371 sumx += x[i];
1372 sumy += y[i];
1373 num++;
1374 }
1375
1376 if (num<1)
1377 return ZdAz(); // FIXME!!!!!!!!!!!!
1378
1379 // Mispointing
1380 mx = sumx/num;
1381 my = sumy/num;
1382
1383#ifdef EXPERT
1384 cout << "Offset-XY: " << mx << " +- " << my << endl;
1385#endif
1386
1387 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg;
1388 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg;
1389/*
1390 ofstream fout1("pointingpos.txt");
1391 fout1 << setprecision(10) << fSao->GetMjd()-52000 << " ";
1392 if (fCosy)
1393 fout1 << fCosy->GetPointingPos() << " ";
1394 fout1 << -pos1.Alt() << " " << pos1.Az() << endl;
1395 */
1396 pos1 -= pos0;
1397/*
1398 ofstream fout2("tracking_error.txt", ios::app);
1399 fout2 << setprecision(10) << fSao->GetMjd()-52000 << " ";
1400 if (fCosy)
1401 fout2 << fCosy->GetPointingPos() << " ";
1402 fout2 << -pos1.Alt() << " " << pos1.Az() << endl;
1403 */
1404 return ZdAz(-pos1.Alt(), pos1.Az());
1405}
1406
1407Int_t MStarguider::CalcTrackingError(Leds &leds, MStarList &stars,
1408 ZdAz &d, MTime &t, double &bright, Int_t &num)
1409{
1410 num = leds.GetEntries();
1411 //cout << "Num: " << num << endl;
1412 if (num < 3) //was 1
1413 {
1414 cout << "Sorry, less than 3 detected spot in FOV!" << endl;
1415 if (fStargTPoint->IsDown())
1416 fStargTPoint->SetDown(kFALSE);
1417 return 0;
1418 }
1419
1420 //cout << "Cat: " << stars.GetRealEntries() << endl;
1421 if (stars.GetRealEntries() < 3)
1422 {
1423 cout << "Sorry, less than 3 stars in FOV!" << endl;
1424 if (fStargTPoint->IsDown())
1425 fStargTPoint->SetDown(kFALSE);
1426 return 0;
1427 }
1428
1429 stars.Sort(); // Sort by magnitude
1430
1431#ifdef EXPERT
1432 TString str = "data/tracking_";
1433 str += fSao->GetMjd();
1434 str += ".txt";
1435
1436 ofstream fout(str);
1437#endif
1438
1439 TArrayF x, y, mag;
1440
1441 // FIXME: Is predefined value 3 a good idea?
1442 Int_t cnt=0;
1443
1444 MStar *star;
1445 MStarListIter NextStar(&stars);
1446 while ((star=NextStar()) && cnt<num+5)
1447 {
1448 TIter NextSp(&leds);
1449 Led *spot=NULL;
1450 while ((spot=(Led*)NextSp()))
1451 {
1452 const XY dpos(spot->GetX()-(768-star->GetX()),
1453 spot->GetY()-star->GetY());
1454
1455 const Int_t idx = x.GetSize();
1456
1457 x.Set(idx+1);
1458 y.Set(idx+1);
1459 mag.Set(idx+1);
1460
1461 x.AddAt(dpos.X(), idx);
1462 y.AddAt(dpos.Y(), idx);
1463 mag.AddAt(log(spot->GetMag())/star->GetMag(), idx);
1464
1465#ifdef EXPERT
1466 if (fout)
1467 {
1468 fout << spot->GetX() << " "
1469 << spot->GetY() << " "
1470 << -2.5*log(spot->GetMag()) << " "
1471 << star->GetX() << " "
1472 << star->GetY() << " "
1473 << star->GetMag() << " ";
1474 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
1475 }
1476#endif
1477 }
1478 cnt++;
1479 }
1480
1481 Int_t numcor = 0;
1482 d = TrackingError(x, y, mag, numcor);
1483 if (numcor<1)
1484 return 0;
1485
1486 //cout << "Cor: " << numcor << endl;
1487
1488 fDZdAz->SetCoordinates(d);
1489
1490 //
1491 // Calculated offsets
1492 //
1493
1494#ifdef EXPERT
1495 // round= floor(x+.5)
1496 cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
1497 cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
1498#endif
1499
1500 //
1501 // Current Pointing position
1502 //
1503 ZdAz cpos = fSao->GetZdAz()-d;
1504 fPZdAz->SetCoordinates(cpos);
1505
1506 // Check StargTPoint data set request
1507 if (!fStargTPoint->IsDown())
1508 return numcor;
1509 fStargTPoint->SetDown(kFALSE);
1510
1511 // If no file open: open new file
1512 if (!fOutStargTp)
1513 {
1514 // open tpoint file
1515 const TString name = MCosy::GetFileName("tpoint", "starg", "txt");
1516 cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
1517
1518 fOutStargTp = new ofstream(name);
1519 *fOutStargTp << "Magic Model STARGTPOINT data file" << endl;
1520 *fOutStargTp << ": ALTAZ" << endl;
1521 *fOutStargTp << "49 48 0 ";
1522 *fOutStargTp << t << endl;
1523 }
1524
1525 // Get tracking coordinates
1526 const XY xy = fCRaDec->GetCoordinates();
1527 const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
1528
1529 // From the star position in the camera we calculate the Alt/Az
1530 // position we are currently tracking (real pointing position)
1531 fSao->SetMjd(t.GetMjd());
1532 AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
1533
1534 //correction with offset from last tpoint measurement
1535 za0 -= fAltAzOffsetFromTp;
1536 MTime t2 = fTimeFromTp;
1537
1538 //if the difference between the tpoint and the starguider tpoint
1539 //is too big, the starguider tpoint is not stored
1540 cout << " mjd difference: " << t.GetMjd()-t2.GetMjd() << endl;
1541// cout << "t: " << setprecision(11) << t.GetMjd() << endl;
1542// cout << "t2: " << setprecision(11) << t2.GetMjd() << endl;
1543 if ((t.GetMjd()-t2.GetMjd())>0.001) //1min20sec
1544 {
1545 cout << " time difference between tpoint and starguider-tpoint > 1 min *" <<
1546 t.GetMjd()-t2.GetMjd() << "s) " << endl;
1547 cout << " => starguider tpoint hasn't been stored. " << endl;
1548 cout << " Please repeat whole procedure. " << endl;
1549 return numcor;
1550 }
1551
1552
1553 // Write real pointing position
1554 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
1555 *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
1556
1557 // Write system pointing position
1558 cout << " SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
1559 *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd();
1560
1561 *fOutStargTp << " " << xy.X() << " " << xy.Y();
1562 *fOutStargTp << " " << d.Zd() << " " << d.Az();
1563 *fOutStargTp << " " << setprecision(11) << t.GetMjd();
1564 *fOutStargTp << " " << num;
1565 *fOutStargTp << " " << bright;
1566 *fOutStargTp << endl;
1567
1568 fTimeFromTp.Set(1970,1,1);
1569
1570 return numcor;
1571}
1572
1573XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Int_t box, XY SearchCenter)
1574{
1575 // Set search Paremeters (FIXME: Get them from user input!)
1576 f.SetCut(cut); // 3.5
1577 f.SetBox(box); // 70
1578
1579 // Try to find Led in this area
1580 Leds leds;
1581 f.FindStar(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y(), true);
1582
1583 // Check whether star found
1584 Led *star = (Led*)leds.At(0);
1585 if (!star || leds.GetEntries()<1)
1586 return XY(.0,.0);
1587
1588// cout << "Found Roque Lamp @ " << flush;
1589 star->Print();
1590 f.MarkPoint(star->GetX(), star->GetY(), 500);
1591
1592// cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl;
1593
1594 XY roquepos(star->GetX(), star->GetY());
1595 XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY());
1596
1597 // If no file open: open new Roque Lamp file
1598 if (!fOutRq)
1599 {
1600 const TString name = MCosy::GetFileName("tpoint", "roquelamp", "txt");
1601 cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl;
1602 fOutRq = new ofstream(name);
1603 *fOutRq << "# Magic Roque Lamp file " << t << endl;
1604 }
1605
1606 return relroquepos;
1607}
1608
1609ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Int_t box, Double_t scalefactor = 1.0)
1610{
1611 // Set search Paremeters (FIXME: Get them from user input!)
1612 f.SetCut(cut); // 3.5
1613 f.SetBox(box); // 70
1614
1615 // Try to find Led in this area
1616 Leds leds;
1617 f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true);
1618
1619 if (leds.GetEntries()<0)
1620 return ZdAz(0, 0);
1621
1622 // Check whether star found
1623 Led *star = (Led*)leds.At(0);
1624 if (!star)
1625 {
1626 if (fTPoint->IsDown())
1627 {
1628 fTPoint->SetDown(kFALSE);
1629 cout << "No star found. Couldn't take a tpoint." << endl;
1630 }
1631 return ZdAz(.0,.0);
1632 }
1633 cout << "Found star @ " << flush;
1634 star->Print();
1635 f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
1636
1637 // Initialize Star Catalog on th camera plane
1638 MGeomCamMagic geom;
1639 MAstroCamera ac;
1640 ac.SetGeom(geom);
1641 ac.SetRadiusFOV(3);
1642 ac.SetObservatory(*fSao);
1643 ac.SetTime(t);
1644
1645 // Get tracking coordinates
1646 const XY xy = fCRaDec->GetCoordinates();
1647 const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
1648
1649 ac.SetRaDec(rd.Ra(), rd.Dec());
1650
1651 // Adapt coordinate system (GUIs and humans are counting Y in different directions)
1652 Double_t x = star->GetX()-center.GetX();
1653 Double_t y = center.GetY()-star->GetY();
1654
1655#ifdef EXPERT
1656 cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix dy=" << y << "pix" << endl;
1657#endif
1658
1659 // MAKE SURE THAT THIS VALUE CAN BE SETUP
1660 // (Scalefactor describes the difference between the tpoint (=1)
1661 // and the starguider (!=1) camera
1662 // Convert from Pixel to millimeter (1pix=2.6mm)
1663 x *= (2.58427 * scalefactor);
1664 y *= (2.58427 * scalefactor);
1665
1666 // Correct for abberation.
1667 x /= 1.0713;
1668 y /= 1.0713;
1669
1670 // Convert offset from camera plane into local ccordinates
1671 Double_t dzd, daz;
1672 ac.GetDiffZdAz(x, y, dzd, daz);
1673
1674#ifdef EXPERT
1675 cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d dAz=" << daz << "d" << endl;
1676#endif
1677
1678 ZdAz zdaz(dzd,daz);
1679
1680 // Check TPoint data set request
1681 if (!fTPoint->IsDown())
1682 return zdaz;
1683 fTPoint->SetDown(kFALSE);
1684
1685 // If no file open: open new file
1686 if (!fOutTp)
1687 {
1688 //
1689 // open tpoint file
1690 //
1691 const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt");
1692 cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
1693
1694 fOutTp = new ofstream(name);
1695 *fOutTp << "Magic Model TPOINT data file" << endl;
1696 *fOutTp << ": ALTAZ" << endl;
1697 *fOutTp << "49 48 0 ";
1698 *fOutTp << t << endl;
1699 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
1700 }
1701
1702 // Output Ra/Dec the drive system thinks that it is currently tracking
1703 cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
1704
1705 // From the star position in the camera we calculate the Alt/Az
1706 // position we are currently tracking (real pointing position)
1707 fSao->SetMjd(t.GetMjd());
1708 AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
1709
1710 //ZdAz za0 = fSao->GetZdAz();
1711 za0 -= AltAz(-dzd, daz);
1712 fAltAzOffsetFromTp = AltAz(-dzd, daz);
1713 fTimeFromTp=t;
1714
1715
1716 // From the Shaftencoders we get the current 'pointing' position
1717 // as it is seen by the drive system (system pointing position)
1718 const ZdAz za1 = fCosy->GetTrackingPosRaw();
1719
1720 // Write real pointing position
1721 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
1722 *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
1723
1724 // Write system pointing position
1725 cout << " SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
1726 *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
1727
1728 *fOutTp << " " << xy.X() << " " << xy.Y();
1729 *fOutTp << " " << -dzd << " " << -daz;
1730 *fOutTp << " " << setprecision(11) << t.GetMjd();
1731 *fOutTp << " " << setprecision(4) << center.GetMag();
1732 *fOutTp << " " << star->GetMag();
1733 *fOutTp << endl;
1734
1735 MLog &outrep = *fCosy->GetOutRep();
1736 if (outrep.Lock("MStarguider::FindStar"))
1737 {
1738 outrep << "FINDSTAR-REPORT 00 " << MTime(-1) << " " << setprecision(7);
1739 outrep << 90-za0.Alt() << " " << za0.Az() << " ";
1740 outrep << za1.Zd() << " " << za1.Az() << " ";
1741 outrep << xy.X() << " " << xy.Y() << " ";
1742 outrep << -dzd << " " << -daz << " ";
1743 outrep << star->GetX() << " " << star->GetY() << " ";
1744 outrep << center.GetX() << " " << center.GetY() << " ";
1745 outrep << x*1.0713/2.58427 << " " << y*1.0713/2.58427 << " " << star->GetMag();
1746 outrep << setprecision(11) << t.GetMjd() << endl;
1747 outrep.UnLock("MStarguider::FindStar");
1748 }
1749
1750 return zdaz;
1751}
1752
1753bool MStarguider::Interpolate(const unsigned long n, byte *img) const
1754{
1755 if (fIntRate<=1)
1756 return true;
1757
1758 static unsigned short myimg[768*576];
1759
1760 unsigned short *f = myimg;
1761 byte *i = img;
1762 byte *e = img+768*576;
1763
1764 while (i<e)
1765 *f++ += *i++;
1766
1767 if (n%fIntRate)
1768 return false;
1769
1770 f = myimg;
1771 i = img;
1772 e = img+768*576;
1773
1774 while (i<e)
1775 *i++ = (byte)(*f++/fIntRate);
1776
1777 memset(myimg, 0, sizeof(myimg));
1778
1779 return true;
1780}
1781
1782void MStarguider::ProcessFrame(const unsigned long n, byte *img,
1783 struct timeval *tm)
1784{
1785 static unsigned long n0 = n;
1786
1787 MTime t(*tm);
1788
1789 const Double_t d = t-fTime;
1790 if (d>1)
1791 {
1792 MString txt;
1793 txt.Print("%dfps", (int)((n-n0)/d+.5));
1794 fFps->SetText(txt);
1795 fTime = t;
1796 n0 = n;
1797 }
1798
1799 if (!Interpolate(n, img))
1800 return;
1801
1802 byte cimg[768*576];
1803 memset(cimg, 0, 768*576);
1804
1805 FilterLed f(img, 768, 576, 2.5); // 2.5
1806 FilterLed f2(cimg, 768, 576); // former color 0xb0
1807
1808 if (fDisplay->IsEntryChecked(IDM_kStretch))
1809 f.Stretch();
1810
1811 if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
1812 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
1813 {
1814
1815 if (fFileType->IsEntryChecked(IDM_kPNG))
1816 Writer::Png("pix/file", img, tm, fCRaDec->GetCoordinates());
1817
1818 if (fFileType->IsEntryChecked(IDM_kPPM))
1819 Writer::Ppm("pix/file", img, tm, fCRaDec->GetCoordinates());
1820
1821 if (fWriteType->IsEntryChecked(IDM_kOnce))
1822 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
1823 }
1824
1825 // Visual Filter, whole FOV
1826 if (fDisplay->IsEntryChecked(IDM_kFilter))
1827 f.Execute();
1828
1829 // Find Center of Camera for Caos and Tpoints
1830 Ring center(768/2, 576/2);
1831 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
1832 {
1833 const bool printl = fCaosPrint->IsEntryChecked(IDM_kCaosPrintLeds);
1834 const bool printr = fCaosPrint->IsEntryChecked(IDM_kCaosPrintRings);
1835 ZdAz pos;
1836 if (fCosy)
1837 pos = fCosy->GetPointingPos();
1838 center = fCaos->Run(img, printl, printr, pos, t, 19, 3.0);
1839 cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << endl;
1840
1841 }
1842
1843 // Find Star at Center---for Tpoint Procedure
1844 if (fDisplay->IsEntryChecked(IDM_kFindStar) &&
1845 center.GetX()>0 && center.GetY()>0)
1846 {
1847 // SCALE FACTOR ASSUMED TO BE 70
1848 FindStar(f, f2, center, t, 3/*3.5*/, 70);
1849 SendAmcTrigger("TPoint");
1850 }
1851
1852 byte zimg[kZOOM*kZOOM];
1853 for (int y=0; y<kZOOM; y++)
1854 for (int x=0; x<kZOOM; x++)
1855 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
1856
1857 fZoomImage->DrawImg(zimg);
1858
1859 if (fCosy)
1860 {
1861 byte simg[(768/2-1)*(576/2-1)];
1862 for (int y=0; y<576/2-1; y++)
1863 for (int x=0; x<768/2-1; x++)
1864 simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;
1865
1866 fCosy->GetWin()->GetImage()->DrawImg(simg);
1867 }
1868
1869 // Find Center of Camera in Starfield Camera picture
1870
1871 Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]
1872 //ZdAz sgcenterzdaz(0, 0); // Center of camera in SG picture [deg]
1873 // // (0,0)_deg is at (53.2, 293.6)_px
1874 ZdAz star(0, 0); // Star on curtain in [deg]
1875
1876 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
1877 {
1878 ZdAz pos;
1879 if (fCosy)
1880 pos = fCosy->GetPointingPos();
1881
1882 sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 19, 3.0); // [px]
1883
1884 //const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
1885
1886 // BE CAREFULL: This transformation is WRONG. It is just
1887 // a transformation of units, but this implies, that the
1888 // coordiante axis in both units look the same. This is
1889 // wrong exspecially near the zenith were az-lines are highly
1890 // curved around the zenith!
1891 //sgcenterzdaz.Zd((sgcenter.GetY()-293.6) * pixsize /3600 );
1892 //sgcenterzdaz.Az((sgcenter.GetX()-53.2) * pixsize /3600 );
1893#ifdef EXPERT
1894 cout << "- LEDs imply offset of Zd="
1895 << sgcenter.GetX()-53.2 << "pix Az="
1896 << sgcenter.GetY()-293.6<< "pix" << endl;
1897#endif
1898 if (fDisplay->IsEntryChecked(IDM_kStargFindStar) &&
1899 sgcenter.GetX()>0 && sgcenter.GetY()>0)
1900 {
1901 star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
1902#ifdef EXPERT
1903 cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az="
1904 << star.Az()*60 << "'" << endl;
1905#endif
1906 fSZdAz->SetCoordinates(star); // Mispointing found from Camera
1907
1908 SendAmcTrigger("Starguider");
1909 }
1910 }
1911
1912// Find Roque Lamp
1913
1914 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
1915 {
1916
1917 Double_t imageclean = 1.5;
1918 Int_t boxradius = 60;
1919 //Double_t scalefactor = 1;
1920 XY searchcenter(768/2-1,576/2+25);
1921
1922 XY roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
1923
1924 if (fOutRq)
1925 {
1926 ZdAz pos = fCosy->GetPointingPos();
1927
1928 *fOutRq << "RoqueLampDirect: " << MTime(-1) << " "
1929 << pos.Zd() << " " << pos.Az() << " "
1930 << roquelamp.X() << " " << roquelamp.Y() << endl;
1931 }
1932
1933 cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl;
1934 cout << ">=>=>=> Roque Lamp found at: >=>=>=> (" << roquelamp.X() << ","
1935 << roquelamp.Y() << ") <=<=<=<" << endl;
1936
1937 }
1938
1939 // Find Spot on Camera Center in Starguider camera
1940 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
1941 {
1942 XY cameraspot(0,0);
1943
1944 Double_t imageclean = 5;
1945 Int_t boxradius = 60;
1946 //Double_t scalefactor = 1;
1947 // XY searchcenter(sgcenter.GetX(),sgcenter.GetY());
1948 XY searchcenter(60.,290.);
1949
1950 cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
1951
1952 if (fOutRq)
1953 {
1954 ZdAz pos = fCosy->GetPointingPos();
1955
1956 *fOutRq << "RoqueLampReflected: " << MTime(-1) << " "
1957 << pos.Zd() << " " << pos.Az() << " "
1958 << cameraspot.X() << " " << cameraspot.Y() << endl;
1959 }
1960
1961 cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << ","
1962 << cameraspot.Y() << ") <<<<<" << endl;
1963
1964 f2.DrawCircle(sgcenter, 5.0, 0x0fa);
1965 f2.DrawCircle(sgcenter, 115.0, 0x0fa);
1966 }
1967 // we calculate the offset given by the three ETH Leds visible to
1968 // the guide camera
1969 // This is an (inferior, obsolete) alternative to the StarCaosFilter
1970 // Led offset;
1971 // if (fDisplay->IsEntryChecked(IDM_kStargLEDFilter))
1972 // fStargLeds->Run(img,offset);
1973
1974 // Position corresponding to the camera center (53.2, 293.6)
1975 //Ring skycenter(392, 318);
1976 // MStarList spots;
1977
1978 // we obtain a list of stars in the FOV from the SAO catalog
1979 if (fDisplay->IsEntryChecked(IDM_kCatalog))
1980 {
1981 MTime time(*tm);
1982
1983 XY xy = fCRaDec->GetCoordinates(); //[h, deg]
1984 fRaDec->Set(xy.X()*360/24, xy.Y()); //[deg,deg]
1985
1986 UpdatePosZoom();
1987
1988 // Always call SetMjd first!
1989 fSao->SetPointing(time.GetMjd(), *fRaDec);
1990 fCZdAz->SetCoordinates(fSao->GetZdAz());
1991
1992 MStarList stars;
1993 fSao->SetBox(230); // Region of interest around center
1994
1995 // very careful: If center of camera cannot be determined
1996 // sgcenter jumps to (0,0)
1997
1998 //Please never change this offsets!!!
1999 // 53.2 and 293.6 are the "preliminary" camera center
2000 // -9 and 28.5 are the offsets of the pointing position in the sky
2001
2002 const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0;
2003// if (centerisvalid)
2004// skycenter.SetXY(sgcenter.GetX() - 53.2,
2005// sgcenter.GetY() - 293.6);
2006
2007 // we obtain stars in the effective star FOV and draw them.
2008 // coordinates are video frame coords.
2009 // We determine the ideal starfield using camera sagging info
2010 // from the LEDs
2011 const XY off(sgcenter.GetX()- 53.2-9,
2012 sgcenter.GetY()-293.6+28.5);
2013
2014 fSao->CalcStars(stars, 530, 292, TMath::FloorNint(off.X()), TMath::FloorNint(off.Y()));
2015 fSao->DrawStars(stars, cimg);
2016
2017 // Position around which the circles are drawn.
2018 const Ring skycenter(768/2-off.X(), 576/2+off.Y());
2019
2020 // There are two corrections to the mispointing
2021 // - Sagging of the camera as measured with the LEDs
2022 // - Star not ideally centered on MAGIC Camera
2023
2024 // Next we evaluate the offset given by the LEDs. This we obtain
2025 // in Zd/Az and add it to the tracking error.
2026 if (fDisplay->IsEntryChecked(IDM_kStarguider))
2027 {
2028 const Float_t cut = atof(fCut->GetText());
2029
2030 Leds spots;
2031 f.SetBox(230);
2032 f.SetCut(cut);
2033
2034 double bright;
2035 f.ExecuteAndMark(spots, 530, 292, bright);
2036
2037 ULong_t color;
2038 gClient->GetColorByName("Green", color);
2039 if (bright> 60)
2040 gClient->GetColorByName("Yellow", color);
2041 if (bright> 85)
2042 gClient->GetColorByName("Orange", color);
2043 if (bright> 95)
2044 gClient->GetColorByName("Red", color);
2045 fSkyBright->SetBackgroundColor(color);
2046
2047 MString txt;
2048 txt.Print("Sky Brightness: %.1f", bright);
2049 fSkyBright->SetText(txt);
2050
2051 const Bool_t brightnessisvalid = bright<1.75*fLastBright &&
2052 bright>30 && bright<110;
2053
2054 fLastBright = bright;
2055
2056 Int_t numstars = 0;
2057 const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars);
2058
2059 const Bool_t monitoring = brightnessisvalid && centerisvalid && fNumStarsCorrelated>2;
2060
2061 fStatus = monitoring ? MDriveCom::kMonitoring : MDriveCom::kError;
2062
2063 if (fCosy)
2064 fPos = fCosy->GetPointingPos();
2065
2066 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
2067 fStargHistograms->Fill(spots, stars, fD,
2068 fSao->GetZdAz(), sgcenter, /*sgcenterzdaz,*/
2069 star, bright, fPos, t);
2070
2071 fNumStarsDetected = numstars;
2072 fNumStarsCorrelated = rc;
2073
2074 if (fCosy)
2075 {
2076 MDriveCom &com = *fCosy->GetDriveCom();
2077 com.SendStargReport(fStatus, fD, fSao->GetZdAz(),
2078 sgcenter, numstars, rc, bright,
2079 time.GetMjd(), 0, 0); // Report
2080 }
2081
2082 } //kStarguider
2083
2084 if (centerisvalid && fNumStarsCorrelated>2)
2085 {
2086 f2.DrawCircle(skycenter, 2.0, 0x0a);
2087
2088 const Double_t ap = fSao->GetPixSize()/3600; //[deg/pix]
2089
2090 f2.DrawCircle(skycenter, 0.10/ap, 0x0a); //0.1deg
2091 f2.DrawHexagon(skycenter, 2.06/ap, 0x0a);
2092 f2.DrawHexagon(skycenter, 3.50/ap, 0x0a);
2093 }
2094
2095 } //CalcStars
2096
2097 // Draw Circles around center of Camera
2098 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) &&
2099 center.GetX()>0 && center.GetY()>0)
2100 {
2101 f2.DrawCircle(center, 0x0a);
2102 f2.DrawCircle(center, 7.0,
2103 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
2104 f2.DrawCircle(center, 115.0, 0x0a);
2105 f2.DrawCircle(center, 230.0, 0x0a);
2106 f2.DrawCircle(center, 245.0, 0x0a);
2107 }
2108
2109 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter) &&
2110 sgcenter.GetX()>0 && sgcenter.GetY()>0)
2111 {
2112 f2.DrawCircle(sgcenter, 0x0a);
2113 f2.DrawCircle(sgcenter, 5.0,
2114 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
2115 }
2116
2117 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
2118 fDisplay->IsEntryChecked(IDM_kCatalog) ||
2119 fDisplay->IsEntryChecked(IDM_kFindStar) ||
2120 fOperations->IsEntryChecked(IDM_kRoqueLampAna))
2121 fImage->DrawColImg(img, cimg);
2122 else
2123 fImage->DrawImg(img);
2124}
2125
2126void MStarguider::UpdatePosZoom()
2127{
2128 MString txt;
2129 if (fDisplay->IsEntryChecked(IDM_kCatalog))
2130 {
2131 // FIXME: Necessary?
2132 fSao->Now();
2133 AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
2134 if (aa.Az()<0)
2135 aa.Az(aa.Az()+360);
2136 txt.Print("(%d, %d) %.1fd/%.1fd", fDx, fDy, -aa.Alt(), aa.Az()-180);
2137 }
2138 else
2139 txt.Print("(%d, %d)", fDx, fDy);
2140 fPosZoom->SetText(txt);
2141}
2142
2143Bool_t MStarguider::HandleDoubleClick(Event_t *event)
2144{
2145 const Int_t w = fImage->GetWidth();
2146 const Int_t h = fImage->GetHeight();
2147 const Int_t x = fImage->GetX();
2148 const Int_t y = fImage->GetY();
2149
2150 if (!(event->fX>x && event->fX<x+w && event->fY>y && event->fY<y+h))
2151 return kTRUE;
2152
2153 Int_t dx = event->fX-x;
2154 Int_t dy = event->fY-y;
2155
2156 if (dx<kZOOM/4) dx=kZOOM/4;
2157 if (dy<kZOOM/4) dy=kZOOM/4;
2158 if (dx>766-kZOOM/4) dx=766-kZOOM/4;
2159 if (dy>574-kZOOM/4) dy=574-kZOOM/4;
2160
2161 fDx = dx;
2162 fDy = dy;
2163
2164 UpdatePosZoom();
2165 return kTRUE;
2166}
2167
2168void MStarguider::Print(TString &str, Double_t deg) const
2169{
2170 Char_t sgn;
2171 UShort_t d, m, s;
2172
2173 MAstro::Deg2Dms(deg, sgn, d, m, s);
2174
2175 MString txt;
2176 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
2177}
Note: See TracBrowser for help on using the repository browser.