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

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