source: trunk/MagicSoft/Mars/datacenter/macros/fillstar.C@ 8959

Last change on this file since 8959 was 8959, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 11.7 KB
Line 
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
80using namespace std;
81
82int 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 && g->GetN()>0 ? Form("%5.1f", g->GetMean(2)) : "NULL";
208 TString rmsclouds = g && g->GetN()>0 ? 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 && g->GetN()>0 ? 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 && g->GetN()>0 ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
221 TString numstarsrms = g && g->GetN()>0 ? Form("%5.1f", g->GetRMS(2)) : "NULL";
222
223 g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
224 if (!g)
225 cout << "WARNING - Reading of NumStarsCor failed." << endl;
226
227 TString numcorsmed = g && g->GetN()>0 ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
228 TString numcorsrms = g && g->GetN()>0 ? Form("%5.1f", g->GetRMS(2)) : "NULL";
229
230 g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
231 if (!g)
232 cout << "WARNING - Reading of SkyBrightness failed." << endl;
233
234 TString skybrightnessmed = g && g->GetN()>0 ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
235 TString skybrightnessrms = g && g->GetN()>0 ? Form("%5.1f", g->GetRMS(2)) : "NULL";
236
237 TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
238 if (sequence.IsNull())
239 {
240 cout << "WARNING - Could not determine sequence# from filename: " << fname << endl;
241 return 2;
242 }
243
244 Int_t seq = atoi(sequence.Data()+5);
245
246 cout << "Sequence #" << seq << endl;
247 cout << " Inhomogeneity " << inhomogen << endl;
248 cout << " PSF [mm] " << PSF << endl;
249 cout << " Island Quality " << islands << endl;
250 cout << " Ratio [%] " << ratio << endl;
251 cout << " Muon Number " << num << endl;
252 cout << " EffOnTime [s] " << effontime << endl;
253 cout << " Muon Rate [Hz] " << muonrate << endl;
254 cout << " # of Events (w/o sparks) " << numevents << endl;
255 cout << " # of Sparks " << numsparks << endl;
256 cout << " Rate after ImgCl [Hz] " << datarate << endl;
257 cout << " Rate of sparks [Hz] " << sparkrate << endl;
258 cout << " Maximum Humidity [%] " << maxhum << endl;
259 cout << " Average Humidity [%] " << avghum << endl;
260 cout << " Average WindSpeed [km/h] " << avgwind << endl;
261 cout << " Average Temp [" << UTF8::kDeg << "C] " << avgtemp << endl;
262 cout << " Average Sky Temp [K] " << avgsky << endl;
263 cout << " Cloundiness [%] " << avgclouds << " +/- " << rmsclouds << endl;
264 cout << " Number of Stars " << numstarsmed << " +/- " << numstarsrms << endl;
265 cout << " Number of cor. Stars " << numcorsmed << " +/- " << numcorsrms << endl;
266 cout << " Skybrightness " << skybrightnessmed << " +/- " << skybrightnessrms << endl;
267
268 TString vars = Form(" fMeanNumberIslands=%s,"
269 " fRatio=%s,"
270 " fMuonNumber=%d,"
271 " fEffOnTime=%d,"
272 " fMuonRate=%s,"
273 " fPSF=%s,"
274 " fDataRate=%d,"
275 " fSparkRate=%s,"
276 " fMaxHumidity=%s,"
277 " fAvgHumidity=%s, "
278 " fAvgTemperature=%s,"
279 " fAvgWindSpeed=%s,"
280 " fAvgTempSky=%s,"
281 " fAvgCloudiness=%s, "
282 " fRmsCloudiness=%s, "
283 " fNumStarsMed=%s,"
284 " fNumStarsRMS=%s,"
285 " fNumStarsCorMed=%s,"
286 " fNumStarsCorRMS=%s,"
287 " fBrightnessMed=%s,"
288 " fBrightnessRMS=%s,"
289 " fInhomogeneity=%s ",
290 islands.Data(), ratio.Data(),
291 num, effontime,
292 muonrate.Data(), PSF.Data(),
293 datarate, sparkrate.Data(), maxhum.Data(),
294 avghum.Data(), avgtemp.Data(), avgwind.Data(),
295 avgsky.Data(), avgclouds.Data(), rmsclouds.Data(),
296 numstarsmed.Data(), numstarsrms.Data(),
297 numcorsmed.Data(), numcorsrms.Data(),
298 skybrightnessmed.Data(), skybrightnessrms.Data(),
299 inhomogen.Data());
300
301 return serv.InsertUpdate("Star", "fSequenceFirst", Form("%d", seq), vars);
302}
303
304int fillstar(TString fname, Bool_t dummy=kTRUE)
305{
306 TEnv env("sql.rc");
307
308 MSQLMagic serv(env);
309 if (!serv.IsConnected())
310 {
311 cout << "ERROR - Connection to database failed." << endl;
312 return 0;
313 }
314
315 cout << "fillstar" << endl;
316 cout << "--------" << endl;
317 cout << endl;
318 cout << "Connected to " << serv.GetName() << endl;
319 cout << "File: " << fname << endl;
320 cout << endl;
321
322 serv.SetIsDummy(dummy);
323
324 return Process(serv, fname);
325}
Note: See TracBrowser for help on using the repository browser.