source: trunk/MagicSoft/Cosy/gui/MGPngReader.cc@ 8814

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