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 | using namespace std;
|
---|
68 |
|
---|
69 | int 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 meani = cam->GetMeanSectors(TArrayI(6, s0), inner);
|
---|
101 | Stat_t meano = cam->GetMeanSectors(TArrayI(6, s0), outer);
|
---|
102 |
|
---|
103 | if (meani<0 || meano<0)
|
---|
104 | {
|
---|
105 | cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
|
---|
106 | cout << "MeanPedRMS inner " << meani << endl;
|
---|
107 | cout << "MeanPedRMS outer " << meano << endl;
|
---|
108 | return 0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | meani = TMath::Nint(meani*10)/10.;
|
---|
112 | meano = TMath::Nint(meano*10)/10.;
|
---|
113 |
|
---|
114 | TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
|
---|
115 | if (sequence.IsNull())
|
---|
116 | {
|
---|
117 | cout << "WARNING - Sequ# empty" << endl;
|
---|
118 | cout << "Sequ# " << sequence << endl;
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | Int_t seq = atoi(sequence.Data()+6);
|
---|
123 | TString meaninner=Form("%4.1f", meani);
|
---|
124 | TString meanouter=Form("%4.1f", meano);
|
---|
125 |
|
---|
126 | cout << "Sequence #" << seq << endl;
|
---|
127 | cout << " Mean Ped RMS inner [phe] " << Form("%4.1f", meani) << endl;
|
---|
128 | cout << " Mean Ped RMS outer [phe] " << Form("%4.1f", meano) << endl;
|
---|
129 |
|
---|
130 | TString query = Form("UPDATE MyMagic.Calibration SET fMeanPedRmsInner=%s, "
|
---|
131 | " fMeanPedRmsOuter=%s WHERE fSequenceFirst='%d' ",
|
---|
132 | meaninner.Data(), meanouter.Data(), seq);
|
---|
133 |
|
---|
134 | if (dummy)
|
---|
135 | return 0;
|
---|
136 |
|
---|
137 | TSQLResult *res = serv.Query(query);
|
---|
138 | if (!res)
|
---|
139 | {
|
---|
140 | cout << "ERROR - Query failed: " << query << endl;
|
---|
141 | return 0;
|
---|
142 | }
|
---|
143 |
|
---|
144 | return 1;
|
---|
145 | }
|
---|
146 |
|
---|
147 | int fillsignal(TString fname, Bool_t dummy=kTRUE)
|
---|
148 | {
|
---|
149 | TEnv env("sql.rc");
|
---|
150 |
|
---|
151 | MSQLServer serv(env);
|
---|
152 | if (!serv.IsConnected())
|
---|
153 | {
|
---|
154 | cout << "ERROR - Connection to database failed." << endl;
|
---|
155 | return 0;
|
---|
156 | }
|
---|
157 |
|
---|
158 | cout << "fillsignal" << endl;
|
---|
159 | cout << "----------" << endl;
|
---|
160 | cout << endl;
|
---|
161 | cout << "Connected to " << serv.GetName() << endl;
|
---|
162 | cout << "File: " << fname << endl;
|
---|
163 | cout << endl;
|
---|
164 |
|
---|
165 | return Process(serv, fname, dummy);
|
---|
166 | }
|
---|