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 <TGraph.h>
|
---|
48 | #include <TProfile.h>
|
---|
49 | #include <TFile.h>
|
---|
50 | #include <TSQLResult.h>
|
---|
51 | #include <TSQLRow.h>
|
---|
52 |
|
---|
53 | #include "MSQLServer.h"
|
---|
54 |
|
---|
55 | #include "MHMuonPar.h"
|
---|
56 | #include "MStatusArray.h"
|
---|
57 | #include "MGeomCamMagic.h"
|
---|
58 | #include "MBadPixelsCam.h"
|
---|
59 |
|
---|
60 | using namespace std;
|
---|
61 |
|
---|
62 | // --------------------------------------------------------------------------
|
---|
63 | //
|
---|
64 | // Checks whether an entry is already existing
|
---|
65 | //
|
---|
66 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
67 | {
|
---|
68 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
69 | TSQLResult *res = serv.Query(query);
|
---|
70 | if (!res)
|
---|
71 | return kFALSE;
|
---|
72 |
|
---|
73 | TSQLRow *row;
|
---|
74 |
|
---|
75 | Bool_t rc = kFALSE;
|
---|
76 | while ((row=res->Next()))
|
---|
77 | {
|
---|
78 | if ((*row)[0])
|
---|
79 | {
|
---|
80 | rc = kTRUE;
|
---|
81 | break;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | delete res;
|
---|
86 |
|
---|
87 | return rc;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
92 | {
|
---|
93 | TFile file(fname, "READ");
|
---|
94 | if (!file.IsOpen())
|
---|
95 | {
|
---|
96 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
97 | return 0;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | MStatusArray arr;
|
---|
102 | if (arr.Read()<=0)
|
---|
103 | {
|
---|
104 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
105 | return 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
|
---|
109 | if (!hmuon)
|
---|
110 | {
|
---|
111 | cout << "WARNING - Reading of MHMuon failed." << endl;
|
---|
112 | return 0;
|
---|
113 | }
|
---|
114 |
|
---|
115 | Float_t psf = (hmuon->GetMeanWidth() - 0.04816)/0.001294;
|
---|
116 | psf = TMath::Nint(psf*10)/10.;
|
---|
117 | TString PSF = Form("%5.1f", psf);
|
---|
118 | Int_t num = (int)hmuon->GetEntries();
|
---|
119 |
|
---|
120 | Float_t integralmc = -1.43*psf + 1035;
|
---|
121 | Float_t ratiodatamc = (hmuon->GetMeanSize()/integralmc)*100;
|
---|
122 | TString ratio = Form("%5.1f", ratiodatamc);
|
---|
123 |
|
---|
124 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
---|
125 | if (!h)
|
---|
126 | {
|
---|
127 | cout << "WARNING - Reading of Islands failed." << endl;
|
---|
128 | return 0;
|
---|
129 | }
|
---|
130 |
|
---|
131 | Float_t quality = h->GetMean();
|
---|
132 | quality = TMath::Nint(quality*10)/10.;
|
---|
133 | TString islands = Form("%6.2f", quality);
|
---|
134 |
|
---|
135 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
---|
136 | if (!h)
|
---|
137 | {
|
---|
138 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
---|
139 | return 0;
|
---|
140 | }
|
---|
141 |
|
---|
142 | Float_t effon = h->Integral();
|
---|
143 | Float_t mrate = num/effon;
|
---|
144 | mrate = TMath::Nint(mrate*100)/100.;
|
---|
145 | TString muonrate = Form("%6.2f", mrate);
|
---|
146 | Int_t effontime = TMath::Nint(effon);
|
---|
147 |
|
---|
148 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
---|
149 | if (!h)
|
---|
150 | {
|
---|
151 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
---|
152 | return 0;
|
---|
153 | }
|
---|
154 |
|
---|
155 | Int_t numevents = (int)h->GetEntries();
|
---|
156 | Int_t datarate = (int)(numevents/effon);
|
---|
157 |
|
---|
158 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
---|
159 | if (!g)
|
---|
160 | {
|
---|
161 | cout << "WARNING - Reading of Humidity failed." << endl;
|
---|
162 | return 0;
|
---|
163 | }
|
---|
164 |
|
---|
165 | Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
|
---|
166 | TString maxhum = Form("%6.1f", max);
|
---|
167 |
|
---|
168 |
|
---|
169 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
170 | if (sequence.IsNull())
|
---|
171 | {
|
---|
172 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
173 | return 0;
|
---|
174 | }
|
---|
175 |
|
---|
176 | Int_t seq = atoi(sequence.Data()+5);
|
---|
177 |
|
---|
178 | cout << "Sequence #" << seq << endl;
|
---|
179 | cout << " PSF [mm] " << PSF << endl;
|
---|
180 | cout << " Island Quality " << islands << endl;
|
---|
181 | cout << " Ratio [%] " << ratio << endl;
|
---|
182 | cout << " Muon Number " << num << endl;
|
---|
183 | cout << " EffOnTime [s] " << effontime << endl;
|
---|
184 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
---|
185 | cout << " # of Events " << numevents << endl;
|
---|
186 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
---|
187 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
---|
188 |
|
---|
189 | TString query;
|
---|
190 | if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
|
---|
191 | {
|
---|
192 | query = Form("INSERT Star SET"
|
---|
193 | " fSequenceFirst=%d,"
|
---|
194 | " fMeanNumberIslands=%s, "
|
---|
195 | " fRatio=%s, "
|
---|
196 | " fMuonNumber=%d, "
|
---|
197 | " fEffOnTime=%d, "
|
---|
198 | " fMuonRate=%s, "
|
---|
199 | " fPSF=%s, "
|
---|
200 | " fDataRate=%d, "
|
---|
201 | " fMaxHumidity=%s ",
|
---|
202 | seq, islands.Data(), ratio.Data(),
|
---|
203 | num, effontime,
|
---|
204 | muonrate.Data(), PSF.Data(),
|
---|
205 | datarate, maxhum.Data());
|
---|
206 | }
|
---|
207 | else
|
---|
208 | {
|
---|
209 | query = Form("UPDATE Star SET"
|
---|
210 | " fMeanNumberIslands=%s, "
|
---|
211 | " fRatio=%s, "
|
---|
212 | " fMuonNumber=%d, "
|
---|
213 | " fEffOnTime=%d, "
|
---|
214 | " fMuonRate=%s, "
|
---|
215 | " fPSF=%s, "
|
---|
216 | " fDataRate=%d, "
|
---|
217 | " fMaxHumidity=%s "
|
---|
218 | " WHERE fSequenceFirst=%d ",
|
---|
219 | islands.Data(), ratio.Data(),
|
---|
220 | num, effontime,
|
---|
221 | muonrate.Data(), PSF.Data(),
|
---|
222 | datarate, maxhum.Data(), seq);
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (dummy)
|
---|
226 | return 0;
|
---|
227 |
|
---|
228 | TSQLResult *res = serv.Query(query);
|
---|
229 | if (!res)
|
---|
230 | {
|
---|
231 | cout << "ERROR - Query failed: " << query << endl;
|
---|
232 | return 0;
|
---|
233 | }
|
---|
234 |
|
---|
235 | return 1;
|
---|
236 | }
|
---|
237 |
|
---|
238 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
239 | {
|
---|
240 | TEnv env("sql.rc");
|
---|
241 |
|
---|
242 | MSQLServer serv(env);
|
---|
243 | if (!serv.IsConnected())
|
---|
244 | {
|
---|
245 | cout << "ERROR - Connection to database failed." << endl;
|
---|
246 | return 0;
|
---|
247 | }
|
---|
248 |
|
---|
249 | cout << "fillstar" << endl;
|
---|
250 | cout << "---------" << endl;
|
---|
251 | cout << endl;
|
---|
252 | cout << "Connected to " << serv.GetName() << endl;
|
---|
253 | cout << "File: " << fname << endl;
|
---|
254 | cout << endl;
|
---|
255 |
|
---|
256 | return Process(serv, fname, dummy);
|
---|
257 | }
|
---|