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

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