source: trunk/MagicSoft/Mars/datacenter/macros/fillstar.C@ 7273

Last change on this file since 7273 was 7252, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.2 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, 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#include <iomanip>
42
43#include <TEnv.h>
44#include <TRegexp.h>
45
46#include <TH1.h>
47#include <TGraph.h>
48#include <TProfile.h>
49#include <TFile.h>
50#include <TSQLResult.h>
51#include <TSQLRow.h>
52
53#include "MSQLServer.h"
54
55#include "MStatusArray.h"
56#include "MGeomCamMagic.h"
57#include "MBadPixelsCam.h"
58
59using namespace std;
60
61// --------------------------------------------------------------------------
62//
63// Checks whether an entry is already existing
64//
65Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
66{
67 TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
68 TSQLResult *res = serv.Query(query);
69 if (!res)
70 return kFALSE;
71
72 TSQLRow *row;
73
74 Bool_t rc = kFALSE;
75 while ((row=res->Next()))
76 {
77 if ((*row)[0])
78 {
79 rc = kTRUE;
80 break;
81 }
82 }
83
84 delete res;
85
86 return rc;
87}
88
89
90int Process(MSQLServer &serv, TString fname, Bool_t dummy)
91{
92 TFile file(fname, "READ");
93 if (!file.IsOpen())
94 {
95 cout << "ERROR - Could not find file " << fname << endl;
96 return 0;
97 }
98
99
100 MStatusArray arr;
101 if (arr.Read()<=0)
102 {
103 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
104 return 0;
105 }
106
107 MHMuonPar *hmuon = (TProfile*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
108 if (!hmuon)
109 {
110 cout << "WARNING - Reading of MHMuon failed." << endl;
111 return 0;
112 }
113
114 Float_t psf = (muon->GetMeanWidth() - 0.04816)/0.001294;
115 psf = TMath::Nint(psf*10)/10.;
116 TString PSF = Form("%5.1f", psf);
117 Int_t num = (int)muon.GetEntries();
118
119 Float_t integralmc = -1.43*psf + 1035;
120 Float_t ratiodatamc = (muon->GetMeanSize()/integralmc)*100;
121 TString ratio = Form("%5.1f", ratiodatamc);
122
123 TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
124 if (!h)
125 {
126 cout << "WARNING - Reading of Islands failed." << endl;
127 return 0;
128 }
129
130 Float_t quality = h->GetMean();
131 quality = TMath::Nint(quality*10)/10.;
132 TString islands = Form("%6.2f", quality);
133
134 h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
135 if (!h)
136 {
137 cout << "WARNING - Reading of EffOnTheta failed." << endl;
138 return 0;
139 }
140
141 Float_t effon = h->Integral();
142 Float_t mrate = num/effon;
143 mrate = TMath::Nint(mrate*100)/100.;
144 TString muonrate = Form("%6.2f", mrate);
145 Int_t effontime = TMath::Nint(effon);
146
147 h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
148 if (!h)
149 {
150 cout << "WARNING - Reading of ProjDeltaT failed." << endl;
151 return 0;
152 }
153
154 Int_t numevents = (int)h->GetEntries();
155 Int_t datarate = (int)(numevents/effon);
156
157 TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
158 if (!g)
159 {
160 cout << "WARNING - Reading of Humidity failed." << endl;
161 return 0;
162 }
163
164 Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
165 TString maxhum = Form("%6.1f", max);
166
167
168 TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
169 if (sequence.IsNull())
170 {
171 cout << "WARNING - Could get sequence# from filename: " << fname << endl;
172 return 0;
173 }
174
175 Int_t seq = atoi(sequence.Data()+5);
176
177 cout << "Sequence #" << seq << endl;
178 cout << " PSF [mm] " << PSF << endl;
179 cout << " Island Quality " << islands << endl;
180 cout << " Ratio [%] " << ratio << endl;
181 cout << " Muon Number " << num << endl;
182 cout << " EffOnTime [s] " << effontime << endl;
183 cout << " Muon Rate [Hz] " << muonrate << endl;
184 cout << " # of Events " << numevents << endl;
185 cout << " Rate after ImgCl [Hz] " << datarate << endl;
186 cout << " Maximum Humidity [%] " << maxhum << endl;
187
188 TString query;
189 if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
190 {
191 query = Form("INSERT Star SET"
192 " fSequenceFirst=%d,"
193 " fMeanNumberIslands=%s, "
194 " fRatio=%s, "
195 " fMuonNumber=%d, "
196 " fEffOnTime=%d, "
197 " fMuonRate=%s, "
198 " fPSF=%s, "
199 " fDataRate=%d, "
200 " fMaxHumidity=%s ",
201 seq, islands.Data(), ratio.Data(),
202 num, effontime,
203 muonrate.Data(), PSF.Data(),
204 datarate, maxhum.Data());
205 }
206 else
207 {
208 query = Form("UPDATE Star SET"
209 " fMeanNumberIslands=%s, "
210 " fRatio=%s, "
211 " fMuonNumber=%d, "
212 " fEffOnTime=%d, "
213 " fMuonRate=%s, "
214 " fPSF=%s, "
215 " fDataRate=%d, "
216 " fMaxHumidity=%s "
217 " WHERE fSequenceFirst=%d ",
218 islands.Data(), ratio.Data(),
219 num, effontime,
220 muonrate.Data(), PSF.Data(),
221 datarate, maxhum.Data(), seq);
222 }
223
224 if (dummy)
225 return 0;
226
227 TSQLResult *res = serv.Query(query);
228 if (!res)
229 {
230 cout << "ERROR - Query failed: " << query << endl;
231 return 0;
232 }
233
234 return 1;
235}
236
237int fillstar(TString fname, Bool_t dummy=kTRUE)
238{
239 TEnv env("sql.rc");
240
241 MSQLServer serv(env);
242 if (!serv.IsConnected())
243 {
244 cout << "ERROR - Connection to database failed." << endl;
245 return 0;
246 }
247
248 cout << "fillstar" << endl;
249 cout << "---------" << endl;
250 cout << endl;
251 cout << "Connected to " << serv.GetName() << endl;
252 cout << "File: " << fname << endl;
253 cout << endl;
254
255 return Process(serv, fname, dummy);
256}
Note: See TracBrowser for help on using the repository browser.