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-2005
|
---|
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 star00000.root.
|
---|
33 | //
|
---|
34 | // Make sure, that database and password are corretly set in a resource
|
---|
35 | // file called sql.rc and the resource file is found.
|
---|
36 | //
|
---|
37 | // Returns 0 in case of failure and 1 in case of success.
|
---|
38 | //
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 | #include <iostream>
|
---|
41 | #include <iomanip>
|
---|
42 |
|
---|
43 | #include <TEnv.h>
|
---|
44 | #include <TRegexp.h>
|
---|
45 |
|
---|
46 | #include <TH1.h>
|
---|
47 | #include <TH2.h>
|
---|
48 | #include <TGraph.h>
|
---|
49 | #include <TProfile.h>
|
---|
50 | #include <TFile.h>
|
---|
51 | #include <TSQLResult.h>
|
---|
52 | #include <TSQLRow.h>
|
---|
53 |
|
---|
54 | #include "MSQLServer.h"
|
---|
55 |
|
---|
56 | #include "MHMuonPar.h"
|
---|
57 | #include "MStatusArray.h"
|
---|
58 | #include "MGeomCamMagic.h"
|
---|
59 | #include "MBadPixelsCam.h"
|
---|
60 |
|
---|
61 | using namespace std;
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Checks whether an entry is already existing
|
---|
66 | //
|
---|
67 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
68 | {
|
---|
69 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
70 | TSQLResult *res = serv.Query(query);
|
---|
71 | if (!res)
|
---|
72 | return kFALSE;
|
---|
73 |
|
---|
74 | TSQLRow *row;
|
---|
75 |
|
---|
76 | Bool_t rc = kFALSE;
|
---|
77 | while ((row=res->Next()))
|
---|
78 | {
|
---|
79 | if ((*row)[0])
|
---|
80 | {
|
---|
81 | rc = kTRUE;
|
---|
82 | break;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | delete res;
|
---|
87 |
|
---|
88 | return rc;
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
93 | {
|
---|
94 | TFile file(fname, "READ");
|
---|
95 | if (!file.IsOpen())
|
---|
96 | {
|
---|
97 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
98 | return 0;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | MStatusArray arr;
|
---|
103 | if (arr.Read()<=0)
|
---|
104 | {
|
---|
105 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
106 | return 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 | TH2F *hcog = (TH2F*)arr.FindObjectInCanvas("Center", "TH2F", "MHHillas");
|
---|
110 | if (!hcog)
|
---|
111 | {
|
---|
112 | cout << "WARNING - Reading of MHHillas failed." << endl;
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 |
|
---|
116 | MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
|
---|
117 | if (!hmuon)
|
---|
118 | {
|
---|
119 | cout << "WARNING - Reading of MHMuon failed." << endl;
|
---|
120 | return 0;
|
---|
121 | }
|
---|
122 |
|
---|
123 | Double_t val[6];
|
---|
124 | for (int x=1; x<hcog->GetNbinsX(); x++)
|
---|
125 | for (int y=1; y<hcog->GetNbinsY(); y++)
|
---|
126 | {
|
---|
127 | Stat_t px = hcog->GetXaxis()->GetBinCenter(x);
|
---|
128 | Stat_t py = hcog->GetYaxis()->GetBinCenter(y);
|
---|
129 | Int_t i = (TMath::Nint(3*TMath::ATan2(px,py)/TMath::Pi())+6)%6;
|
---|
130 | val[i] += hcog->GetBinContent(x, y);
|
---|
131 | }
|
---|
132 |
|
---|
133 | Double_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
|
---|
134 | inhom = TMath::Nint(inhom*10)/10.;
|
---|
135 | TString inhomogen = Form("%5.1f", inhom);
|
---|
136 |
|
---|
137 | Float_t mw = hmuon->GetMeanWidth();
|
---|
138 | Float_t psf = 51.505292*mw - 31.147126;
|
---|
139 | psf = TMath::Nint(psf*10)/10.;
|
---|
140 | TString PSF = Form("%5.1f", psf);
|
---|
141 | Int_t num = (int)hmuon->GetEntries();
|
---|
142 |
|
---|
143 | Float_t ratiodatamc = (hmuon->GetMeanSize()/9340.)*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 0;
|
---|
151 | }
|
---|
152 |
|
---|
153 | Float_t quality = h->GetMean();
|
---|
154 | quality = TMath::Nint(quality*100)/100.;
|
---|
155 | TString islands = Form("%6.2f", quality);
|
---|
156 |
|
---|
157 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
---|
158 | if (!h)
|
---|
159 | {
|
---|
160 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
---|
161 | return 0;
|
---|
162 | }
|
---|
163 |
|
---|
164 | Float_t effon = h->Integral();
|
---|
165 | Float_t mrate = num/effon;
|
---|
166 | mrate = TMath::Nint(mrate*100)/100.;
|
---|
167 | TString muonrate = Form("%6.2f", mrate);
|
---|
168 | Int_t effontime = TMath::Nint(effon);
|
---|
169 |
|
---|
170 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
---|
171 | if (!h)
|
---|
172 | {
|
---|
173 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
---|
174 | return 0;
|
---|
175 | }
|
---|
176 |
|
---|
177 | Int_t numevents = (int)h->GetEntries();
|
---|
178 | Int_t datarate = (int)(numevents/effon);
|
---|
179 |
|
---|
180 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
---|
181 | if (!g)
|
---|
182 | {
|
---|
183 | cout << "WARNING - Reading of Humidity failed." << endl;
|
---|
184 | return 0;
|
---|
185 | }
|
---|
186 |
|
---|
187 | Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
|
---|
188 | TString maxhum = Form("%6.1f", max);
|
---|
189 |
|
---|
190 |
|
---|
191 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
192 | if (sequence.IsNull())
|
---|
193 | {
|
---|
194 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
195 | return 0;
|
---|
196 | }
|
---|
197 |
|
---|
198 | Int_t seq = atoi(sequence.Data()+5);
|
---|
199 |
|
---|
200 | cout << "Sequence #" << seq << endl;
|
---|
201 | cout << " Inhomogeneity " << inhomogen << endl;
|
---|
202 | cout << " PSF [mm] " << PSF << endl;
|
---|
203 | cout << " Island Quality " << islands << endl;
|
---|
204 | cout << " Ratio [%] " << ratio << endl;
|
---|
205 | cout << " Muon Number " << num << endl;
|
---|
206 | cout << " EffOnTime [s] " << effontime << endl;
|
---|
207 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
---|
208 | cout << " # of Events " << numevents << endl;
|
---|
209 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
---|
210 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
---|
211 |
|
---|
212 | TString query;
|
---|
213 | if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
|
---|
214 | {
|
---|
215 | query = Form("INSERT Star SET"
|
---|
216 | " fSequenceFirst=%d,"
|
---|
217 | " fMeanNumberIslands=%s, "
|
---|
218 | " fRatio=%s, "
|
---|
219 | " fMuonNumber=%d, "
|
---|
220 | " fEffOnTime=%d, "
|
---|
221 | " fMuonRate=%s, "
|
---|
222 | " fPSF=%s, "
|
---|
223 | " fDataRate=%d, "
|
---|
224 | " fMaxHumidity=%s ,"
|
---|
225 | " fInhomogeneity=%s ",
|
---|
226 | seq, islands.Data(), ratio.Data(),
|
---|
227 | num, effontime,
|
---|
228 | muonrate.Data(), PSF.Data(),
|
---|
229 | datarate, maxhum.Data(),
|
---|
230 | inhomogen.Data());
|
---|
231 | }
|
---|
232 | else
|
---|
233 | {
|
---|
234 | query = Form("UPDATE Star SET"
|
---|
235 | " fMeanNumberIslands=%s, "
|
---|
236 | " fRatio=%s, "
|
---|
237 | " fMuonNumber=%d, "
|
---|
238 | " fEffOnTime=%d, "
|
---|
239 | " fMuonRate=%s, "
|
---|
240 | " fPSF=%s, "
|
---|
241 | " fDataRate=%d, "
|
---|
242 | " fMaxHumidity=%s, "
|
---|
243 | " fInhomogeneity=%s "
|
---|
244 | " WHERE fSequenceFirst=%d ",
|
---|
245 | islands.Data(), ratio.Data(),
|
---|
246 | num, effontime,
|
---|
247 | muonrate.Data(), PSF.Data(),
|
---|
248 | datarate, maxhum.Data(),
|
---|
249 | inhomogen.Data(), seq);
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (dummy)
|
---|
253 | return 0;
|
---|
254 |
|
---|
255 | TSQLResult *res = serv.Query(query);
|
---|
256 | if (!res)
|
---|
257 | {
|
---|
258 | cout << "ERROR - Query failed: " << query << endl;
|
---|
259 | return 0;
|
---|
260 | }
|
---|
261 |
|
---|
262 | return 1;
|
---|
263 | }
|
---|
264 |
|
---|
265 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
266 | {
|
---|
267 | TEnv env("sql.rc");
|
---|
268 |
|
---|
269 | MSQLServer serv(env);
|
---|
270 | if (!serv.IsConnected())
|
---|
271 | {
|
---|
272 | cout << "ERROR - Connection to database failed." << endl;
|
---|
273 | return 0;
|
---|
274 | }
|
---|
275 |
|
---|
276 | cout << "fillstar" << endl;
|
---|
277 | cout << "---------" << endl;
|
---|
278 | cout << endl;
|
---|
279 | cout << "Connected to " << serv.GetName() << endl;
|
---|
280 | cout << "File: " << fname << endl;
|
---|
281 | cout << endl;
|
---|
282 |
|
---|
283 | return Process(serv, fname, dummy);
|
---|
284 | }
|
---|