1 | #include "MStargHistograms.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 | #include <iomanip>
|
---|
5 |
|
---|
6 | #include <TSystem.h>
|
---|
7 | #include <TFile.h>
|
---|
8 | #include <TTree.h>
|
---|
9 | #include <TH1.h>
|
---|
10 | #include <TH2.h>
|
---|
11 | #include <TGraph.h>
|
---|
12 | #include <TCanvas.h>
|
---|
13 |
|
---|
14 | #include "MTime.h"
|
---|
15 | #include "MPointing.h"
|
---|
16 |
|
---|
17 | #include "Led.h"
|
---|
18 | #include "Leds.h"
|
---|
19 | #include "Ring.h"
|
---|
20 | #include "Rings.h"
|
---|
21 | #include "FilterLed.h"
|
---|
22 | #include "MStarList.h"
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | void MStargHistograms::OpenFile()
|
---|
27 | {
|
---|
28 | int i=0;
|
---|
29 | char name[100];
|
---|
30 | while (1)
|
---|
31 | {
|
---|
32 | sprintf(name, "data/starg%03d.root", i++);
|
---|
33 | if (gSystem->AccessPathName(name, kFileExists))
|
---|
34 | break;
|
---|
35 | }
|
---|
36 |
|
---|
37 | if (fFile)
|
---|
38 | delete fFile;
|
---|
39 |
|
---|
40 | fFile = new TFile(name, "RECREATE");
|
---|
41 |
|
---|
42 | if (!fFile->IsOpen())
|
---|
43 | {
|
---|
44 | delete fFile;
|
---|
45 | fFile = NULL;
|
---|
46 |
|
---|
47 | cout << "Error: Cannot open file '" << name << "'" << endl;
|
---|
48 | }
|
---|
49 |
|
---|
50 | TTree *tree = new TTree("Data", "Real Starg Data");
|
---|
51 |
|
---|
52 |
|
---|
53 | fEvtTime = 0;
|
---|
54 |
|
---|
55 |
|
---|
56 | // Tracking Position Zd, Az in deg
|
---|
57 | tree->Branch("PosZd.", &fZenithDist, "fZenithDist/D");
|
---|
58 | tree->Branch("PosAz.", &fAzimuth, "fAzimuth/D");
|
---|
59 | // Event time, arbitrary start
|
---|
60 | tree->Branch("EvtTime.", &fEvtTime, "fEvtTime/D");
|
---|
61 | // Pointing Position Zd, Az in deg
|
---|
62 | tree->Branch("SaoZd.", &fNomZd, "fNomZd/D");
|
---|
63 | tree->Branch("SaoAz.", &fNomAz, "fNomAz/D");
|
---|
64 | // Misspointing from Starguider Zd, Az in deg
|
---|
65 | tree->Branch("MisZd.", &fdZd, "fdZd/D");
|
---|
66 | tree->Branch("MisAz.", &fdAz, "fdAz/D");
|
---|
67 | // LED Offset from StargLEDFinder, obsolete
|
---|
68 | tree->Branch("LEDOffsetX.", &fOffsetX, "fOffsX/D");
|
---|
69 | tree->Branch("LEDOffsetY.", &fOffsetY, "fOffsY/D");
|
---|
70 | // Center of Camera, offset from arb coords, in pix
|
---|
71 | tree->Branch("CenterX.", &fCenterX, "fCenterX/D");
|
---|
72 | tree->Branch("CenterY.", &fCenterY, "fCenterY/D");
|
---|
73 | // number of spots found
|
---|
74 | tree->Branch("Spots.", &fSpots, "fSpots/D");
|
---|
75 | // number of stars expected
|
---|
76 | tree->Branch("Stars.", &fStars, "fStars/D");
|
---|
77 | tree->Branch("Bright.", &fBright, "fBright/D");
|
---|
78 |
|
---|
79 | cout << "Root file '" << name << "' open." << endl;
|
---|
80 | }
|
---|
81 |
|
---|
82 | void MStargHistograms::CloseFile()
|
---|
83 | {
|
---|
84 | if (!fFile)
|
---|
85 | return;
|
---|
86 |
|
---|
87 | const TString name = fFile->GetName();
|
---|
88 | const Double_t n = ((TTree*)fFile->Get("Data"))->GetEntries();
|
---|
89 |
|
---|
90 | fFile->Write();
|
---|
91 | delete fFile;
|
---|
92 | fFile = NULL;
|
---|
93 |
|
---|
94 | cout << "Root file closed (n=" << n << ")" << endl;
|
---|
95 |
|
---|
96 | if (n<1)
|
---|
97 | {
|
---|
98 | gSystem->Unlink(name);
|
---|
99 | cout << "Root file deleted - no entries." << endl;
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | void MStargHistograms::Fill(Leds &spots, MStarList &stars, ZdAz &d, ZdAz sao, Ring ¢er, Double_t bright, const ZdAz &pos, const MTime &t)
|
---|
104 | {
|
---|
105 | // FIXME!
|
---|
106 | static const MTime t0(t);
|
---|
107 | fEvtTime = t-t0;
|
---|
108 |
|
---|
109 | if (fFile && spots.GetEntries()>0)
|
---|
110 | {
|
---|
111 | fZenithDist = pos.Zd(); //fCosy ? fCosy->GetPointingPos().Zd() : 0
|
---|
112 | fAzimuth = pos.Az(); //fCosy ? fCosy->GetPointingPos().Az() : 0;
|
---|
113 | fNomZd = sao.Zd();
|
---|
114 | fNomAz = sao.Az();
|
---|
115 | fdZd = d.Zd();
|
---|
116 | fdAz = d.Az();
|
---|
117 |
|
---|
118 | fCenterX = center.GetX();
|
---|
119 | fCenterY = center.GetY();
|
---|
120 | fStars = stars.GetRealEntries();
|
---|
121 | fSpots = spots.GetEntries();
|
---|
122 | fBright = bright;
|
---|
123 |
|
---|
124 | TTree *t = (TTree*)fFile->Get("Data");
|
---|
125 | t->Fill();
|
---|
126 | }
|
---|
127 | }
|
---|