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

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