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

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