source: trunk/MagicSoft/Mars/datacenter/macros/fillganymed.C@ 7353

Last change on this file since 7353 was 7333, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 5.9 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/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
58using namespace std;
59
60// --------------------------------------------------------------------------
61//
62// Checks whether an entry is already existing
63//
64Bool_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
89int 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: " << signif << endl;
146 cout << " Scale Factor: " << scale << 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=%s, "
163 " fScaleFactor=%s, "
164 " fEffOnTime=%d ",
165 ds, exc, bgd, sig,
166 signif.Data(),
167 scale.Data(), tm);
168 }
169 else
170 {
171 query = Form("UPDATE Ganymed SET"
172 " fExcessEvents=%d, "
173 " fBackgroundEvents=%d, "
174 " fSignalEvents=%d, "
175 " fSignificance=%s, "
176 " fScaleFactor=%s, "
177 " fEffOnTime=%d "
178 " WHERE fDataSetNumber=%d ",
179 exc, bgd, sig, signif.Data(),
180 scale.Data(), tm, ds);
181 }
182
183 cout << "q: " << query << endl;
184 if (dummy)
185 return 0;
186
187 TSQLResult *res = serv.Query(query);
188 if (!res)
189 {
190 cout << "ERROR - Query failed: " << query << endl;
191 return 0;
192 }
193 return 1;
194}
195
196int fillganymed(TString fname, Bool_t dummy=kTRUE)
197{
198 TEnv env("sql.rc");
199
200 MSQLServer serv(env);
201 if (!serv.IsConnected())
202 {
203 cout << "ERROR - Connection to database failed." << endl;
204 return 0;
205 }
206
207 cout << "fillganymed" << endl;
208 cout << "-----------" << endl;
209 cout << endl;
210 cout << "Connected to " << serv.GetName() << endl;
211 cout << "File: " << fname << endl;
212 cout << endl;
213
214 return Process(serv, fname, dummy);
215}
Note: See TracBrowser for help on using the repository browser.