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

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