source: branches/removing_cpp11_features/datacenter/macros/fillmccalib.C@ 18160

Last change on this file since 18160 was 9225, checked in by hoehne, 16 years ago
*** empty log message ***
File size: 10.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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
20! Author(s): Daniel Hoehne-Moench, 01/2009 <mailto:hoehne@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2009
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// fillmccalib.C
30// ===========
31//
32// This macro is used to read the calibration-/callisto-output files.
33// These files are automatically called calib00000.root.
34//
35// From this file the MBadPixelsCam and the MGeomCam is extracted. If
36// the geometry isn't found MGeomCamMagic is used as a default.
37// The bad pixel information and other information, extracted from the status
38// display, is inserted into the database in the table MCCalibration, which
39// stores the results from the calibration.
40// The corresponding sequence number is extracted from the filename...
41//
42// Usage:
43// .x fillmccalib.C("/magic/montecarlo/callisto/0002/00048270/calib00028270.root", kTRUE)
44//
45// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
46// switched on and nothing will be written into the database. This is usefull
47// for tests.
48//
49// The macro can also be run without ACLiC but this is a lot slower...
50//
51// Remark: Running it from the commandline looks like this:
52// root -q -l -b fillmccalib.C+\(\"filename\"\,kFALSE\)
53//
54// Make sure, that database and password are corretly set in a resource
55// file called sql.rc and the resource file is found.
56//
57// Returns 2 in case of failure, 1 in case of success and 0 if the connection
58// to the database is not working.
59//
60/////////////////////////////////////////////////////////////////////////////
61#include <iostream>
62
63#include <TRegexp.h>
64
65#include <TH1.h>
66
67#include <TFile.h>
68#include <TSQLResult.h>
69#include <TSQLRow.h>
70
71#include "MSQLServer.h"
72#include "MSQLMagic.h"
73
74#include "MStatusArray.h"
75#include "MHCamera.h"
76#include "MSequence.h"
77#include "MGeomCamMagic.h"
78#include "MBadPixelsCam.h"
79
80using namespace std;
81
82int Process(MSQLMagic &serv, TString fname)
83{
84 //getting number of unsuitable, unreliable and isolated pixel
85 MBadPixelsCam badpix;
86
87 TFile file(fname, "READ");
88 if (!file.IsOpen())
89 {
90 cout << "ERROR - Could not find file " << fname << endl;
91 return 2;
92 }
93
94 if (badpix.Read("MBadPixelsCam")<=0)
95 {
96 cout << "ERROR - Reading of MBadPixelsCam failed." << endl;
97 return 2;
98 }
99
100 MGeomCamMagic def;
101
102 MGeomCam *geom = (MGeomCam*)file.Get("MGeomCam");
103 if (!geom)
104 {
105 cout << "WARNING - Reading of MGeomCam failed... using default <MGeomCamMagic>" << endl;
106 geom = &def;
107 }
108
109 cout << "Camera Geometry: " << geom->ClassName() << endl;
110
111 const Short_t unsin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 0);
112 const Short_t unsout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 1);
113
114 const Short_t unrin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 0);
115 const Short_t unrout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 1);
116
117 const Short_t isoin = badpix.GetNumIsolated(*geom, 0);
118 const Short_t isoout = badpix.GetNumIsolated(*geom, 1);
119
120 const Short_t clumax = badpix.GetNumMaxCluster(*geom);
121
122 if (unsin<0 || unsout<0 || unrin<0 || unrout<0 || isoin<0 || isoout<0 || clumax<0)
123 {
124 cout << "ERROR - one of the pixel values < 0." << endl;
125 return 2;
126 }
127
128 //Getting values from the status display
129 MStatusArray arr;
130 if (arr.Read()<=0)
131 {
132 cout << "ERROR - could not read MStatusArray." << endl;
133 return 2;
134 }
135
136 TH1 *h;
137
138 //getting the mean and rms from the arrival time (inner cam)
139 h = (TH1*)arr.FindObjectInCanvas("HRelTimeHiGainArea0", "TH1F", "Time");
140 if (!h)
141 {
142 cout << "ERROR - Could not find histogram HRelTimeHiGainArea0." << endl;
143 return 2;
144 }
145
146 TString meaninner = Form("%5.1f", h->GetMean());
147 TString rmsinner = Form("%6.2f", h->GetRMS());
148
149 //getting the mean and rms from the arrival time (outer cam)
150 h = (TH1*)arr.FindObjectInCanvas("HRelTimeHiGainArea1", "TH1F", "Time");
151 if (!h)
152 {
153 cout << "ERROR - Could not find histogram HRelTimeHiGainArea1." << endl;
154 return 2;
155 }
156
157 TString meanouter = Form("%5.1f", h->GetMean());
158 TString rmsouter = Form("%6.2f", h->GetRMS());
159
160 //Getting conversion factors
161 MHCamera *c = (MHCamera*)arr.FindObjectInCanvas("TotalConvPhe", "MHCamera", "Conversion");
162 if (!c)
163 {
164 cout << "ERROR - Could not find MHCamera TotalConv." << endl;
165 return 2;
166 }
167
168 TArrayI inner(1), outer(1);
169 inner[0] = 0;
170 outer[0] = 1;
171
172 Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
173
174 Stat_t meanconvi = c->GetMeanSectors(TArrayI(6, s0), inner);
175 Stat_t meanconvo = c->GetMeanSectors(TArrayI(6, s0), outer);
176 TString meanconvinner=Form("%6.3f", meanconvi);
177 TString meanconvouter=Form("%6.3f", meanconvo);
178
179 //Getting relative charge rms
180 c = (MHCamera*)arr.FindObjectInCanvas("RMSperMean", "MHCamera", "FitCharge");
181 if (!c)
182 {
183 cout << "ERROR - Could not find MHCamera RMSperMean in FitCharge." << endl;
184 return 2;
185 }
186
187 Stat_t relrmsi = c->GetMedianSectors(TArrayI(6, s0), inner);
188 Stat_t relrmso = c->GetMedianSectors(TArrayI(6, s0), outer);
189 TString relrmsinner=Form("%6.3f", relrmsi);
190 TString relrmsouter=Form("%6.3f", relrmso);
191
192 //Getting relative charge rms
193 c = (MHCamera*)arr.FindObjectInCanvas("NumPhes", "MHCamera", "FitCharge");
194 if (!c)
195 {
196 cout << "ERROR - Could not find MHCamera NumPhes in FitCharge." << endl;
197 return 2;
198 }
199
200 Stat_t numphei = c->GetMedianSectors(TArrayI(6, s0), inner);
201 Stat_t numpheo = c->GetMedianSectors(TArrayI(6, s0), outer);
202 TString numpheinner=Form("%5.1f", numphei);
203 TString numpheouter=Form("%5.1f", numpheo);
204
205 MSequence seq;
206 if (seq.Read("sequence[0-9]{8}[.]txt|MSequence")<=0)
207 {
208 cout << "ERROR - Could not find sequence in file: " << fname << endl;
209 return 2;
210 }
211 if (!seq.IsValid())
212 {
213 cout << "ERROR - Sequence read from file inavlid: " << fname << endl;
214 return 2;
215 }
216
217 //getting the ratio of calibration events used
218 h = (TH1*)arr.FindObjectInCanvas("ArrTm;avg", "MHCamera", "ArrTm");
219 if (!h)
220 {
221 cout << "ERROR - Could not find histogram ArrTime;avg." << endl;
222 return 2;
223 }
224
225 UInt_t nevts = TMath::Nint(h->GetEntries());
226
227 //Num of calibration events is 5000 for all MC C runs
228 UInt_t calevts = 5000;
229
230 Float_t ratiocalib = 100.*nevts/calevts;
231
232 TString ratiocal = Form("%.1f", ratiocalib);
233
234 cout << "Sequence " << seq.GetSequence() << endl;
235 cout << " Unsuitable: (i/o) " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
236 cout << " Unreliable: (i/o) " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
237 cout << " Isolated: (i/o) " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
238 cout << " Max.Cluster: " << Form("%3d", (int)clumax) << endl; // Max Cluster
239 cout << " Arr Time inner: " << meaninner << " +- " << rmsinner << endl;
240 cout << " Arr Time outer: " << meanouter << " +- " << rmsouter << endl;
241 cout << " Mean Conv inner: " << meanconvinner << endl;
242 cout << " Mean Conv outer: " << meanconvouter << endl;
243 cout << " Rel.charge rms in: " << relrmsinner << endl;
244 cout << " Rel.charge rms out: " << relrmsouter << endl;
245 cout << " Med. num phe inner: " << numpheinner << endl;
246 cout << " Med. num phe outer: " << numpheouter << endl;
247 cout << " Ratio Calib Evts: " << ratiocal << endl;
248
249 //inserting or updating the information in the database
250 TString vars =
251 Form(" fSequenceFirst=%d, "
252 " fUnsuitableInner=%d, "
253 " fUnsuitableOuter=%d, "
254 " fUnreliableInner=%d, "
255 " fUnreliableOuter=%d, "
256 " fIsolatedInner=%d, "
257 " fIsolatedOuter=%d, "
258 " fIsolatedMaxCluster=%d, "
259 " fArrTimeMeanInner=%s, "
260 " fArrTimeRmsInner=%s, "
261 " fArrTimeMeanOuter=%s, "
262 " fArrTimeRmsOuter=%s, "
263 " fConvFactorInner=%s, "
264 " fConvFactorOuter=%s, "
265 " fRatioCalEvts=%s, "
266 " fRelChargeRmsInner=%s, "
267 " fRelChargeRmsOuter=%s, "
268 " fMedNumPheInner=%s, "
269 " fMedNumPheOuter=%s ",
270 seq.GetSequence(),
271 (int)unsin, (int)unsout, (int)unrin,
272 (int)unrout, (int)isoin, (int)isoout, (int)clumax,
273 meaninner.Data(), rmsinner.Data(),
274 meanouter.Data(), rmsouter.Data(),
275 meanconvinner.Data(), meanconvouter.Data(),
276 ratiocal.Data(),
277 relrmsinner.Data(), relrmsouter.Data(),
278 numpheinner.Data(), numpheouter.Data()
279 );
280
281 TString where = Form("fSequenceFirst=%d", seq.GetSequence());
282
283 return serv.InsertUpdate("MCCalibration", vars, where) ? 1 : 2;
284}
285
286int fillmccalib(TString fname, Bool_t dummy=kTRUE)
287{
288 MSQLMagic serv("sql.rc");
289 if (!serv.IsConnected())
290 {
291 cout << "ERROR - Connection to database failed." << endl;
292 return 0;
293 }
294
295 cout << "fillmccalib" << endl;
296 cout << "---------" << endl;
297 cout << endl;
298 cout << "Connected to " << serv.GetName() << endl;
299 cout << "File: " << fname << endl;
300 cout << endl;
301
302 serv.SetIsDummy(dummy);
303
304 return Process(serv, fname);
305}
Note: See TracBrowser for help on using the repository browser.