source: trunk/MagicSoft/Cosy/main/MStargHistograms.cc@ 9306

Last change on this file since 9306 was 8847, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 4.5 KB
Line 
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
24using namespace std;
25
26void 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 // Center of Camera, offset from arb coords, in Zd, Az, deg
74// tree->Branch("CenterZd.", &fCenterZd, "fCenterZd/D");
75// tree->Branch("CenterAz.", &fCenterAz, "fCenterAz/D");
76 // Position of Star in Camera in Zd, Az
77 tree->Branch("StarZd.", &fStarZd, "fStarZd/D");
78 tree->Branch("StarAz.", &fStarAz, "fStarAz/D");
79 // number of spots found
80 tree->Branch("Spots.", &fSpots, "fSpots/D");
81 // number of stars expected
82 tree->Branch("Stars.", &fStars, "fStars/D");
83 tree->Branch("Bright.", &fBright, "fBright/D");
84
85
86 cout << "Root file '" << name << "' open." << endl;
87}
88
89void MStargHistograms::CloseFile()
90{
91 if (!fFile)
92 return;
93
94 const TString name = fFile->GetName();
95 const Double_t n = ((TTree*)fFile->Get("Data"))->GetEntries();
96
97 fFile->Write();
98 delete fFile;
99 fFile = NULL;
100
101 cout << "Root file closed (n=" << n << ")" << endl;
102
103 if (n<1)
104 {
105 gSystem->Unlink(name);
106 cout << "Root file deleted - no entries." << endl;
107 }
108}
109
110void MStargHistograms::InitHistograms()
111{
112
113}
114
115void MStargHistograms::DeleteHistograms()
116{
117
118}
119
120void MStargHistograms::ShowHistograms()
121{
122
123}
124
125void MStargHistograms::ResetHistograms()
126{
127
128}
129
130void MStargHistograms::Fill(Leds &spots, MStarList &stars, ZdAz &d, ZdAz sao, Ring &center, ZdAz &star, Double_t bright, const ZdAz &pos, const MTime &t)
131{
132 // FIXME!
133 static const MTime t0(t);
134 fEvtTime = t-t0;
135
136 // cout << "@ evttime " << fEvtTime << endl;
137
138 if (fFile && spots.GetEntries()>0)
139 {
140 fZenithDist = pos.Zd(); //fCosy ? fCosy->GetPointingPos().Zd() : 0
141 fAzimuth = pos.Az(); //fCosy ? fCosy->GetPointingPos().Az() : 0;
142 fNomZd = sao.Zd();
143 fNomAz = sao.Az();
144 fdZd = d.Zd();
145 fdAz = d.Az();
146
147 fCenterX = center.GetX();
148 fCenterY = center.GetY();
149 //fCenterZd = centerzdaz.Zd();
150 //fCenterAz = centerzdaz.Az();
151 fStarZd = star.Zd();
152 fStarAz = star.Az();
153 fStars = stars.GetRealEntries();
154 fSpots = spots.GetEntries();
155 fBright = bright;
156
157 // cout << " Evttime=" << fEvtTime
158// << " ZD=" << fZenithDist
159// << " Az=" << fAzimuth
160// << " NomZd=" << fNomZd
161// << " NomAz=" << fNomAz
162// << " dZd=" << fdZd
163// << " dAz=" << fdAz
164// << " OffsX=" << fOffsetX
165// << " OffsY=" << fOffsetY
166// <<endl;
167
168 TTree *t = (TTree*)fFile->Get("Data");
169 t->Fill();
170 }
171
172}
Note: See TracBrowser for help on using the repository browser.