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

Last change on this file since 8987 was 8987, 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
82bool CheckGraph(const TGraph *g)
83{
84 return g && g->GetN()>0 && !(g->GetN()==1 && g->GetX()[0]==0);
85}
86
87int Process(MSQLMagic &serv, TString fname)
88{
89 TFile file(fname, "READ");
90 if (!file.IsOpen())
91 {
92 cout << "ERROR - Could not find file " << fname << endl;
93 return 2;
94 }
95
96
97 MStatusArray arr;
98 if (arr.Read()<=0)
99 {
100 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
101 return 2;
102 }
103
104 MHCamera *hsparks = (MHCamera*)arr.FindObjectInCanvas("Sparks;avg", "MHCamera", "Sparks");
105 if (!hsparks)
106 {
107 cout << "WARNING - Reading of Sparks failed." << endl;
108 return 2;
109 }
110
111 TH2F *hcog = (TH2F*)arr.FindObjectInCanvas("Center", "TH2F", "MHHillas");
112 if (!hcog)
113 {
114 cout << "WARNING - Reading of MHHillas failed." << endl;
115 return 2;
116 }
117
118 MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
119 if (!hmuon)
120 {
121 cout << "WARNING - Reading of MHMuon failed." << endl;
122 return 2;
123 }
124
125 Double_t val[6];
126 for (int x=1; x<hcog->GetNbinsX(); x++)
127 for (int y=1; y<hcog->GetNbinsY(); y++)
128 {
129 Stat_t px = hcog->GetXaxis()->GetBinCenter(x);
130 Stat_t py = hcog->GetYaxis()->GetBinCenter(y);
131 Int_t i = (TMath::Nint(3*TMath::ATan2(px,py)/TMath::Pi())+6)%6;
132 val[i] += hcog->GetBinContent(x, y);
133 }
134
135 Double_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
136 inhom = TMath::Nint(inhom*10)/10.;
137 TString inhomogen = Form("%5.1f", inhom);
138
139 Float_t mw = hmuon->GetMeanWidth();
140 Float_t psf = 70.205*mw - 28.055;
141 TString PSF = Form("%5.1f", psf<0?0:psf);
142 Int_t num = (int)hmuon->GetEntries();
143
144 Float_t ratiodatamc = (hmuon->GetMeanSize()/7216)*100;
145 TString ratio = Form("%5.1f", ratiodatamc);
146
147 TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
148 if (!h)
149 {
150 cout << "WARNING - Reading of Islands failed." << endl;
151 return 2;
152 }
153
154 TString islands = Form("%6.2f", h->GetMean());
155
156 h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
157 if (!h)
158 {
159 cout << "WARNING - Reading of EffOnTheta failed." << endl;
160 return 2;
161 }
162
163 Float_t effon = h->Integral();
164 Float_t mrate = num/effon;
165 TString muonrate = Form("%6.2f", mrate<0?0:mrate);
166 Int_t effontime = TMath::Nint(effon);
167
168 h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
169 if (!h)
170 {
171 cout << "WARNING - Reading of ProjDeltaT failed." << endl;
172 return 2;
173 }
174
175 Int_t numsparks = (int)hsparks->GetEntries();
176 Int_t numevents = (int)h->GetEntries() - numsparks;
177 Int_t datarate = (int)(numevents/effon);
178
179 TString sparkrate = Form("%5.2f", numsparks/effon);
180
181 if (sparkrate.Contains("inf"))
182 sparkrate="0.00";
183
184 TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
185 if (!g)
186 {
187 cout << "WARNING - Reading of Humidity failed." << endl;
188 return 2;
189 }
190 TString maxhum = CheckGraph(g) ? Form("%5.1f", TMath::MaxElement(g->GetN(), g->GetY())) : "NULL";
191 TString avghum = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
192
193 g = (TGraph*)arr.FindObjectInCanvas("Temperature", "TGraph", "MHWeather");
194 if (!g)
195 {
196 cout << "WARNING - Reading of Temperature failed." << endl;
197 return 2;
198 }
199 TString avgtemp = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
200
201 g = (TGraph*)arr.FindObjectInCanvas("WindSpeed", "TGraph", "MHWeather");
202 if (!g)
203 {
204 cout << "WARNING - Reading of WindSpeed failed." << endl;
205 return 2;
206 }
207 TString avgwind = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
208
209 g = (TGraph*)arr.FindObjectInCanvas("Cloudiness", "TGraph", "MHWeather");
210 if (!g)
211 cout << "WARNING - Reading of Cloudiness failed." << endl;
212
213 TString avgclouds = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
214 TString rmsclouds = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
215
216 g = (TGraph*)arr.FindObjectInCanvas("TempSky", "TGraph", "MHWeather");
217 if (!g)
218 cout << "WARNING - Reading of TempSky failed." << endl;
219 TString avgsky = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)+200) : "NULL";
220
221
222 g = (TGraph*)arr.FindObjectInCanvas("NumStars", "TGraph", "MHPointing");
223 if (!g)
224 cout << "WARNING - Reading of NumStars failed." << endl;
225
226 TString numstarsmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
227 TString numstarsrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
228
229 g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
230 if (!g)
231 cout << "WARNING - Reading of NumStarsCor failed." << endl;
232
233 TString numcorsmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
234 TString numcorsrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
235
236 g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
237 if (!g)
238 cout << "WARNING - Reading of SkyBrightness failed." << endl;
239
240 TString skybrightnessmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
241 TString skybrightnessrms = CheckGraph(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 [" << UTF8::kDeg << "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
310int 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}
Note: See TracBrowser for help on using the repository browser.