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, 04/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Daniela Dorner, 04/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2006
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // fillsignal.C
|
---|
29 | // ============
|
---|
30 | //
|
---|
31 | // This macro is used to read the calibration-/callisto-output files
|
---|
32 | // signal00000.root.
|
---|
33 | //
|
---|
34 | // From this file the mean pedrms, the mean signal and the pulse position
|
---|
35 | // for the inner and outer camera is extracted and inserted into the database
|
---|
36 | // in the table Calibration, where the results of callisto are stored.
|
---|
37 | // The sequence number is extracted from the filename.
|
---|
38 | //
|
---|
39 | // Usage:
|
---|
40 | // .x fillsignal.C("/magic/data/callisto/0004/00047421/signal00047421.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 fillsignal.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillsignal.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 <TEnv.h>
|
---|
62 | #include <TRegexp.h>
|
---|
63 |
|
---|
64 | #include <TFile.h>
|
---|
65 | #include <TGraph.h>
|
---|
66 | #include <TSQLResult.h>
|
---|
67 |
|
---|
68 | #include "MSQLServer.h"
|
---|
69 |
|
---|
70 | #include "MStatusArray.h"
|
---|
71 | #include "MHCamera.h"
|
---|
72 | #include "MHVsTime.h"
|
---|
73 |
|
---|
74 | #include "MCalibrationPulseTimeCam.h"
|
---|
75 | #include "MCalibrationPix.h"
|
---|
76 |
|
---|
77 | using namespace std;
|
---|
78 |
|
---|
79 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
80 | {
|
---|
81 | TFile file(fname, "READ");
|
---|
82 | if (!file.IsOpen())
|
---|
83 | {
|
---|
84 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
85 | return 2;
|
---|
86 | }
|
---|
87 |
|
---|
88 | Float_t meanextpul = -1;
|
---|
89 | Float_t rmsextpul = -1;
|
---|
90 |
|
---|
91 | MCalibrationPulseTimeCam *pt;
|
---|
92 | file.GetObject("MCalibrationPulseTimeCam", pt);
|
---|
93 | if (pt)
|
---|
94 | {
|
---|
95 | meanextpul = pt->GetAverageArea(0).GetHiGainMean();
|
---|
96 | rmsextpul = pt->GetAverageArea(0).GetHiGainRms();
|
---|
97 |
|
---|
98 | meanextpul = TMath::Nint(meanextpul*100)/100.;
|
---|
99 | rmsextpul = TMath::Nint(rmsextpul*100)/100.;
|
---|
100 | }
|
---|
101 |
|
---|
102 | MStatusArray arr;
|
---|
103 | if (arr.Read()<=0)
|
---|
104 | {
|
---|
105 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
106 | return 2;
|
---|
107 | }
|
---|
108 |
|
---|
109 | MHCamera *cam = (MHCamera*)arr.FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
|
---|
110 | if (!cam)
|
---|
111 | {
|
---|
112 | cout << "WARNING - Reading of PedRMS;avg failed." << endl;
|
---|
113 | return 2;
|
---|
114 | }
|
---|
115 |
|
---|
116 | MHCamera *pul = (MHCamera*)arr.FindObjectInCanvas("PulsePos;avg", "MHCamera", "PulsePos");
|
---|
117 | if (!pul)
|
---|
118 | {
|
---|
119 | cout << "WARNING - Reading of PulsePos;avg failed." << endl;
|
---|
120 | return 2;
|
---|
121 | }
|
---|
122 | /*
|
---|
123 | MHCamera *difflo = (MHCamera*)arr.FindObjectInCanvas("DiffLo;avg", "MHCamera", "DiffLo");
|
---|
124 | if (!difflo)
|
---|
125 | {
|
---|
126 | cout << "WARNING - Reading of DiffLo;avg failed." << endl;
|
---|
127 | return 2;
|
---|
128 | }
|
---|
129 | MHCamera *diffhi = (MHCamera*)arr.FindObjectInCanvas("DiffHi;avg", "MHCamera", "DiffHi");
|
---|
130 | if (!diffhi)
|
---|
131 | {
|
---|
132 | cout << "WARNING - Reading of DiffHi;avg failed." << endl;
|
---|
133 | return 2;
|
---|
134 | }
|
---|
135 | */
|
---|
136 |
|
---|
137 | //get sequence number from the filename
|
---|
138 | TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
|
---|
139 | if (sequence.IsNull())
|
---|
140 | {
|
---|
141 | cout << "WARNING - Sequ# empty" << endl;
|
---|
142 | cout << "Sequ# " << sequence << endl;
|
---|
143 | return 2;
|
---|
144 | }
|
---|
145 |
|
---|
146 | Int_t seq = atoi(sequence.Data()+6);
|
---|
147 |
|
---|
148 | Double_t medoff;
|
---|
149 | Double_t devoff;
|
---|
150 |
|
---|
151 | Double_t medcal;
|
---|
152 | Double_t devcal;
|
---|
153 |
|
---|
154 | TString medpuloff("NULL");
|
---|
155 | TString devpuloff("NULL");
|
---|
156 | TString medhilocal("NULL");
|
---|
157 | TString devhilocal("NULL");
|
---|
158 |
|
---|
159 | if (seq < 200000)
|
---|
160 | {
|
---|
161 | MHCamera *hilooff = (MHCamera*)arr.FindObjectInCanvas("HiLoOff;avg", "MHCamera", "HiLoOff");
|
---|
162 | if (!hilooff)
|
---|
163 | {
|
---|
164 | cout << "WARNING - Reading of HiLoOff failed." << endl;
|
---|
165 | return 2;
|
---|
166 | }
|
---|
167 |
|
---|
168 | MHCamera *hilocal = (MHCamera*)arr.FindObjectInCanvas("HiLoCal;avg", "MHCamera", "HiLoCal");
|
---|
169 | if (!hilocal)
|
---|
170 | {
|
---|
171 | cout << "WARNING - Reading of HiLoCal failed." << endl;
|
---|
172 | return 2;
|
---|
173 | }
|
---|
174 |
|
---|
175 | medoff = TMath::Nint(hilooff->GetMedian()*10000)/10000.;
|
---|
176 | devoff = TMath::Nint(hilooff->GetDev() *10000)/10000.;
|
---|
177 |
|
---|
178 | medcal = TMath::Nint(hilocal->GetMedian()*100)/100.;
|
---|
179 | devcal = TMath::Nint(hilocal->GetDev() *100)/100.;
|
---|
180 |
|
---|
181 | medpuloff.Form("%7.4f", medoff);
|
---|
182 | devpuloff.Form("%7.4f", devoff);
|
---|
183 | medhilocal.Form("%6.2f", medcal);
|
---|
184 | devhilocal.Form("%6.2f", devcal);
|
---|
185 | }
|
---|
186 |
|
---|
187 | TArrayI inner(1);
|
---|
188 | inner[0] = 0;
|
---|
189 |
|
---|
190 | TArrayI outer(1);
|
---|
191 | outer[0] = 1;
|
---|
192 |
|
---|
193 | Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
|
---|
194 |
|
---|
195 | Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
196 | Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
197 |
|
---|
198 | if (meanrmsi<0 || meanrmso<0)
|
---|
199 | {
|
---|
200 | cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
|
---|
201 | cout << "MeanPedRMS inner " << meanrmsi << endl;
|
---|
202 | cout << "MeanPedRMS outer " << meanrmso << endl;
|
---|
203 | return 2;
|
---|
204 | }
|
---|
205 |
|
---|
206 | meanrmsi = TMath::Nint(meanrmsi*100)/100.;
|
---|
207 | meanrmso = TMath::Nint(meanrmso*100)/100.;
|
---|
208 |
|
---|
209 | cam = (MHCamera*)arr.FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
|
---|
210 | if (!cam)
|
---|
211 | {
|
---|
212 | cout << "WARNING - Reading of Interp'd;avg failed." << endl;
|
---|
213 | return 2;
|
---|
214 | }
|
---|
215 |
|
---|
216 | Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
217 | Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
218 |
|
---|
219 | if (meansigi<0 || meansigo<0)
|
---|
220 | {
|
---|
221 | cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
|
---|
222 | cout << "MeanInterp'd inner " << meansigi << endl;
|
---|
223 | cout << "MeanInterp'd outer " << meansigo << endl;
|
---|
224 | return 2;
|
---|
225 | }
|
---|
226 |
|
---|
227 | meansigi = TMath::Nint(meansigi*100)/100.;
|
---|
228 | meansigo = TMath::Nint(meansigo*100)/100.;
|
---|
229 |
|
---|
230 | Stat_t meanpul = pul->GetMean();
|
---|
231 | Stat_t rmspul = pul->GetRMS();
|
---|
232 |
|
---|
233 | if (meanpul<0 || rmspul<0)
|
---|
234 | {
|
---|
235 | cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
|
---|
236 | cout << "PulsePos'd mean " << meanpul << endl;
|
---|
237 | cout << "PulsePos'd rms " << rmspul << endl;
|
---|
238 | return 2;
|
---|
239 | }
|
---|
240 |
|
---|
241 | meanpul = TMath::Nint(meanpul*100)/100.;
|
---|
242 | rmspul = TMath::Nint(rmspul *100)/100.;
|
---|
243 |
|
---|
244 | cam = (MHCamera*)arr.FindObjectInCanvas("Unsuitable;avg", "MHCamera", "Unsuitable");
|
---|
245 | if (!cam)
|
---|
246 | {
|
---|
247 | cout << "WARNING - Reading of Unsuitable;avg failed." << endl;
|
---|
248 | return 2;
|
---|
249 | }
|
---|
250 |
|
---|
251 | Int_t unsuitable50 = cam->GetNumBinsAboveThreshold(0.50);
|
---|
252 | Int_t unsuitable01 = cam->GetNumBinsAboveThreshold(0.01);
|
---|
253 |
|
---|
254 | TString unsuitablemax = "NULL";
|
---|
255 | TString deadmax = "NULL";
|
---|
256 |
|
---|
257 | TGraph *gr = (TGraph*)arr.FindObjectInCanvas("BadPixTm", "TGraph", "BadPixTm");
|
---|
258 | if (gr)
|
---|
259 | {
|
---|
260 | const Int_t p = TMath::FloorNint(gr->GetN()*0.999);
|
---|
261 | unsuitablemax = Form("%d", TMath::Nint(TMath::KOrdStat(gr->GetN(), gr->GetY(), p)));
|
---|
262 | }
|
---|
263 |
|
---|
264 | gr = (TGraph*)arr.FindObjectInCanvas("DeadPixTm", "TGraph", "DeadPixTm");
|
---|
265 | if (gr)
|
---|
266 | deadmax = Form("%d", TMath::Nint(TMath::MaxElement(gr->GetN(), gr->GetY())));
|
---|
267 |
|
---|
268 |
|
---|
269 | /*
|
---|
270 | Double_t meanhi = TMath::Nint(pulhi->GetMean()*100.)/100.;
|
---|
271 | Double_t rmshi = TMath::Nint(pulhi->GetRMS() *100.)/100.;
|
---|
272 |
|
---|
273 | Double_t meanlo = TMath::Nint(pullo->GetMean()*100.)/100.;
|
---|
274 | Double_t rmslo = TMath::Nint(pullo->GetRMS() *100.)/100.;
|
---|
275 | pullo->Add(pullo, pulhi, 1, -1);
|
---|
276 | pullo->ResetBit(MHCamera::kProfile);
|
---|
277 |
|
---|
278 | Double_t meanoff = TMath::Nint(pullo->GetMean()*100.)/100.;
|
---|
279 | Double_t rmsoff = TMath::Nint(pullo->GetRMS() *100.)/100.;
|
---|
280 | */
|
---|
281 |
|
---|
282 | // USE MEDIAN INSTEAD? GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0);
|
---|
283 |
|
---|
284 |
|
---|
285 | TString meanrmsinner =Form("%6.2f", meanrmsi);
|
---|
286 | TString meanrmsouter =Form("%6.2f", meanrmso);
|
---|
287 | TString meansiginner =Form("%6.2f", meansigi);
|
---|
288 | TString meansigouter =Form("%6.2f", meansigo);
|
---|
289 | TString meanpulpos =Form("%6.2f", meanpul);
|
---|
290 | TString rmspulpos =Form("%6.2f", rmspul);
|
---|
291 | TString meanextpulpos=Form("%6.2f", meanextpul);
|
---|
292 | TString rmsextpulpos =Form("%6.2f", rmsextpul);
|
---|
293 | /*
|
---|
294 | TString meanpulhi =Form("%6.2f", meanhi);
|
---|
295 | TString rmspulhi =Form("%6.2f", rmshi);
|
---|
296 |
|
---|
297 | TString meanpullo =Form("%6.2f", meanlo);
|
---|
298 | TString rmspullo =Form("%6.2f", rmslo);
|
---|
299 | */
|
---|
300 |
|
---|
301 | if (meanextpul<0 && rmsextpul<0)
|
---|
302 | {
|
---|
303 | meanextpulpos = "NULL";
|
---|
304 | rmsextpulpos = "NULL";
|
---|
305 | }
|
---|
306 |
|
---|
307 | // *****************************************************
|
---|
308 |
|
---|
309 | // *****************************************************
|
---|
310 |
|
---|
311 |
|
---|
312 | cout << "Sequence #" << seq << endl;
|
---|
313 | cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
|
---|
314 | cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
|
---|
315 | cout << " Mean Signal inner [phe] " << meansiginner << endl;
|
---|
316 | cout << " Mean Signal outer [phe] " << meansigouter << endl;
|
---|
317 | cout << " Mean calibrated PulsePos " << meanpulpos << " +- " << rmspulpos << endl;
|
---|
318 | cout << " Mean extracted PulsePos " << meanextpulpos << " +- " << rmsextpulpos << endl;
|
---|
319 | // cout << " Mean ext.HiGain PulsePos " << meanpulhi << " +- " << rmspulhi << endl;
|
---|
320 | // cout << " Mean ext.LoGain PulsePos " << meanpullo << " +- " << rmspullo << endl;
|
---|
321 | cout << " Lo-Hi gain offset: " << medpuloff << " +- " << devpuloff << endl;
|
---|
322 | cout << " Hi/Lo gain ratio: " << medhilocal << " +- " << devhilocal << endl;
|
---|
323 | cout << " Unsuitable > 50%: " << setw(6) << unsuitable50 << endl;
|
---|
324 | cout << " Unsuitable > 1%: " << setw(6) << unsuitable01 << endl;
|
---|
325 | cout << " UnsuitableMax (99.9%) " << setw(6) << unsuitablemax << endl;
|
---|
326 | cout << " DeadMax " << setw(6) << deadmax << endl;
|
---|
327 | cout << endl;
|
---|
328 |
|
---|
329 | //build query and insert information into the database
|
---|
330 | // here only a update query is built, as this macro is exexuted after
|
---|
331 | // the macro fillcalib.C in the script fillcallisto
|
---|
332 | // and so the table Calibration is always updated
|
---|
333 | TString query = Form("UPDATE Calibration SET "
|
---|
334 | " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
|
---|
335 | " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
|
---|
336 | " fPulsePosMean=%s, fPulsePosRms=%s, "
|
---|
337 | " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s, "
|
---|
338 | //" fPulsePosHiMean=%s, fPulsePosHiRms=%s, "
|
---|
339 | //" fPulsePosLoMean=%s, fPulsePosLoRms=%s, "
|
---|
340 | " fPulsePosOffMed=%s, fPulsePosOffDev=%s, "
|
---|
341 | " fHiLoGainRatioMed=%s, fHiLoGainRatioDev=%s, "
|
---|
342 | " fUnsuitable50=%d, fUnsuitable01=%d, "
|
---|
343 | " fUnsuitableMax=%s, fDeadMax=%s "
|
---|
344 | " WHERE fSequenceFirst='%d' ",
|
---|
345 | meanrmsinner.Data(), meanrmsouter.Data(),
|
---|
346 | meansiginner.Data(), meansigouter.Data(),
|
---|
347 | meanpulpos.Data(), rmspulpos.Data(),
|
---|
348 | meanextpulpos.Data(), rmsextpulpos.Data(),
|
---|
349 | //meanpulhi.Data(), rmspulhi.Data(),
|
---|
350 | //meanpullo.Data(), rmspullo.Data(),
|
---|
351 | medpuloff.Data(), devpuloff.Data(),
|
---|
352 | medhilocal.Data(), devhilocal.Data(),
|
---|
353 | unsuitable50, unsuitable01,
|
---|
354 | unsuitablemax.Data(), deadmax.Data(),
|
---|
355 | seq);
|
---|
356 |
|
---|
357 | if (dummy)
|
---|
358 | return 1;
|
---|
359 |
|
---|
360 | TSQLResult *res = serv.Query(query);
|
---|
361 | if (!res)
|
---|
362 | {
|
---|
363 | cout << "ERROR - Query failed: " << query << endl;
|
---|
364 | return 2;
|
---|
365 | }
|
---|
366 | delete res;
|
---|
367 | return 1;
|
---|
368 | }
|
---|
369 |
|
---|
370 | int fillsignal(TString fname, Bool_t dummy=kTRUE)
|
---|
371 | {
|
---|
372 | TEnv env("sql.rc");
|
---|
373 |
|
---|
374 | MSQLServer serv(env);
|
---|
375 | if (!serv.IsConnected())
|
---|
376 | {
|
---|
377 | cout << "ERROR - Connection to database failed." << endl;
|
---|
378 | return 0;
|
---|
379 | }
|
---|
380 |
|
---|
381 | cout << "fillsignal" << endl;
|
---|
382 | cout << "----------" << endl;
|
---|
383 | cout << endl;
|
---|
384 | cout << "Connected to " << serv.GetName() << endl;
|
---|
385 | cout << "File: " << fname << endl;
|
---|
386 | cout << endl;
|
---|
387 |
|
---|
388 | //process file
|
---|
389 | return Process(serv, fname, dummy);
|
---|
390 | }
|
---|