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

Last change on this file since 7076 was 7062, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
File size: 5.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
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
57using namespace std;
58
59// --------------------------------------------------------------------------
60//
61// Checks whether an entry is already existing
62//
63Bool_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
88int Process(MSQLServer &serv, TString fname, Bool_t dummy)
89{
90 TFile file(fname, "READ");
91
92 MStatusArray arr;
93 if (arr.Read()<=0)
94 {
95 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
96 return 0;
97 }
98
99 TProfile *h1 = (TProfile*)arr.FindObjectInCanvas("RingBroadening", "TProfile", "MHMuonPar");
100 if (!h1)
101 {
102 cout << "WARNING - Reading of RingBroadening failed." << endl;
103 return 0;
104 }
105
106 Float_t psf = (h1->Integral(5, 14) - 0.837)/0.0252;
107 psf = TMath::Nint(psf*10)/10.;
108 TString PSF = Form("%5.1f", psf);
109
110 TProfile *h2 = (TProfile*)arr.FindObjectInCanvas("SizeVsRadius", "TProfile", "MHMuonPar");
111 if (!h1)
112 {
113 cout << "WARNING - Reading of SizeVsRadius failed." << endl;
114 return 0;
115 }
116
117 Float_t integral = h2->Integral(5, 14);
118 Float_t integralmc = -35.6*psf + 11000;
119 Float_t ratiodatamc = (integral/integralmc)*100;
120 TString ratio = Form("%5.1f", ratiodatamc);
121
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("%5.1f", quality);
133
134 TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
135 if (sequence.IsNull())
136 {
137 cout << "WARNING - Could get sequence# from filename: " << fname << endl;
138 return 0;
139 }
140
141 Int_t seq = atoi(sequence.Data()+5);
142
143 cout << "Sequence #" << seq << endl;
144 cout << " PSF [mm] " << Form("%5.1f", psf) << endl;
145 cout << " Island Quality " << Form("%5.1f", quality) << endl;
146 cout << " Ratio [%] " << Form("%5.1f", ratiodatamc) << endl;
147
148 TString query;
149 if (!ExistStr(serv, "fSequenceFirst", "MyMagic.Star", seq))
150 {
151 query = Form("INSERT MyMagic.Star SET"
152 " fSequenceFirst=%d,"
153 " fMeanNumberIslands=%s, "
154 " fRatio=%s, "
155 " fPSF=%s ",
156 seq, islands.Data(), ratio.Data(), PSF.Data());
157 }
158 else
159 {
160 query = Form("UPDATE MyMagic.Star SET"
161 " fMeanNumberIslands=%s, "
162 " fRatio=%s, "
163 " fPSF=%s "
164 " WHERE fSequenceFirst=%d ",
165 islands.Data(), ratio.Data(), PSF.Data(), seq);
166 }
167
168 if (dummy)
169 return 0;
170
171 TSQLResult *res = serv.Query(query);
172 if (!res)
173 {
174 cout << "ERROR - Query failed: " << query << endl;
175 return 0;
176 }
177
178 return 1;
179}
180
181int fillstar(TString fname, Bool_t dummy=kTRUE)
182{
183 TEnv env("sql.rc");
184
185 MSQLServer serv(env);
186 if (!serv.IsConnected())
187 {
188 cout << "ERROR - Connection to database failed." << endl;
189 return 0;
190 }
191
192 cout << "fillstar" << endl;
193 cout << "---------" << endl;
194 cout << endl;
195 cout << "Connected to " << serv.GetName() << endl;
196 cout << "File: " << fname << endl;
197 cout << endl;
198
199 return Process(serv, fname, dummy);
200}
Note: See TracBrowser for help on using the repository browser.