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

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