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

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