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

Last change on this file since 9492 was 9386, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.5 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-2006
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// From MAlphaFitter and the Status Display the results from ganymed are
33// extracted an inserted into the database, where they are stored in the table
34// Ganymed.
35// The dataset number is extracted from the filename.
36//
37// Usage:
38// .x fillganymed.C("/magic/data/ganymed/0000/0001/ganmymed0001.root", kTRUE)
39//
40// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
41// switched on and nothing will be written into the database. This is usefull
42// for tests.
43//
44// Remark: Running it from the commandline looks like this:
45// root -q -l -b fillganymed.C+\(\"filename\"\,kFALSE\) 2>&1 | tee file.log
46//
47// Make sure, that database and password are corretly set in a resource
48// file called sql.rc and the resource file is found.
49//
50// Returns 2 in case of failure, 1 in case of success and 0 if the connection
51// to the database is not working.
52//
53/////////////////////////////////////////////////////////////////////////////
54#include <iostream>
55#include <iomanip>
56
57#include <TRegexp.h>
58
59#include <TH1.h>
60#include <TGraph.h>
61#include <TProfile.h>
62#include <TFile.h>
63#include <TSQLResult.h>
64#include <TSQLRow.h>
65
66#include "MSQLMagic.h"
67
68#include "MStatusArray.h"
69#include "MGeomCamMagic.h"
70#include "MAlphaFitter.h"
71
72using namespace std;
73
74int Process(MSQLMagic &serv, TString fname, Bool_t dummy)
75{
76 TFile file(fname, "READ");
77 if (!file.IsOpen())
78 {
79 cout << "ERROR - Could not find file " << fname << endl;
80 return 2;
81 }
82
83 //get excess, signal, background events and the scale factor from MAlphaFitter
84 MAlphaFitter *fit;
85 file.GetObject("MAlphaFitter", fit);
86
87 if (!fit)
88 {
89 cout << "WARNING - Reading of MAlphaFitter failed." << endl;
90 return 2;
91 }
92
93 Int_t exc = (Int_t)fit->GetEventsExcess();
94 Int_t sig = (Int_t)fit->GetEventsSignal();
95 Int_t bgd = (Int_t)fit->GetEventsBackground();
96 Float_t S = fit->GetSignificance();
97 TString signif = Form("%5.1f", S);
98 Float_t f = fit->GetScaleFactor();
99 TString scale = Form("%5.2f", f);
100
101 //get effective ontime from the status display
102 MStatusArray arr;
103 if (arr.Read()<=0)
104 {
105 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
106 return 2;
107 }
108
109 TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta", "TH1D", "OnTime");
110 if (!vstime)
111 {
112 cout << "WARNING - Reading of Theta failed." << endl;
113 return 2;
114 }
115
116
117 Int_t tm = (Int_t)vstime->Integral();
118
119 //get dataset number from filename
120 TString dataset = fname(TRegexp("ganymed[0-9]+[.]root$"));
121 if (dataset.IsNull())
122 {
123 cout << "WARNING - Could get dataset# from filename: " << fname << endl;
124 return 2;
125 }
126
127 Int_t ds = atoi(dataset.Data()+8);
128
129 cout << "Dataset #" << ds << endl;
130 cout << " Excess Events: " << exc << endl;
131 cout << " Background Events: " << bgd << endl;
132 cout << " Signal Events: " << sig << endl;
133 cout << " Significance: " << signif << endl;
134 cout << " Scale Factor: " << scale << endl;
135 cout << " Total eff. on-time: " << tm << "s = " << tm/3600. << "h" << endl;
136
137// cout << " Excess Rate: " << exc*60/tm << " evts/min" << endl;
138// cout << " Background Rate: " << bgd*60/tm << " evts/min" << endl;
139// cout << " Significance Rate: " << S/TMath::Sqrt(tm/3600.) << " sigma/sqrt(h)" << endl;
140
141 TString vars = Form(" fDataSetNumber=%d, "
142 " fExcessEvents=%d, "
143 " fBackgroundEvents=%d, "
144 " fSignalEvents=%d, "
145 " fSignificance=%s, "
146 " fScaleFactor=%s, "
147 " fEffOnTime=%d ",
148 ds, exc, bgd, sig,
149 signif.Data(),
150 scale.Data(), tm);
151
152
153 TString where = Form("fDataSetNumber=%d", ds);
154
155 return serv.InsertUpdate("Ganymed", vars, where) ? 1 : 2;
156}
157
158int fillganymed(TString fname, Bool_t dummy=kTRUE)
159{
160 MSQLMagic serv("sql.rc");
161 if (!serv.IsConnected())
162 {
163 cout << "ERROR - Connection to database failed." << endl;
164 return 0;
165 }
166
167 cout << "fillganymed" << endl;
168 cout << "-----------" << endl;
169 cout << endl;
170 cout << "Connected to " << serv.GetName() << endl;
171 cout << "File: " << fname << endl;
172 cout << endl;
173
174 serv.SetIsDummy(dummy);
175
176 return Process(serv, fname, dummy);
177}
Note: See TracBrowser for help on using the repository browser.