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

Last change on this file since 7112 was 7112, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
File size: 6.6 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 <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 "MBadPixelsCam.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
99 MStatusArray arr;
100 if (arr.Read()<=0)
101 {
102 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
103 return 0;
104 }
105
106 TProfile *h1 = (TProfile*)arr.FindObjectInCanvas("RingBroadening", "TProfile", "MHMuonPar");
107 if (!h1)
108 {
109 cout << "WARNING - Reading of RingBroadening failed." << endl;
110 return 0;
111 }
112
113 //spline
114// Float_t psf = (h1->Integral(5, 14) - 0.818)/0.0276;
115 //df
116 Float_t psf = (h1->Integral(5, 14) - 0.736)/0.0276;
117 psf = TMath::Nint(psf*10)/10.;
118 TString PSF = Form("%5.1f", psf);
119 Int_t num = (int)h1->GetEntries();
120
121 TProfile *h2 = (TProfile*)arr.FindObjectInCanvas("SizeVsRadius", "TProfile", "MHMuonPar");
122 if (!h1)
123 {
124 cout << "WARNING - Reading of SizeVsRadius failed." << endl;
125 return 0;
126 }
127
128 Float_t integral = h2->Integral(5, 14);
129 //spline
130// Float_t integralmc = -36.06*psf + 11023;
131 //df
132 Float_t integralmc = -26.1*psf + 9750;
133 Float_t ratiodatamc = (integral/integralmc)*100;
134 TString ratio = Form("%5.1f", ratiodatamc);
135
136
137 TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
138 if (!h)
139 {
140 cout << "WARNING - Reading of Islands failed." << endl;
141 return 0;
142 }
143
144 Float_t quality = h->GetMean();
145 quality = TMath::Nint(quality*10)/10.;
146 TString islands = Form("%5.1f", quality);
147
148 h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
149 if (!h)
150 {
151 cout << "WARNING - Reading of EffOnTime failed." << endl;
152 return kFALSE;
153 }
154
155 Float_t effon = h->Integral();
156 Float_t rate = num/effon;
157 rate = TMath::Nint(rate*100)/100.;
158 TString muonrate = Form("%6.2f", rate);
159 Int_t effontime = TMath::Nint(effon);
160
161 TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
162 if (sequence.IsNull())
163 {
164 cout << "WARNING - Could get sequence# from filename: " << fname << endl;
165 return 0;
166 }
167
168 Int_t seq = atoi(sequence.Data()+5);
169
170 cout << "Sequence #" << seq << endl;
171 cout << " PSF [mm] " << PSF << endl;
172 cout << " Island Quality " << islands << endl;
173 cout << " Ratio [%] " << ratio << endl;
174 cout << " Muon Number " << num << endl;
175 cout << " EffOnTime [s] " << effontime << endl;
176 cout << " Muon Rate [Hz] " << muonrate << endl;
177
178 TString query;
179 if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
180 {
181 query = Form("INSERT Star SET"
182 " fSequenceFirst=%d,"
183 " fMeanNumberIslands=%s, "
184 " fRatio=%s, "
185 " fMuonNumber=%d, "
186 " fEffOnTime=%d, "
187 " fMuonRate=%s, "
188 " fPSF=%s ",
189 seq, islands.Data(), ratio.Data(),
190 num, effontime,
191 muonrate.Data(), PSF.Data());
192 }
193 else
194 {
195 query = Form("UPDATE Star SET"
196 " fMeanNumberIslands=%s, "
197 " fRatio=%s, "
198 " fMuonNumber=%d, "
199 " fEffOnTime=%d, "
200 " fMuonRate=%s, "
201 " fPSF=%s "
202 " WHERE fSequenceFirst=%d ",
203 islands.Data(), ratio.Data(),
204 num, effontime,
205 muonrate.Data(), PSF.Data(), seq);
206 }
207
208 if (dummy)
209 return 0;
210
211 TSQLResult *res = serv.Query(query);
212 if (!res)
213 {
214 cout << "ERROR - Query failed: " << query << endl;
215 return 0;
216 }
217
218 return 1;
219}
220
221int fillstar(TString fname, Bool_t dummy=kTRUE)
222{
223 TEnv env("sql.rc");
224
225 MSQLServer serv(env);
226 if (!serv.IsConnected())
227 {
228 cout << "ERROR - Connection to database failed." << endl;
229 return 0;
230 }
231
232 cout << "fillstar" << endl;
233 cout << "---------" << endl;
234 cout << endl;
235 cout << "Connected to " << serv.GetName() << endl;
236 cout << "File: " << fname << endl;
237 cout << endl;
238
239 return Process(serv, fname, dummy);
240}
Note: See TracBrowser for help on using the repository browser.