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 |
|
---|
60 | #include <TEnv.h>
|
---|
61 | #include <TRegexp.h>
|
---|
62 |
|
---|
63 | #include <TFile.h>
|
---|
64 | #include <TSQLResult.h>
|
---|
65 |
|
---|
66 | #include "MSQLServer.h"
|
---|
67 |
|
---|
68 | #include "MStatusArray.h"
|
---|
69 | #include "MHCamera.h"
|
---|
70 |
|
---|
71 | #include "MCalibrationPulseTimeCam.h"
|
---|
72 | #include "MCalibrationPix.h"
|
---|
73 |
|
---|
74 | using namespace std;
|
---|
75 |
|
---|
76 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
77 | {
|
---|
78 | TFile file(fname, "READ");
|
---|
79 | if (!file.IsOpen())
|
---|
80 | {
|
---|
81 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
82 | return 2;
|
---|
83 | }
|
---|
84 |
|
---|
85 | Float_t meanextpul = -1;
|
---|
86 | Float_t rmsextpul = -1;
|
---|
87 |
|
---|
88 | MCalibrationPulseTimeCam *pt;
|
---|
89 | file.GetObject("MCalibrationPulseTimeCam", pt);
|
---|
90 | if (pt)
|
---|
91 | {
|
---|
92 | meanextpul = pt->GetAverageArea(0).GetHiGainMean();
|
---|
93 | rmsextpul = pt->GetAverageArea(0).GetHiGainRms();
|
---|
94 |
|
---|
95 | meanextpul = TMath::Nint(meanextpul*100)/100.;
|
---|
96 | rmsextpul = TMath::Nint(rmsextpul*100)/100.;
|
---|
97 | }
|
---|
98 |
|
---|
99 | MStatusArray arr;
|
---|
100 | if (arr.Read()<=0)
|
---|
101 | {
|
---|
102 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
103 | return 2;
|
---|
104 | }
|
---|
105 |
|
---|
106 | MHCamera *cam = (MHCamera*)arr.FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
|
---|
107 | if (!cam)
|
---|
108 | {
|
---|
109 | cout << "WARNING - Reading of PedRMS;avg failed." << endl;
|
---|
110 | return 2;
|
---|
111 | }
|
---|
112 |
|
---|
113 | MHCamera *pul = (MHCamera*)arr.FindObjectInCanvas("PulsePos;avg", "MHCamera", "PulsePos");
|
---|
114 | if (!pul)
|
---|
115 | {
|
---|
116 | cout << "WARNING - Reading of PulsePos;avg failed." << endl;
|
---|
117 | return 2;
|
---|
118 | }
|
---|
119 | /*
|
---|
120 | MHCamera *difflo = (MHCamera*)arr.FindObjectInCanvas("DiffLo;avg", "MHCamera", "DiffLo");
|
---|
121 | if (!difflo)
|
---|
122 | {
|
---|
123 | cout << "WARNING - Reading of DiffLo;avg failed." << endl;
|
---|
124 | return 2;
|
---|
125 | }
|
---|
126 | MHCamera *diffhi = (MHCamera*)arr.FindObjectInCanvas("DiffHi;avg", "MHCamera", "DiffHi");
|
---|
127 | if (!diffhi)
|
---|
128 | {
|
---|
129 | cout << "WARNING - Reading of DiffHi;avg failed." << endl;
|
---|
130 | return 2;
|
---|
131 | }
|
---|
132 | */
|
---|
133 | MHCamera *hilooff = (MHCamera*)arr.FindObjectInCanvas("HiLoOff;avg", "MHCamera", "HiLoOff");
|
---|
134 | if (!hilooff)
|
---|
135 | {
|
---|
136 | cout << "WARNING - Reading of HiLoOff failed." << endl;
|
---|
137 | return 2;
|
---|
138 | }
|
---|
139 |
|
---|
140 | MHCamera *hilocal = (MHCamera*)arr.FindObjectInCanvas("HiLoCal;avg", "MHCamera", "HiLoCal");
|
---|
141 | if (!hilocal)
|
---|
142 | {
|
---|
143 | cout << "WARNING - Reading of HiLoCal failed." << endl;
|
---|
144 | return 2;
|
---|
145 | }
|
---|
146 |
|
---|
147 | TArrayI inner(1);
|
---|
148 | inner[0] = 0;
|
---|
149 |
|
---|
150 | TArrayI outer(1);
|
---|
151 | outer[0] = 1;
|
---|
152 |
|
---|
153 | Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
|
---|
154 |
|
---|
155 | Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
156 | Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
157 |
|
---|
158 | if (meanrmsi<0 || meanrmso<0)
|
---|
159 | {
|
---|
160 | cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
|
---|
161 | cout << "MeanPedRMS inner " << meanrmsi << endl;
|
---|
162 | cout << "MeanPedRMS outer " << meanrmso << endl;
|
---|
163 | return 2;
|
---|
164 | }
|
---|
165 |
|
---|
166 | meanrmsi = TMath::Nint(meanrmsi*100)/100.;
|
---|
167 | meanrmso = TMath::Nint(meanrmso*100)/100.;
|
---|
168 |
|
---|
169 | cam = (MHCamera*)arr.FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
|
---|
170 | if (!cam)
|
---|
171 | {
|
---|
172 | cout << "WARNING - Reading of Interp'd;avg failed." << endl;
|
---|
173 | return 2;
|
---|
174 | }
|
---|
175 |
|
---|
176 | Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
177 | Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
178 |
|
---|
179 | if (meansigi<0 || meansigo<0)
|
---|
180 | {
|
---|
181 | cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
|
---|
182 | cout << "MeanInterp'd inner " << meansigi << endl;
|
---|
183 | cout << "MeanInterp'd outer " << meansigo << endl;
|
---|
184 | return 2;
|
---|
185 | }
|
---|
186 |
|
---|
187 | meansigi = TMath::Nint(meansigi*100)/100.;
|
---|
188 | meansigo = TMath::Nint(meansigo*100)/100.;
|
---|
189 |
|
---|
190 | Stat_t meanpul = pul->GetMean();
|
---|
191 | Stat_t rmspul = pul->GetRMS();
|
---|
192 |
|
---|
193 | if (meanpul<0 || rmspul<0)
|
---|
194 | {
|
---|
195 | cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
|
---|
196 | cout << "PulsePos'd mean " << meanpul << endl;
|
---|
197 | cout << "PulsePos'd rms " << rmspul << endl;
|
---|
198 | return 2;
|
---|
199 | }
|
---|
200 |
|
---|
201 | meanpul = TMath::Nint(meanpul*100)/100.;
|
---|
202 | rmspul = TMath::Nint(rmspul *100)/100.;
|
---|
203 |
|
---|
204 | /*
|
---|
205 | Double_t meanhi = TMath::Nint(pulhi->GetMean()*100.)/100.;
|
---|
206 | Double_t rmshi = TMath::Nint(pulhi->GetRMS() *100.)/100.;
|
---|
207 |
|
---|
208 | Double_t meanlo = TMath::Nint(pullo->GetMean()*100.)/100.;
|
---|
209 | Double_t rmslo = TMath::Nint(pullo->GetRMS() *100.)/100.;
|
---|
210 | pullo->Add(pullo, pulhi, 1, -1);
|
---|
211 | pullo->ResetBit(MHCamera::kProfile);
|
---|
212 |
|
---|
213 | Double_t meanoff = TMath::Nint(pullo->GetMean()*100.)/100.;
|
---|
214 | Double_t rmsoff = TMath::Nint(pullo->GetRMS() *100.)/100.;
|
---|
215 | */
|
---|
216 |
|
---|
217 | // USE MEDIAN INSTEAD? GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0);
|
---|
218 |
|
---|
219 | Double_t medoff = TMath::Nint(hilooff->GetMedian() *10000)/10000.;
|
---|
220 | Double_t devoff = TMath::Nint(hilooff->GetMedianDev()*10000)/10000.;
|
---|
221 |
|
---|
222 | Double_t medcal = TMath::Nint(hilocal->GetMedian() *100)/100.;
|
---|
223 | Double_t devcal = TMath::Nint(hilocal->GetMedianDev()*100)/100.;
|
---|
224 |
|
---|
225 | //get sequence number from the filename
|
---|
226 | TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
|
---|
227 | if (sequence.IsNull())
|
---|
228 | {
|
---|
229 | cout << "WARNING - Sequ# empty" << endl;
|
---|
230 | cout << "Sequ# " << sequence << endl;
|
---|
231 | return 2;
|
---|
232 | }
|
---|
233 |
|
---|
234 | Int_t seq = atoi(sequence.Data()+6);
|
---|
235 | TString meanrmsinner =Form("%6.2f", meanrmsi);
|
---|
236 | TString meanrmsouter =Form("%6.2f", meanrmso);
|
---|
237 | TString meansiginner =Form("%6.2f", meansigi);
|
---|
238 | TString meansigouter =Form("%6.2f", meansigo);
|
---|
239 | TString meanpulpos =Form("%6.2f", meanpul);
|
---|
240 | TString rmspulpos =Form("%6.2f", rmspul);
|
---|
241 | TString meanextpulpos=Form("%6.2f", meanextpul);
|
---|
242 | TString rmsextpulpos =Form("%6.2f", rmsextpul);
|
---|
243 | /*
|
---|
244 | TString meanpulhi =Form("%6.2f", meanhi);
|
---|
245 | TString rmspulhi =Form("%6.2f", rmshi);
|
---|
246 |
|
---|
247 | TString meanpullo =Form("%6.2f", meanlo);
|
---|
248 | TString rmspullo =Form("%6.2f", rmslo);
|
---|
249 | */
|
---|
250 | TString medpuloff =Form("%7.4f", medoff);
|
---|
251 | TString devpuloff =Form("%7.4f", devoff);
|
---|
252 | TString medhilocal =Form("%6.2f", medcal);
|
---|
253 | TString devhilocal =Form("%6.2f", devcal);
|
---|
254 |
|
---|
255 | if (meanextpul<0 && rmsextpul<0)
|
---|
256 | {
|
---|
257 | meanextpulpos = "NULL";
|
---|
258 | rmsextpulpos = "NULL";
|
---|
259 | }
|
---|
260 |
|
---|
261 | // *****************************************************
|
---|
262 |
|
---|
263 | // *****************************************************
|
---|
264 |
|
---|
265 |
|
---|
266 | cout << "Sequence #" << seq << endl;
|
---|
267 | cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
|
---|
268 | cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
|
---|
269 | cout << " Mean Signal inner [phe] " << meansiginner << endl;
|
---|
270 | cout << " Mean Signal outer [phe] " << meansigouter << endl;
|
---|
271 | cout << " Mean calibrated PulsePos " << meanpulpos << " +- " << rmspulpos << endl;
|
---|
272 | cout << " Mean extracted PulsePos " << meanextpulpos << " +- " << rmsextpulpos << endl;
|
---|
273 | // cout << " Mean ext.HiGain PulsePos " << meanpulhi << " +- " << rmspulhi << endl;
|
---|
274 | // cout << " Mean ext.LoGain PulsePos " << meanpullo << " +- " << rmspullo << endl;
|
---|
275 | cout << " Lo-Hi gain offset: " << medpuloff << " +- " << devpuloff << endl;
|
---|
276 | cout << " Hi/Lo gain ratio: " << medhilocal << " +- " << devhilocal << endl;
|
---|
277 | cout << endl;
|
---|
278 |
|
---|
279 | //build query and insert information into the database
|
---|
280 | // here only a update query is built, as this macro is exexuted after
|
---|
281 | // the macro fillcalib.C in the script fillcallisto
|
---|
282 | // and so the table Calibration is always updated
|
---|
283 | TString query = Form("UPDATE Calibration SET "
|
---|
284 | " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
|
---|
285 | " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
|
---|
286 | " fPulsePosMean=%s, fPulsePosRms=%s, "
|
---|
287 | " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s, "
|
---|
288 | //" fPulsePosHiMean=%s, fPulsePosHiRms=%s, "
|
---|
289 | //" fPulsePosLoMean=%s, fPulsePosLoRms=%s, "
|
---|
290 | " fPulsePosOffMed=%s, fPulsePosOffDev=%s, "
|
---|
291 | " fHiLoGainRatioMed=%s, fHiLoGainRatioDev=%s "
|
---|
292 | " WHERE fSequenceFirst='%d' ",
|
---|
293 | meanrmsinner.Data(), meanrmsouter.Data(),
|
---|
294 | meansiginner.Data(), meansigouter.Data(),
|
---|
295 | meanpulpos.Data(), rmspulpos.Data(),
|
---|
296 | meanextpulpos.Data(), rmsextpulpos.Data(),
|
---|
297 | //meanpulhi.Data(), rmspulhi.Data(),
|
---|
298 | //meanpullo.Data(), rmspullo.Data(),
|
---|
299 | medpuloff.Data(), devpuloff.Data(),
|
---|
300 | medhilocal.Data(), devhilocal.Data(),
|
---|
301 | seq);
|
---|
302 |
|
---|
303 | if (dummy)
|
---|
304 | return 1;
|
---|
305 |
|
---|
306 | TSQLResult *res = serv.Query(query);
|
---|
307 | if (!res)
|
---|
308 | {
|
---|
309 | cout << "ERROR - Query failed: " << query << endl;
|
---|
310 | return 2;
|
---|
311 | }
|
---|
312 | delete res;
|
---|
313 | return 1;
|
---|
314 | }
|
---|
315 |
|
---|
316 | int fillsignal(TString fname, Bool_t dummy=kTRUE)
|
---|
317 | {
|
---|
318 | TEnv env("sql.rc");
|
---|
319 |
|
---|
320 | MSQLServer serv(env);
|
---|
321 | if (!serv.IsConnected())
|
---|
322 | {
|
---|
323 | cout << "ERROR - Connection to database failed." << endl;
|
---|
324 | return 0;
|
---|
325 | }
|
---|
326 |
|
---|
327 | cout << "fillsignal" << endl;
|
---|
328 | cout << "----------" << endl;
|
---|
329 | cout << endl;
|
---|
330 | cout << "Connected to " << serv.GetName() << endl;
|
---|
331 | cout << "File: " << fname << endl;
|
---|
332 | cout << endl;
|
---|
333 |
|
---|
334 | //process file
|
---|
335 | return Process(serv, fname, dummy);
|
---|
336 | }
|
---|