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

Last change on this file since 7382 was 7363, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 5.8 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
67using namespace std;
68
69int Process(MSQLServer &serv, TString fname, Bool_t dummy)
70{
71 TFile file(fname, "READ");
72 if (!file.IsOpen())
73 {
74 cout << "ERROR - Could not find file " << fname << endl;
75 return 0;
76 }
77
78 MStatusArray *arr = (MStatusArray*)file.Get("MStatusDisplay");
79 if (!arr)
80 {
81 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
82 return 0;
83 }
84
85 MHCamera *cam = (MHCamera*)arr->FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
86 if (!cam)
87 {
88 cout << "WARNING - Reading of PedRMS;avg failed." << endl;
89 return 0;
90 }
91
92 TArrayI inner(1);
93 inner[0] = 0;
94
95 TArrayI outer(1);
96 outer[0] = 1;
97
98 Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
99
100 Stat_t meanrmsi = cam->GetMeanSectors(TArrayI(6, s0), inner);
101 Stat_t meanrmso = cam->GetMeanSectors(TArrayI(6, s0), outer);
102
103 if (meanrmsi<0 || meanrmso<0)
104 {
105 cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
106 cout << "MeanPedRMS inner " << meanrmsi << endl;
107 cout << "MeanPedRMS outer " << meanrmso << endl;
108 return 0;
109 }
110
111 meanrmsi = TMath::Nint(meanrmsi*100)/100.;
112 meanrmso = TMath::Nint(meanrmso*100)/100.;
113
114 cam = (MHCamera*)arr->FindObjectInCanvas("Interp'd;avg", "MHCamera", "Interp'd");
115 if (!cam)
116 {
117 cout << "WARNING - Reading of Interp'd;avg failed." << endl;
118 return 0;
119 }
120
121 Stat_t meansigi = cam->GetMeanSectors(TArrayI(6, s0), inner);
122 Stat_t meansigo = cam->GetMeanSectors(TArrayI(6, s0), outer);
123
124 if (meansigi<0 || meansigo<0)
125 {
126 cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
127 cout << "MeanInterp'd inner " << meansigi << endl;
128 cout << "MeanInterp'd outer " << meansigo << endl;
129 return 0;
130 }
131
132 meansigi = TMath::Nint(meansigi*100)/100.;
133 meansigo = TMath::Nint(meansigo*100)/100.;
134
135 TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
136 if (sequence.IsNull())
137 {
138 cout << "WARNING - Sequ# empty" << endl;
139 cout << "Sequ# " << sequence << endl;
140 return 0;
141 }
142
143 Int_t seq = atoi(sequence.Data()+6);
144 TString meanrmsinner=Form("%6.2f", meanrmsi);
145 TString meanrmsouter=Form("%6.2f", meanrmso);
146 TString meansiginner=Form("%6.2f", meansigi);
147 TString meansigouter=Form("%6.2f", meansigo);
148
149 cout << "Sequence #" << seq << endl;
150 cout << " Mean Ped RMS inner [phe] " << meanrmsinner << endl;
151 cout << " Mean Ped RMS outer [phe] " << meanrmsouter << endl;
152 cout << " Mean Signal inner [phe] " << meansiginner << endl;
153 cout << " Mean Signal outer [phe] " << meansigouter << endl;
154
155 TString query = Form("UPDATE Calibration SET "
156 " fMeanPedRmsInner=%s, fMeanPedRmsOuter=%s, "
157 " fMeanSignalInner=%s, fMeanSignalOuter=%s "
158 " WHERE fSequenceFirst='%d' ",
159 meanrmsinner.Data(), meanrmsouter.Data(),
160 meansiginner.Data(), meansigouter.Data(),
161 seq);
162
163 if (dummy)
164 return 0;
165
166 TSQLResult *res = serv.Query(query);
167 if (!res)
168 {
169 cout << "ERROR - Query failed: " << query << endl;
170 return 0;
171 }
172
173 return 1;
174}
175
176int fillsignal(TString fname, Bool_t dummy=kTRUE)
177{
178 TEnv env("sql.rc");
179
180 MSQLServer serv(env);
181 if (!serv.IsConnected())
182 {
183 cout << "ERROR - Connection to database failed." << endl;
184 return 0;
185 }
186
187 cout << "fillsignal" << endl;
188 cout << "----------" << endl;
189 cout << endl;
190 cout << "Connected to " << serv.GetName() << endl;
191 cout << "File: " << fname << endl;
192 cout << endl;
193
194 return Process(serv, fname, dummy);
195}
Note: See TracBrowser for help on using the repository browser.