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-2008
|
---|
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 "MSQLMagic.h"
|
---|
73 |
|
---|
74 | #include "MHCamera.h"
|
---|
75 | #include "MHMuonPar.h"
|
---|
76 | #include "MStatusArray.h"
|
---|
77 | #include "MGeomCamMagic.h"
|
---|
78 | #include "MBadPixelsCam.h"
|
---|
79 |
|
---|
80 | using namespace std;
|
---|
81 |
|
---|
82 | int Process(MSQLMagic &serv, TString fname)
|
---|
83 | {
|
---|
84 | TFile file(fname, "READ");
|
---|
85 | if (!file.IsOpen())
|
---|
86 | {
|
---|
87 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
88 | return 2;
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | MStatusArray arr;
|
---|
93 | if (arr.Read()<=0)
|
---|
94 | {
|
---|
95 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
96 | return 2;
|
---|
97 | }
|
---|
98 |
|
---|
99 | MHCamera *hsparks = (MHCamera*)arr.FindObjectInCanvas("Sparks;avg", "MHCamera", "Sparks");
|
---|
100 | if (!hsparks)
|
---|
101 | {
|
---|
102 | cout << "WARNING - Reading of Sparks failed." << endl;
|
---|
103 | return 2;
|
---|
104 | }
|
---|
105 |
|
---|
106 | TH2F *hcog = (TH2F*)arr.FindObjectInCanvas("Center", "TH2F", "MHHillas");
|
---|
107 | if (!hcog)
|
---|
108 | {
|
---|
109 | cout << "WARNING - Reading of MHHillas failed." << endl;
|
---|
110 | return 2;
|
---|
111 | }
|
---|
112 |
|
---|
113 | MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
|
---|
114 | if (!hmuon)
|
---|
115 | {
|
---|
116 | cout << "WARNING - Reading of MHMuon failed." << endl;
|
---|
117 | return 2;
|
---|
118 | }
|
---|
119 |
|
---|
120 | Double_t val[6];
|
---|
121 | for (int x=1; x<hcog->GetNbinsX(); x++)
|
---|
122 | for (int y=1; y<hcog->GetNbinsY(); y++)
|
---|
123 | {
|
---|
124 | Stat_t px = hcog->GetXaxis()->GetBinCenter(x);
|
---|
125 | Stat_t py = hcog->GetYaxis()->GetBinCenter(y);
|
---|
126 | Int_t i = (TMath::Nint(3*TMath::ATan2(px,py)/TMath::Pi())+6)%6;
|
---|
127 | val[i] += hcog->GetBinContent(x, y);
|
---|
128 | }
|
---|
129 |
|
---|
130 | Double_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
|
---|
131 | inhom = TMath::Nint(inhom*10)/10.;
|
---|
132 | TString inhomogen = Form("%5.1f", inhom);
|
---|
133 |
|
---|
134 | Float_t mw = hmuon->GetMeanWidth();
|
---|
135 | Float_t psf = 70.205*mw - 28.055;
|
---|
136 | TString PSF = Form("%5.1f", psf<0?0:psf);
|
---|
137 | Int_t num = (int)hmuon->GetEntries();
|
---|
138 |
|
---|
139 | Float_t ratiodatamc = (hmuon->GetMeanSize()/7216)*100;
|
---|
140 | TString ratio = Form("%5.1f", ratiodatamc);
|
---|
141 |
|
---|
142 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
---|
143 | if (!h)
|
---|
144 | {
|
---|
145 | cout << "WARNING - Reading of Islands failed." << endl;
|
---|
146 | return 2;
|
---|
147 | }
|
---|
148 |
|
---|
149 | TString islands = Form("%6.2f", h->GetMean());
|
---|
150 |
|
---|
151 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
---|
152 | if (!h)
|
---|
153 | {
|
---|
154 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
---|
155 | return 2;
|
---|
156 | }
|
---|
157 |
|
---|
158 | Float_t effon = h->Integral();
|
---|
159 | Float_t mrate = num/effon;
|
---|
160 | TString muonrate = Form("%6.2f", mrate<0?0:mrate);
|
---|
161 | Int_t effontime = TMath::Nint(effon);
|
---|
162 |
|
---|
163 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
---|
164 | if (!h)
|
---|
165 | {
|
---|
166 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
---|
167 | return 2;
|
---|
168 | }
|
---|
169 |
|
---|
170 | Int_t numsparks = (int)hsparks->GetEntries();
|
---|
171 | Int_t numevents = (int)h->GetEntries() - numsparks;
|
---|
172 | Int_t datarate = (int)(numevents/effon);
|
---|
173 |
|
---|
174 | TString sparkrate = Form("%5.2f", numsparks/effon);
|
---|
175 |
|
---|
176 | if (sparkrate.Contains("inf"))
|
---|
177 | sparkrate="0.00";
|
---|
178 |
|
---|
179 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
---|
180 | if (!g)
|
---|
181 | {
|
---|
182 | cout << "WARNING - Reading of Humidity failed." << endl;
|
---|
183 | return 2;
|
---|
184 | }
|
---|
185 | TString maxhum = g->GetN()>0 ? Form("%5.1f", TMath::MaxElement(g->GetN(), g->GetY())) : "NULL";
|
---|
186 | TString avghum = g->GetN()>0 ? Form("%5.1f", g->GetMean(2)) : "NULL";
|
---|
187 |
|
---|
188 | g = (TGraph*)arr.FindObjectInCanvas("Temperature", "TGraph", "MHWeather");
|
---|
189 | if (!g)
|
---|
190 | {
|
---|
191 | cout << "WARNING - Reading of Temperature failed." << endl;
|
---|
192 | return 2;
|
---|
193 | }
|
---|
194 | TString avgtemp = g->GetN()>0 ? Form("%5.1f", g->GetMean(2)) : "NULL";
|
---|
195 |
|
---|
196 | g = (TGraph*)arr.FindObjectInCanvas("WindSpeed", "TGraph", "MHWeather");
|
---|
197 | if (!g)
|
---|
198 | {
|
---|
199 | cout << "WARNING - Reading of WindSpeed failed." << endl;
|
---|
200 | return 2;
|
---|
201 | }
|
---|
202 | TString avgwind = g->GetN()>0 ? Form("%5.1f", g->GetMean(2)) : "NULL";
|
---|
203 |
|
---|
204 | g = (TGraph*)arr.FindObjectInCanvas("Cloudiness", "TGraph", "MHWeather");
|
---|
205 | if (!g)
|
---|
206 | cout << "WARNING - Reading of Cloudiness failed." << endl;
|
---|
207 | TString avgclouds = g ? Form("%5.1f", g->GetMean(2)) : "NULL";
|
---|
208 | TString rmsclouds = g ? Form("%5.1f", g->GetRMS(2)) : "NULL";
|
---|
209 |
|
---|
210 | g = (TGraph*)arr.FindObjectInCanvas("TempSky", "TGraph", "MHWeather");
|
---|
211 | if (!g)
|
---|
212 | cout << "WARNING - Reading of TempSky failed." << endl;
|
---|
213 | TString avgsky = g ? Form("%5.1f", g->GetMean(2)+200) : "NULL";
|
---|
214 |
|
---|
215 |
|
---|
216 | g = (TGraph*)arr.FindObjectInCanvas("NumStars", "TGraph", "MHPointing");
|
---|
217 | if (!g)
|
---|
218 | cout << "WARNING - Reading of NumStars failed." << endl;
|
---|
219 |
|
---|
220 | TString numstarsmed = g ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
|
---|
221 | TString numstarsrms = g ? Form("%5.1f", g->GetRMS(2)) : "NULL";
|
---|
222 |
|
---|
223 | g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
|
---|
224 | if (!g)
|
---|
225 | {
|
---|
226 | cout << "WARNING - Reading of NumStarsCor failed." << endl;
|
---|
227 | // return 2;
|
---|
228 | }
|
---|
229 |
|
---|
230 | TString numcorsmed = g ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
|
---|
231 | TString numcorsrms = g ? Form("%5.1f", g->GetRMS(2)) : "NULL";
|
---|
232 |
|
---|
233 | g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
|
---|
234 | if (!g)
|
---|
235 | {
|
---|
236 | cout << "WARNING - Reading of SkyBrightness failed." << endl;
|
---|
237 | // return 2;
|
---|
238 | }
|
---|
239 |
|
---|
240 | TString skybrightnessmed = g ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
|
---|
241 | TString skybrightnessrms = g ? Form("%5.1f", g->GetRMS(2)) : "NULL";
|
---|
242 |
|
---|
243 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
244 | if (sequence.IsNull())
|
---|
245 | {
|
---|
246 | cout << "WARNING - Could not determine sequence# from filename: " << fname << endl;
|
---|
247 | return 2;
|
---|
248 | }
|
---|
249 |
|
---|
250 | Int_t seq = atoi(sequence.Data()+5);
|
---|
251 |
|
---|
252 | cout << "Sequence #" << seq << endl;
|
---|
253 | cout << " Inhomogeneity " << inhomogen << endl;
|
---|
254 | cout << " PSF [mm] " << PSF << endl;
|
---|
255 | cout << " Island Quality " << islands << endl;
|
---|
256 | cout << " Ratio [%] " << ratio << endl;
|
---|
257 | cout << " Muon Number " << num << endl;
|
---|
258 | cout << " EffOnTime [s] " << effontime << endl;
|
---|
259 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
---|
260 | cout << " # of Events (w/o sparks) " << numevents << endl;
|
---|
261 | cout << " # of Sparks " << numsparks << endl;
|
---|
262 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
---|
263 | cout << " Rate of sparks [Hz] " << sparkrate << endl;
|
---|
264 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
---|
265 | cout << " Average Humidity [%] " << avghum << endl;
|
---|
266 | cout << " Average WindSpeed [km/h] " << avgwind << endl;
|
---|
267 | cout << " Average Temp [°C] " << avgtemp << endl;
|
---|
268 | cout << " Average Sky Temp [K] " << avgsky << endl;
|
---|
269 | cout << " Cloundiness [%] " << avgclouds << " +/- " << rmsclouds << endl;
|
---|
270 | cout << " Number of Stars " << numstarsmed << " +/- " << numstarsrms << endl;
|
---|
271 | cout << " Number of cor. Stars " << numcorsmed << " +/- " << numcorsrms << endl;
|
---|
272 | cout << " Skybrightness " << skybrightnessmed << " +/- " << skybrightnessrms << endl;
|
---|
273 |
|
---|
274 | TString vars = Form(" fMeanNumberIslands=%s,"
|
---|
275 | " fRatio=%s,"
|
---|
276 | " fMuonNumber=%d,"
|
---|
277 | " fEffOnTime=%d,"
|
---|
278 | " fMuonRate=%s,"
|
---|
279 | " fPSF=%s,"
|
---|
280 | " fDataRate=%d,"
|
---|
281 | " fSparkRate=%s,"
|
---|
282 | " fMaxHumidity=%s,"
|
---|
283 | " fAvgHumidity=%s, "
|
---|
284 | " fAvgTemperature=%s,"
|
---|
285 | " fAvgWindSpeed=%s,"
|
---|
286 | " fAvgTempSky=%s,"
|
---|
287 | " fAvgCloudiness=%s, "
|
---|
288 | " fRmsCloudiness=%s, "
|
---|
289 | " fNumStarsMed=%s,"
|
---|
290 | " fNumStarsRMS=%s,"
|
---|
291 | " fNumStarsCorMed=%s,"
|
---|
292 | " fNumStarsCorRMS=%s,"
|
---|
293 | " fBrightnessMed=%s,"
|
---|
294 | " fBrightnessRMS=%s,"
|
---|
295 | " fInhomogeneity=%s ",
|
---|
296 | islands.Data(), ratio.Data(),
|
---|
297 | num, effontime,
|
---|
298 | muonrate.Data(), PSF.Data(),
|
---|
299 | datarate, sparkrate.Data(), maxhum.Data(),
|
---|
300 | avghum.Data(), avgtemp.Data(), avgwind.Data(),
|
---|
301 | avgsky.Data(), avgclouds.Data(), rmsclouds.Data(),
|
---|
302 | numstarsmed.Data(), numstarsrms.Data(),
|
---|
303 | numcorsmed.Data(), numcorsrms.Data(),
|
---|
304 | skybrightnessmed.Data(), skybrightnessrms.Data(),
|
---|
305 | inhomogen.Data());
|
---|
306 |
|
---|
307 | return serv.InsertUpdate("Star", "fSequenceFirst", Form("%d", seq), vars);
|
---|
308 | }
|
---|
309 |
|
---|
310 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
311 | {
|
---|
312 | TEnv env("sql.rc");
|
---|
313 |
|
---|
314 | MSQLMagic serv(env);
|
---|
315 | if (!serv.IsConnected())
|
---|
316 | {
|
---|
317 | cout << "ERROR - Connection to database failed." << endl;
|
---|
318 | return 0;
|
---|
319 | }
|
---|
320 |
|
---|
321 | cout << "fillstar" << endl;
|
---|
322 | cout << "--------" << endl;
|
---|
323 | cout << endl;
|
---|
324 | cout << "Connected to " << serv.GetName() << endl;
|
---|
325 | cout << "File: " << fname << endl;
|
---|
326 | cout << endl;
|
---|
327 |
|
---|
328 | serv.SetIsDummy(dummy);
|
---|
329 |
|
---|
330 | return Process(serv, fname);
|
---|
331 | }
|
---|