| 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-2006
|
|---|
| 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 star00000000.root.
|
|---|
| 33 | // From these files the muon parameters (psf, muon number, ratio, muon rate),
|
|---|
| 34 | // the rate, the number of islands, the effective ontime, the maximum
|
|---|
| 35 | // humidity and a parameter describing the inhomogeneity are extracted from
|
|---|
| 36 | // the status display.
|
|---|
| 37 | // The sequence number is extracted from the filename.
|
|---|
| 38 | //
|
|---|
| 39 | // Usage:
|
|---|
| 40 | // .x fillstar.C("/magic/data/star/0004/00047421/star00047421.root", kTRUE)
|
|---|
| 41 | //
|
|---|
| 42 | // The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
|
|---|
| 43 | // switched on and nothing will be written into the database. This is usefull
|
|---|
| 44 | // for tests.
|
|---|
| 45 | //
|
|---|
| 46 | // The macro can also be run without ACLiC but this is a lot slower...
|
|---|
| 47 | //
|
|---|
| 48 | // Remark: Running it from the commandline looks like this:
|
|---|
| 49 | // root -q -l -b fillstar.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillstar.log
|
|---|
| 50 | //
|
|---|
| 51 | // Make sure, that database and password are corretly set in a resource
|
|---|
| 52 | // file called sql.rc and the resource file is found.
|
|---|
| 53 | //
|
|---|
| 54 | // Returns 2 in case of failure, 1 in case of success and 0 if the connection
|
|---|
| 55 | // to the database is not working.
|
|---|
| 56 | //
|
|---|
| 57 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 58 | #include <iostream>
|
|---|
| 59 | #include <iomanip>
|
|---|
| 60 |
|
|---|
| 61 | #include <TEnv.h>
|
|---|
| 62 | #include <TRegexp.h>
|
|---|
| 63 |
|
|---|
| 64 | #include <TH1.h>
|
|---|
| 65 | #include <TH2.h>
|
|---|
| 66 | #include <TGraph.h>
|
|---|
| 67 | #include <TProfile.h>
|
|---|
| 68 | #include <TFile.h>
|
|---|
| 69 | #include <TSQLResult.h>
|
|---|
| 70 | #include <TSQLRow.h>
|
|---|
| 71 |
|
|---|
| 72 | #include "MSQLServer.h"
|
|---|
| 73 |
|
|---|
| 74 | #include "MHMuonPar.h"
|
|---|
| 75 | #include "MStatusArray.h"
|
|---|
| 76 | #include "MGeomCamMagic.h"
|
|---|
| 77 | #include "MBadPixelsCam.h"
|
|---|
| 78 |
|
|---|
| 79 | using namespace std;
|
|---|
| 80 |
|
|---|
| 81 | // --------------------------------------------------------------------------
|
|---|
| 82 | //
|
|---|
| 83 | // Checks whether an entry is already existing
|
|---|
| 84 | //
|
|---|
| 85 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
|---|
| 86 | {
|
|---|
| 87 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
|---|
| 88 | TSQLResult *res = serv.Query(query);
|
|---|
| 89 | if (!res)
|
|---|
| 90 | return kFALSE;
|
|---|
| 91 |
|
|---|
| 92 | TSQLRow *row;
|
|---|
| 93 |
|
|---|
| 94 | Bool_t rc = kFALSE;
|
|---|
| 95 | while ((row=res->Next()))
|
|---|
| 96 | {
|
|---|
| 97 | if ((*row)[0])
|
|---|
| 98 | {
|
|---|
| 99 | rc = kTRUE;
|
|---|
| 100 | break;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | delete res;
|
|---|
| 105 |
|
|---|
| 106 | return rc;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
|---|
| 111 | {
|
|---|
| 112 | TFile file(fname, "READ");
|
|---|
| 113 | if (!file.IsOpen())
|
|---|
| 114 | {
|
|---|
| 115 | cout << "ERROR - Could not find file " << fname << endl;
|
|---|
| 116 | return 2;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | MStatusArray arr;
|
|---|
| 121 | if (arr.Read()<=0)
|
|---|
| 122 | {
|
|---|
| 123 | cout << "ERROR - Reading of MStatusDisplay failed." << endl;
|
|---|
| 124 | return 2;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | TH2F *hcog = (TH2F*)arr.FindObjectInCanvas("Center", "TH2F", "MHHillas");
|
|---|
| 128 | if (!hcog)
|
|---|
| 129 | {
|
|---|
| 130 | cout << "WARNING - Reading of MHHillas failed." << endl;
|
|---|
| 131 | return 2;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
|
|---|
| 135 | if (!hmuon)
|
|---|
| 136 | {
|
|---|
| 137 | cout << "WARNING - Reading of MHMuon failed." << endl;
|
|---|
| 138 | return 2;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | Double_t val[6];
|
|---|
| 142 | for (int x=1; x<hcog->GetNbinsX(); x++)
|
|---|
| 143 | for (int y=1; y<hcog->GetNbinsY(); y++)
|
|---|
| 144 | {
|
|---|
| 145 | Stat_t px = hcog->GetXaxis()->GetBinCenter(x);
|
|---|
| 146 | Stat_t py = hcog->GetYaxis()->GetBinCenter(y);
|
|---|
| 147 | Int_t i = (TMath::Nint(3*TMath::ATan2(px,py)/TMath::Pi())+6)%6;
|
|---|
| 148 | val[i] += hcog->GetBinContent(x, y);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | Double_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
|
|---|
| 152 | inhom = TMath::Nint(inhom*10)/10.;
|
|---|
| 153 | TString inhomogen = Form("%5.1f", inhom);
|
|---|
| 154 |
|
|---|
| 155 | Float_t mw = hmuon->GetMeanWidth();
|
|---|
| 156 | Float_t psf = 58.5480*mw - 37.3829;
|
|---|
| 157 | psf = TMath::Nint(psf*10)/10.;
|
|---|
| 158 | TString PSF = Form("%5.1f", psf);
|
|---|
| 159 | Int_t num = (int)hmuon->GetEntries();
|
|---|
| 160 |
|
|---|
| 161 | Float_t ratiodatamc = (hmuon->GetMeanSize()/9327.)*100;
|
|---|
| 162 | TString ratio = Form("%5.1f", ratiodatamc);
|
|---|
| 163 |
|
|---|
| 164 | TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
|
|---|
| 165 | if (!h)
|
|---|
| 166 | {
|
|---|
| 167 | cout << "WARNING - Reading of Islands failed." << endl;
|
|---|
| 168 | return 2;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | Float_t quality = h->GetMean();
|
|---|
| 172 | quality = TMath::Nint(quality*100)/100.;
|
|---|
| 173 | TString islands = Form("%6.2f", quality);
|
|---|
| 174 |
|
|---|
| 175 | h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
|
|---|
| 176 | if (!h)
|
|---|
| 177 | {
|
|---|
| 178 | cout << "WARNING - Reading of EffOnTheta failed." << endl;
|
|---|
| 179 | return 2;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | Float_t effon = h->Integral();
|
|---|
| 183 | Float_t mrate = num/effon;
|
|---|
| 184 | mrate = TMath::Nint(mrate*100)/100.;
|
|---|
| 185 | TString muonrate = Form("%6.2f", mrate);
|
|---|
| 186 | Int_t effontime = TMath::Nint(effon);
|
|---|
| 187 |
|
|---|
| 188 | h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
|
|---|
| 189 | if (!h)
|
|---|
| 190 | {
|
|---|
| 191 | cout << "WARNING - Reading of ProjDeltaT failed." << endl;
|
|---|
| 192 | return 2;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | Int_t numevents = (int)h->GetEntries();
|
|---|
| 196 | Int_t datarate = (int)(numevents/effon);
|
|---|
| 197 |
|
|---|
| 198 | TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
|
|---|
| 199 | if (!g)
|
|---|
| 200 | {
|
|---|
| 201 | cout << "WARNING - Reading of Humidity failed." << endl;
|
|---|
| 202 | return 2;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | Double_t max = TMath::MaxElement(g->GetN(), g->GetY());
|
|---|
| 206 | TString maxhum = Form("%6.1f", max);
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | g = (TGraph*)arr.FindObjectInCanvas("NumStars", "TGraph", "MHPointing");
|
|---|
| 210 | if (!g)
|
|---|
| 211 | {
|
|---|
| 212 | cout << "WARNING - Reading of NumStars failed." << endl;
|
|---|
| 213 | // return 2;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | Double_t numstarmed = g ? TMath::Median(g->GetN(), g->GetY()) : -1;
|
|---|
| 217 | TString numstarsmed = Form("%5.1f", numstarmed);
|
|---|
| 218 | Double_t numstarrms = g ? g->GetRMS(2) : -1;
|
|---|
| 219 | TString numstarsrms = Form("%5.1f", numstarrms);
|
|---|
| 220 |
|
|---|
| 221 | g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
|
|---|
| 222 | if (!g)
|
|---|
| 223 | {
|
|---|
| 224 | cout << "WARNING - Reading of NumStarsCor failed." << endl;
|
|---|
| 225 | // return 2;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | Double_t numcormed = g ? TMath::Median(g->GetN(), g->GetY()) : -1;
|
|---|
| 229 | TString numcorsmed = Form("%5.1f", numcormed);
|
|---|
| 230 | Double_t numcorrms = g ? g->GetRMS(2) : -1;
|
|---|
| 231 | TString numcorsrms = Form("%5.1f", numcorrms);
|
|---|
| 232 |
|
|---|
| 233 | g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
|
|---|
| 234 | if (!g)
|
|---|
| 235 | {
|
|---|
| 236 | cout << "WARNING - Reading of SkyBrightness failed." << endl;
|
|---|
| 237 | // return 2;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | Double_t brightnessmed = g ? TMath::Median(g->GetN(), g->GetY()) : -1;
|
|---|
| 241 | TString skybrightnessmed = Form("%5.1f", brightnessmed);
|
|---|
| 242 | Double_t brightnessrms = g ? g->GetRMS(2) : -1;
|
|---|
| 243 | TString skybrightnessrms = Form("%5.1f", brightnessrms);
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 | TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
|
|---|
| 247 | if (sequence.IsNull())
|
|---|
| 248 | {
|
|---|
| 249 | cout << "WARNING - Could not determine sequence# from filename: " << fname << endl;
|
|---|
| 250 | return 2;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | Int_t seq = atoi(sequence.Data()+5);
|
|---|
| 254 |
|
|---|
| 255 | cout << "Sequence #" << seq << endl;
|
|---|
| 256 | cout << " Inhomogeneity " << inhomogen << endl;
|
|---|
| 257 | cout << " PSF [mm] " << PSF << endl;
|
|---|
| 258 | cout << " Island Quality " << islands << endl;
|
|---|
| 259 | cout << " Ratio [%] " << ratio << endl;
|
|---|
| 260 | cout << " Muon Number " << num << endl;
|
|---|
| 261 | cout << " EffOnTime [s] " << effontime << endl;
|
|---|
| 262 | cout << " Muon Rate [Hz] " << muonrate << endl;
|
|---|
| 263 | cout << " # of Events " << numevents << endl;
|
|---|
| 264 | cout << " Rate after ImgCl [Hz] " << datarate << endl;
|
|---|
| 265 | cout << " Maximum Humidity [%] " << maxhum << endl;
|
|---|
| 266 | cout << " Number of Stars " << numstarsmed << " +/- " << numstarsrms << endl;
|
|---|
| 267 | cout << " Number of cor. Stars " << numcormed << " +/- " << numcorrms << endl;
|
|---|
| 268 | cout << " Skybrightness " << skybrightnessmed << " +/- " << skybrightnessrms << endl;
|
|---|
| 269 |
|
|---|
| 270 | TString query;
|
|---|
| 271 | if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
|
|---|
| 272 | {
|
|---|
| 273 | query = Form("INSERT Star SET"
|
|---|
| 274 | " fSequenceFirst=%d,"
|
|---|
| 275 | " fMeanNumberIslands=%s, "
|
|---|
| 276 | " fRatio=%s, "
|
|---|
| 277 | " fMuonNumber=%d, "
|
|---|
| 278 | " fEffOnTime=%d, "
|
|---|
| 279 | " fMuonRate=%s, "
|
|---|
| 280 | " fPSF=%s, "
|
|---|
| 281 | " fDataRate=%d, "
|
|---|
| 282 | " fMaxHumidity=%s ,"
|
|---|
| 283 | " fNumStarsMed=%s ,"
|
|---|
| 284 | " fNumStarsRMS=%s ,"
|
|---|
| 285 | " fNumStarsCorMed=%s ,"
|
|---|
| 286 | " fNumStarsCorRMS=%s ,"
|
|---|
| 287 | " fBrightnessMed=%s ,"
|
|---|
| 288 | " fBrightnessRMS=%s ,"
|
|---|
| 289 | " fInhomogeneity=%s ",
|
|---|
| 290 | seq, islands.Data(), ratio.Data(),
|
|---|
| 291 | num, effontime,
|
|---|
| 292 | muonrate.Data(), PSF.Data(),
|
|---|
| 293 | datarate, maxhum.Data(),
|
|---|
| 294 | numstarsmed.Data(), numstarsrms.Data(),
|
|---|
| 295 | numcorsmed.Data(), numcorsrms.Data(),
|
|---|
| 296 | skybrightnessmed.Data(), skybrightnessrms.Data(),
|
|---|
| 297 | inhomogen.Data());
|
|---|
| 298 | }
|
|---|
| 299 | else
|
|---|
| 300 | {
|
|---|
| 301 | query = Form("UPDATE Star SET"
|
|---|
| 302 | " fMeanNumberIslands=%s, "
|
|---|
| 303 | " fRatio=%s, "
|
|---|
| 304 | " fMuonNumber=%d, "
|
|---|
| 305 | " fEffOnTime=%d, "
|
|---|
| 306 | " fMuonRate=%s, "
|
|---|
| 307 | " fPSF=%s, "
|
|---|
| 308 | " fDataRate=%d, "
|
|---|
| 309 | " fMaxHumidity=%s, "
|
|---|
| 310 | " fNumStarsMed=%s ,"
|
|---|
| 311 | " fNumStarsRMS=%s ,"
|
|---|
| 312 | " fNumStarsCorMed=%s ,"
|
|---|
| 313 | " fNumStarsCorRMS=%s ,"
|
|---|
| 314 | " fBrightnessMed=%s ,"
|
|---|
| 315 | " fBrightnessRMS=%s ,"
|
|---|
| 316 | " fInhomogeneity=%s "
|
|---|
| 317 | " WHERE fSequenceFirst=%d ",
|
|---|
| 318 | islands.Data(), ratio.Data(),
|
|---|
| 319 | num, effontime,
|
|---|
| 320 | muonrate.Data(), PSF.Data(),
|
|---|
| 321 | datarate, maxhum.Data(),
|
|---|
| 322 | numstarsmed.Data(), numstarsrms.Data(),
|
|---|
| 323 | numcorsmed.Data(), numcorsrms.Data(),
|
|---|
| 324 | skybrightnessmed.Data(), skybrightnessrms.Data(),
|
|---|
| 325 | inhomogen.Data(), seq);
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | cout << "Q: " << query << endl;
|
|---|
| 329 |
|
|---|
| 330 | if (dummy)
|
|---|
| 331 | return 1;
|
|---|
| 332 |
|
|---|
| 333 | TSQLResult *res = serv.Query(query);
|
|---|
| 334 | if (!res)
|
|---|
| 335 | {
|
|---|
| 336 | cout << "ERROR - Query failed: " << query << endl;
|
|---|
| 337 | return 2;
|
|---|
| 338 | }
|
|---|
| 339 | delete res;
|
|---|
| 340 |
|
|---|
| 341 | return 1;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | int fillstar(TString fname, Bool_t dummy=kTRUE)
|
|---|
| 345 | {
|
|---|
| 346 | TEnv env("sql.rc");
|
|---|
| 347 |
|
|---|
| 348 | MSQLServer serv(env);
|
|---|
| 349 | if (!serv.IsConnected())
|
|---|
| 350 | {
|
|---|
| 351 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 352 | return 0;
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | cout << "fillstar" << endl;
|
|---|
| 356 | cout << "---------" << endl;
|
|---|
| 357 | cout << endl;
|
|---|
| 358 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 359 | cout << "File: " << fname << endl;
|
|---|
| 360 | cout << endl;
|
|---|
| 361 |
|
|---|
| 362 | return Process(serv, fname, dummy);
|
|---|
| 363 | }
|
|---|