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

Last change on this file since 7428 was 7428, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 7.7 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-2004
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 for the inner and outer camera is extracted.
35//
36// Usage:
37// .x fillsignal.C("/data/MAGIC/Period014/signal00000.root", kTRUE)
38//
39// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
40// switched on and nothing will be written into the database. This is usefull
41// for tests.
42//
43// The macro can also be run without ACLiC but this is a lot slower...
44//
45// Remark: Running it from the commandline looks like this:
46// root -q -l -b fillsignal.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillsignal.log
47//
48// Make sure, that database and password are corretly set in a resource
49// file called sql.rc and the resource file is found.
50//
51// Returns 0 in case of failure and 1 in case of success.
52//
53/////////////////////////////////////////////////////////////////////////////
54#include <iostream>
55
56#include <TEnv.h>
57#include <TRegexp.h>
58
59#include <TFile.h>
60#include <TSQLResult.h>
61
62#include "MSQLServer.h"
63
64#include "MStatusArray.h"
65#include "MHCamera.h"
66
67#include "MCalibrationPulseTimeCam.h"
68#include "MCalibrationPix.h"
69
70using namespace std;
71
72int Process(MSQLServer &serv, TString fname, Bool_t dummy)
73{
74 TFile file(fname, "READ");
75 if (!file.IsOpen())
76 {
77 cout << "ERROR - Could not find file " << fname << endl;
78 return 0;
79 }
80
81 Float_t meanextpul = -1;
82 Float_t rmsextpul = -1;
83
84 MCalibrationPulseTimeCam *pt;
85 file.GetObject("MCalibrationPulseTimeCam", pt);
86 if (pt)
87 {
88 meanextpul = pt->GetAverageArea(0).GetHiGainMean();
89 rmsextpul = pt->GetAverageArea(0).GetHiGainRms();
90
91 meanextpul = TMath::Nint(meanextpul*100)/100.;
92 rmsextpul = TMath::Nint(rmsextpul*100)/100.;
93 }
94
95 MStatusArray arr;
96 if (arr.Read()<=0)
97 {
98 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
99 return 0;
100 }
101
102 MHCamera *cam = (MHCamera*)arr.FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
103 if (!cam)
104 {
105 cout << "WARNING - Reading of PedRMS;avg failed." << endl;
106 return 0;
107 }
108
109 MHCamera *pul = (MHCamera*)arr.FindObjectInCanvas("PulsePos;avg", "MHCamera", "PulsePos");
110 if (!pul)
111 {
112 cout << "WARNING - Reading of PulsePos;avg failed." << endl;
113 return 0;
114 }
115
116 TArrayI inner(1);
117 inner[0] = 0;
118
119 TArrayI outer(1);
120 outer[0] = 1;
121
122 Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
123
124 Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
125 Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
126
127 if (meanrmsi<0 || meanrmso<0)
128 {
129 cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
130 cout << "MeanPedRMS inner " << meanrmsi << endl;
131 cout << "MeanPedRMS outer " << meanrmso << endl;
132 return 0;
133 }
134
135 meanrmsi = TMath::Nint(meanrmsi*100)/100.;
136 meanrmso = TMath::Nint(meanrmso*100)/100.;
137
138 cam = (MHCamera*)arr.FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
139 if (!cam)
140 {
141 cout << "WARNING - Reading of Interp'd;avg failed." << endl;
142 return 0;
143 }
144
145 Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
146 Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
147
148 if (meansigi<0 || meansigo<0)
149 {
150 cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
151 cout << "MeanInterp'd inner " << meansigi << endl;
152 cout << "MeanInterp'd outer " << meansigo << endl;
153 return 0;
154 }
155
156 meansigi = TMath::Nint(meansigi*100)/100.;
157 meansigo = TMath::Nint(meansigo*100)/100.;
158
159 Stat_t meanpul = pul->GetMean();
160 Stat_t rmspul = pul->GetRMS();
161
162 if (meanpul<0 || rmspul<0)
163 {
164 cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
165 cout << "PulsePos'd mean " << meanpul << endl;
166 cout << "PulsePos'd rms " << rmspul << endl;
167 return 0;
168 }
169
170 meanpul = TMath::Nint(meanpul*100)/100.;
171 rmspul = TMath::Nint(rmspul*100)/100.;
172
173 TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
174 if (sequence.IsNull())
175 {
176 cout << "WARNING - Sequ# empty" << endl;
177 cout << "Sequ# " << sequence << endl;
178 return 0;
179 }
180
181 Int_t seq = atoi(sequence.Data()+6);
182 TString meanrmsinner =Form("%6.2f", meanrmsi);
183 TString meanrmsouter =Form("%6.2f", meanrmso);
184 TString meansiginner =Form("%6.2f", meansigi);
185 TString meansigouter =Form("%6.2f", meansigo);
186 TString meanpulpos =Form("%6.2f", meanpul);
187 TString rmspulpos =Form("%6.2f", rmspul);
188 TString meanextpulpos=Form("%6.2f", meanextpul);
189 TString rmsextpulpos =Form("%6.2f", rmsextpul);
190
191 if (meanextpul<0 && rmsextpul<0)
192 {
193 meanextpulpos = "NULL";
194 rmsextpulpos = "NULL";
195 }
196
197 cout << "Sequence #" << seq << endl;
198 cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
199 cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
200 cout << " Mean Signal inner [phe] " << meansiginner << endl;
201 cout << " Mean Signal outer [phe] " << meansigouter << endl;
202 cout << " Mean calibrated PulsePos " << meanpulpos << endl;
203 cout << " Rms calibrated PulsePos " << rmspulpos << endl;
204 cout << " Mean extracted PulsePos " << meanextpulpos << endl;
205 cout << " Rms extracted PulsePos " << rmsextpulpos << endl;
206
207 TString query = Form("UPDATE Calibration SET "
208 " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
209 " fMeanSignalInner=%s, fMeanSignalOuter=%s, "
210 " fPulsePosMean=%s, fPulsePosRms=%s, "
211 " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s "
212 " WHERE fSequenceFirst='%d' ",
213 meanrmsinner.Data(), meanrmsouter.Data(),
214 meansiginner.Data(), meansigouter.Data(),
215 meanpulpos.Data(), rmspulpos.Data(),
216 meanextpulpos.Data(), rmsextpulpos.Data(),
217 seq);
218
219 if (dummy)
220 return 0;
221
222 TSQLResult *res = serv.Query(query);
223 if (!res)
224 {
225 cout << "ERROR - Query failed: " << query << endl;
226 return 0;
227 }
228
229 return 1;
230}
231
232int fillsignal(TString fname, Bool_t dummy=kTRUE)
233{
234 TEnv env("sql.rc");
235
236 MSQLServer serv(env);
237 if (!serv.IsConnected())
238 {
239 cout << "ERROR - Connection to database failed." << endl;
240 return 0;
241 }
242
243 cout << "fillsignal" << endl;
244 cout << "----------" << endl;
245 cout << endl;
246 cout << "Connected to " << serv.GetName() << endl;
247 cout << "File: " << fname << endl;
248 cout << endl;
249
250 return Process(serv, fname, dummy);
251}
Note: See TracBrowser for help on using the repository browser.