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 | Float_t numerator = 0;
|
---|
115 | Float_t denominator = 0;
|
---|
116 | Float_t summe = 0;
|
---|
117 |
|
---|
118 | for(Int_t i=5; i<15; i++)
|
---|
119 | {
|
---|
120 | numerator += h1->GetBinContent(i)*h1->GetBinEntries(i);
|
---|
121 | denominator += h1->GetBinEntries(i);
|
---|
122 | }
|
---|
123 |
|
---|
124 | summe = numerator/denominator;
|
---|
125 |
|
---|
126 | Float_t psf = (summe - 0.04816)/0.001294;
|
---|
127 | psf = TMath::Nint(psf*10)/10.;
|
---|
128 | TString PSF = Form("%5.1f", psf);
|
---|
129 | Int_t num = (int)h1->GetEntries();
|
---|
130 |
|
---|
131 | TProfile *h2 = (TProfile*)arr.FindObjectInCanvas("SizeVsRadius", "TProfile", "MHMuonPar");
|
---|
132 | if (!h1)
|
---|
133 | {
|
---|
134 | cout << "WARNING - Reading of SizeVsRadius failed." << endl;
|
---|
135 | return 0;
|
---|
136 | }
|
---|
137 |
|
---|
138 | numerator = 0;
|
---|
139 | denominator = 0;
|
---|
140 | summe = 0;
|
---|
141 |
|
---|
142 | for(Int_t i=5; i<15; i++)
|
---|
143 | {
|
---|
144 | numerator += h2->GetBinContent(i)*h2->GetBinEntries(i);
|
---|
145 | denominator += h2->GetBinEntries(i);
|
---|
146 | }
|
---|
147 |
|
---|
148 | summe = numerator/denominator;
|
---|
149 |
|
---|
150 | Float_t integralmc = -1.43*psf + 1035;
|
---|
151 | Float_t ratiodatamc = (summe/integralmc)*100;
|
---|
152 | TString ratio = Form("%5.1f", ratiodatamc);
|
---|
153 |
|
---|
154 |
|
---|
155 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
---|
156 | if (!h)
|
---|
157 | {
|
---|
158 | cout << "WARNING - Reading of Islands failed." << endl;
|
---|
159 | return 0;
|
---|
160 | }
|
---|
161 |
|
---|
162 | Float_t quality = h->GetMean();
|
---|
163 | quality = TMath::Nint(quality*10)/10.;
|
---|
164 | TString islands = Form("%6.2f", quality);
|
---|
165 |
|
---|
166 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
---|
167 | if (!h)
|
---|
168 | {
|
---|
169 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
---|
170 | return 0;
|
---|
171 | }
|
---|
172 |
|
---|
173 | Float_t effon = h->Integral();
|
---|
174 | Float_t mrate = num/effon;
|
---|
175 | mrate = TMath::Nint(mrate*100)/100.;
|
---|
176 | TString muonrate = Form("%6.2f", mrate);
|
---|
177 | Int_t effontime = TMath::Nint(effon);
|
---|
178 |
|
---|
179 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
---|
180 | if (!h)
|
---|
181 | {
|
---|
182 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
---|
183 | return 0;
|
---|
184 | }
|
---|
185 |
|
---|
186 | Int_t numevents = (int)h->GetEntries();
|
---|
187 | Int_t datarate = (int)(numevents/effon);
|
---|
188 |
|
---|
189 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
---|
190 | if (!g)
|
---|
191 | {
|
---|
192 | cout << "WARNING - Reading of Humidity failed." << endl;
|
---|
193 | return 0;
|
---|
194 | }
|
---|
195 |
|
---|
196 | Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
|
---|
197 | TString maxhum = Form("%6.1f", max);
|
---|
198 |
|
---|
199 |
|
---|
200 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
201 | if (sequence.IsNull())
|
---|
202 | {
|
---|
203 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
204 | return 0;
|
---|
205 | }
|
---|
206 |
|
---|
207 | Int_t seq = atoi(sequence.Data()+5);
|
---|
208 |
|
---|
209 | cout << "Sequence #" << seq << endl;
|
---|
210 | cout << " PSF [mm] " << PSF << endl;
|
---|
211 | cout << " Island Quality " << islands << endl;
|
---|
212 | cout << " Ratio [%] " << ratio << endl;
|
---|
213 | cout << " Muon Number " << num << endl;
|
---|
214 | cout << " EffOnTime [s] " << effontime << endl;
|
---|
215 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
---|
216 | cout << " # of Events " << numevents << endl;
|
---|
217 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
---|
218 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
---|
219 |
|
---|
220 | TString query;
|
---|
221 | if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
|
---|
222 | {
|
---|
223 | query = Form("INSERT Star SET"
|
---|
224 | " fSequenceFirst=%d,"
|
---|
225 | " fMeanNumberIslands=%s, "
|
---|
226 | " fRatio=%s, "
|
---|
227 | " fMuonNumber=%d, "
|
---|
228 | " fEffOnTime=%d, "
|
---|
229 | " fMuonRate=%s, "
|
---|
230 | " fPSF=%s, "
|
---|
231 | " fDataRate=%d, "
|
---|
232 | " fMaxHumidity=%s ",
|
---|
233 | seq, islands.Data(), ratio.Data(),
|
---|
234 | num, effontime,
|
---|
235 | muonrate.Data(), PSF.Data(),
|
---|
236 | datarate, maxhum.Data());
|
---|
237 | }
|
---|
238 | else
|
---|
239 | {
|
---|
240 | query = Form("UPDATE Star SET"
|
---|
241 | " fMeanNumberIslands=%s, "
|
---|
242 | " fRatio=%s, "
|
---|
243 | " fMuonNumber=%d, "
|
---|
244 | " fEffOnTime=%d, "
|
---|
245 | " fMuonRate=%s, "
|
---|
246 | " fPSF=%s, "
|
---|
247 | " fDataRate=%d, "
|
---|
248 | " fMaxHumidity=%s "
|
---|
249 | " WHERE fSequenceFirst=%d ",
|
---|
250 | islands.Data(), ratio.Data(),
|
---|
251 | num, effontime,
|
---|
252 | muonrate.Data(), PSF.Data(),
|
---|
253 | datarate, maxhum.Data(), seq);
|
---|
254 | }
|
---|
255 |
|
---|
256 | if (dummy)
|
---|
257 | return 0;
|
---|
258 |
|
---|
259 | TSQLResult *res = serv.Query(query);
|
---|
260 | if (!res)
|
---|
261 | {
|
---|
262 | cout << "ERROR - Query failed: " << query << endl;
|
---|
263 | return 0;
|
---|
264 | }
|
---|
265 |
|
---|
266 | return 1;
|
---|
267 | }
|
---|
268 |
|
---|
269 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
270 | {
|
---|
271 | TEnv env("sql.rc");
|
---|
272 |
|
---|
273 | MSQLServer serv(env);
|
---|
274 | if (!serv.IsConnected())
|
---|
275 | {
|
---|
276 | cout << "ERROR - Connection to database failed." << endl;
|
---|
277 | return 0;
|
---|
278 | }
|
---|
279 |
|
---|
280 | cout << "fillstar" << endl;
|
---|
281 | cout << "---------" << endl;
|
---|
282 | cout << endl;
|
---|
283 | cout << "Connected to " << serv.GetName() << endl;
|
---|
284 | cout << "File: " << fname << endl;
|
---|
285 | cout << endl;
|
---|
286 |
|
---|
287 | return Process(serv, fname, dummy);
|
---|
288 | }
|
---|