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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // fillcalib.C
|
---|
29 | // ===========
|
---|
30 | //
|
---|
31 | // This macro is used to read the calibartion-/callisto-output files.
|
---|
32 | // These files are automatically called calib00000.root.
|
---|
33 | //
|
---|
34 | // From this file the MBadPixelsCam and the MGeomCam is extracted. If
|
---|
35 | // the geometry isn't found MGeomCamMagic is used as a default.
|
---|
36 | //
|
---|
37 | // Usage:
|
---|
38 | // .x fillcalib.C("/data/MAGIC/Period014/calib00000.root", kTRUE)
|
---|
39 | //
|
---|
40 | // The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
|
---|
41 | // switched on and nothing will be written into the database. This is usefull
|
---|
42 | // for tests.
|
---|
43 | //
|
---|
44 | // The corresponding sequence number is extracted from the filename...
|
---|
45 | // FIXME: MSeqeuence should be stored in the calib-file?
|
---|
46 | //
|
---|
47 | // The macro can also be run without ACLiC but this is a lot slower...
|
---|
48 | //
|
---|
49 | // Remark: Running it from the commandline looks like this:
|
---|
50 | // root -q -l -b fillcalib.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillcalib.log
|
---|
51 | //
|
---|
52 | // Make sure, that database and password are corretly set in a resource
|
---|
53 | // file called sql.rc and the resource file is found.
|
---|
54 | //
|
---|
55 | // Returns 0 in case of failure and 1 in case of success.
|
---|
56 | //
|
---|
57 | /////////////////////////////////////////////////////////////////////////////
|
---|
58 | #include <iostream>
|
---|
59 |
|
---|
60 | #include <TEnv.h>
|
---|
61 | #include <TRegexp.h>
|
---|
62 |
|
---|
63 | #include <TH1.h>
|
---|
64 |
|
---|
65 | #include <TFile.h>
|
---|
66 | #include <TSQLResult.h>
|
---|
67 | #include <TSQLRow.h>
|
---|
68 |
|
---|
69 | #include "MSQLServer.h"
|
---|
70 |
|
---|
71 | #include "MStatusArray.h"
|
---|
72 | #include "MHCamera.h"
|
---|
73 | #include "MGeomCamMagic.h"
|
---|
74 | #include "MBadPixelsCam.h"
|
---|
75 |
|
---|
76 | using namespace std;
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Checks whether an entry is already existing
|
---|
81 | //
|
---|
82 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
83 | {
|
---|
84 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
85 | TSQLResult *res = serv.Query(query);
|
---|
86 | if (!res)
|
---|
87 | return kFALSE;
|
---|
88 |
|
---|
89 | TSQLRow *row;
|
---|
90 |
|
---|
91 | Bool_t rc = kFALSE;
|
---|
92 | while ((row=res->Next()))
|
---|
93 | {
|
---|
94 | if ((*row)[0])
|
---|
95 | {
|
---|
96 | rc = kTRUE;
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | delete res;
|
---|
102 |
|
---|
103 | return rc;
|
---|
104 | }
|
---|
105 |
|
---|
106 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
107 | {
|
---|
108 | MBadPixelsCam badpix;
|
---|
109 |
|
---|
110 | TFile file(fname, "READ");
|
---|
111 | if (badpix.Read("MBadPixelsCam")<=0)
|
---|
112 | {
|
---|
113 | cout << "ERROR - Reading of MBadPixelsCam failed." << endl;
|
---|
114 | return 0;
|
---|
115 | }
|
---|
116 |
|
---|
117 | MGeomCamMagic def;
|
---|
118 |
|
---|
119 | MGeomCam *geom = (MGeomCam*)file.Get("MGeomCam");
|
---|
120 | if (!geom)
|
---|
121 | {
|
---|
122 | cout << "WARNING - Reading of MGeomCam failed... using default <MGeomCamMagic>" << endl;
|
---|
123 | geom = &def;
|
---|
124 | }
|
---|
125 |
|
---|
126 | cout << "Camera Geometry: " << geom->ClassName() << endl;
|
---|
127 |
|
---|
128 | const Short_t unsin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 0);
|
---|
129 | const Short_t unsout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 1);
|
---|
130 |
|
---|
131 | const Short_t unrin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 0);
|
---|
132 | const Short_t unrout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 1);
|
---|
133 |
|
---|
134 | const Short_t isoin = badpix.GetNumIsolated(*geom, 0);
|
---|
135 | const Short_t isoout = badpix.GetNumIsolated(*geom, 1);
|
---|
136 |
|
---|
137 | const Short_t clumax = badpix.GetNumMaxCluster(*geom);
|
---|
138 |
|
---|
139 | if (unsin<0 || unsout<0 || unrin<0 || unrout<0 || isoin<0 || isoout<0 || clumax<0)
|
---|
140 | return 0;
|
---|
141 |
|
---|
142 | // MHCamera hist(geom);
|
---|
143 | // hist.SetCamContent(badpix, 1);
|
---|
144 | // hist.DrawCopy();
|
---|
145 | // hist.SetCamContent(badpix, 3);
|
---|
146 | // hist.DrawCopy();
|
---|
147 |
|
---|
148 | //Getting values from the status display
|
---|
149 | MStatusArray arr;
|
---|
150 | if (arr.Read()<=0)
|
---|
151 | return 0;
|
---|
152 |
|
---|
153 | TH1 *h;
|
---|
154 |
|
---|
155 | //getting the mean and rms from the arrival time (inner cam)
|
---|
156 | h = (TH1*)arr.FindObjectInCanvas("HRelTimeHiGainArea0", "TH1F", "Time");
|
---|
157 | if (!h)
|
---|
158 | {
|
---|
159 | cout << "WARNING - Could not find histogram HRelTimeHiGainArea0." << endl;
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 |
|
---|
163 | Float_t meani = h->GetMean();
|
---|
164 | Float_t rmsi = h->GetRMS();
|
---|
165 | meani = TMath::Nint(meani*10)/10.;
|
---|
166 | rmsi = TMath::Nint(rmsi*10)/10.;
|
---|
167 | TString meaninner = Form("%4.1f", meani);
|
---|
168 | TString rmsinner = Form("%4.1f", rmsi);
|
---|
169 |
|
---|
170 | cout << "bla: " << meaninner << ", " << rmsinner << endl;
|
---|
171 | cout << "bla: " << meaninner.Data() << ", " << rmsinner.Data() << endl;
|
---|
172 |
|
---|
173 |
|
---|
174 | //getting the mean and rms from the arrival time (outer cam)
|
---|
175 | h = (TH1*)arr.FindObjectInCanvas("HRelTimeHiGainArea1", "TH1F", "Time");
|
---|
176 | if (!h)
|
---|
177 | {
|
---|
178 | cout << "WARNING - Could not find histogram HRelTimeHiGainArea1." << endl;
|
---|
179 | return 0;
|
---|
180 | }
|
---|
181 |
|
---|
182 | Float_t meano = h->GetMean();
|
---|
183 | Float_t rmso = h->GetRMS();
|
---|
184 | meano = TMath::Nint(meano*10)/10.;
|
---|
185 | rmso = TMath::Nint(rmso*10)/10.;
|
---|
186 | TString meanouter = Form("%4.1f", meano);
|
---|
187 | TString rmsouter = Form("%4.1f", rmso);
|
---|
188 |
|
---|
189 |
|
---|
190 | //Getting conversion factors
|
---|
191 | MHCamera *c = (MHCamera*)arr.FindObjectInCanvas("TotalConv", "MHCamera", "Conversion");
|
---|
192 | if (!c)
|
---|
193 | {
|
---|
194 | cout << "WARNING - Could not find MHCamera TotalConv." << endl;
|
---|
195 | return 0;
|
---|
196 | }
|
---|
197 |
|
---|
198 | TArrayI inner(1), outer(1);
|
---|
199 | inner[0] = 0;
|
---|
200 | outer[0] = 1;
|
---|
201 |
|
---|
202 | Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
|
---|
203 |
|
---|
204 | Stat_t meanconvi = c->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
205 | Stat_t meanconvo = c->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
206 | meanconvi = TMath::Nint(meanconvi*10)/10.;
|
---|
207 | meanconvo = TMath::Nint(meanconvo*10)/10.;
|
---|
208 | TString meanconvinner=Form("%4.1f", meanconvi);
|
---|
209 | TString meanconvouter=Form("%4.1f", meanconvo);
|
---|
210 |
|
---|
211 |
|
---|
212 | //Getting sequ# from filename
|
---|
213 | TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
|
---|
214 | if (sequence.IsNull())
|
---|
215 | {
|
---|
216 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
217 | return 0;
|
---|
218 | }
|
---|
219 |
|
---|
220 | Int_t seq = atoi(sequence.Data()+5);
|
---|
221 |
|
---|
222 |
|
---|
223 | cout << "Sequence #" << seq << endl;
|
---|
224 | cout << " Unsuitable: (i/o) " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
|
---|
225 | cout << " Unreliable: (i/o) " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
|
---|
226 | cout << " Isolated: (i/o) " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
|
---|
227 | cout << " Max.Cluster: " << Form("%3d", (int)clumax) << endl; // Max Cluster
|
---|
228 | cout << " Arr Time inner: " << Form("%4.1f +- %4.1f", meani, rmsi) << endl;
|
---|
229 | cout << " Arr Time outer: " << Form("%4.1f +- %4.1f", meano, rmso) << endl;
|
---|
230 | cout << " Mean Conv inner: " << Form("%4.1f", meanconvi) << endl;
|
---|
231 | cout << " Mean Conv outer: " << Form("%4.1f", meanconvo) << endl;
|
---|
232 |
|
---|
233 | TString query;
|
---|
234 | if (!ExistStr(serv, "fSequenceFirst", "MyMagic.Calibration", seq))
|
---|
235 | {
|
---|
236 | query = Form("INSERT MyMagic.Calibration SET"
|
---|
237 | " fSequenceFirst=%d,"
|
---|
238 | " fUnsuitableInner=%d, "
|
---|
239 | " fUnsuitableOuter=%d, "
|
---|
240 | " fUnreliableInner=%d, "
|
---|
241 | " fUnreliableOuter=%d, "
|
---|
242 | " fIsolatedInner=%d, "
|
---|
243 | " fIsolatedOuter=%d, "
|
---|
244 | " fIsolatedMaxCluster=%d, ",
|
---|
245 | " fArrTimeMeanInner=%s, "
|
---|
246 | " fArrTimeRmsInner=%s, "
|
---|
247 | " fArrTimeMeanOuter=%s, "
|
---|
248 | " fArrTimeRmsOuter=%s, "
|
---|
249 | " fConvFactorInner=%s, "
|
---|
250 | " fConvFactorOuter=%s ",
|
---|
251 | seq, (int)unsin, (int)unsout, (int)unrin,
|
---|
252 | (int)unrout, (int)isoin, (int)isoout,
|
---|
253 | (int)clumax,
|
---|
254 | meaninner.Data(), rmsinner.Data(),
|
---|
255 | meanouter.Data(), rmsouter.Data(),
|
---|
256 | meanconvinner.Data(), meanconvouter.Data());
|
---|
257 | }
|
---|
258 | else
|
---|
259 | {
|
---|
260 | query = Form("UPDATE MyMagic.Calibration SET"
|
---|
261 | " fUnsuitableInner=%d, "
|
---|
262 | " fUnsuitableOuter=%d, "
|
---|
263 | " fUnreliableInner=%d, "
|
---|
264 | " fUnreliableOuter=%d, "
|
---|
265 | " fIsolatedInner=%d, "
|
---|
266 | " fIsolatedOuter=%d, "
|
---|
267 | " fIsolatedMaxCluster=%d, "
|
---|
268 | " fArrTimeMeanInner=%s, "
|
---|
269 | " fArrTimeRmsInner=%s, "
|
---|
270 | " fArrTimeMeanOuter=%s, "
|
---|
271 | " fArrTimeRmsOuter=%s, "
|
---|
272 | " fConvFactorInner=%s, "
|
---|
273 | " fConvFactorOuter=%s "
|
---|
274 | " WHERE fSequenceFirst=%d ",
|
---|
275 | (int)unsin, (int)unsout, (int)unrin,(int)unrout,
|
---|
276 | (int)isoin, (int)isoout, (int)clumax,
|
---|
277 | meaninner.Data(), rmsinner.Data(),
|
---|
278 | meanouter.Data(), rmsouter.Data(),
|
---|
279 | meanconvinner.Data(), meanconvouter.Data(),
|
---|
280 | seq);
|
---|
281 | }
|
---|
282 |
|
---|
283 | if (dummy)
|
---|
284 | return 0;
|
---|
285 |
|
---|
286 | TSQLResult *res = serv.Query(query);
|
---|
287 | if (!res)
|
---|
288 | {
|
---|
289 | cout << "ERROR - Query failed: " << query << endl;
|
---|
290 | return 0;
|
---|
291 | }
|
---|
292 | delete res;
|
---|
293 |
|
---|
294 | return 1;
|
---|
295 | }
|
---|
296 |
|
---|
297 | int fillcalib(TString fname, Bool_t dummy=kTRUE)
|
---|
298 | {
|
---|
299 | TEnv env("sql.rc");
|
---|
300 |
|
---|
301 | MSQLServer serv(env);
|
---|
302 | if (!serv.IsConnected())
|
---|
303 | {
|
---|
304 | cout << "ERROR - Connection to database failed." << endl;
|
---|
305 | return 0;
|
---|
306 | }
|
---|
307 |
|
---|
308 | cout << "fillcalib" << endl;
|
---|
309 | cout << "---------" << endl;
|
---|
310 | cout << endl;
|
---|
311 | cout << "Connected to " << serv.GetName() << endl;
|
---|
312 | cout << "File: " << fname << endl;
|
---|
313 | cout << endl;
|
---|
314 |
|
---|
315 | return Process(serv, fname, dummy);
|
---|
316 | }
|
---|