1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // fillstar.C
|
---|
29 | // ==========
|
---|
30 | //
|
---|
31 | // This macro is used to read the star-output files.
|
---|
32 | // These files are automatically called star00000.root.
|
---|
33 | //
|
---|
34 | // Make sure, that database and password are corretly set in a resource
|
---|
35 | // file called sql.rc and the resource file is found.
|
---|
36 | //
|
---|
37 | // Returns 0 in case of failure and 1 in case of success.
|
---|
38 | //
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 | #include <iostream>
|
---|
41 | #include <iomanip>
|
---|
42 |
|
---|
43 | #include <TEnv.h>
|
---|
44 | #include <TRegexp.h>
|
---|
45 |
|
---|
46 | #include <TH1.h>
|
---|
47 | #include <TGraph.h>
|
---|
48 | #include <TProfile.h>
|
---|
49 | #include <TFile.h>
|
---|
50 | #include <TSQLResult.h>
|
---|
51 | #include <TSQLRow.h>
|
---|
52 |
|
---|
53 | #include "MSQLServer.h"
|
---|
54 |
|
---|
55 | #include "MStatusArray.h"
|
---|
56 | #include "MGeomCamMagic.h"
|
---|
57 | #include "MBadPixelsCam.h"
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | // --------------------------------------------------------------------------
|
---|
62 | //
|
---|
63 | // Checks whether an entry is already existing
|
---|
64 | //
|
---|
65 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
66 | {
|
---|
67 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
68 | TSQLResult *res = serv.Query(query);
|
---|
69 | if (!res)
|
---|
70 | return kFALSE;
|
---|
71 |
|
---|
72 | TSQLRow *row;
|
---|
73 |
|
---|
74 | Bool_t rc = kFALSE;
|
---|
75 | while ((row=res->Next()))
|
---|
76 | {
|
---|
77 | if ((*row)[0])
|
---|
78 | {
|
---|
79 | rc = kTRUE;
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | delete res;
|
---|
85 |
|
---|
86 | return rc;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
91 | {
|
---|
92 | TFile file(fname, "READ");
|
---|
93 | if (!file.IsOpen())
|
---|
94 | {
|
---|
95 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
96 | return 0;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | MStatusArray arr;
|
---|
101 | if (arr.Read()<=0)
|
---|
102 | {
|
---|
103 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
104 | return 0;
|
---|
105 | }
|
---|
106 |
|
---|
107 | TProfile *h1 = (TProfile*)arr.FindObjectInCanvas("RingBroadening", "TProfile", "MHMuonPar");
|
---|
108 | if (!h1)
|
---|
109 | {
|
---|
110 | cout << "WARNING - Reading of RingBroadening failed." << endl;
|
---|
111 | return 0;
|
---|
112 | }
|
---|
113 |
|
---|
114 | //spline
|
---|
115 | // Float_t psf = (h1->Integral(5, 14) - 0.818)/0.0276;
|
---|
116 | //df
|
---|
117 | Float_t psf = (h1->Integral(5, 14) - 0.736)/0.0276;
|
---|
118 | psf = TMath::Nint(psf*10)/10.;
|
---|
119 | TString PSF = Form("%5.1f", psf);
|
---|
120 | Int_t num = (int)h1->GetEntries();
|
---|
121 |
|
---|
122 | TProfile *h2 = (TProfile*)arr.FindObjectInCanvas("SizeVsRadius", "TProfile", "MHMuonPar");
|
---|
123 | if (!h1)
|
---|
124 | {
|
---|
125 | cout << "WARNING - Reading of SizeVsRadius failed." << endl;
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 |
|
---|
129 | Float_t integral = h2->Integral(5, 14);
|
---|
130 | //spline
|
---|
131 | // Float_t integralmc = -36.06*psf + 11023;
|
---|
132 | //df
|
---|
133 | Float_t integralmc = -26.1*psf + 9750;
|
---|
134 | Float_t ratiodatamc = (integral/integralmc)*100;
|
---|
135 | TString ratio = Form("%5.1f", ratiodatamc);
|
---|
136 |
|
---|
137 |
|
---|
138 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
---|
139 | if (!h)
|
---|
140 | {
|
---|
141 | cout << "WARNING - Reading of Islands failed." << endl;
|
---|
142 | return 0;
|
---|
143 | }
|
---|
144 |
|
---|
145 | Float_t quality = h->GetMean();
|
---|
146 | quality = TMath::Nint(quality*10)/10.;
|
---|
147 | TString islands = Form("%6.2f", quality);
|
---|
148 |
|
---|
149 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
---|
150 | if (!h)
|
---|
151 | {
|
---|
152 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
---|
153 | return 0;
|
---|
154 | }
|
---|
155 |
|
---|
156 | Float_t effon = h->Integral();
|
---|
157 | Float_t mrate = num/effon;
|
---|
158 | mrate = TMath::Nint(mrate*100)/100.;
|
---|
159 | TString muonrate = Form("%6.2f", mrate);
|
---|
160 | Int_t effontime = TMath::Nint(effon);
|
---|
161 |
|
---|
162 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
---|
163 | if (!h)
|
---|
164 | {
|
---|
165 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
---|
166 | return 0;
|
---|
167 | }
|
---|
168 |
|
---|
169 | Int_t numevents = (int)h->GetEntries();
|
---|
170 | Int_t datarate = (int)(numevents/effon);
|
---|
171 |
|
---|
172 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
---|
173 | if (!g)
|
---|
174 | {
|
---|
175 | cout << "WARNING - Reading of Humidity failed." << endl;
|
---|
176 | return 0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
|
---|
180 | TString maxhum = Form("%6.1f", max);
|
---|
181 |
|
---|
182 |
|
---|
183 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
184 | if (sequence.IsNull())
|
---|
185 | {
|
---|
186 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
187 | return 0;
|
---|
188 | }
|
---|
189 |
|
---|
190 | Int_t seq = atoi(sequence.Data()+5);
|
---|
191 |
|
---|
192 | cout << "Sequence #" << seq << endl;
|
---|
193 | cout << " PSF [mm] " << PSF << endl;
|
---|
194 | cout << " Island Quality " << islands << endl;
|
---|
195 | cout << " Ratio [%] " << ratio << endl;
|
---|
196 | cout << " Muon Number " << num << endl;
|
---|
197 | cout << " EffOnTime [s] " << effontime << endl;
|
---|
198 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
---|
199 | cout << " # of Events " << numevents << endl;
|
---|
200 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
---|
201 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
---|
202 |
|
---|
203 | TString query;
|
---|
204 | if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
|
---|
205 | {
|
---|
206 | query = Form("INSERT Star SET"
|
---|
207 | " fSequenceFirst=%d,"
|
---|
208 | " fMeanNumberIslands=%s, "
|
---|
209 | " fRatio=%s, "
|
---|
210 | " fMuonNumber=%d, "
|
---|
211 | " fEffOnTime=%d, "
|
---|
212 | " fMuonRate=%s, "
|
---|
213 | " fPSF=%s, "
|
---|
214 | " fDataRate=%d, "
|
---|
215 | " fMaxHumidity=%s ",
|
---|
216 | seq, islands.Data(), ratio.Data(),
|
---|
217 | num, effontime,
|
---|
218 | muonrate.Data(), PSF.Data(),
|
---|
219 | datarate, maxhum.Data());
|
---|
220 | }
|
---|
221 | else
|
---|
222 | {
|
---|
223 | query = Form("UPDATE Star SET"
|
---|
224 | " fMeanNumberIslands=%s, "
|
---|
225 | " fRatio=%s, "
|
---|
226 | " fMuonNumber=%d, "
|
---|
227 | " fEffOnTime=%d, "
|
---|
228 | " fMuonRate=%s, "
|
---|
229 | " fPSF=%s, "
|
---|
230 | " fDataRate=%d, "
|
---|
231 | " fMaxHumidity=%s "
|
---|
232 | " WHERE fSequenceFirst=%d ",
|
---|
233 | islands.Data(), ratio.Data(),
|
---|
234 | num, effontime,
|
---|
235 | muonrate.Data(), PSF.Data(),
|
---|
236 | datarate, maxhum.Data(), seq);
|
---|
237 | }
|
---|
238 |
|
---|
239 | if (dummy)
|
---|
240 | return 0;
|
---|
241 |
|
---|
242 | TSQLResult *res = serv.Query(query);
|
---|
243 | if (!res)
|
---|
244 | {
|
---|
245 | cout << "ERROR - Query failed: " << query << endl;
|
---|
246 | return 0;
|
---|
247 | }
|
---|
248 |
|
---|
249 | return 1;
|
---|
250 | }
|
---|
251 |
|
---|
252 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
253 | {
|
---|
254 | TEnv env("sql.rc");
|
---|
255 |
|
---|
256 | MSQLServer serv(env);
|
---|
257 | if (!serv.IsConnected())
|
---|
258 | {
|
---|
259 | cout << "ERROR - Connection to database failed." << endl;
|
---|
260 | return 0;
|
---|
261 | }
|
---|
262 |
|
---|
263 | cout << "fillstar" << endl;
|
---|
264 | cout << "---------" << endl;
|
---|
265 | cout << endl;
|
---|
266 | cout << "Connected to " << serv.GetName() << endl;
|
---|
267 | cout << "File: " << fname << endl;
|
---|
268 | cout << endl;
|
---|
269 |
|
---|
270 | return Process(serv, fname, dummy);
|
---|
271 | }
|
---|