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-2006
|
---|
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 star00000000.root.
|
---|
33 | // From these files the muon parameters (psf, muon number, ratio, muon rate),
|
---|
34 | // the rate, the number of islands, the effective ontime, the maximum
|
---|
35 | // humidity and a parameter describing the inhomogeneity are extracted from
|
---|
36 | // the status display.
|
---|
37 | // The sequence number is extracted from the filename.
|
---|
38 | //
|
---|
39 | // Usage:
|
---|
40 | // .x fillstar.C("/magic/data/star/0004/00047421/star00047421.root", kTRUE)
|
---|
41 | //
|
---|
42 | // The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
|
---|
43 | // switched on and nothing will be written into the database. This is usefull
|
---|
44 | // for tests.
|
---|
45 | //
|
---|
46 | // The macro can also be run without ACLiC but this is a lot slower...
|
---|
47 | //
|
---|
48 | // Remark: Running it from the commandline looks like this:
|
---|
49 | // root -q -l -b fillstar.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillstar.log
|
---|
50 | //
|
---|
51 | // Make sure, that database and password are corretly set in a resource
|
---|
52 | // file called sql.rc and the resource file is found.
|
---|
53 | //
|
---|
54 | // Returns 2 in case of failure, 1 in case of success and 0 if the connection
|
---|
55 | // to the database is not working.
|
---|
56 | //
|
---|
57 | /////////////////////////////////////////////////////////////////////////////
|
---|
58 | #include <iostream>
|
---|
59 | #include <iomanip>
|
---|
60 |
|
---|
61 | #include <TEnv.h>
|
---|
62 | #include <TRegexp.h>
|
---|
63 |
|
---|
64 | #include <TH1.h>
|
---|
65 | #include <TH2.h>
|
---|
66 | #include <TGraph.h>
|
---|
67 | #include <TProfile.h>
|
---|
68 | #include <TFile.h>
|
---|
69 | #include <TSQLResult.h>
|
---|
70 | #include <TSQLRow.h>
|
---|
71 |
|
---|
72 | #include "MSQLServer.h"
|
---|
73 |
|
---|
74 | #include "MHMuonPar.h"
|
---|
75 | #include "MStatusArray.h"
|
---|
76 | #include "MGeomCamMagic.h"
|
---|
77 | #include "MBadPixelsCam.h"
|
---|
78 |
|
---|
79 | using namespace std;
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Checks whether an entry is already existing
|
---|
84 | //
|
---|
85 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
86 | {
|
---|
87 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
88 | TSQLResult *res = serv.Query(query);
|
---|
89 | if (!res)
|
---|
90 | return kFALSE;
|
---|
91 |
|
---|
92 | TSQLRow *row;
|
---|
93 |
|
---|
94 | Bool_t rc = kFALSE;
|
---|
95 | while ((row=res->Next()))
|
---|
96 | {
|
---|
97 | if ((*row)[0])
|
---|
98 | {
|
---|
99 | rc = kTRUE;
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | delete res;
|
---|
105 |
|
---|
106 | return rc;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
111 | {
|
---|
112 | TFile file(fname, "READ");
|
---|
113 | if (!file.IsOpen())
|
---|
114 | {
|
---|
115 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
116 | return 2;
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | MStatusArray arr;
|
---|
121 | if (arr.Read()<=0)
|
---|
122 | {
|
---|
123 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
124 | return 2;
|
---|
125 | }
|
---|
126 |
|
---|
127 | TH2F *hcog = (TH2F*)arr.FindObjectInCanvas("Center", "TH2F", "MHHillas");
|
---|
128 | if (!hcog)
|
---|
129 | {
|
---|
130 | cout << "WARNING - Reading of MHHillas failed." << endl;
|
---|
131 | return 2;
|
---|
132 | }
|
---|
133 |
|
---|
134 | MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
|
---|
135 | if (!hmuon)
|
---|
136 | {
|
---|
137 | cout << "WARNING - Reading of MHMuon failed." << endl;
|
---|
138 | return 2;
|
---|
139 | }
|
---|
140 |
|
---|
141 | Double_t val[6];
|
---|
142 | for (int x=1; x<hcog->GetNbinsX(); x++)
|
---|
143 | for (int y=1; y<hcog->GetNbinsY(); y++)
|
---|
144 | {
|
---|
145 | Stat_t px = hcog->GetXaxis()->GetBinCenter(x);
|
---|
146 | Stat_t py = hcog->GetYaxis()->GetBinCenter(y);
|
---|
147 | Int_t i = (TMath::Nint(3*TMath::ATan2(px,py)/TMath::Pi())+6)%6;
|
---|
148 | val[i] += hcog->GetBinContent(x, y);
|
---|
149 | }
|
---|
150 |
|
---|
151 | Double_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
|
---|
152 | inhom = TMath::Nint(inhom*10)/10.;
|
---|
153 | TString inhomogen = Form("%5.1f", inhom);
|
---|
154 |
|
---|
155 | Float_t mw = hmuon->GetMeanWidth();
|
---|
156 | Float_t psf = 51.505292*mw - 31.147126;
|
---|
157 | psf = TMath::Nint(psf*10)/10.;
|
---|
158 | TString PSF = Form("%5.1f", psf);
|
---|
159 | Int_t num = (int)hmuon->GetEntries();
|
---|
160 |
|
---|
161 | Float_t ratiodatamc = (hmuon->GetMeanSize()/9340.)*100;
|
---|
162 | TString ratio = Form("%5.1f", ratiodatamc);
|
---|
163 |
|
---|
164 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
---|
165 | if (!h)
|
---|
166 | {
|
---|
167 | cout << "WARNING - Reading of Islands failed." << endl;
|
---|
168 | return 2;
|
---|
169 | }
|
---|
170 |
|
---|
171 | Float_t quality = h->GetMean();
|
---|
172 | quality = TMath::Nint(quality*100)/100.;
|
---|
173 | TString islands = Form("%6.2f", quality);
|
---|
174 |
|
---|
175 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
---|
176 | if (!h)
|
---|
177 | {
|
---|
178 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
---|
179 | return 2;
|
---|
180 | }
|
---|
181 |
|
---|
182 | Float_t effon = h->Integral();
|
---|
183 | Float_t mrate = num/effon;
|
---|
184 | mrate = TMath::Nint(mrate*100)/100.;
|
---|
185 | TString muonrate = Form("%6.2f", mrate);
|
---|
186 | Int_t effontime = TMath::Nint(effon);
|
---|
187 |
|
---|
188 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
---|
189 | if (!h)
|
---|
190 | {
|
---|
191 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
---|
192 | return 2;
|
---|
193 | }
|
---|
194 |
|
---|
195 | Int_t numevents = (int)h->GetEntries();
|
---|
196 | Int_t datarate = (int)(numevents/effon);
|
---|
197 |
|
---|
198 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
---|
199 | if (!g)
|
---|
200 | {
|
---|
201 | cout << "WARNING - Reading of Humidity failed." << endl;
|
---|
202 | return 2;
|
---|
203 | }
|
---|
204 |
|
---|
205 | Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
|
---|
206 | TString maxhum = Form("%6.1f", max);
|
---|
207 |
|
---|
208 |
|
---|
209 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
210 | if (sequence.IsNull())
|
---|
211 | {
|
---|
212 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
213 | return 2;
|
---|
214 | }
|
---|
215 |
|
---|
216 | Int_t seq = atoi(sequence.Data()+5);
|
---|
217 |
|
---|
218 | cout << "Sequence #" << seq << endl;
|
---|
219 | cout << " Inhomogeneity " << inhomogen << endl;
|
---|
220 | cout << " PSF [mm] " << PSF << endl;
|
---|
221 | cout << " Island Quality " << islands << endl;
|
---|
222 | cout << " Ratio [%] " << ratio << endl;
|
---|
223 | cout << " Muon Number " << num << endl;
|
---|
224 | cout << " EffOnTime [s] " << effontime << endl;
|
---|
225 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
---|
226 | cout << " # of Events " << numevents << endl;
|
---|
227 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
---|
228 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
---|
229 |
|
---|
230 | TString query;
|
---|
231 | if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
|
---|
232 | {
|
---|
233 | query = Form("INSERT Star SET"
|
---|
234 | " fSequenceFirst=%d,"
|
---|
235 | " fMeanNumberIslands=%s, "
|
---|
236 | " fRatio=%s, "
|
---|
237 | " fMuonNumber=%d, "
|
---|
238 | " fEffOnTime=%d, "
|
---|
239 | " fMuonRate=%s, "
|
---|
240 | " fPSF=%s, "
|
---|
241 | " fDataRate=%d, "
|
---|
242 | " fMaxHumidity=%s ,"
|
---|
243 | " fInhomogeneity=%s ",
|
---|
244 | seq, islands.Data(), ratio.Data(),
|
---|
245 | num, effontime,
|
---|
246 | muonrate.Data(), PSF.Data(),
|
---|
247 | datarate, maxhum.Data(),
|
---|
248 | inhomogen.Data());
|
---|
249 | }
|
---|
250 | else
|
---|
251 | {
|
---|
252 | query = Form("UPDATE Star SET"
|
---|
253 | " fMeanNumberIslands=%s, "
|
---|
254 | " fRatio=%s, "
|
---|
255 | " fMuonNumber=%d, "
|
---|
256 | " fEffOnTime=%d, "
|
---|
257 | " fMuonRate=%s, "
|
---|
258 | " fPSF=%s, "
|
---|
259 | " fDataRate=%d, "
|
---|
260 | " fMaxHumidity=%s, "
|
---|
261 | " fInhomogeneity=%s "
|
---|
262 | " WHERE fSequenceFirst=%d ",
|
---|
263 | islands.Data(), ratio.Data(),
|
---|
264 | num, effontime,
|
---|
265 | muonrate.Data(), PSF.Data(),
|
---|
266 | datarate, maxhum.Data(),
|
---|
267 | inhomogen.Data(), seq);
|
---|
268 | }
|
---|
269 |
|
---|
270 | if (dummy)
|
---|
271 | return 1;
|
---|
272 |
|
---|
273 | TSQLResult *res = serv.Query(query);
|
---|
274 | if (!res)
|
---|
275 | {
|
---|
276 | cout << "ERROR - Query failed: " << query << endl;
|
---|
277 | return 2;
|
---|
278 | }
|
---|
279 |
|
---|
280 | return 1;
|
---|
281 | }
|
---|
282 |
|
---|
283 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
284 | {
|
---|
285 | TEnv env("sql.rc");
|
---|
286 |
|
---|
287 | MSQLServer serv(env);
|
---|
288 | if (!serv.IsConnected())
|
---|
289 | {
|
---|
290 | cout << "ERROR - Connection to database failed." << endl;
|
---|
291 | return 0;
|
---|
292 | }
|
---|
293 |
|
---|
294 | cout << "fillstar" << endl;
|
---|
295 | cout << "---------" << endl;
|
---|
296 | cout << endl;
|
---|
297 | cout << "Connected to " << serv.GetName() << endl;
|
---|
298 | cout << "File: " << fname << endl;
|
---|
299 | cout << endl;
|
---|
300 |
|
---|
301 | return Process(serv, fname, dummy);
|
---|
302 | }
|
---|