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

Last change on this file since 8931 was 8931, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 10.8 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
186 Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
187 TString maxhum = Form("%5.1f", max);
188
189 g = (TGraph*)arr.FindObjectInCanvas("Temperature", "TGraph", "MHWeather");
190 if (!g)
191 {
192 cout << "WARNING - Reading of Temperature failed." << endl;
193 return 2;
194 }
195
196 Double_t temp = g->GetMean(2);
197 TString avgtemp = Form("%5.1f", temp);
198
199 g = (TGraph*)arr.FindObjectInCanvas("WindSpeed", "TGraph", "MHWeather");
200 if (!g)
201 {
202 cout << "WARNING - Reading of WindSpeed failed." << endl;
203 return 2;
204 }
205
206 Double_t wind = g->GetMean(2);
207 TString avgwind = Form("%5.1f", wind);
208
209
210 g = (TGraph*)arr.FindObjectInCanvas("NumStars", "TGraph", "MHPointing");
211 if (!g)
212 {
213 cout << "WARNING - Reading of NumStars failed." << endl;
214// return 2;
215 }
216
217 Double_t numstarmed = g ? TMath::Median(g->GetN(), g->GetY()) : -1;
218 TString numstarsmed = Form("%5.1f", numstarmed);
219 Double_t numstarrms = g ? g->GetRMS(2) : -1;
220 TString numstarsrms = Form("%5.1f", numstarrms);
221
222 g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
223 if (!g)
224 {
225 cout << "WARNING - Reading of NumStarsCor failed." << endl;
226// return 2;
227 }
228
229 Double_t numcormed = g ? TMath::Median(g->GetN(), g->GetY()) : -1;
230 TString numcorsmed = Form("%5.1f", numcormed);
231 Double_t numcorrms = g ? g->GetRMS(2) : -1;
232 TString numcorsrms = Form("%5.1f", numcorrms);
233
234 g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
235 if (!g)
236 {
237 cout << "WARNING - Reading of SkyBrightness failed." << endl;
238// return 2;
239 }
240
241 Double_t brightnessmed = g ? TMath::Median(g->GetN(), g->GetY()) : -1;
242 TString skybrightnessmed = Form("%5.1f", brightnessmed);
243 Double_t brightnessrms = g ? g->GetRMS(2) : -1;
244 TString skybrightnessrms = Form("%5.1f", brightnessrms);
245
246
247 TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
248 if (sequence.IsNull())
249 {
250 cout << "WARNING - Could not determine sequence# from filename: " << fname << endl;
251 return 2;
252 }
253
254 Int_t seq = atoi(sequence.Data()+5);
255
256 cout << "Sequence #" << seq << endl;
257 cout << " Inhomogeneity " << inhomogen << endl;
258 cout << " PSF [mm] " << PSF << endl;
259 cout << " Island Quality " << islands << endl;
260 cout << " Ratio [%] " << ratio << endl;
261 cout << " Muon Number " << num << endl;
262 cout << " EffOnTime [s] " << effontime << endl;
263 cout << " Muon Rate [Hz] " << muonrate << endl;
264 cout << " # of Events (w/o sparks) " << numevents << endl;
265 cout << " # of Sparks " << numsparks << endl;
266 cout << " Rate after ImgCl [Hz] " << datarate << endl;
267 cout << " Rate of sparks [Hz] " << sparkrate << endl;
268 cout << " Maximum Humidity [%] " << maxhum << endl;
269 cout << " Average Temp [°C] " << avgtemp << endl;
270 cout << " Average WindSpeed [km/h] " << avgwind << endl;
271 cout << " Number of Stars " << numstarsmed << " +/- " << numstarsrms << endl;
272 cout << " Number of cor. Stars " << numcormed << " +/- " << numcorrms << endl;
273 cout << " Skybrightness " << skybrightnessmed << " +/- " << skybrightnessrms << endl;
274
275 TString vars = Form(" fMeanNumberIslands=%s,"
276 " fRatio=%s,"
277 " fMuonNumber=%d,"
278 " fEffOnTime=%d,"
279 " fMuonRate=%s,"
280 " fPSF=%s,"
281 " fDataRate=%d,"
282 " fSparkRate=%s,"
283 " fMaxHumidity=%s,"
284 " fAvgTemperature=%s,"
285 " fAvgWindSpeed=%s,"
286 " fNumStarsMed=%s,"
287 " fNumStarsRMS=%s,"
288 " fNumStarsCorMed=%s,"
289 " fNumStarsCorRMS=%s,"
290 " fBrightnessMed=%s,"
291 " fBrightnessRMS=%s,"
292 " fInhomogeneity=%s ",
293 islands.Data(), ratio.Data(),
294 num, effontime,
295 muonrate.Data(), PSF.Data(),
296 datarate, sparkrate.Data(), maxhum.Data(),
297 avgtemp.Data(), avgwind.Data(),
298 numstarsmed.Data(), numstarsrms.Data(),
299 numcorsmed.Data(), numcorsrms.Data(),
300 skybrightnessmed.Data(), skybrightnessrms.Data(),
301 inhomogen.Data());
302
303 return serv.InsertUpdate("Star", "fSequenceFirst", Form("%d", seq), vars);
304}
305
306int fillstar(TString fname, Bool_t dummy=kTRUE)
307{
308 TEnv env("sql.rc");
309
310 MSQLMagic serv(env);
311 if (!serv.IsConnected())
312 {
313 cout << "ERROR - Connection to database failed." << endl;
314 return 0;
315 }
316
317 cout << "fillstar" << endl;
318 cout << "--------" << endl;
319 cout << endl;
320 cout << "Connected to " << serv.GetName() << endl;
321 cout << "File: " << fname << endl;
322 cout << endl;
323
324 serv.SetIsDummy(dummy);
325
326 return Process(serv, fname);
327}
Note: See TracBrowser for help on using the repository browser.