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

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