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 0 in case of failure and 1 in case of success.
|
---|
55 | //
|
---|
56 | /////////////////////////////////////////////////////////////////////////////
|
---|
57 | #include <iostream>
|
---|
58 |
|
---|
59 | #include <TEnv.h>
|
---|
60 | #include <TRegexp.h>
|
---|
61 |
|
---|
62 | #include <TFile.h>
|
---|
63 | #include <TSQLResult.h>
|
---|
64 |
|
---|
65 | #include "MSQLServer.h"
|
---|
66 |
|
---|
67 | #include "MStatusArray.h"
|
---|
68 | #include "MHCamera.h"
|
---|
69 |
|
---|
70 | #include "MCalibrationPulseTimeCam.h"
|
---|
71 | #include "MCalibrationPix.h"
|
---|
72 |
|
---|
73 | using namespace std;
|
---|
74 |
|
---|
75 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
76 | {
|
---|
77 | TFile file(fname, "READ");
|
---|
78 | if (!file.IsOpen())
|
---|
79 | {
|
---|
80 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
81 | return 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | Float_t meanextpul = -1;
|
---|
85 | Float_t rmsextpul = -1;
|
---|
86 |
|
---|
87 | MCalibrationPulseTimeCam *pt;
|
---|
88 | file.GetObject("MCalibrationPulseTimeCam", pt);
|
---|
89 | if (pt)
|
---|
90 | {
|
---|
91 | meanextpul = pt->GetAverageArea(0).GetHiGainMean();
|
---|
92 | rmsextpul = pt->GetAverageArea(0).GetHiGainRms();
|
---|
93 |
|
---|
94 | meanextpul = TMath::Nint(meanextpul*100)/100.;
|
---|
95 | rmsextpul = TMath::Nint(rmsextpul*100)/100.;
|
---|
96 | }
|
---|
97 |
|
---|
98 | MStatusArray arr;
|
---|
99 | if (arr.Read()<=0)
|
---|
100 | {
|
---|
101 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
102 | return 0;
|
---|
103 | }
|
---|
104 |
|
---|
105 | MHCamera *cam = (MHCamera*)arr.FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
|
---|
106 | if (!cam)
|
---|
107 | {
|
---|
108 | cout << "WARNING - Reading of PedRMS;avg failed." << endl;
|
---|
109 | return 0;
|
---|
110 | }
|
---|
111 |
|
---|
112 | MHCamera *pul = (MHCamera*)arr.FindObjectInCanvas("PulsePos;avg", "MHCamera", "PulsePos");
|
---|
113 | if (!pul)
|
---|
114 | {
|
---|
115 | cout << "WARNING - Reading of PulsePos;avg failed." << endl;
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | TArrayI inner(1);
|
---|
120 | inner[0] = 0;
|
---|
121 |
|
---|
122 | TArrayI outer(1);
|
---|
123 | outer[0] = 1;
|
---|
124 |
|
---|
125 | Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
|
---|
126 |
|
---|
127 | Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
128 | Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
129 |
|
---|
130 | if (meanrmsi<0 || meanrmso<0)
|
---|
131 | {
|
---|
132 | cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
|
---|
133 | cout << "MeanPedRMS inner " << meanrmsi << endl;
|
---|
134 | cout << "MeanPedRMS outer " << meanrmso << endl;
|
---|
135 | return 0;
|
---|
136 | }
|
---|
137 |
|
---|
138 | meanrmsi = TMath::Nint(meanrmsi*100)/100.;
|
---|
139 | meanrmso = TMath::Nint(meanrmso*100)/100.;
|
---|
140 |
|
---|
141 | cam = (MHCamera*)arr.FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
|
---|
142 | if (!cam)
|
---|
143 | {
|
---|
144 | cout << "WARNING - Reading of Interp'd;avg failed." << endl;
|
---|
145 | return 0;
|
---|
146 | }
|
---|
147 |
|
---|
148 | Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
149 | Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
150 |
|
---|
151 | if (meansigi<0 || meansigo<0)
|
---|
152 | {
|
---|
153 | cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
|
---|
154 | cout << "MeanInterp'd inner " << meansigi << endl;
|
---|
155 | cout << "MeanInterp'd outer " << meansigo << endl;
|
---|
156 | return 0;
|
---|
157 | }
|
---|
158 |
|
---|
159 | meansigi = TMath::Nint(meansigi*100)/100.;
|
---|
160 | meansigo = TMath::Nint(meansigo*100)/100.;
|
---|
161 |
|
---|
162 | Stat_t meanpul = pul->GetMean();
|
---|
163 | Stat_t rmspul = pul->GetRMS();
|
---|
164 |
|
---|
165 | if (meanpul<0 || rmspul<0)
|
---|
166 | {
|
---|
167 | cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
|
---|
168 | cout << "PulsePos'd mean " << meanpul << endl;
|
---|
169 | cout << "PulsePos'd rms " << rmspul << endl;
|
---|
170 | return 0;
|
---|
171 | }
|
---|
172 |
|
---|
173 | meanpul = TMath::Nint(meanpul*100)/100.;
|
---|
174 | rmspul = TMath::Nint(rmspul*100)/100.;
|
---|
175 |
|
---|
176 | //get sequence number from the filename
|
---|
177 | TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
|
---|
178 | if (sequence.IsNull())
|
---|
179 | {
|
---|
180 | cout << "WARNING - Sequ# empty" << endl;
|
---|
181 | cout << "Sequ# " << sequence << endl;
|
---|
182 | return 0;
|
---|
183 | }
|
---|
184 |
|
---|
185 | Int_t seq = atoi(sequence.Data()+6);
|
---|
186 | TString meanrmsinner =Form("%6.2f", meanrmsi);
|
---|
187 | TString meanrmsouter =Form("%6.2f", meanrmso);
|
---|
188 | TString meansiginner =Form("%6.2f", meansigi);
|
---|
189 | TString meansigouter =Form("%6.2f", meansigo);
|
---|
190 | TString meanpulpos =Form("%6.2f", meanpul);
|
---|
191 | TString rmspulpos =Form("%6.2f", rmspul);
|
---|
192 | TString meanextpulpos=Form("%6.2f", meanextpul);
|
---|
193 | TString rmsextpulpos =Form("%6.2f", rmsextpul);
|
---|
194 |
|
---|
195 | if (meanextpul<0 && rmsextpul<0)
|
---|
196 | {
|
---|
197 | meanextpulpos = "NULL";
|
---|
198 | rmsextpulpos = "NULL";
|
---|
199 | }
|
---|
200 |
|
---|
201 | cout << "Sequence #" << seq << endl;
|
---|
202 | cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
|
---|
203 | cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
|
---|
204 | cout << " Mean Signal inner [phe] " << meansiginner << endl;
|
---|
205 | cout << " Mean Signal outer [phe] " << meansigouter << endl;
|
---|
206 | cout << " Mean calibrated PulsePos " << meanpulpos << endl;
|
---|
207 | cout << " Rms calibrated PulsePos " << rmspulpos << endl;
|
---|
208 | cout << " Mean extracted PulsePos " << meanextpulpos << endl;
|
---|
209 | cout << " Rms extracted PulsePos " << rmsextpulpos << endl;
|
---|
210 |
|
---|
211 | //build query and insert information into the database
|
---|
212 | // here only a update query is built, as this macro is exexuted after
|
---|
213 | // the macro fillcalib.C in the script fillcallisto
|
---|
214 | // and so the table Calibration is always updated
|
---|
215 | TString query = Form("UPDATE Calibration SET "
|
---|
216 | " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
|
---|
217 | " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
|
---|
218 | " fPulsePosMean=%s, fPulsePosRms=%s, "
|
---|
219 | " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s "
|
---|
220 | " WHERE fSequenceFirst='%d' ",
|
---|
221 | meanrmsinner.Data(), meanrmsouter.Data(),
|
---|
222 | meansiginner.Data(), meansigouter.Data(),
|
---|
223 | meanpulpos.Data(), rmspulpos.Data(),
|
---|
224 | meanextpulpos.Data(), rmsextpulpos.Data(),
|
---|
225 | seq);
|
---|
226 |
|
---|
227 | if (dummy)
|
---|
228 | return 0;
|
---|
229 |
|
---|
230 | TSQLResult *res = serv.Query(query);
|
---|
231 | if (!res)
|
---|
232 | {
|
---|
233 | cout << "ERROR - Query failed: " << query << endl;
|
---|
234 | return 0;
|
---|
235 | }
|
---|
236 |
|
---|
237 | return 1;
|
---|
238 | }
|
---|
239 |
|
---|
240 | int fillsignal(TString fname, Bool_t dummy=kTRUE)
|
---|
241 | {
|
---|
242 | TEnv env("sql.rc");
|
---|
243 |
|
---|
244 | MSQLServer serv(env);
|
---|
245 | if (!serv.IsConnected())
|
---|
246 | {
|
---|
247 | cout << "ERROR - Connection to database failed." << endl;
|
---|
248 | return 0;
|
---|
249 | }
|
---|
250 |
|
---|
251 | cout << "fillsignal" << endl;
|
---|
252 | cout << "----------" << endl;
|
---|
253 | cout << endl;
|
---|
254 | cout << "Connected to " << serv.GetName() << endl;
|
---|
255 | cout << "File: " << fname << endl;
|
---|
256 | cout << endl;
|
---|
257 |
|
---|
258 | //process file
|
---|
259 | return Process(serv, fname, dummy);
|
---|
260 | }
|
---|