source: tags/Mars-V0.9.4.1/datacenter/macros/fillganymed.C

Last change on this file was 7280, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 6.1 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 Double_t exc = fit->GetEventsExcess();
108 Double_t sig = fit->GetEventsSignal();
109 Double_t bgd = fit->GetEventsBackground();
110 Double_t S = fit->GetSignificance();
111 Double_t f = fit->GetScaleFactor();
112
113 MStatusArray arr;
114 if (arr.Read()<=0)
115 {
116 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
117 return 0;
118 }
119
120 TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta", "TH1D", "OnTime");
121 if (!vstime)
122 {
123 cout << "WARNING - Reading of Theta failed." << endl;
124 return kFALSE;
125 }
126
127
128 Double_t tm = vstime->Integral();
129
130 TString dataset = fname(TRegexp("ganymed[0-9]+[.]root$"));
131 if (dataset.IsNull())
132 {
133 cout << "WARNING - Could get dataset# from filename: " << fname << endl;
134 return 0;
135 }
136
137 Int_t ds = atoi(dataset.Data()+8);
138
139 cout << "Dataset #" << ds << endl;
140 cout << " Excess Events: " << exc << endl;
141 cout << " Background Events: " << bgd << endl;
142 cout << " Signal Events: " << sig << endl;
143 cout << " Significance: " << S << endl;
144 cout << " Scale Factor: " << f << endl;
145 cout << " Total eff. on-time: " << tm << "s = " << tm/3600. << "h" << endl;
146
147 cout << " Excess Rate: " << exc*60/tm << " evts/min" << endl;
148 cout << " Background Rate: " << bgd*60/tm << " evts/min" << endl;
149 cout << " Significance Rate: " << S/TMath::Sqrt(tm/3600.) << " sigma/sqrt(h)" << endl;
150
151
152 TString query;
153 if (!ExistStr(serv, "fDataSetNumber", "Ganymed", ds))
154 {
155 query = Form("INSERT Ganymed SET"
156 " fDataSetNumber=%d,"
157 " fExcessEvents=%f, "
158 " fBackgroundEvents=%f, "
159 " fSignalEvents=%f, "
160 " fSignificance=%f, "
161 " fScaleFactor=%f, "
162 " fEffOnTime=%f, "
163 " fExcessRate=%f, "
164 " fBackgroundRate=%f, "
165 " fSignificanceRate=%f ",
166 ds, exc, bgd, sig, S, f, tm,
167 exc*60/tm, bgd*60/tm,
168 S/TMath::Sqrt(tm/3600));
169 }
170 else
171 {
172 query = Form("UPDATE Ganymed SET"
173 " fExcessEvents=%f, "
174 " fBackgroundEvents=%f, "
175 " fSignalEvents=%f, "
176 " fSignificance=%f, "
177 " fScaleFactor=%f, "
178 " fEffOnTime=%f, "
179 " fExcessRate=%f, "
180 " fBackgroundRate=%f, "
181 " fSignificanceRate=%f ",
182 " WHERE fDataSetNumber=%d ",
183 exc, bgd, sig, S, f, tm,
184 exc*60/tm, bgd*60/tm,
185 S/TMath::Sqrt(tm/3600), ds);
186 }
187
188 if (dummy)
189 return 0;
190
191 TSQLResult *res = serv.Query(query);
192 if (!res)
193 {
194 cout << "ERROR - Query failed: " << query << endl;
195 return 0;
196 }
197 return 1;
198}
199
200int fillganymed(TString fname, Bool_t dummy=kTRUE)
201{
202 TEnv env("sql.rc");
203
204 MSQLServer serv(env);
205 if (!serv.IsConnected())
206 {
207 cout << "ERROR - Connection to database failed." << endl;
208 return 0;
209 }
210
211 cout << "fillganymed" << endl;
212 cout << "-----------" << endl;
213 cout << endl;
214 cout << "Connected to " << serv.GetName() << endl;
215 cout << "File: " << fname << endl;
216 cout << endl;
217
218 return Process(serv, fname, dummy);
219}
Note: See TracBrowser for help on using the repository browser.