source: trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C@ 8475

Last change on this file since 8475 was 8475, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 11.6 KB
Line 
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
74using namespace std;
75
76int 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
134 //get sequence number from the filename
135 TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
136 if (sequence.IsNull())
137 {
138 cout << "WARNING - Sequ# empty" << endl;
139 cout << "Sequ# " << sequence << endl;
140 return 2;
141 }
142
143 Int_t seq = atoi(sequence.Data()+6);
144
145 Double_t medoff;
146 Double_t devoff;
147
148 Double_t medcal;
149 Double_t devcal;
150
151 TString medpuloff("NULL");
152 TString devpuloff("NULL");
153 TString medhilocal("NULL");
154 TString devhilocal("NULL");
155
156 if (seq < 200000)
157 {
158 MHCamera *hilooff = (MHCamera*)arr.FindObjectInCanvas("HiLoOff;avg", "MHCamera", "HiLoOff");
159 if (!hilooff)
160 {
161 cout << "WARNING - Reading of HiLoOff failed." << endl;
162 return 2;
163 }
164
165 MHCamera *hilocal = (MHCamera*)arr.FindObjectInCanvas("HiLoCal;avg", "MHCamera", "HiLoCal");
166 if (!hilocal)
167 {
168 cout << "WARNING - Reading of HiLoCal failed." << endl;
169 return 2;
170 }
171
172 medoff = TMath::Nint(hilooff->GetMedian()*10000)/10000.;
173 devoff = TMath::Nint(hilooff->GetDev() *10000)/10000.;
174
175 medcal = TMath::Nint(hilocal->GetMedian()*100)/100.;
176 devcal = TMath::Nint(hilocal->GetDev() *100)/100.;
177
178 medpuloff.Form("%7.4f", medoff);
179 devpuloff.Form("%7.4f", devoff);
180 medhilocal.Form("%6.2f", medcal);
181 devhilocal.Form("%6.2f", devcal);
182 }
183
184 TArrayI inner(1);
185 inner[0] = 0;
186
187 TArrayI outer(1);
188 outer[0] = 1;
189
190 Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
191
192 Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
193 Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
194
195 if (meanrmsi<0 || meanrmso<0)
196 {
197 cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
198 cout << "MeanPedRMS inner " << meanrmsi << endl;
199 cout << "MeanPedRMS outer " << meanrmso << endl;
200 return 2;
201 }
202
203 meanrmsi = TMath::Nint(meanrmsi*100)/100.;
204 meanrmso = TMath::Nint(meanrmso*100)/100.;
205
206 cam = (MHCamera*)arr.FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
207 if (!cam)
208 {
209 cout << "WARNING - Reading of Interp'd;avg failed." << endl;
210 return 2;
211 }
212
213 Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
214 Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
215
216 if (meansigi<0 || meansigo<0)
217 {
218 cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
219 cout << "MeanInterp'd inner " << meansigi << endl;
220 cout << "MeanInterp'd outer " << meansigo << endl;
221 return 2;
222 }
223
224 meansigi = TMath::Nint(meansigi*100)/100.;
225 meansigo = TMath::Nint(meansigo*100)/100.;
226
227 Stat_t meanpul = pul->GetMean();
228 Stat_t rmspul = pul->GetRMS();
229
230 if (meanpul<0 || rmspul<0)
231 {
232 cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
233 cout << "PulsePos'd mean " << meanpul << endl;
234 cout << "PulsePos'd rms " << rmspul << endl;
235 return 2;
236 }
237
238 meanpul = TMath::Nint(meanpul*100)/100.;
239 rmspul = TMath::Nint(rmspul *100)/100.;
240
241/*
242 Double_t meanhi = TMath::Nint(pulhi->GetMean()*100.)/100.;
243 Double_t rmshi = TMath::Nint(pulhi->GetRMS() *100.)/100.;
244
245 Double_t meanlo = TMath::Nint(pullo->GetMean()*100.)/100.;
246 Double_t rmslo = TMath::Nint(pullo->GetRMS() *100.)/100.;
247 pullo->Add(pullo, pulhi, 1, -1);
248 pullo->ResetBit(MHCamera::kProfile);
249
250 Double_t meanoff = TMath::Nint(pullo->GetMean()*100.)/100.;
251 Double_t rmsoff = TMath::Nint(pullo->GetRMS() *100.)/100.;
252 */
253
254 // USE MEDIAN INSTEAD? GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0);
255
256
257 TString meanrmsinner =Form("%6.2f", meanrmsi);
258 TString meanrmsouter =Form("%6.2f", meanrmso);
259 TString meansiginner =Form("%6.2f", meansigi);
260 TString meansigouter =Form("%6.2f", meansigo);
261 TString meanpulpos =Form("%6.2f", meanpul);
262 TString rmspulpos =Form("%6.2f", rmspul);
263 TString meanextpulpos=Form("%6.2f", meanextpul);
264 TString rmsextpulpos =Form("%6.2f", rmsextpul);
265 /*
266 TString meanpulhi =Form("%6.2f", meanhi);
267 TString rmspulhi =Form("%6.2f", rmshi);
268
269 TString meanpullo =Form("%6.2f", meanlo);
270 TString rmspullo =Form("%6.2f", rmslo);
271 */
272
273 if (meanextpul<0 && rmsextpul<0)
274 {
275 meanextpulpos = "NULL";
276 rmsextpulpos = "NULL";
277 }
278
279 // *****************************************************
280
281 // *****************************************************
282
283
284 cout << "Sequence #" << seq << endl;
285 cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
286 cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
287 cout << " Mean Signal inner [phe] " << meansiginner << endl;
288 cout << " Mean Signal outer [phe] " << meansigouter << endl;
289 cout << " Mean calibrated PulsePos " << meanpulpos << " +- " << rmspulpos << endl;
290 cout << " Mean extracted PulsePos " << meanextpulpos << " +- " << rmsextpulpos << endl;
291// cout << " Mean ext.HiGain PulsePos " << meanpulhi << " +- " << rmspulhi << endl;
292// cout << " Mean ext.LoGain PulsePos " << meanpullo << " +- " << rmspullo << endl;
293 cout << " Lo-Hi gain offset: " << medpuloff << " +- " << devpuloff << endl;
294 cout << " Hi/Lo gain ratio: " << medhilocal << " +- " << devhilocal << endl;
295 cout << endl;
296
297 //build query and insert information into the database
298 // here only a update query is built, as this macro is exexuted after
299 // the macro fillcalib.C in the script fillcallisto
300 // and so the table Calibration is always updated
301 TString query = Form("UPDATE Calibration SET "
302 " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
303 " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
304 " fPulsePosMean=%s, fPulsePosRms=%s, "
305 " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s, "
306 //" fPulsePosHiMean=%s, fPulsePosHiRms=%s, "
307 //" fPulsePosLoMean=%s, fPulsePosLoRms=%s, "
308 " fPulsePosOffMed=%s, fPulsePosOffDev=%s, "
309 " fHiLoGainRatioMed=%s, fHiLoGainRatioDev=%s "
310 " WHERE fSequenceFirst='%d' ",
311 meanrmsinner.Data(), meanrmsouter.Data(),
312 meansiginner.Data(), meansigouter.Data(),
313 meanpulpos.Data(), rmspulpos.Data(),
314 meanextpulpos.Data(), rmsextpulpos.Data(),
315 //meanpulhi.Data(), rmspulhi.Data(),
316 //meanpullo.Data(), rmspullo.Data(),
317 medpuloff.Data(), devpuloff.Data(),
318 medhilocal.Data(), devhilocal.Data(),
319 seq);
320
321 if (dummy)
322 return 1;
323
324 TSQLResult *res = serv.Query(query);
325 if (!res)
326 {
327 cout << "ERROR - Query failed: " << query << endl;
328 return 2;
329 }
330 delete res;
331 return 1;
332}
333
334int fillsignal(TString fname, Bool_t dummy=kTRUE)
335{
336 TEnv env("sql.rc");
337
338 MSQLServer serv(env);
339 if (!serv.IsConnected())
340 {
341 cout << "ERROR - Connection to database failed." << endl;
342 return 0;
343 }
344
345 cout << "fillsignal" << endl;
346 cout << "----------" << endl;
347 cout << endl;
348 cout << "Connected to " << serv.GetName() << endl;
349 cout << "File: " << fname << endl;
350 cout << endl;
351
352 //process file
353 return Process(serv, fname, dummy);
354}
Note: See TracBrowser for help on using the repository browser.