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-2008
|
---|
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 | // The bad pixel information and other information, extracted from the status
|
---|
37 | // display, is inserted into the database in the table Calibration, which
|
---|
38 | // stores the results from the calibration.
|
---|
39 | // The corresponding sequence number is extracted from the filename...
|
---|
40 | // FIXME: MSeqeuence should be stored in the calib-file?
|
---|
41 | //
|
---|
42 | // Usage:
|
---|
43 | // .x fillcalib.C("/magic/data/callisto/0004/00047421/calib00047421.root", kTRUE)
|
---|
44 | //
|
---|
45 | // The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
|
---|
46 | // switched on and nothing will be written into the database. This is usefull
|
---|
47 | // for tests.
|
---|
48 | //
|
---|
49 | // The macro can also be run without ACLiC but this is a lot slower...
|
---|
50 | //
|
---|
51 | // Remark: Running it from the commandline looks like this:
|
---|
52 | // root -q -l -b fillcalib.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillcalib.log
|
---|
53 | //
|
---|
54 | // Make sure, that database and password are corretly set in a resource
|
---|
55 | // file called sql.rc and the resource file is found.
|
---|
56 | //
|
---|
57 | // Returns 2 in case of failure, 1 in case of success and 0 if the connection
|
---|
58 | // to the database is not working.
|
---|
59 | //
|
---|
60 | /////////////////////////////////////////////////////////////////////////////
|
---|
61 | #include <iostream>
|
---|
62 |
|
---|
63 | #include <TEnv.h>
|
---|
64 | #include <TRegexp.h>
|
---|
65 |
|
---|
66 | #include <TH1.h>
|
---|
67 |
|
---|
68 | #include <TFile.h>
|
---|
69 | #include <TSQLResult.h>
|
---|
70 | #include <TSQLRow.h>
|
---|
71 |
|
---|
72 | #include "MSQLMagic.h"
|
---|
73 |
|
---|
74 | #include "MStatusArray.h"
|
---|
75 | #include "MHCamera.h"
|
---|
76 | #include "MGeomCamMagic.h"
|
---|
77 | #include "MBadPixelsCam.h"
|
---|
78 |
|
---|
79 | using namespace std;
|
---|
80 |
|
---|
81 | int Process(MSQLMagic &serv, TString fname)
|
---|
82 | {
|
---|
83 | //getting number of unsuitable, unreliable and isolated pixel
|
---|
84 | MBadPixelsCam badpix;
|
---|
85 |
|
---|
86 | TFile file(fname, "READ");
|
---|
87 | if (!file.IsOpen())
|
---|
88 | {
|
---|
89 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
90 | return 2;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (badpix.Read("MBadPixelsCam")<=0)
|
---|
94 | {
|
---|
95 | cout << "ERROR - Reading of MBadPixelsCam failed." << endl;
|
---|
96 | return 2;
|
---|
97 | }
|
---|
98 |
|
---|
99 | MGeomCamMagic def;
|
---|
100 |
|
---|
101 | MGeomCam *geom = (MGeomCam*)file.Get("MGeomCam");
|
---|
102 | if (!geom)
|
---|
103 | {
|
---|
104 | cout << "WARNING - Reading of MGeomCam failed... using default <MGeomCamMagic>" << endl;
|
---|
105 | geom = &def;
|
---|
106 | }
|
---|
107 |
|
---|
108 | cout << "Camera Geometry: " << geom->ClassName() << endl;
|
---|
109 |
|
---|
110 | const Short_t unsin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 0);
|
---|
111 | const Short_t unsout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 1);
|
---|
112 |
|
---|
113 | const Short_t unrin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 0);
|
---|
114 | const Short_t unrout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 1);
|
---|
115 |
|
---|
116 | const Short_t isoin = badpix.GetNumIsolated(*geom, 0);
|
---|
117 | const Short_t isoout = badpix.GetNumIsolated(*geom, 1);
|
---|
118 |
|
---|
119 | const Short_t clumax = badpix.GetNumMaxCluster(*geom);
|
---|
120 |
|
---|
121 | if (unsin<0 || unsout<0 || unrin<0 || unrout<0 || isoin<0 || isoout<0 || clumax<0)
|
---|
122 | {
|
---|
123 | cout << "ERROR - one of the pixel values < 0." << endl;
|
---|
124 | return 2;
|
---|
125 | }
|
---|
126 |
|
---|
127 | // MHCamera hist(geom);
|
---|
128 | // hist.SetCamContent(badpix, 1);
|
---|
129 | // hist.DrawCopy();
|
---|
130 | // hist.SetCamContent(badpix, 3);
|
---|
131 | // hist.DrawCopy();
|
---|
132 |
|
---|
133 | //Getting values from the status display
|
---|
134 | MStatusArray arr;
|
---|
135 | if (arr.Read()<=0)
|
---|
136 | {
|
---|
137 | cout << "ERROR - could not read MStatusArray." << endl;
|
---|
138 | return 2;
|
---|
139 | }
|
---|
140 |
|
---|
141 | TH1 *h;
|
---|
142 |
|
---|
143 | //getting the mean and rms from the arrival time (inner cam)
|
---|
144 | h = (TH1*)arr.FindObjectInCanvas("HRelTimeHiGainArea0", "TH1F", "Time");
|
---|
145 | if (!h)
|
---|
146 | {
|
---|
147 | cout << "WARNING - Could not find histogram HRelTimeHiGainArea0." << endl;
|
---|
148 | return 2;
|
---|
149 | }
|
---|
150 |
|
---|
151 | Float_t meani = h->GetMean();
|
---|
152 | Float_t rmsi = h->GetRMS();
|
---|
153 | meani = TMath::Nint(meani*10)/10.;
|
---|
154 | rmsi = TMath::Nint(rmsi*100)/100.;
|
---|
155 | TString meaninner = Form("%5.1f", meani);
|
---|
156 | TString rmsinner = Form("%6.2f", rmsi);
|
---|
157 |
|
---|
158 |
|
---|
159 | //getting the mean and rms from the arrival time (outer cam)
|
---|
160 | h = (TH1*)arr.FindObjectInCanvas("HRelTimeHiGainArea1", "TH1F", "Time");
|
---|
161 | if (!h)
|
---|
162 | {
|
---|
163 | cout << "WARNING - Could not find histogram HRelTimeHiGainArea1." << endl;
|
---|
164 | return 2;
|
---|
165 | }
|
---|
166 |
|
---|
167 | Float_t meano = h->GetMean();
|
---|
168 | Float_t rmso = h->GetRMS();
|
---|
169 | meano = TMath::Nint(meano*10)/10.;
|
---|
170 | rmso = TMath::Nint(rmso*100)/100.;
|
---|
171 | TString meanouter = Form("%5.1f", meano);
|
---|
172 | TString rmsouter = Form("%6.2f", rmso);
|
---|
173 |
|
---|
174 |
|
---|
175 | //Getting conversion factors
|
---|
176 | MHCamera *c = (MHCamera*)arr.FindObjectInCanvas("TotalConvPhe", "MHCamera", "Conversion");
|
---|
177 | if (!c)
|
---|
178 | {
|
---|
179 | cout << "WARNING - Could not find MHCamera TotalConv." << endl;
|
---|
180 | return 2;
|
---|
181 | }
|
---|
182 |
|
---|
183 | TArrayI inner(1), outer(1);
|
---|
184 | inner[0] = 0;
|
---|
185 | outer[0] = 1;
|
---|
186 |
|
---|
187 | Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
|
---|
188 |
|
---|
189 | Stat_t meanconvi = c->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
190 | Stat_t meanconvo = c->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
191 | meanconvi = TMath::Nint(meanconvi*1000)/1000.;
|
---|
192 | meanconvo = TMath::Nint(meanconvo*1000)/1000.;
|
---|
193 | TString meanconvinner=Form("%6.3f", meanconvi);
|
---|
194 | TString meanconvouter=Form("%6.3f", meanconvo);
|
---|
195 |
|
---|
196 | //Getting sequ# from filename
|
---|
197 | TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
|
---|
198 | if (sequence.IsNull())
|
---|
199 | {
|
---|
200 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
201 | return 2;
|
---|
202 | }
|
---|
203 |
|
---|
204 | Int_t seq = atoi(sequence.Data()+5);
|
---|
205 |
|
---|
206 | //getting the ratio of calibration events used
|
---|
207 | h = (TH1*)arr.FindObjectInCanvas("ArrTm;avg", "MHCamera", "ArrTm");
|
---|
208 | if (!h)
|
---|
209 | {
|
---|
210 | cout << "WARNING - Could not find histogram ArrTime;avg." << endl;
|
---|
211 | return 2;
|
---|
212 | }
|
---|
213 |
|
---|
214 | UInt_t nevts = h->GetEntries();
|
---|
215 |
|
---|
216 | TString query;
|
---|
217 | query = Form("SELECT SUM(fNumEvents) FROM RunData "
|
---|
218 | "LEFT JOIN RunType ON RunType.fRunTypeKEY=RunData.fRunTypeKEY "
|
---|
219 | "WHERE fSequenceFirst=%d AND RunType.fRunTypeName='Calibration'",
|
---|
220 | seq);
|
---|
221 |
|
---|
222 | TSQLResult *res = serv.Query(query);
|
---|
223 | if (!res)
|
---|
224 | {
|
---|
225 | cout << "ERROR - Query failed: " << query << endl;
|
---|
226 | return 2;
|
---|
227 | }
|
---|
228 |
|
---|
229 | TSQLRow *row = res->Next();
|
---|
230 | if (!row)
|
---|
231 | {
|
---|
232 | cout << "ERROR - Query failed: " << query << endl;
|
---|
233 | return 2;
|
---|
234 | }
|
---|
235 |
|
---|
236 | Float_t ratiocalib = 100.*nevts/atof((*row)[0]);
|
---|
237 |
|
---|
238 | TString ratiocal = Form("%.1f", ratiocalib);
|
---|
239 |
|
---|
240 | delete res;
|
---|
241 |
|
---|
242 | cout << "Sequence #" << seq << endl;
|
---|
243 | cout << " Unsuitable: (i/o) " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
|
---|
244 | cout << " Unreliable: (i/o) " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
|
---|
245 | cout << " Isolated: (i/o) " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
|
---|
246 | cout << " Max.Cluster: " << Form("%3d", (int)clumax) << endl; // Max Cluster
|
---|
247 | cout << " Arr Time inner: " << meaninner << " +- " << rmsinner << endl;
|
---|
248 | cout << " Arr Time outer: " << meanouter << " +- " << rmsouter << endl;
|
---|
249 | cout << " Mean Conv inner: " << meanconvinner << endl;
|
---|
250 | cout << " Mean Conv outer: " << meanconvouter << endl;
|
---|
251 | cout << " Ratio Calib Evts: " << ratiocal << endl;
|
---|
252 |
|
---|
253 | //inserting or updating the information in the database
|
---|
254 | TString vars =
|
---|
255 | Form(" fSequenceFirst=%d,"
|
---|
256 | " fUnsuitableInner=%d, "
|
---|
257 | " fUnsuitableOuter=%d, "
|
---|
258 | " fUnreliableInner=%d, "
|
---|
259 | " fUnreliableOuter=%d, "
|
---|
260 | " fIsolatedInner=%d, "
|
---|
261 | " fIsolatedOuter=%d, "
|
---|
262 | " fIsolatedMaxCluster=%d, "
|
---|
263 | " fArrTimeMeanInner=%s, "
|
---|
264 | " fArrTimeRmsInner=%s, "
|
---|
265 | " fArrTimeMeanOuter=%s, "
|
---|
266 | " fArrTimeRmsOuter=%s, "
|
---|
267 | " fConvFactorInner=%s, "
|
---|
268 | " fConvFactorOuter=%s, "
|
---|
269 | " fRatioCalEvents=%s ",
|
---|
270 | seq, (int)unsin, (int)unsout, (int)unrin,
|
---|
271 | (int)unrout, (int)isoin, (int)isoout, (int)clumax,
|
---|
272 | meaninner.Data(), rmsinner.Data(),
|
---|
273 | meanouter.Data(), rmsouter.Data(),
|
---|
274 | meanconvinner.Data(), meanconvouter.Data(),
|
---|
275 | ratiocal.Data());
|
---|
276 |
|
---|
277 | return serv.InsertUpdate("Calibration", "fSequenceFirst",
|
---|
278 | Form("%d", seq), vars.Data()) ? 1 : 2;
|
---|
279 | }
|
---|
280 |
|
---|
281 | int fillcalib(TString fname, Bool_t dummy=kTRUE)
|
---|
282 | {
|
---|
283 | TEnv env("sql.rc");
|
---|
284 |
|
---|
285 | MSQLMagic serv(env);
|
---|
286 | if (!serv.IsConnected())
|
---|
287 | {
|
---|
288 | cout << "ERROR - Connection to database failed." << endl;
|
---|
289 | return 0;
|
---|
290 | }
|
---|
291 |
|
---|
292 | cout << "fillcalib" << endl;
|
---|
293 | cout << "---------" << endl;
|
---|
294 | cout << endl;
|
---|
295 | cout << "Connected to " << serv.GetName() << endl;
|
---|
296 | cout << "File: " << fname << endl;
|
---|
297 | cout << endl;
|
---|
298 |
|
---|
299 | serv.SetIsDummy(dummy);
|
---|
300 |
|
---|
301 | return Process(serv, fname);
|
---|
302 | }
|
---|