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

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