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