source: trunk/MagicSoft/Cosy/gui/MGStarguider.cc@ 1959

Last change on this file since 1959 was 1959, checked in by tbretz, 22 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 32.7 KB
Line 
1#include "MGStarguider.h"
2
3#include <fstream.h> // ifstream
4#include <iostream.h> // cout
5#include <iomanip.h> // cout
6
7#include <TTimer.h>
8
9#include <TGMenu.h>
10#include <TGLabel.h>
11#include <TSystem.h>
12#include <TGSplitter.h> // TGHorizontal3DLine
13#include <TGTextEntry.h>
14
15#include "MGImage.h"
16#include "MGCoordinates.h"
17
18#include "coord.h"
19
20#include "StarCatalog.h"
21
22#include "Filter.h"
23#include "Filter2.h"
24#include "CaosFilter.h"
25#include "Writer.h"
26#include "base/timer.h"
27
28#include "MStarList.h"
29
30#include <TH1.h>
31#include <TH2.h>
32#include <TGraph.h>
33#include <TCanvas.h>
34
35#include <TFile.h>
36#include <TTree.h>
37#include <TBranch.h>
38
39#include "Led.h"
40#include "Leds.h"
41#include "Rings.h"
42
43#include "MGMenu.h"
44
45ClassImp(MGStarguider);
46
47enum {
48 IDM_kFilter,
49 IDM_kCaosFilter,
50 IDM_kCatalog,
51 IDM_kStarguider,
52 IDM_kStart,
53 IDM_kStop,
54 IDM_kFileType,
55 IDM_kPPM,
56 IDM_kPNG,
57 IDM_kOnce,
58 IDM_kStretch,
59 IDM_kUseFileRaDec,
60 IDM_kContinous,
61 IDM_kRate25ps,
62 IDM_kRate5ps,
63 IDM_kRate1s,
64 IDM_kRate5s,
65 IDM_kRate30s,
66 IDM_kRate1m,
67 IDM_kRate5m,
68 IDM_kSetup,
69 IDM_kLimMag3,
70 IDM_kLimMag4,
71 IDM_kLimMag5,
72 IDM_kLimMag6,
73 IDM_kLimMag7,
74 IDM_kLimMag8,
75 IDM_kLimMag9,
76 IDM_kPixSize,
77 IDM_kAngle,
78 IDM_kInterpol125,
79 IDM_kInterpol25,
80 IDM_kInterpol10,
81 IDM_kInterpol5,
82 IDM_kInterpol2,
83 IDM_kInterpol1,
84 IDM_kPositions,
85 IDM_kRings,
86 IDM_kLeds,
87 IDM_kStartAnalyse,
88 IDM_kStopAnalyse,
89 IDM_kResetHistograms
90};
91
92Bool_t MGStarguider::HandleTimer(TTimer *t)
93{
94 fImage->DoRedraw();
95 fZoomImage->DoRedraw();
96 return kTRUE;
97}
98
99#define kZOOM 96
100
101void MGStarguider::InitHists()
102{
103 Double_t xmin = 480.1-1.0;
104 Double_t xmax = 480.1+1.0;
105
106 Double_t ymin = 217.5-1.0;
107 Double_t ymax = 217.5+1.0;
108
109 Double_t rmin = 117.4-1.0;
110 Double_t rmax = 117.4+1.0;
111
112 Int_t xbin = 60;
113 Int_t ybin = 60;
114 Int_t rbin = 60;
115
116 fHistpr = new TH1F;
117 fHistpr->SetNameTitle("pr","Radius of the ring");
118 fHistpr->SetBins(rbin, rmin, rmax);
119 fHistpr->SetXTitle("r [mm]");
120 fHistpr->SetYTitle("counts");
121
122 fHistprx = new TH1F;
123 fHistprx->SetNameTitle("prx","x-coordinate of the ring-center");
124 fHistprx->SetBins(xbin, xmin, xmax);
125 fHistprx->SetXTitle("x [mm]");
126 fHistprx->SetYTitle("counts");
127
128 fHistpry = new TH1F;
129 fHistpry->SetNameTitle("pry","y-coordniate of the ring-center");
130 fHistpry->SetBins(ybin, ymin, ymax);
131 fHistpry->SetXTitle("y [mm]");
132 fHistpry->SetYTitle("counts");
133
134 for (int i=0; i<6; i++)
135 {
136 TString name = "Angle";
137 TString title = "Angle of Led ";
138
139 name += i;
140 title += i;
141
142 fHistw[i] = new TH1F;
143 fHistw[i]->SetNameTitle(name, title);
144 fHistw[i]->SetBins(26, -25, 25);
145 fHistw[i]->SetXTitle("\\Phi [arcmin]");
146 fHistw[i]->SetYTitle("counts");
147
148 name = "Angles";
149 title = "Angles of the Leds ";
150
151 name += i;
152 title += i;
153
154 fHistv[i] = new TH1F;
155 fHistv[i]->SetNameTitle(name, title);
156 fHistv[i]->SetBins(721, -180.5, 180.5);
157 fHistv[i]->SetXTitle("\\Phi [deg]");
158 fHistv[i]->SetYTitle("counts");
159 }
160
161 fHistallw = new TH1F;
162 fHistallw->SetNameTitle("allw","Rotation angel");
163 fHistallw->SetBins(26, -25, 25);
164 fHistallw->SetXTitle("\\Phi [arcmin]");
165 fHistallw->SetYTitle("counts");
166
167 fHistprxpry = new TH2F;
168 fHistprxpry->SetNameTitle("prx und pry","x- and y-coordniate of the ring-center");
169 fHistprxpry->SetBins(xbin, xmin, xmax, ybin, ymin, ymax);
170 fHistprxpry->SetXTitle("x [mm]");
171 fHistprxpry->SetYTitle("y [mm]");
172 fHistprxpry->SetZTitle("counts");
173}
174
175void MGStarguider::InitGraphs()
176{
177 fGraphprx = new TGraph;
178 fGraphprx->SetTitle("time-developement of the x-coordinate of the ring-center");
179
180 fGraphpry = new TGraph;
181 fGraphpry->SetTitle("time-developement of the y-coordinate of the ring-center");
182
183 for (int i=0; i<6; i++)
184 {
185 TString title = "Time-developement of the angle ";
186 title += i;
187
188 fGraphw[i] = new TGraph;
189 fGraphw[i]->SetTitle(title);
190 }
191}
192
193void MGStarguider::InitGui()
194{
195 fList = new MGList;
196
197 const TGWindow *p=gClient->GetRoot();
198
199 //
200 // Create Menu for MGStarguider Display
201 //
202 fDisplay = new MGPopupMenu(p);
203 fDisplay->AddEntry("&Filter", IDM_kFilter);
204 fDisplay->AddEntry("C&aosFilter", IDM_kCaosFilter);
205 fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
206 fDisplay->AddEntry("Starguider", IDM_kStarguider);
207 fDisplay->AddEntry("Stretch", IDM_kStretch);
208 fDisplay->DisableEntry(IDM_kStarguider);
209 fDisplay->CheckEntry(IDM_kStretch);
210 fDisplay->Associate(this);
211 fList->Add(fDisplay);
212
213 fFileType = new MGPopupMenu(p);
214 fFileType->AddEntry("PP&M", IDM_kPPM);
215 fFileType->AddEntry("&PNG", IDM_kPNG);
216 fFileType->CheckEntry(IDM_kPNG);
217 fFileType->Associate(this);
218 fList->Add(fFileType);
219
220 fWriteType = new MGPopupMenu(p);
221 fWriteType->AddEntry("&Once", IDM_kOnce);
222 fWriteType->AddEntry("&Continous", IDM_kContinous);
223 fWriteType->CheckEntry(IDM_kOnce);
224 fWriteType->Associate(this);
225 fList->Add(fWriteType);
226
227 fWriteRate = new MGPopupMenu(p);
228 fWriteRate->AddEntry("25/s", IDM_kRate25ps);
229 fWriteRate->AddEntry("5/s", IDM_kRate5ps);
230 fWriteRate->AddEntry("1s", IDM_kRate1s);
231 fWriteRate->AddEntry("5s", IDM_kRate5s);
232 fWriteRate->AddEntry("30s", IDM_kRate30s);
233 fWriteRate->AddEntry("1min", IDM_kRate1m);
234 fWriteRate->AddEntry("5min", IDM_kRate5m);
235 fWriteRate->CheckEntry(IDM_kRate1m);
236 fWriteRate->Associate(this);
237 fList->Add(fWriteRate);
238
239 fWrtRate = 25*60;
240
241 fWritePictures = new MGPopupMenu(p);
242 fWritePictures->AddEntry("&Start", IDM_kStart);
243 fWritePictures->AddEntry("Sto&p", IDM_kStop);
244 fWritePictures->AddSeparator();
245 fWritePictures->AddPopup("File &Type", fFileType);
246 fWritePictures->AddPopup("&Write Type", fWriteType);
247 fWritePictures->AddPopup("Write &Rate", fWriteRate);
248 fWritePictures->DisableEntry(IDM_kStop);
249 fWritePictures->Associate(this);
250 fList->Add(fWritePictures);
251
252 fLimMag = new MGPopupMenu(p);
253 fLimMag->AddEntry("3", IDM_kLimMag3);
254 fLimMag->AddEntry("4", IDM_kLimMag4);
255 fLimMag->AddEntry("5", IDM_kLimMag5);
256 fLimMag->AddEntry("6", IDM_kLimMag6);
257 fLimMag->AddEntry("7", IDM_kLimMag7);
258 fLimMag->AddEntry("8", IDM_kLimMag8);
259 fLimMag->AddEntry("9", IDM_kLimMag9);
260 fLimMag->CheckEntry(IDM_kLimMag8);
261 fLimMag->Associate(this);
262 fList->Add(fLimMag);
263
264 fSao->SetLimitMag(7.0);
265
266 fInterpol = new MGPopupMenu(p);
267 fInterpol->AddEntry("125", IDM_kInterpol125);
268 fInterpol->AddEntry("25", IDM_kInterpol25);
269 fInterpol->AddEntry("10", IDM_kInterpol10);
270 fInterpol->AddEntry("5", IDM_kInterpol5);
271 fInterpol->AddEntry("2", IDM_kInterpol2);
272 fInterpol->AddEntry("Off", IDM_kInterpol1);
273 fInterpol->CheckEntry(IDM_kInterpol1);
274 fInterpol->Associate(this);
275 fList->Add(fInterpol);
276
277 fIntRate = 1;
278
279 fSetup = new MGPopupMenu(p);
280 fSetup->AddPopup("Lim. &Magnitude", fLimMag);
281 fSetup->AddPopup("Disp. &Interpolation", fInterpol);
282 fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
283 fSetup->Associate(this);
284 fList->Add(fSetup);
285
286 fWrite = new MGPopupMenu(p);
287 fWrite->AddEntry("&Positions", IDM_kPositions);
288 fWrite->AddEntry("&Leds", IDM_kLeds);
289 fWrite->AddEntry("&Rings", IDM_kRings);
290 fWrite->Associate(this);
291 fList->Add(fWrite);
292
293 fAnalyse = new MGPopupMenu(p);
294 fAnalyse->AddEntry("S&tart Analyse", IDM_kStartAnalyse);
295 fAnalyse->AddEntry("St&opp Analyse", IDM_kStopAnalyse);
296 fAnalyse->DisableEntry(IDM_kStopAnalyse);
297 fAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
298// fAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
299 fAnalyse->Associate(this);
300 fList->Add(fAnalyse);
301
302 fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
303 fMenu->AddPopup("&Display", fDisplay, NULL);
304 fMenu->AddPopup("&WritePics", fWritePictures, NULL);
305 fMenu->AddPopup("&Setup", fSetup, NULL);
306 fMenu->Resize(fMenu->GetDefaultSize());
307 fMenu->BindKeys(this);
308 AddFrame(fMenu); //, new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0));
309 fList->Add(fMenu);
310
311 fCaOs = new MGPopupMenu(p);
312 fCaOs->AddPopup("&Write", fWrite);
313 fCaOs->AddPopup("&Analyse", fAnalyse);
314 fCaOs->Associate(this);
315 fCaOs->BindKeys(fMenu, this);
316 fList->Add(fCaOs);
317
318 fCRaDec = new MGCoordinates(this, kETypeRaDec);
319 fCRaDec->Move(1, fMenu->GetDefaultHeight()+584);
320 AddFrame(fCRaDec);
321 fList->Add(fCRaDec);
322
323 fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
324 fCZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+584);
325 AddFrame(fCZdAz);
326 fList->Add(fCZdAz);
327
328 fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
329 fPZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+630);
330 AddFrame(fPZdAz);
331 fList->Add(fPZdAz);
332
333 TGLabel *l = new TGLabel(this, "Arb.-Sky Pos");
334 l->SetTextJustify(kTextLeft);
335 l->Move(480+32, fMenu->GetDefaultHeight()+590);
336 AddFrame(l);
337 fList->Add(l);
338
339 l = new TGLabel(this, "arcsec/pix");
340 l->SetTextJustify(kTextLeft);
341 l->Move(605, fMenu->GetDefaultHeight()+619+13);
342 AddFrame(l);
343 fList->Add(l);
344
345 l = new TGLabel(this, "deg");
346 l->SetTextJustify(kTextLeft);
347 l->Move(605, fMenu->GetDefaultHeight()+619-10);
348 AddFrame(l);
349 fList->Add(l);
350
351 l = new TGLabel(this, "Pointing Pos");
352 l->SetTextJustify(kTextLeft);
353 l->Move(480+32, fMenu->GetDefaultHeight()+655);
354 AddFrame(l);
355 fList->Add(l);
356
357 const Double_t pixsize = 23.4;
358
359 fSao->SetPixSize(pixsize/3600);
360 fSao->SetRotationAngle(0);
361
362 TString txt;
363 txt += pixsize;
364
365 fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
366 fPixSize->SetAlignment(kTextCenterX);
367 fPixSize->Move(547, fMenu->GetDefaultHeight()+617+13);
368 AddFrame(fPixSize);
369 fList->Add(fPixSize);
370
371 fAngle = new TGTextEntry(this, " 0", IDM_kAngle);
372 fAngle->SetAlignment(kTextCenterX);
373 fAngle->Move(547, fMenu->GetDefaultHeight()+617-10);
374 AddFrame(fAngle);
375 fList->Add(fAngle);
376
377 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
378 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
379 // fList->Add(fLineSep);
380
381 //
382 // Create Image Display
383 //
384 fZoomImage = new MGImage(this, kZOOM, kZOOM);
385 fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
386 AddFrame(fZoomImage);
387 fList->Add(fZoomImage);
388
389 fImage = new MGImage(this, 768, 576);
390 fImage->Move(0, fMenu->GetDefaultHeight());
391 AddFrame(fImage);
392 fList->Add(fImage);
393
394 //
395 // Make everything visible
396 //
397 SetWindowName("MGStarguider Main Window");
398 SetIconName("MGStarguider");
399
400 MapSubwindows();
401 MapWindow();
402
403 //------------------------------------------------------------
404 // XY xy(3.819444, 24.05333);
405 // fCRaDec->SetCoordinates(xy);
406 // fRaDec->Set(xy.X()*360/24, xy.Y());
407 //------------------------------------------------------------
408}
409
410MGStarguider::MGStarguider(MObservatory::LocationName_t obs)
411: TGMainFrame(gClient->GetRoot(), 768, 740), fFile(NULL), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
412{
413 fSao = new StarCatalog(obs);
414 fRaDec = new RaDec(180, 40);
415
416 InitHists();
417 InitGraphs();
418
419 InitGui();
420
421 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
422
423 fTimer=new TTimer(this, 100); // 100ms
424 fTimer->TurnOn();
425}
426
427MGStarguider::~MGStarguider()
428{
429 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
430
431 fTimer->TurnOff();
432 delete fTimer;
433
434 delete fList;
435
436 delete fSao;
437 delete fRaDec;
438
439 delete fHistpr;
440 delete fHistprx;
441 delete fHistpry;
442 delete fHistprxpry;
443 delete fHistallw;
444 delete fGraphprx;
445 delete fGraphpry;
446
447 for (int i=0; i<6; i++)
448 {
449 delete fHistw[i];
450 delete fHistv[i];
451 delete fGraphw[i];
452 }
453
454 cout << "Camera Display destroyed." << endl;
455}
456
457void MGStarguider::Layout()
458{
459 // Resize(GetDefaultSize());
460}
461
462void MGStarguider::CloseWindow()
463{
464 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
465
466 //fClient.ExitLoop();
467 // cout << "FIXME: ExitLoop not called!!!!!!" << endl;
468 gSystem->ExitLoop();
469}
470
471void MGStarguider::Toggle(MGPopupMenu *p, UInt_t id)
472{
473 if (p->IsEntryChecked(id))
474 p->UnCheckEntry(id);
475 else
476 p->CheckEntry(id);
477}
478
479void MGStarguider::ResetHists()
480{
481 fHistprx->Reset();
482 fHistpry->Reset();
483 fHistpr->Reset();
484 fHistprxpry->Reset();
485 fHistallw->Reset();
486 for (int i=0; i<6; i++)
487 {
488 fHistw[i]->Reset();
489 fHistv[i]->Reset();
490 }
491}
492
493void MGStarguider::DisplayAnalysis()
494{
495 TCanvas *c = new TCanvas("cring", "Center of the ring", 800, 800);
496 c->Divide(2,2);
497 c->cd(1);
498 fHistprx->Fit("gaus");
499 fHistprx->DrawCopy();
500 c->cd(2);
501 fHistpry->Fit("gaus");
502 fHistpry->DrawCopy();
503 c->cd(3);
504 fHistpr->Fit("gaus");
505 fHistpr->DrawCopy();
506 c->cd(4);
507 fHistprxpry->DrawCopy(/*"surf2"*/);
508 c->Update();
509
510 c = new TCanvas("c3", "Absolute angles of the leds", 800, 800);
511 c->Divide(2,3);
512 for (int i=0; i<6; i++)
513 {
514 c->cd(i+1);
515 TH1 *h = fHistv[i]->DrawCopy();
516 h->SetLineColor(i+1);
517 cout << "Led #" << i << ": MeanPhi=" << h->GetMean() << endl;
518 }
519 c->Update();
520
521 c = new TCanvas("c5", "timedevelopement of prx", 800, 800);
522 fGraphprx->Draw("ALP*");
523 fGraphprx->GetHistogram()->SetXTitle("time [1/25 s]");
524 fGraphprx->GetHistogram()->SetYTitle("x-coordinate");
525 c->Modified();
526 c->Update();
527
528 c = new TCanvas("c6", "timedevelopement of pry", 800, 800);
529 fGraphpry->Draw("ALP*");
530 fGraphpry->GetHistogram()->SetXTitle("time [1/25 s]");
531 fGraphpry->GetHistogram()->SetYTitle("y-coordinate");
532 c->Modified();
533 c->Update();
534
535 c = new TCanvas("c2", "Relative angles of the Leds", 800, 800);
536 c->Divide(2,3);
537 for (int i=0; i<6; i++)
538 {
539 c->cd(i+1);
540 fHistw[i]->DrawCopy();
541 }
542 c->Update();
543
544 c = new TCanvas("c7", "timedevelopement of the relative angles of the Leds", 800, 800);
545 c->Divide(2,3);
546 for (int i=0; i<6; i++)
547 {
548 c->cd(i+1);
549 fGraphw[i]->Draw("ALP*");
550 fGraphw[i]->GetHistogram()->SetXTitle("t [1/25s]");
551 fGraphw[i]->GetHistogram()->SetYTitle("[deg]");
552 }
553 c->Modified();
554 c->Update();
555
556 c = new TCanvas("c4", "rotation angle ", 800, 800);
557 fHistallw->Fit("gaus");
558 fHistallw->DrawCopy();
559}
560
561void MGStarguider::OpenFile()
562{
563 int i=0;
564 char name[100];
565 while (1)
566 {
567 sprintf(name, "data/data%03d.root", i++);
568 if (gSystem->AccessPathName(name, kFileExists))
569 break;
570 }
571
572 fFile = new TFile(name, "RECREATE");
573
574 if (!fFile->IsOpen())
575 {
576 delete fFile;
577 fFile = NULL;
578
579 cout << "Error: Cannot open file '" << name << "'" << endl;
580
581 }
582
583 fTree = new TTree("Data", "Real CaOs Data");
584
585 fLeds = NULL;
586 fRings = NULL;
587 fTime = 0;
588
589 fBranchL = fTree->Branch("Leds.", "Leds", &fLeds);
590 fBranchR = fTree->Branch("Rings.", "Rings", &fRings);
591 fBranchT = fTree->Branch("Time.", &fTime, "fTime/D");//, &fTime);
592
593 cout << "Root file '" << name << "' open." << endl;
594}
595
596Bool_t MGStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
597{
598 switch (GET_MSG(msg))
599 {
600 case kC_TEXTENTRY:
601 if (GET_SUBMSG(msg)==kTE_ENTER)
602 switch (mp1)
603 {
604 case IDM_kPixSize:
605 {
606 const Float_t pixsize = atof(fPixSize->GetText());
607 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
608 fSao->SetPixSize(pixsize/3600);
609 return kTRUE;
610 }
611 case IDM_kAngle:
612 {
613 const Float_t angle = atof(fAngle->GetText());
614 cout << "Rotation Angle changed to " << angle << "deg" << endl;
615 fSao->SetRotationAngle(angle);
616 return kTRUE;
617 }
618 }
619 return kTRUE;
620
621 case kC_COMMAND:
622 //cout << "kC_COMMAND" << endl;
623 switch (GET_SUBMSG(msg))
624 {
625 case kCM_MENU:
626 //cout << "kCM_MENU #" << mp1 << endl;
627 switch (mp1)
628 {
629 case IDM_kCatalog:
630 Toggle(fDisplay, IDM_kCatalog);
631 if (fDisplay->IsEntryChecked(IDM_kCatalog))
632 fDisplay->EnableEntry(IDM_kStarguider);
633 else
634 {
635 fDisplay->UnCheckEntry(IDM_kStarguider);
636 fDisplay->DisableEntry(IDM_kStarguider);
637 }
638 return kTRUE;
639
640 case IDM_kStarguider:
641 Toggle(fDisplay, IDM_kStarguider);
642 gSystem->Unlink("tracking_error.txt");
643 return kTRUE;
644
645 case IDM_kFilter:
646 Toggle(fDisplay, IDM_kFilter);
647 if (fDisplay->IsEntryChecked(IDM_kFilter))
648 fDisplay->EnableEntry(IDM_kStarguider);
649 else
650 {
651 fDisplay->UnCheckEntry(IDM_kStarguider);
652 fDisplay->DisableEntry(IDM_kStarguider);
653 }
654 return kTRUE;
655
656 case IDM_kStretch:
657 Toggle(fDisplay, IDM_kStretch);
658 return kTRUE;
659
660 case IDM_kCaosFilter:
661 if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
662 OpenFile();
663 Toggle(fDisplay, IDM_kCaosFilter);
664 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
665 fMenu->AddPopup("&CaOs", fCaOs, NULL);
666 else
667 {
668 fFile->Write();
669 delete fFile;
670 fFile = NULL;
671
672 cout << "Root file closed." << endl;
673
674 if(fWrite->IsEntryChecked(IDM_kPositions))
675 fWrite->UnCheckEntry(IDM_kPositions);
676 if(fWrite->IsEntryChecked(IDM_kLeds))
677 fWrite->UnCheckEntry(IDM_kLeds);
678 if(fWrite->IsEntryChecked(IDM_kRings))
679 fWrite->UnCheckEntry(IDM_kRings);
680 if(fAnalyse->IsEntryEnabled(IDM_kStopAnalyse))
681 {
682 fAnalyse->DisableEntry(IDM_kStopAnalyse);
683 fAnalyse->EnableEntry(IDM_kStartAnalyse);
684 ResetHists();
685 // Graphs are not reset !!!
686 }
687 fMenu->RemovePopup("CaOs");
688 }
689 fMenu->Resize(fMenu->GetDefaultSize());
690 MapSubwindows();
691 MapWindow();
692 return kTRUE;
693
694 case IDM_kPositions:
695 Toggle(fWrite, IDM_kPositions);
696 return kTRUE;
697
698 case IDM_kLeds:
699 Toggle(fWrite, IDM_kLeds);
700 return kTRUE;
701
702 case IDM_kRings:
703 Toggle(fWrite, IDM_kRings);
704 return kTRUE;
705
706 case IDM_kStartAnalyse:
707 fAnalyse->DisableEntry(IDM_kStartAnalyse);
708 fAnalyse->EnableEntry(IDM_kStopAnalyse);
709 return kTRUE;
710
711 case IDM_kStopAnalyse:
712 {
713 fAnalyse->DisableEntry(IDM_kStopAnalyse);
714 fAnalyse->EnableEntry(IDM_kStartAnalyse);
715
716 DisplayAnalysis();
717
718 return kTRUE;
719 }
720
721 case IDM_kResetHistograms:
722 ResetHists();
723 return kTRUE;
724
725/* case IDM_kResetGraph:
726 {
727 fGraphx->GetHistogram()->Reset();
728
729 }
730*/
731
732 case IDM_kUseFileRaDec:
733 Toggle(fSetup, IDM_kUseFileRaDec);
734 return kTRUE;
735
736 case IDM_kStart:
737 fWritePictures->DisableEntry(IDM_kStart);
738 fWritePictures->EnableEntry(IDM_kStop);
739 return kTRUE;
740
741 case IDM_kStop:
742 fWritePictures->DisableEntry(IDM_kStop);
743 fWritePictures->EnableEntry(IDM_kStart);
744 return kTRUE;
745
746 case IDM_kPNG:
747 fFileType->CheckEntry(IDM_kPNG);
748 fFileType->UnCheckEntry(IDM_kPPM);
749 return kTRUE;
750
751 case IDM_kPPM:
752 fFileType->CheckEntry(IDM_kPPM);
753 fFileType->UnCheckEntry(IDM_kPNG);
754 return kTRUE;
755
756 case IDM_kOnce:
757 fWriteType->CheckEntry(IDM_kOnce);
758 fWriteType->UnCheckEntry(IDM_kContinous);
759 return kTRUE;
760
761 case IDM_kContinous:
762 fWriteType->CheckEntry(IDM_kContinous);
763 fWriteType->UnCheckEntry(IDM_kOnce);
764 return kTRUE;
765
766 case IDM_kRate25ps:
767 case IDM_kRate5ps:
768 case IDM_kRate1s:
769 case IDM_kRate5s:
770 case IDM_kRate30s:
771 case IDM_kRate1m:
772 case IDM_kRate5m:
773 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
774 if (mp1==i)
775 fWriteRate->CheckEntry(i);
776 else
777 fWriteRate->UnCheckEntry(i);
778 switch (mp1)
779 {
780 case IDM_kRate25ps:
781 fWrtRate = 1;
782 return kTRUE;
783 case IDM_kRate5ps:
784 fWrtRate = 5;
785 return kTRUE;
786 case IDM_kRate1s:
787 fWrtRate = 25;
788 return kTRUE;
789 case IDM_kRate5s:
790 fWrtRate = 5*25;
791 return kTRUE;
792 case IDM_kRate30s:
793 fWrtRate = 30*25;
794 return kTRUE;
795 case IDM_kRate1m:
796 fWrtRate = 60*25;
797 return kTRUE;
798 case IDM_kRate5m:
799 fWrtRate = 5*60*25;
800 return kTRUE;
801 }
802 return kTRUE;
803
804 case IDM_kInterpol125:
805 case IDM_kInterpol25:
806 case IDM_kInterpol10:
807 case IDM_kInterpol5:
808 case IDM_kInterpol2:
809 case IDM_kInterpol1:
810 for (int i=IDM_kInterpol125; i<=IDM_kInterpol1; i++)
811 if (mp1==i)
812 fInterpol->CheckEntry(i);
813 else
814 fInterpol->UnCheckEntry(i);
815 switch (mp1)
816 {
817 case IDM_kInterpol1:
818 fIntRate = 1;
819 return kTRUE;
820 case IDM_kInterpol2:
821 fIntRate = 2;
822 return kTRUE;
823 case IDM_kInterpol5:
824 fIntRate = 5;
825 return kTRUE;
826 case IDM_kInterpol10:
827 fIntRate = 10;
828 return kTRUE;
829 case IDM_kInterpol25:
830 fIntRate = 25;
831 return kTRUE;
832 case IDM_kInterpol125:
833 fIntRate = 125;
834 return kTRUE;
835 }
836 return kTRUE;
837
838 case IDM_kLimMag3:
839 case IDM_kLimMag4:
840 case IDM_kLimMag5:
841 case IDM_kLimMag6:
842 case IDM_kLimMag7:
843 case IDM_kLimMag8:
844 case IDM_kLimMag9:
845 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
846 if (mp1==i)
847 fLimMag->CheckEntry(i);
848 else
849 fLimMag->UnCheckEntry(i);
850
851 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
852 return kTRUE;
853 }
854 break;
855 }
856 break;
857 }
858
859 return kTRUE;
860}
861
862void MGStarguider::GetCoordinates()
863{
864 XY xy = fCRaDec->GetCoordinates();
865
866 if (fSetup->IsEntryChecked(IDM_kUseFileRaDec))
867 {
868 ifstream fin("coordinates.txt");
869 if (!fin)
870 cout << "Error: Cannot open 'coordinates.txt' using fall back solution." << endl;
871 else
872 fin >> xy;
873 }
874
875 fCRaDec->SetCoordinates(xy);
876 fRaDec->Set(xy.X()*360/24, xy.Y());
877}
878
879ZdAz MGStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const
880{
881 //
882 // Viewable area (FIXME: AZ)
883 //
884 TH2F h("Hist", "dX/dY", 77, -768/2-.5, 768/2+.5, 58, -576/2-.5, 576/2+.5); // 3
885
886 /*
887 TH1F hmag("HistMag", "Mag", 19, 0, 100);
888 for (int i=0; i<mag.GetSize(); i++)
889 hmag.Fill(mag[i]);
890 */
891
892 //
893 // Search for matching Magnitudes
894 //
895 for (int i=0; i<mag.GetSize(); i++)
896 {
897 if (mag[i]>48-15 && mag[i]<48+15)
898 h.Fill(x[i], y[i]);
899 }
900
901 //
902 // Serach for an excess in the histogram
903 //
904 Int_t mx, my, dummy;
905 h.GetMaximumBin(mx, my, dummy);
906
907 const double xmax = h.GetXaxis()->GetBinCenter(mx);
908 const double dx = h.GetXaxis()->GetBinWidth(mx);
909
910 const double ymax = h.GetYaxis()->GetBinCenter(my);
911 const double dy = h.GetYaxis()->GetBinWidth(my);
912
913 cout << setprecision(3);
914 cout << "Cut-XY: " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl;
915
916 TGraph g;
917 for (int i=0; i<mag.GetSize(); i++)
918 {
919 if (!(x[i]>xmax-dx && x[i]<xmax+dx &&
920 y[i]>ymax-dy && y[i]<ymax+dy &&
921 mag[i]>48-15 && mag[i]<48+15))
922 continue;
923
924 g.SetPoint(g.GetN(), x[i], y[i]);
925 }
926
927 cout << "Offset-XY: " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / ";
928 cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl;
929
930 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg;
931 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg;
932
933 ofstream fout1("pointingpos.txt");
934 fout1 << setprecision(10) << fSao->GetMjd()-52000 << " " << -pos1.Alt() << " " << pos1.Az() << endl;
935
936 pos1 -= pos0;
937
938 ofstream fout2("tracking_error.txt", ios::app);
939 fout2 << setprecision(10) << fSao->GetMjd()-52000 << " " << -pos1.Alt() << " " << pos1.Az() << endl;
940
941 return ZdAz(-pos1.Alt(), pos1.Az());
942}
943
944void MGStarguider::CalcTrackingError(Leds &leds, MStarList &stars)
945{
946 const Int_t max = leds.GetEntries();
947
948 if (stars.GetRealEntries() < 3)
949 {
950 cout << "Sorry, less than 3 stars in FOV!" << endl;
951 return;
952 }
953
954 if (max < 1)
955 {
956 cout << "Sorry, less than 1 detected spot in FOV!" << endl;
957 return;
958 }
959
960 stars.Sort(); // Sort by magnitude
961
962 TString str = "data/tracking_";
963 str += fSao->GetMjd()-52000;
964 str += ".txt";
965
966 ofstream fout(str);
967
968 TArrayF x, y, mag;
969
970 Int_t num = 0;
971
972 // FIXME: Is predifined value 3 a good idea?
973
974 MStar *star;
975 MStarListIter NextStar(&stars);
976 while ((star=NextStar()) && num++<max+3)
977 {
978 TIter NextSp(&leds);
979 Led *spot=NULL;
980 while ((spot=(Led*)NextSp()))
981 {
982 const XY dpos(spot->GetX()-star->GetX(), spot->GetY()-star->GetY());
983
984 const Int_t idx = x.GetSize();
985
986 x.Set(idx+1);
987 y.Set(idx+1);
988 mag.Set(idx+1);
989
990 x.AddAt(dpos.X(), idx);
991 y.AddAt(dpos.Y(), idx);
992 mag.AddAt(spot->GetMag()/star->GetMag(), idx);
993
994 if (fout)
995 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
996 }
997 }
998
999 ZdAz d = TrackingError(x, y, mag);
1000
1001 //
1002 // Calculated offsets
1003 //
1004
1005 // round= floor(x+.5)
1006 cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
1007 cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
1008
1009 //
1010 // Current Pointing position
1011 //
1012 ZdAz cpos = fSao->GetZdAz()-d;
1013 fPZdAz->SetCoordinates(cpos);
1014}
1015
1016
1017void MGStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
1018{
1019 static float myimg[768*576];
1020
1021 for (int i=0; i<768*576; i++)
1022 myimg[i] += img[i];
1023
1024 if (n%fIntRate)
1025 return;
1026
1027 //cout << "Img: " << n << endl;
1028
1029 byte c[768*576];
1030 for (int i=0; i<768*576; i++)
1031 c[i] = (byte)(myimg[i]/fIntRate+.5);
1032
1033 if (fDisplay->IsEntryChecked(IDM_kStretch))
1034 Filter::Stretch(c);
1035
1036 if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
1037 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
1038 {
1039 if (fFileType->IsEntryChecked(IDM_kPNG))
1040 Writer::Png("pix/file", c, tm);
1041
1042 if (fFileType->IsEntryChecked(IDM_kPPM))
1043 Writer::Ppm("pix/file", c, tm);
1044
1045 if (fWriteType->IsEntryChecked(IDM_kOnce))
1046 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
1047 }
1048
1049 MStarList spots;
1050
1051 /*
1052 if (fDisplay->IsEntryChecked(IDM_kStarguider))
1053 Filter2::Execute(spots, c);
1054 else
1055 */
1056 if (fDisplay->IsEntryChecked(IDM_kFilter))
1057 Filter::Execute(c);
1058
1059 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
1060 {
1061 // Double_t kConv = 0.502; // [pix/mm]
1062
1063 static Timer t0(tm);
1064 Timer t(tm);
1065
1066 fTime = (t.GetMjd()-t0.GetMjd())*24*60*60;
1067
1068 Leds leds;
1069 CaosFilter::Execute(c, leds, 1);
1070
1071 if (fWrite->IsEntryChecked(IDM_kPositions))
1072 leds.Print();
1073
1074 CaosFilter::FilterLeds(leds);
1075 leds.Compress();
1076
1077 if (fWrite->IsEntryChecked(IDM_kLeds))
1078 leds.Print();
1079
1080 Rings rings;
1081 rings.CalcRings(leds);
1082
1083 leds.Sort();
1084
1085 fLeds = &leds;
1086 fRings = &rings;
1087
1088 if (fFile)
1089 fTree->Fill();
1090
1091 if (fWrite->IsEntryChecked(IDM_kRings))
1092 rings.Print();
1093
1094 if (fAnalyse->IsEntryEnabled(IDM_kStopAnalyse))
1095 {
1096 const Ring &center = rings.GetCenter();
1097
1098 Double_t phi[6] =
1099 {
1100 -124.727,
1101 -61.0495,
1102 -16.7907,
1103 49.3119,
1104 139.086
1105 };
1106
1107 fHistpr->Fill(center.GetR());
1108 fHistprx->Fill(center.GetX());
1109 fHistpry->Fill(center.GetY());
1110 fHistprxpry->Fill(center.GetX(), center.GetY());
1111
1112 Double_t sum = 0;
1113 for (int i=0; i<6 && leds.At(i); i++)
1114 {
1115 const Double_t w = (leds(i).GetPhi()-phi[i])*60;
1116
1117 sum += w;
1118
1119 fHistw[i]->Fill(w);
1120 fHistv[i]->Fill(leds(i).GetPhi());
1121 fGraphw[i]->SetPoint(fGraphw[i]->GetN(), fTime, w);
1122 }
1123 fHistallw->Fill(sum/5);
1124
1125 fGraphprx->SetPoint(fGraphprx->GetN(), fTime, center.GetX());
1126 fGraphpry->SetPoint(fGraphpry->GetN(), fTime, center.GetY());
1127 }
1128 }
1129
1130 byte zimg[kZOOM*kZOOM];
1131 for (int y=0; y<kZOOM; y++)
1132 for (int x=0; x<kZOOM; x++)
1133 zimg[x+y*kZOOM] = c[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
1134
1135 fZoomImage->DrawImg(zimg);
1136
1137 if (fDisplay->IsEntryChecked(IDM_kCatalog))
1138 {
1139 Timer time(tm);
1140
1141 GetCoordinates();
1142
1143 MStarList stars;
1144 fSao->GetStars(stars, time.GetMjd(), *fRaDec);
1145
1146 if (fDisplay->IsEntryChecked(IDM_kStarguider))
1147 {
1148 Leds leds;
1149 CaosFilter::Execute(c, leds, 1);
1150
1151 cout << "Found: " << leds.GetEntries() << " leds" << endl;
1152
1153 CaosFilter::RemoveTwins(leds, 3);
1154 leds.Compress();
1155
1156 cout << "Rest: " << leds.GetEntries() << " leds" << endl;
1157
1158 CalcTrackingError(leds, stars);
1159 }
1160
1161 byte cimg[768*576];
1162 fSao->GetImg(c, cimg, stars);
1163
1164 DrawCircle(c, 0.5);
1165 DrawCircle(c, 1.0);
1166 DrawCircle(c, 1.5);
1167
1168 fCZdAz->SetCoordinates(fSao->GetZdAz());
1169
1170 fImage->DrawColImg(c, cimg);
1171 }
1172 else
1173 fImage->DrawImg(c);
1174
1175 memset(myimg, 0, 768*576*sizeof(float));
1176}
1177
1178void MGStarguider::DrawCircle(byte *img, double r)
1179{
1180 const double rpix = r*60*60/fSao->GetPixSize()+1;
1181 const int cx = 768/2;
1182 const int cy = 576/2;
1183 for (int dx=-(int)(rpix*0.7); dx<(int)(rpix*0.7); dx++)
1184 {
1185 const int dy = (int)sqrt(rpix*rpix-dx*dx);
1186 img[cx+dx + (cy-dy)*768] = 0x40;
1187 img[cx+dx + (cy+dy)*768] = 0x40;
1188 img[cx-dy + (cy+dx)*768] = 0x40;
1189 img[cx+dy + (cy+dx)*768] = 0x40;
1190 }
1191}
1192
1193Bool_t MGStarguider::HandleDoubleClick(Event_t *event)
1194{
1195 const Int_t w = fImage->GetWidth();
1196 const Int_t h = fImage->GetHeight();
1197 const Int_t x = fImage->GetX();
1198 const Int_t y = fImage->GetY();
1199
1200 if (!(event->fX>x && event->fX<x+w && event->fY>y && event->fY<y+h))
1201 return kTRUE;
1202
1203 Int_t dx = event->fX-x;
1204 Int_t dy = event->fY-y;
1205
1206 if (dx<kZOOM/4) dx=kZOOM/4;
1207 if (dy<kZOOM/4) dy=kZOOM/4;
1208 if (dx>766-kZOOM/2) dx=766-kZOOM/4;
1209 if (dy>510-kZOOM/2) dy=510-kZOOM/4;
1210
1211 fDx = dx;
1212 fDy = dy;
1213
1214 fSao->Now();
1215 AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
1216
1217 cout << "New coordinates for zoom - x, y : " << fDx << " " << fDy << endl;
1218 cout << "New coordinates for zoom - Alt, az: " << aa.Alt() << " " << aa.Az() << endl;
1219
1220 return kTRUE;
1221}
Note: See TracBrowser for help on using the repository browser.