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

Last change on this file since 7854 was 7854, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 11.2 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 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 Double_t meanoff = TMath::Nint(hilooff->GetMean()*100.)/100.;
217 Double_t rmsoff = TMath::Nint(hilooff->GetRMS() *100.)/100.;
218
219 Double_t meancal = TMath::Nint(hilocal->GetMean()*100.)/100.;
220 Double_t rmscal = TMath::Nint(hilocal->GetRMS() *100.)/100.;
221
222 //get sequence number from the filename
223 TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
224 if (sequence.IsNull())
225 {
226 cout << "WARNING - Sequ# empty" << endl;
227 cout << "Sequ# " << sequence << endl;
228 return 2;
229 }
230
231 Int_t seq = atoi(sequence.Data()+6);
232 TString meanrmsinner =Form("%6.2f", meanrmsi);
233 TString meanrmsouter =Form("%6.2f", meanrmso);
234 TString meansiginner =Form("%6.2f", meansigi);
235 TString meansigouter =Form("%6.2f", meansigo);
236 TString meanpulpos =Form("%6.2f", meanpul);
237 TString rmspulpos =Form("%6.2f", rmspul);
238 TString meanextpulpos=Form("%6.2f", meanextpul);
239 TString rmsextpulpos =Form("%6.2f", rmsextpul);
240 /*
241 TString meanpulhi =Form("%6.2f", meanhi);
242 TString rmspulhi =Form("%6.2f", rmshi);
243
244 TString meanpullo =Form("%6.2f", meanlo);
245 TString rmspullo =Form("%6.2f", rmslo);
246 */
247 TString meanpuloff =Form("%6.2f", meanoff);
248 TString rmspuloff =Form("%6.2f", rmsoff);
249 TString meanhilocal =Form("%6.2f", meancal);
250 TString rmshilocal =Form("%6.2f", rmscal);
251
252 if (meanextpul<0 && rmsextpul<0)
253 {
254 meanextpulpos = "NULL";
255 rmsextpulpos = "NULL";
256 }
257
258 // *****************************************************
259
260 // *****************************************************
261
262
263 cout << "Sequence #" << seq << endl;
264 cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
265 cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
266 cout << " Mean Signal inner [phe] " << meansiginner << endl;
267 cout << " Mean Signal outer [phe] " << meansigouter << endl;
268 cout << " Mean calibrated PulsePos " << meanpulpos << " +- " << rmspulpos << endl;
269 cout << " Mean extracted PulsePos " << meanextpulpos << " +- " << rmsextpulpos << endl;
270// cout << " Mean ext.HiGain PulsePos " << meanpulhi << " +- " << rmspulhi << endl;
271// cout << " Mean ext.LoGain PulsePos " << meanpullo << " +- " << rmspullo << endl;
272 cout << " Lo-Hi gain offset: " << meanpuloff << " +- " << rmspuloff << endl;
273 cout << " Hi/Lo gain ratio: " << meanhilocal << " +- " << rmshilocal << endl;
274 cout << endl;
275
276 //build query and insert information into the database
277 // here only a update query is built, as this macro is exexuted after
278 // the macro fillcalib.C in the script fillcallisto
279 // and so the table Calibration is always updated
280 TString query = Form("UPDATE Calibration SET "
281 " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
282 " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
283 " fPulsePosMean=%s, fPulsePosRms=%s, "
284 " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s, "
285 //" fPulsePosHiMean=%s, fPulsePosHiRms=%s, "
286 //" fPulsePosLoMean=%s, fPulsePosLoRms=%s, "
287 " fPulsePosOffMean=%s, fPulsePosOffRms=%s, "
288 " fHiLoGainRatioMean=%s, fHiLoGainRatioRms=%s, "
289 " WHERE fSequenceFirst='%d' ",
290 meanrmsinner.Data(), meanrmsouter.Data(),
291 meansiginner.Data(), meansigouter.Data(),
292 meanpulpos.Data(), rmspulpos.Data(),
293 meanextpulpos.Data(), rmsextpulpos.Data(),
294 //meanpulhi.Data(), rmspulhi.Data(),
295 //meanpullo.Data(), rmspullo.Data(),
296 meanpuloff.Data(), rmspuloff.Data(),
297 meanhilocal.Data(), rmshilocal.Data(),
298 seq);
299
300 if (dummy)
301 return 1;
302
303 TSQLResult *res = serv.Query(query);
304 if (!res)
305 {
306 cout << "ERROR - Query failed: " << query << endl;
307 return 2;
308 }
309 delete res;
310 return 1;
311}
312
313int fillsignal(TString fname, Bool_t dummy=kTRUE)
314{
315 TEnv env("sql.rc");
316
317 MSQLServer serv(env);
318 if (!serv.IsConnected())
319 {
320 cout << "ERROR - Connection to database failed." << endl;
321 return 0;
322 }
323
324 cout << "fillsignal" << endl;
325 cout << "----------" << endl;
326 cout << endl;
327 cout << "Connected to " << serv.GetName() << endl;
328 cout << "File: " << fname << endl;
329 cout << endl;
330
331 //process file
332 return Process(serv, fname, dummy);
333}
Note: See TracBrowser for help on using the repository browser.