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

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