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/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // fillganymed.C
|
---|
28 | // =============
|
---|
29 | //
|
---|
30 | // This macro is used to read the ganymed-output files.
|
---|
31 | // These files are automatically called ganymed00000.root.
|
---|
32 | //
|
---|
33 | // Make sure, that database and password are corretly set in a resource
|
---|
34 | // file called sql.rc and the resource file is found.
|
---|
35 | //
|
---|
36 | // Returns 0 in case of failure and 1 in case of success.
|
---|
37 | //
|
---|
38 | /////////////////////////////////////////////////////////////////////////////
|
---|
39 | #include <iostream>
|
---|
40 | #include <iomanip>
|
---|
41 |
|
---|
42 | #include <TEnv.h>
|
---|
43 | #include <TRegexp.h>
|
---|
44 |
|
---|
45 | #include <TH1.h>
|
---|
46 | #include <TGraph.h>
|
---|
47 | #include <TProfile.h>
|
---|
48 | #include <TFile.h>
|
---|
49 | #include <TSQLResult.h>
|
---|
50 | #include <TSQLRow.h>
|
---|
51 |
|
---|
52 | #include "MSQLServer.h"
|
---|
53 |
|
---|
54 | #include "MStatusArray.h"
|
---|
55 | #include "MGeomCamMagic.h"
|
---|
56 | #include "MAlphaFitter.h"
|
---|
57 |
|
---|
58 | using namespace std;
|
---|
59 |
|
---|
60 | // --------------------------------------------------------------------------
|
---|
61 | //
|
---|
62 | // Checks whether an entry is already existing
|
---|
63 | //
|
---|
64 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
65 | {
|
---|
66 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
67 | TSQLResult *res = serv.Query(query);
|
---|
68 | if (!res)
|
---|
69 | return kFALSE;
|
---|
70 |
|
---|
71 | TSQLRow *row;
|
---|
72 |
|
---|
73 | Bool_t rc = kFALSE;
|
---|
74 | while ((row=res->Next()))
|
---|
75 | {
|
---|
76 | if ((*row)[0])
|
---|
77 | {
|
---|
78 | rc = kTRUE;
|
---|
79 | break;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | delete res;
|
---|
84 |
|
---|
85 | return rc;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
90 | {
|
---|
91 | TFile file(fname, "READ");
|
---|
92 | if (!file.IsOpen())
|
---|
93 | {
|
---|
94 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | MAlphaFitter *fit;
|
---|
99 | file.GetObject("MAlphaFitter", fit);
|
---|
100 |
|
---|
101 | if (!fit)
|
---|
102 | {
|
---|
103 | cout << "WARNING - Reading of MAlphaFitter failed." << endl;
|
---|
104 | return 0;
|
---|
105 | }
|
---|
106 |
|
---|
107 | Int_t exc = (Int_t)fit->GetEventsExcess();
|
---|
108 | Int_t sig = (Int_t)fit->GetEventsSignal();
|
---|
109 | Int_t bgd = (Int_t)fit->GetEventsBackground();
|
---|
110 | Float_t S = fit->GetSignificance();
|
---|
111 | TString signif = Form("%5.1f", S);
|
---|
112 | Float_t f = fit->GetScaleFactor();
|
---|
113 | TString scale = Form("%5.2f", f);
|
---|
114 |
|
---|
115 | MStatusArray arr;
|
---|
116 | if (arr.Read()<=0)
|
---|
117 | {
|
---|
118 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta", "TH1D", "OnTime");
|
---|
123 | if (!vstime)
|
---|
124 | {
|
---|
125 | cout << "WARNING - Reading of Theta failed." << endl;
|
---|
126 | return kFALSE;
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | Int_t tm = (Int_t)vstime->Integral();
|
---|
131 |
|
---|
132 | TString dataset = fname(TRegexp("ganymed[0-9]+[.]root$"));
|
---|
133 | if (dataset.IsNull())
|
---|
134 | {
|
---|
135 | cout << "WARNING - Could get dataset# from filename: " << fname << endl;
|
---|
136 | return 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 | Int_t ds = atoi(dataset.Data()+8);
|
---|
140 |
|
---|
141 | cout << "Dataset #" << ds << endl;
|
---|
142 | cout << " Excess Events: " << exc << endl;
|
---|
143 | cout << " Background Events: " << bgd << endl;
|
---|
144 | cout << " Signal Events: " << sig << endl;
|
---|
145 | cout << " Significance: " << S << endl;
|
---|
146 | cout << " Scale Factor: " << f << endl;
|
---|
147 | cout << " Total eff. on-time: " << tm << "s = " << tm/3600. << "h" << endl;
|
---|
148 |
|
---|
149 | // cout << " Excess Rate: " << exc*60/tm << " evts/min" << endl;
|
---|
150 | // cout << " Background Rate: " << bgd*60/tm << " evts/min" << endl;
|
---|
151 | // cout << " Significance Rate: " << S/TMath::Sqrt(tm/3600.) << " sigma/sqrt(h)" << endl;
|
---|
152 |
|
---|
153 |
|
---|
154 | TString query;
|
---|
155 | if (!ExistStr(serv, "fDataSetNumber", "Ganymed", ds))
|
---|
156 | {
|
---|
157 | query = Form("INSERT Ganymed SET"
|
---|
158 | " fDataSetNumber=%d,"
|
---|
159 | " fExcessEvents=%d, "
|
---|
160 | " fBackgroundEvents=%d, "
|
---|
161 | " fSignalEvents=%d, "
|
---|
162 | " fSignificance=%f, "
|
---|
163 | " fScaleFactor=%f, "
|
---|
164 | " fEffOnTime=%d ", //, "
|
---|
165 | // " fExcessRate=%f, "
|
---|
166 | // " fBackgroundRate=%f, "
|
---|
167 | // " fSignificanceRate=%f ",
|
---|
168 | ds, exc, bgd, sig, S, f, tm);//,
|
---|
169 | // exc*60/tm, bgd*60/tm,
|
---|
170 | // S/TMath::Sqrt(tm/3600));
|
---|
171 | }
|
---|
172 | else
|
---|
173 | {
|
---|
174 | query = Form("UPDATE Ganymed SET"
|
---|
175 | " fExcessEvents=%d, "
|
---|
176 | " fBackgroundEvents=%d, "
|
---|
177 | " fSignalEvents=%d, "
|
---|
178 | " fSignificance=%f, "
|
---|
179 | " fScaleFactor=%f, "
|
---|
180 | " fEffOnTime=%d " //, "
|
---|
181 | // " fExcessRate=%f, "
|
---|
182 | // " fBackgroundRate=%f, "
|
---|
183 | // " fSignificanceRate=%f ",
|
---|
184 | " WHERE fDataSetNumber=%d ",
|
---|
185 | exc, bgd, sig, S, f, tm, ds);
|
---|
186 | // exc*60/tm, bgd*60/tm,
|
---|
187 | // S/TMath::Sqrt(tm/3600), ds);
|
---|
188 | }
|
---|
189 |
|
---|
190 | cout << "q: " << query << endl;
|
---|
191 | if (dummy)
|
---|
192 | return 0;
|
---|
193 |
|
---|
194 | TSQLResult *res = serv.Query(query);
|
---|
195 | if (!res)
|
---|
196 | {
|
---|
197 | cout << "ERROR - Query failed: " << query << endl;
|
---|
198 | return 0;
|
---|
199 | }
|
---|
200 | return 1;
|
---|
201 | }
|
---|
202 |
|
---|
203 | int fillganymed(TString fname, Bool_t dummy=kTRUE)
|
---|
204 | {
|
---|
205 | TEnv env("sql.rc");
|
---|
206 |
|
---|
207 | MSQLServer serv(env);
|
---|
208 | if (!serv.IsConnected())
|
---|
209 | {
|
---|
210 | cout << "ERROR - Connection to database failed." << endl;
|
---|
211 | return 0;
|
---|
212 | }
|
---|
213 |
|
---|
214 | cout << "fillganymed" << endl;
|
---|
215 | cout << "-----------" << endl;
|
---|
216 | cout << endl;
|
---|
217 | cout << "Connected to " << serv.GetName() << endl;
|
---|
218 | cout << "File: " << fname << endl;
|
---|
219 | cout << endl;
|
---|
220 |
|
---|
221 | return Process(serv, fname, dummy);
|
---|
222 | }
|
---|