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

Last change on this file since 9067 was 9062, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 12.1 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 <TFile.h>
62#include <TH1.h>
63#include <TH2.h>
64#include <TGraph.h>
65
66#include "MSQLMagic.h"
67
68#include "MHCamera.h"
69#include "MHMuonPar.h"
70#include "MSequence.h"
71#include "MStatusArray.h"
72#include "MBadPixelsCam.h"
73#include "MHEffectiveOnTime.h"
74
75using namespace std;
76
77bool CheckGraph(const TGraph *g)
78{
79 return g && g->GetN()>0 && !(g->GetN()==1 && g->GetX()[0]==0);
80}
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 << "ERROR - 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 << "ERROR - 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 << "ERROR - 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 Float_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
131 TString inhomogen = Form("%5.1f", inhom);
132
133 Float_t mw = hmuon->GetMeanWidth();
134 Float_t psf = 70.205*mw - 28.055;
135 TString PSF = Form("%5.1f", (psf<0?0:psf));
136 Int_t num = (int)hmuon->GetEntries();
137
138 Float_t ratiodatamc = (hmuon->GetMeanSize()/7216)*100;
139 TString ratio = Form("%5.1f", ratiodatamc);
140
141 TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
142 if (!h)
143 {
144 cout << "ERROR - Reading of Islands failed." << endl;
145 return 2;
146 }
147
148 TString islands = Form("%6.2f", h->GetMean());
149
150 h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
151
152 Float_t effon = h ? h->Integral() : -1;
153
154 h = (TH1*)arr.FindObjectInCanvas("Cleaned;avg", "TH1D", "Cleaned");
155 if (!h)
156 {
157 cout << "ERROR - Reading of Cleaned;avg failed." << endl;
158 return 2;
159 }
160
161 if (effon<0)
162 effon = h->GetEntries()/100;
163
164 Float_t mrate = num/effon;
165 TString muonrate = Form("%6.2f", mrate<0?0:mrate);
166 TString effontime = Form("%.1f", effon);
167
168 Int_t numsparks = (int)hsparks->GetEntries();
169 Int_t numevents = (int)h->GetEntries() - numsparks;
170 Int_t datarate = TMath::Nint(numevents/effon);
171
172 TString sparkrate = Form("%5.2f", numsparks/effon);
173
174 if (sparkrate.Contains("inf"))
175 sparkrate="0.00";
176
177 MHEffectiveOnTime *ontm = (MHEffectiveOnTime*)arr.FindObjectInCanvas("MHEffectiveOnTime", "MHEffectiveOnTime", "EffOnTime");
178 TString totontime = ontm ? Form("%d", TMath::Nint(ontm->GetTotalTime())) : "NULL";
179 TString relontime = ontm ? Form("%.2f", effon/ontm->GetTotalTime()*100) : "NULL";
180
181 TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
182
183 TString maxhum = CheckGraph(g) ? Form("%5.1f", TMath::MaxElement(g->GetN(), g->GetY())) : "NULL";
184 TString avghum = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
185
186 g = (TGraph*)arr.FindObjectInCanvas("Temperature", "TGraph", "MHWeather");
187
188 TString avgtemp = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
189
190 g = (TGraph*)arr.FindObjectInCanvas("WindSpeed", "TGraph", "MHWeather");
191
192 TString avgwind = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
193
194 g = (TGraph*)arr.FindObjectInCanvas("Cloudiness", "TGraph", "MHWeather");
195 //if (!g)
196 // cout << "WARNING - Reading of Cloudiness failed." << endl;
197 TString avgclouds = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
198 TString rmsclouds = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
199
200 g = (TGraph*)arr.FindObjectInCanvas("TempSky", "TGraph", "MHWeather");
201 //if (!g)
202 // cout << "WARNING - Reading of TempSky failed." << endl;
203 TString avgsky = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)+200) : "NULL";
204
205
206 g = (TGraph*)arr.FindObjectInCanvas("NumStars", "TGraph", "MHPointing");
207 //if (!g)
208 // cout << "WARNING - Reading of NumStars failed." << endl;
209 TString numstarsmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
210 TString numstarsrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
211
212 g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
213 //if (!g)
214 // cout << "WARNING - Reading of NumStarsCor failed." << endl;
215 TString numcorsmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
216 TString numcorsrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
217
218 g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
219 //if (!g)
220 // cout << "WARNING - Reading of SkyBrightness failed." << endl;
221 TString skybrightnessmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
222 TString skybrightnessrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
223
224 MSequence seq;
225 if (seq.Read("sequence[0-9]{8}|MSequence")<=0)
226 {
227 cout << "ERROR - Could not find sequence in file: " << fname << endl;
228 return 2;
229 }
230 if (!seq.IsValid())
231 {
232 cout << "ERROR - Sequence read from file inavlid: " << fname << endl;
233 return 2;
234 }
235
236 cout << "Sequence M" << seq.GetTelescope() << ":" << seq.GetSequence() << endl;
237 cout << " Inhomogeneity " << inhomogen << endl;
238 cout << " PSF [mm] " << PSF << endl;
239 cout << " Island Quality " << islands << endl;
240 cout << " Ratio [%] " << ratio << endl;
241 cout << " Muon Number " << num << endl;
242 cout << " Eff. OnTime [s] " << effontime << endl;
243 cout << " Tot. OnTime [s] " << totontime << endl;
244 cout << " Rel. OnTime [%] " << relontime << endl;
245 cout << " Muon Rate [Hz] " << muonrate << endl;
246 cout << " # of Events (w/o sparks) " << numevents << endl;
247 cout << " # of Sparks " << numsparks << endl;
248 cout << " Rate after ImgCl [Hz] " << datarate << endl;
249 cout << " Rate of sparks [Hz] " << sparkrate << endl;
250 cout << " Maximum Humidity [%] " << maxhum << endl;
251 cout << " Average Humidity [%] " << avghum << endl;
252 cout << " Average WindSpeed [km/h] " << avgwind << endl;
253 cout << " Average Temp [" << UTF8::kDeg << "C] " << avgtemp << endl;
254 cout << " Average Sky Temp [K] " << avgsky << endl;
255 cout << " Cloundiness [%] " << avgclouds << " +/- " << rmsclouds << endl;
256 cout << " Number of Stars " << numstarsmed << " +/- " << numstarsrms << endl;
257 cout << " Number of cor. Stars " << numcorsmed << " +/- " << numcorsrms << endl;
258 cout << " Skybrightness " << skybrightnessmed << " +/- " << skybrightnessrms << endl;
259
260 TString vars = Form(" fSequenceFirst=%d, "
261 " fTelescopeNumber=%d, "
262 " fMeanNumberIslands=%s,"
263 " fRatio=%s,"
264 " fMuonNumber=%d,"
265 " fEffOnTime=%s,"
266 " fTotOnTime=%s,"
267 " fMuonRate=%s,"
268 " fPSF=%s,"
269 " fDataRate=%d,"
270 " fSparkRate=%s,"
271 " fMaxHumidity=%s,"
272 " fAvgHumidity=%s, "
273 " fAvgTemperature=%s,"
274 " fAvgWindSpeed=%s,"
275 " fAvgTempSky=%s,"
276 " fAvgCloudiness=%s, "
277 " fRmsCloudiness=%s, "
278 " fNumStarsMed=%s,"
279 " fNumStarsRMS=%s,"
280 " fNumStarsCorMed=%s,"
281 " fNumStarsCorRMS=%s,"
282 " fBrightnessMed=%s,"
283 " fBrightnessRMS=%s,"
284 " fInhomogeneity=%s ",
285 seq.GetSequence(), seq.GetTelescope(),
286 islands.Data(), ratio.Data(),
287 num, effontime.Data(), totontime.Data(),
288 muonrate.Data(), PSF.Data(),
289 datarate, sparkrate.Data(), maxhum.Data(),
290 avghum.Data(), avgtemp.Data(), avgwind.Data(),
291 avgsky.Data(), avgclouds.Data(), rmsclouds.Data(),
292 numstarsmed.Data(), numstarsrms.Data(),
293 numcorsmed.Data(), numcorsrms.Data(),
294 skybrightnessmed.Data(), skybrightnessrms.Data(),
295 inhomogen.Data());
296
297 TString where = Form("fSequenceFirst=%d AND fTelescopeNumber=%d",
298 seq.GetSequence(), seq.GetTelescope());
299
300 return serv.InsertUpdate("Star", vars, where) ? 1 : 2;
301}
302
303int fillstar(TString fname, Bool_t dummy=kTRUE)
304{
305 MSQLMagic serv("sql.rc");
306 if (!serv.IsConnected())
307 {
308 cout << "ERROR - Connection to database failed." << endl;
309 return 0;
310 }
311
312 cout << "fillstar" << endl;
313 cout << "--------" << endl;
314 cout << endl;
315 cout << "Connected to " << serv.GetName() << endl;
316 cout << "File: " << fname << endl;
317 cout << endl;
318
319 serv.SetIsDummy(dummy);
320
321 return Process(serv, fname);
322}
Note: See TracBrowser for help on using the repository browser.