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

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