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