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

Last change on this file since 7528 was 7528, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 8.3 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 TArrayI inner(1);
121 inner[0] = 0;
122
123 TArrayI outer(1);
124 outer[0] = 1;
125
126 Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
127
128 Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
129 Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
130
131 if (meanrmsi<0 || meanrmso<0)
132 {
133 cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
134 cout << "MeanPedRMS inner " << meanrmsi << endl;
135 cout << "MeanPedRMS outer " << meanrmso << endl;
136 return 2;
137 }
138
139 meanrmsi = TMath::Nint(meanrmsi*100)/100.;
140 meanrmso = TMath::Nint(meanrmso*100)/100.;
141
142 cam = (MHCamera*)arr.FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
143 if (!cam)
144 {
145 cout << "WARNING - Reading of Interp'd;avg failed." << endl;
146 return 2;
147 }
148
149 Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
150 Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
151
152 if (meansigi<0 || meansigo<0)
153 {
154 cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
155 cout << "MeanInterp'd inner " << meansigi << endl;
156 cout << "MeanInterp'd outer " << meansigo << endl;
157 return 2;
158 }
159
160 meansigi = TMath::Nint(meansigi*100)/100.;
161 meansigo = TMath::Nint(meansigo*100)/100.;
162
163 Stat_t meanpul = pul->GetMean();
164 Stat_t rmspul = pul->GetRMS();
165
166 if (meanpul<0 || rmspul<0)
167 {
168 cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
169 cout << "PulsePos'd mean " << meanpul << endl;
170 cout << "PulsePos'd rms " << rmspul << endl;
171 return 2;
172 }
173
174 meanpul = TMath::Nint(meanpul*100)/100.;
175 rmspul = TMath::Nint(rmspul*100)/100.;
176
177 //get sequence number from the filename
178 TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
179 if (sequence.IsNull())
180 {
181 cout << "WARNING - Sequ# empty" << endl;
182 cout << "Sequ# " << sequence << endl;
183 return 2;
184 }
185
186 Int_t seq = atoi(sequence.Data()+6);
187 TString meanrmsinner =Form("%6.2f", meanrmsi);
188 TString meanrmsouter =Form("%6.2f", meanrmso);
189 TString meansiginner =Form("%6.2f", meansigi);
190 TString meansigouter =Form("%6.2f", meansigo);
191 TString meanpulpos =Form("%6.2f", meanpul);
192 TString rmspulpos =Form("%6.2f", rmspul);
193 TString meanextpulpos=Form("%6.2f", meanextpul);
194 TString rmsextpulpos =Form("%6.2f", rmsextpul);
195
196 if (meanextpul<0 && rmsextpul<0)
197 {
198 meanextpulpos = "NULL";
199 rmsextpulpos = "NULL";
200 }
201
202 cout << "Sequence #" << seq << endl;
203 cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
204 cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
205 cout << " Mean Signal inner [phe] " << meansiginner << endl;
206 cout << " Mean Signal outer [phe] " << meansigouter << endl;
207 cout << " Mean calibrated PulsePos " << meanpulpos << endl;
208 cout << " Rms calibrated PulsePos " << rmspulpos << endl;
209 cout << " Mean extracted PulsePos " << meanextpulpos << endl;
210 cout << " Rms extracted PulsePos " << rmsextpulpos << endl;
211
212 //build query and insert information into the database
213 // here only a update query is built, as this macro is exexuted after
214 // the macro fillcalib.C in the script fillcallisto
215 // and so the table Calibration is always updated
216 TString query = Form("UPDATE Calibration SET "
217 " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
218 " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
219 " fPulsePosMean=%s, fPulsePosRms=%s, "
220 " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s "
221 " WHERE fSequenceFirst='%d' ",
222 meanrmsinner.Data(), meanrmsouter.Data(),
223 meansiginner.Data(), meansigouter.Data(),
224 meanpulpos.Data(), rmspulpos.Data(),
225 meanextpulpos.Data(), rmsextpulpos.Data(),
226 seq);
227
228 if (dummy)
229 return 1;
230
231 TSQLResult *res = serv.Query(query);
232 if (!res)
233 {
234 cout << "ERROR - Query failed: " << query << endl;
235 return 2;
236 }
237
238 return 1;
239}
240
241int fillsignal(TString fname, Bool_t dummy=kTRUE)
242{
243 TEnv env("sql.rc");
244
245 MSQLServer serv(env);
246 if (!serv.IsConnected())
247 {
248 cout << "ERROR - Connection to database failed." << endl;
249 return 0;
250 }
251
252 cout << "fillsignal" << endl;
253 cout << "----------" << endl;
254 cout << endl;
255 cout << "Connected to " << serv.GetName() << endl;
256 cout << "File: " << fname << endl;
257 cout << endl;
258
259 //process file
260 return Process(serv, fname, dummy);
261}
Note: See TracBrowser for help on using the repository browser.