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, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // fillstar.C
|
---|
29 | // ==========
|
---|
30 | //
|
---|
31 | // This macro is used to read the star-output files.
|
---|
32 | // These files are automatically called star00000.root.
|
---|
33 | //
|
---|
34 | // Make sure, that database and password are corretly set in a resource
|
---|
35 | // file called sql.rc and the resource file is found.
|
---|
36 | //
|
---|
37 | // Returns 0 in case of failure and 1 in case of success.
|
---|
38 | //
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 | #include <iostream>
|
---|
41 |
|
---|
42 | #include <TEnv.h>
|
---|
43 | #include <TRegexp.h>
|
---|
44 |
|
---|
45 | #include <TH1.h>
|
---|
46 | #include <TProfile.h>
|
---|
47 | #include <TFile.h>
|
---|
48 | #include <TSQLResult.h>
|
---|
49 | #include <TSQLRow.h>
|
---|
50 |
|
---|
51 | #include "MSQLServer.h"
|
---|
52 |
|
---|
53 | #include "MStatusArray.h"
|
---|
54 | #include "MGeomCamMagic.h"
|
---|
55 | #include "MBadPixelsCam.h"
|
---|
56 |
|
---|
57 | using namespace std;
|
---|
58 |
|
---|
59 | // --------------------------------------------------------------------------
|
---|
60 | //
|
---|
61 | // Checks whether an entry is already existing
|
---|
62 | //
|
---|
63 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
---|
64 | {
|
---|
65 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
---|
66 | TSQLResult *res = serv.Query(query);
|
---|
67 | if (!res)
|
---|
68 | return kFALSE;
|
---|
69 |
|
---|
70 | TSQLRow *row;
|
---|
71 |
|
---|
72 | Bool_t rc = kFALSE;
|
---|
73 | while ((row=res->Next()))
|
---|
74 | {
|
---|
75 | if ((*row)[0])
|
---|
76 | {
|
---|
77 | rc = kTRUE;
|
---|
78 | break;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | delete res;
|
---|
83 |
|
---|
84 | return rc;
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
---|
89 | {
|
---|
90 | TFile file(fname, "READ");
|
---|
91 | if (!file.IsOpen())
|
---|
92 | {
|
---|
93 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
94 | return 0;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | MStatusArray arr;
|
---|
99 | if (arr.Read()<=0)
|
---|
100 | {
|
---|
101 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
---|
102 | return 0;
|
---|
103 | }
|
---|
104 |
|
---|
105 | TProfile *h1 = (TProfile*)arr.FindObjectInCanvas("RingBroadening", "TProfile", "MHMuonPar");
|
---|
106 | if (!h1)
|
---|
107 | {
|
---|
108 | cout << "WARNING - Reading of RingBroadening failed." << endl;
|
---|
109 | return 0;
|
---|
110 | }
|
---|
111 |
|
---|
112 | Float_t psf = (h1->Integral(5, 14) - 0.759)/0.027;
|
---|
113 | psf = TMath::Nint(psf*10)/10.;
|
---|
114 | TString PSF = Form("%5.1f", psf);
|
---|
115 |
|
---|
116 | TProfile *h2 = (TProfile*)arr.FindObjectInCanvas("SizeVsRadius", "TProfile", "MHMuonPar");
|
---|
117 | if (!h1)
|
---|
118 | {
|
---|
119 | cout << "WARNING - Reading of SizeVsRadius failed." << endl;
|
---|
120 | return 0;
|
---|
121 | }
|
---|
122 |
|
---|
123 | Float_t integral = h2->Integral(5, 14);
|
---|
124 | Float_t integralmc = -33.0*psf + 10517;
|
---|
125 | Float_t ratiodatamc = (integral/integralmc)*100;
|
---|
126 | TString ratio = Form("%5.1f", ratiodatamc);
|
---|
127 |
|
---|
128 |
|
---|
129 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
---|
130 | if (!h)
|
---|
131 | {
|
---|
132 | cout << "WARNING - Reading of Islands failed." << endl;
|
---|
133 | return 0;
|
---|
134 | }
|
---|
135 |
|
---|
136 | Float_t quality = h->GetMean();
|
---|
137 | quality = TMath::Nint(quality*10)/10.;
|
---|
138 | TString islands = Form("%5.1f", quality);
|
---|
139 |
|
---|
140 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
---|
141 | if (sequence.IsNull())
|
---|
142 | {
|
---|
143 | cout << "WARNING - Could get sequence# from filename: " << fname << endl;
|
---|
144 | return 0;
|
---|
145 | }
|
---|
146 |
|
---|
147 | Int_t seq = atoi(sequence.Data()+5);
|
---|
148 |
|
---|
149 | cout << "Sequence #" << seq << endl;
|
---|
150 | cout << " PSF [mm] " << Form("%5.1f", psf) << endl;
|
---|
151 | cout << " Island Quality " << Form("%5.1f", quality) << endl;
|
---|
152 | cout << " Ratio [%] " << Form("%5.1f", ratiodatamc) << endl;
|
---|
153 |
|
---|
154 | TString query;
|
---|
155 | if (!ExistStr(serv, "fSequenceFirst", "MyMagic.Star", seq))
|
---|
156 | {
|
---|
157 | query = Form("INSERT MyMagic.Star SET"
|
---|
158 | " fSequenceFirst=%d,"
|
---|
159 | " fMeanNumberIslands=%s, "
|
---|
160 | " fRatio=%s, "
|
---|
161 | " fPSF=%s ",
|
---|
162 | seq, islands.Data(), ratio.Data(), PSF.Data());
|
---|
163 | }
|
---|
164 | else
|
---|
165 | {
|
---|
166 | query = Form("UPDATE MyMagic.Star SET"
|
---|
167 | " fMeanNumberIslands=%s, "
|
---|
168 | " fRatio=%s, "
|
---|
169 | " fPSF=%s "
|
---|
170 | " WHERE fSequenceFirst=%d ",
|
---|
171 | islands.Data(), ratio.Data(), PSF.Data(), seq);
|
---|
172 | }
|
---|
173 |
|
---|
174 | if (dummy)
|
---|
175 | return 0;
|
---|
176 |
|
---|
177 | TSQLResult *res = serv.Query(query);
|
---|
178 | if (!res)
|
---|
179 | {
|
---|
180 | cout << "ERROR - Query failed: " << query << endl;
|
---|
181 | return 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | return 1;
|
---|
185 | }
|
---|
186 |
|
---|
187 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
---|
188 | {
|
---|
189 | TEnv env("sql.rc");
|
---|
190 |
|
---|
191 | MSQLServer serv(env);
|
---|
192 | if (!serv.IsConnected())
|
---|
193 | {
|
---|
194 | cout << "ERROR - Connection to database failed." << endl;
|
---|
195 | return 0;
|
---|
196 | }
|
---|
197 |
|
---|
198 | cout << "fillstar" << endl;
|
---|
199 | cout << "---------" << endl;
|
---|
200 | cout << endl;
|
---|
201 | cout << "Connected to " << serv.GetName() << endl;
|
---|
202 | cout << "File: " << fname << endl;
|
---|
203 | cout << endl;
|
---|
204 |
|
---|
205 | return Process(serv, fname, dummy);
|
---|
206 | }
|
---|