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 |
|
---|
72 | using namespace std;
|
---|
73 |
|
---|
74 | int 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(" fExcessEvents=%d, "
|
---|
142 | " fBackgroundEvents=%d, "
|
---|
143 | " fSignalEvents=%d, "
|
---|
144 | " fSignificance=%s, "
|
---|
145 | " fScaleFactor=%s, "
|
---|
146 | " fEffOnTime=%d ",
|
---|
147 | exc, bgd, sig,
|
---|
148 | signif.Data(),
|
---|
149 | scale.Data(), tm);
|
---|
150 |
|
---|
151 |
|
---|
152 | TString where = Form("fDataSetNumber=%d", ds);
|
---|
153 |
|
---|
154 | return serv.InsertUpdate("Ganymed", vars, where) ? 1 : 2;
|
---|
155 | }
|
---|
156 |
|
---|
157 | int fillganymed(TString fname, Bool_t dummy=kTRUE)
|
---|
158 | {
|
---|
159 | MSQLMagic serv("sql.rc");
|
---|
160 | if (!serv.IsConnected())
|
---|
161 | {
|
---|
162 | cout << "ERROR - Connection to database failed." << endl;
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | cout << "fillganymed" << endl;
|
---|
167 | cout << "-----------" << endl;
|
---|
168 | cout << endl;
|
---|
169 | cout << "Connected to " << serv.GetName() << endl;
|
---|
170 | cout << "File: " << fname << endl;
|
---|
171 | cout << endl;
|
---|
172 |
|
---|
173 | serv.SetIsDummy(dummy);
|
---|
174 |
|
---|
175 | return Process(serv, fname, dummy);
|
---|
176 | }
|
---|