| 1 | /* ======================================================================== *\ | 
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: plotstat.C,v 1.8 2008-07-14 19:59:06 tbretz Exp $ | 
|---|
| 3 | ! -------------------------------------------------------------------------- | 
|---|
| 4 | ! | 
|---|
| 5 | ! * | 
|---|
| 6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction | 
|---|
| 7 | ! * Software. It is distributed to you in the hope that it can be a useful | 
|---|
| 8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. | 
|---|
| 9 | ! * It is distributed WITHOUT ANY WARRANTY. | 
|---|
| 10 | ! * | 
|---|
| 11 | ! * Permission to use, copy, modify and distribute this software and its | 
|---|
| 12 | ! * documentation for any purpose is hereby granted without fee, | 
|---|
| 13 | ! * provided that the above copyright notice appear in all copies and | 
|---|
| 14 | ! * that both that copyright notice and this permission notice appear | 
|---|
| 15 | ! * in supporting documentation. It is provided "as is" without express | 
|---|
| 16 | ! * or implied warranty. | 
|---|
| 17 | ! * | 
|---|
| 18 | ! | 
|---|
| 19 | ! | 
|---|
| 20 | !   Author(s): Thomas Bretz, 02/2006 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 21 | !   Author(s): Daniela Dorner, 02/2006 <mailto:dorner@astro.uni-wuerzburg.de> | 
|---|
| 22 | ! | 
|---|
| 23 | !   Copyright: MAGIC Software Development, 2000-2008 | 
|---|
| 24 | ! | 
|---|
| 25 | ! | 
|---|
| 26 | \* ======================================================================== */ | 
|---|
| 27 |  | 
|---|
| 28 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 29 | // | 
|---|
| 30 | // plotstat.C | 
|---|
| 31 | // ========== | 
|---|
| 32 | // | 
|---|
| 33 | // This macro is used to plot processing statistics from the db. | 
|---|
| 34 | // | 
|---|
| 35 | // Normally all period are processed. If you want to restric processing to | 
|---|
| 36 | // less periods, use: | 
|---|
| 37 | //   > root plotstat.C+(20, -1) | 
|---|
| 38 | // means that all periods since 20 are taken into account. The two numbers | 
|---|
| 39 | // denote the first and last period taken into account, -1 means | 
|---|
| 40 | // open start or open end. | 
|---|
| 41 | // | 
|---|
| 42 | // Make sure, that database and password are corretly set in a resource | 
|---|
| 43 | // file called sql.rc and the resource file is found. | 
|---|
| 44 | // | 
|---|
| 45 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 46 | #include <iostream> | 
|---|
| 47 | #include <iomanip> | 
|---|
| 48 |  | 
|---|
| 49 | #include <TH2.h> | 
|---|
| 50 | #include <TPad.h> | 
|---|
| 51 | #include <TLine.h> | 
|---|
| 52 | #include <TText.h> | 
|---|
| 53 | #include <TCanvas.h> | 
|---|
| 54 | #include <TLegend.h> | 
|---|
| 55 | #include <TPaveText.h> | 
|---|
| 56 | #include <TEllipse.h> | 
|---|
| 57 | #include <TSQLRow.h> | 
|---|
| 58 | #include <TSQLResult.h> | 
|---|
| 59 |  | 
|---|
| 60 | #include "MH.h" | 
|---|
| 61 | #include "MTime.h" | 
|---|
| 62 | #include "MBinning.h" | 
|---|
| 63 | #include "MSQLServer.h" | 
|---|
| 64 | #include "MStatusDisplay.h" | 
|---|
| 65 |  | 
|---|
| 66 | using namespace std; | 
|---|
| 67 |  | 
|---|
| 68 | TString GetFullQuery(TString query, TString from="", TString to="") | 
|---|
| 69 | { | 
|---|
| 70 | if (from.IsNull()) | 
|---|
| 71 | return query; | 
|---|
| 72 |  | 
|---|
| 73 | if (!query.Contains("where", TString::kIgnoreCase)) | 
|---|
| 74 | query += " where "; | 
|---|
| 75 | else | 
|---|
| 76 | query += " and "; | 
|---|
| 77 |  | 
|---|
| 78 | query += " fRunStart>'"; | 
|---|
| 79 | query += from; | 
|---|
| 80 | query += "' and fRunStart<'"; | 
|---|
| 81 | query += to; | 
|---|
| 82 | query += "'"; | 
|---|
| 83 |  | 
|---|
| 84 | return query; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | Double_t GetTime(MSQLServer &serv, TString query, TString from="", TString to="") | 
|---|
| 88 | { | 
|---|
| 89 | query = GetFullQuery(query, from, to); | 
|---|
| 90 |  | 
|---|
| 91 | TSQLResult *res = serv.Query(query); | 
|---|
| 92 | if (!res) | 
|---|
| 93 | { | 
|---|
| 94 | cout << "ERROR - Query failed: " << query << endl; | 
|---|
| 95 | return -1; | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | TSQLRow *row=res->Next(); | 
|---|
| 99 | if (!row) | 
|---|
| 100 | { | 
|---|
| 101 | cout << "ERROR - Query " << query << " empty." << endl; | 
|---|
| 102 | delete res; | 
|---|
| 103 | return -1; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | const char *time = (*row)[0]; | 
|---|
| 107 |  | 
|---|
| 108 | const Double_t rc = time ? atof(time) : 0; | 
|---|
| 109 |  | 
|---|
| 110 | delete res; | 
|---|
| 111 | return rc<0 || rc>200 ? 0 : rc; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | TArrayD GetObsDist(MSQLServer &serv, TString from="", TString to="") | 
|---|
| 115 | { | 
|---|
| 116 | // 8: Sequenced RunTime per source and night | 
|---|
| 117 | //query[8]  = "select SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600, "; | 
|---|
| 118 | //query[8] += "DATE_FORMAT(ADDDATE(fRunStart,Interval 12 hour), '%Y-%m-%d') as Start,"; | 
|---|
| 119 | //query[8] += "from RunData where fRunTypeKEY=2 and fExcludedFDAKEY=1 group by Start, fSourceKEY"; | 
|---|
| 120 |  | 
|---|
| 121 | TString query; | 
|---|
| 122 |  | 
|---|
| 123 | query  = "SELECT SUM(fRunTime)/3600, "; | 
|---|
| 124 | query += "DATE_FORMAT(ADDDATE(fRunStart, INTERVAL 12 hour), '%Y-%m-%d') AS Start "; | 
|---|
| 125 | query += "FROM Sequences "; | 
|---|
| 126 |  | 
|---|
| 127 | query  = GetFullQuery(query, from, to); | 
|---|
| 128 | query += " GROUP BY Start, fSourceKEY"; | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | TSQLResult *res = serv.Query(query); | 
|---|
| 132 | if (!res) | 
|---|
| 133 | { | 
|---|
| 134 | cout << "ERROR - Query failed: " << query << endl; | 
|---|
| 135 | return -1; | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | TSQLRow *row = 0; | 
|---|
| 139 |  | 
|---|
| 140 | TArrayD arr; | 
|---|
| 141 |  | 
|---|
| 142 | while ((row=res->Next())) | 
|---|
| 143 | { | 
|---|
| 144 | const char *time = (*row)[0]; | 
|---|
| 145 |  | 
|---|
| 146 | const Double_t rc = time ? atof(time) : 0; | 
|---|
| 147 |  | 
|---|
| 148 | if (rc>0 && rc<200) | 
|---|
| 149 | { | 
|---|
| 150 | arr.Set(arr.GetSize()+1); | 
|---|
| 151 | arr[arr.GetSize()-1] = rc; | 
|---|
| 152 | } | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | delete res; | 
|---|
| 156 |  | 
|---|
| 157 | return arr; | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | void DrawYears() | 
|---|
| 161 | { | 
|---|
| 162 | UInt_t year   = 2004; | 
|---|
| 163 | Int_t  period = 0; | 
|---|
| 164 |  | 
|---|
| 165 | MTime past, from, now(-1); | 
|---|
| 166 | past.Set(2004, 1, 1, 13, 1); | 
|---|
| 167 |  | 
|---|
| 168 | TLine l; | 
|---|
| 169 | l.SetLineStyle(kDotted); | 
|---|
| 170 | l.SetLineColor(kWhite); | 
|---|
| 171 | while (past<now) | 
|---|
| 172 | { | 
|---|
| 173 | if (period!=past.GetMagicPeriod()) | 
|---|
| 174 | { | 
|---|
| 175 | period = past.GetMagicPeriod(); | 
|---|
| 176 | from = past; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | if (past.Year()!=year) | 
|---|
| 180 | { | 
|---|
| 181 | Double_t dx = (past.GetMjd()-from.GetMjd())/28; | 
|---|
| 182 | l.DrawLine(past.GetMagicPeriod()+dx, 0, | 
|---|
| 183 | past.GetMagicPeriod()+dx, gPad->GetUymax()); | 
|---|
| 184 | year = past.Year(); | 
|---|
| 185 | } | 
|---|
| 186 | past.SetMjd(past.GetMjd()+1); | 
|---|
| 187 | } | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | void DrawCake(TH1F *h, Int_t p0=-1, Int_t p1=9999) | 
|---|
| 191 | { | 
|---|
| 192 | gPad->Range(-1, -0.9, 1, 1.1); | 
|---|
| 193 |  | 
|---|
| 194 | gPad->SetFillColor(kWhite); | 
|---|
| 195 | gPad->SetBorderMode(0); | 
|---|
| 196 | gPad->SetFrameBorderMode(0); | 
|---|
| 197 |  | 
|---|
| 198 | const Double_t r1 = 0.8; | 
|---|
| 199 | const Double_t r2 = 0.59; | 
|---|
| 200 |  | 
|---|
| 201 | const Double_t tot0 = h[0].Integral(p0, p1); | 
|---|
| 202 | const Double_t tot1 = h[1].Integral(p0, p1); | 
|---|
| 203 | const Double_t tot2 = h[2].Integral(p0, p1); | 
|---|
| 204 | const Double_t tot3 = h[3].Integral(p0, p1); | 
|---|
| 205 | const Double_t tot4 = h[4].Integral(p0, p1); | 
|---|
| 206 | const Double_t tot5 = h[5].Integral(p0, p1); | 
|---|
| 207 | const Double_t tot6 = h[6].Integral(p0, p1); | 
|---|
| 208 | const Double_t tot7 = h[7].Integral(p0, p1); | 
|---|
| 209 |  | 
|---|
| 210 | TString title = Form("Total = %.1fh (excl=%.1fh)", tot1, tot1-tot2); | 
|---|
| 211 |  | 
|---|
| 212 | if (p0>0 && p1<9000 && p0==p1) | 
|---|
| 213 | title.Prepend(Form("P%d: ", TMath::Nint(h[0].GetBinCenter(p0)))); | 
|---|
| 214 |  | 
|---|
| 215 | TPaveText *pave = new TPaveText(-0.99, 0.92, 0.99, 1.09); | 
|---|
| 216 | pave->SetBorderSize(1); | 
|---|
| 217 | pave->AddText(title)->SetTextAlign(22); | 
|---|
| 218 | pave->SetBit(kCanDelete); | 
|---|
| 219 | pave->Draw(); | 
|---|
| 220 |  | 
|---|
| 221 | if (tot1<0.1) | 
|---|
| 222 | return; | 
|---|
| 223 |  | 
|---|
| 224 | TEllipse e; | 
|---|
| 225 | e.SetFillColor(15); | 
|---|
| 226 | //e.SetLineColor(15); | 
|---|
| 227 | e.DrawEllipse(0, 0, r1*1.1, r2*1.1, 90, tot0/tot1*360+90, 0); | 
|---|
| 228 |  | 
|---|
| 229 | //    0    : hollow | 
|---|
| 230 | //    1001 : Solid | 
|---|
| 231 | //    2001 : hatch style | 
|---|
| 232 | //    3000+pattern_number (see below) | 
|---|
| 233 | //    4000 :the window is transparent. | 
|---|
| 234 | //    4000 to 4100 the window is 100% transparent to 100% opaque | 
|---|
| 235 |  | 
|---|
| 236 | e.SetLineColor(10);//17); | 
|---|
| 237 | e.SetFillColor(10);//17); | 
|---|
| 238 | e.DrawEllipse(0, 0, r1, r2, 0, 360, 0); | 
|---|
| 239 | e.SetLineColor(kBlack); | 
|---|
| 240 |  | 
|---|
| 241 | e.SetFillColor(kBlack); | 
|---|
| 242 | e.DrawEllipse(0, 0, r1, r2, 90, tot2/tot1*360+90, 0); | 
|---|
| 243 | //e.SetLineColor(kBlue); | 
|---|
| 244 | e.SetFillColor(kBlue); | 
|---|
| 245 | e.DrawEllipse(0, 0, r1, r2, 90, tot3/tot1*360+90, 0); | 
|---|
| 246 | //e.SetLineColor(kRed); | 
|---|
| 247 | e.SetFillColor(kRed); | 
|---|
| 248 | e.DrawEllipse(0, 0, r1, r2, 90, tot4/tot1*360+90, 0); | 
|---|
| 249 | //e.SetLineColor(kGreen); | 
|---|
| 250 | e.SetFillColor(kGreen); | 
|---|
| 251 | e.DrawEllipse(0, 0, r1, r2, 90, tot5/tot1*360+90, 0); | 
|---|
| 252 | //e.SetLineColor(kRed+100); | 
|---|
| 253 | e.SetFillColor(kRed+100); | 
|---|
| 254 | e.DrawEllipse(0, 0, r1, r2, 90, tot6/tot1*360+90, 0); | 
|---|
| 255 | //e.SetLineColor(kGreen+100); | 
|---|
| 256 | e.SetFillColor(kGreen+100); | 
|---|
| 257 | e.DrawEllipse(0, 0, r1, r2, 90, tot7/tot1*360+90, 0); | 
|---|
| 258 |  | 
|---|
| 259 | TText txt; | 
|---|
| 260 | txt.SetTextSize(0.08); | 
|---|
| 261 |  | 
|---|
| 262 | txt.SetTextAlign(32); | 
|---|
| 263 |  | 
|---|
| 264 | txt.SetTextColor(kBlack); | 
|---|
| 265 | txt.DrawText(0.99, 0.65,    Form("%.1f%%", (tot2-tot3)/tot1*100)); | 
|---|
| 266 | txt.SetTextColor(kBlue); | 
|---|
| 267 | txt.DrawText(0.99, -0.58,   Form("%.1f%%", (tot3-tot4)/tot1*100)); | 
|---|
| 268 | txt.SetTextColor(kRed+100); | 
|---|
| 269 | txt.DrawText(-0.35, -0.70,  Form("%.1f%%", (tot6-tot7)/tot1*100)); | 
|---|
| 270 |  | 
|---|
| 271 | txt.SetTextAlign(12); | 
|---|
| 272 |  | 
|---|
| 273 | txt.SetTextColor(kBlack); | 
|---|
| 274 | txt.DrawText(0, 0.77,       Form("%.1f%%", (tot1-tot2)/tot1*100)); | 
|---|
| 275 | txt.SetTextColor(15); | 
|---|
| 276 | txt.DrawText(-0.99, 0.65,   Form("%.1f%%", tot0/tot1*100)); | 
|---|
| 277 | txt.SetTextColor(kGreen+100); | 
|---|
| 278 | txt.DrawText(-0.99, -0.58,  Form("%.1f%%", tot7/tot1*100)); | 
|---|
| 279 | txt.SetTextColor(kRed); | 
|---|
| 280 | txt.DrawText(0.35, -0.70,   Form("%.1f%%", (tot4-tot5)/tot1*100)); | 
|---|
| 281 |  | 
|---|
| 282 | txt.SetTextAlign(22); | 
|---|
| 283 |  | 
|---|
| 284 | txt.SetTextColor(kGreen); | 
|---|
| 285 | txt.DrawText(0, -0.79,      Form("%.1f%%", (tot5-tot6)/tot1*100)); | 
|---|
| 286 | } | 
|---|
| 287 |  | 
|---|
| 288 | void DrawLegend(TH1F *h) | 
|---|
| 289 | { | 
|---|
| 290 | TLegend leg(0.01, 0.12, 0.99, 0.98, "Data Statistics"); | 
|---|
| 291 | leg.SetBorderSize(1); | 
|---|
| 292 | leg.SetTextSize(0.1); | 
|---|
| 293 |  | 
|---|
| 294 | TH1 *hc[8]; | 
|---|
| 295 |  | 
|---|
| 296 | for (int i=0; i<8; i++) | 
|---|
| 297 | { | 
|---|
| 298 | hc[i] = (TH1*)h[i].Clone(); | 
|---|
| 299 | hc[i]->SetBit(kCanDelete); | 
|---|
| 300 | hc[i]->SetDirectory(0); | 
|---|
| 301 | } | 
|---|
| 302 |  | 
|---|
| 303 | leg.AddEntry(hc[0], "Files available",     "L"); | 
|---|
| 304 | leg.AddEntry(hc[1], "Excluded data",       "F"); | 
|---|
| 305 | leg.AddEntry(hc[2], "Not sequenced",       "F"); | 
|---|
| 306 | leg.AddEntry(hc[3], "Callisto not done",   "F"); | 
|---|
| 307 | leg.AddEntry(hc[4], "Callisto failed",     "F"); | 
|---|
| 308 | leg.AddEntry(hc[5], "Star not done",       "F"); | 
|---|
| 309 | leg.AddEntry(hc[6], "Star failed",         "F"); | 
|---|
| 310 | leg.AddEntry(hc[7], "Star OK",             "F"); | 
|---|
| 311 |  | 
|---|
| 312 | gROOT->SetSelectedPad(0); | 
|---|
| 313 | leg.DrawClone()->SetBit(kCanDelete);; | 
|---|
| 314 | } | 
|---|
| 315 |  | 
|---|
| 316 | Bool_t plot(MStatusDisplay &d, MSQLServer &serv, Int_t first, Int_t last) | 
|---|
| 317 | { | 
|---|
| 318 | TString query[8]; | 
|---|
| 319 |  | 
|---|
| 320 | // 0: All data for which are files available | 
|---|
| 321 | query[0]  = "SELECT SUM(TIME_TO_SEC(TIMEDIFF(fRunStop, fRunStart)))/3600 "; | 
|---|
| 322 | query[0] += "FROM RunData "; | 
|---|
| 323 | query[0] += "LEFT JOIN RunProcessStatus USING (fTelescopeNumber, fRunNumber, fFileNumber) "; | 
|---|
| 324 | query[0] += "WHERE fRunTypeKey=2 AND NOT ISNULL(fRawFileAvail)"; | 
|---|
| 325 | /* | 
|---|
| 326 | if (tel>0) | 
|---|
| 327 | { | 
|---|
| 328 | query[0] += " AND fTelescopeNumber="; | 
|---|
| 329 | query[0] += tel; | 
|---|
| 330 | } | 
|---|
| 331 | */ | 
|---|
| 332 |  | 
|---|
| 333 | // 1: All data | 
|---|
| 334 | query[1]  = "SELECTT SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600 "; | 
|---|
| 335 | query[1] += "FROM RunData WHERE fRunTypeKEY=2"; | 
|---|
| 336 |  | 
|---|
| 337 | // 2: All data which is not excluded | 
|---|
| 338 | query[2]  = "SELECT SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600 "; | 
|---|
| 339 | query[2] += "FROM RunData WHERE fRunTypeKEY=2 AND fExcludedFDAKEY=1"; | 
|---|
| 340 |  | 
|---|
| 341 | // 3: All sequences | 
|---|
| 342 | query[3]  = "SELECT SUM(fRunTime)/3600 FROM Sequences"; | 
|---|
| 343 |  | 
|---|
| 344 | // 4: All sequences with callisto failed | 
|---|
| 345 | query[4]  = "SELECT SUM(fRunTime)/3600 FROM Sequences "; | 
|---|
| 346 | query[4] += "LEFT JOIN SequenceProcessStatus USING (fSequenceFirst) "; | 
|---|
| 347 | query[4] += "WHERE ISNULL(fCallisto) AND NOT ISNULL(fFailedTime) AND NOT ISNULL(fAllFilesAvail)"; | 
|---|
| 348 |  | 
|---|
| 349 | // 5: All sequences with callisto=OK | 
|---|
| 350 | query[5]  = "SELECT SUM(fRunTime)/3600 FROM Sequences "; | 
|---|
| 351 | query[5] += "LEFT JOIN SequenceProcessStatus USING (fSequenceFirst) "; | 
|---|
| 352 | query[5] += "WHERE NOT ISNULL(fCallisto)"; | 
|---|
| 353 |  | 
|---|
| 354 | // 6: All sequences with star failed | 
|---|
| 355 | query[6]  = "SELECT SUM(fRunTime)/3600 FROM Sequences "; | 
|---|
| 356 | query[6] += "LEFT JOIN SequenceProcessStatus USING (fSequenceFirst) "; | 
|---|
| 357 | query[6] += "WHERE ISNULL(fStar) AND NOT ISNULL(fFailedTime) AND NOT ISNULL(fCallisto)"; | 
|---|
| 358 |  | 
|---|
| 359 | // 7: All sequences with star=OK | 
|---|
| 360 | query[7]  = "SELECT SUM(fRunTime)/3600 FROM Sequences "; | 
|---|
| 361 | query[7] += "LEFT JOIN SequenceProcessStatus USING (fSequenceFirst) "; | 
|---|
| 362 | query[7] += "WHERE NOT ISNULL(fStar)"; | 
|---|
| 363 |  | 
|---|
| 364 | // 0: All data | 
|---|
| 365 | // 1: All data which is not excluded | 
|---|
| 366 | // 2: All data for which are files available | 
|---|
| 367 | // 3: All sequences | 
|---|
| 368 | // 4: All sequences with callisto=not done | 
|---|
| 369 | // 5: All sequences with callisto not done and failed | 
|---|
| 370 | // 6: All sequences with star=not done | 
|---|
| 371 | // 7: All sequences with star not done and failed | 
|---|
| 372 |  | 
|---|
| 373 | MTime now(-1); | 
|---|
| 374 | MTime past; | 
|---|
| 375 | past.Set(2004, 1, 1, 13, 1); | 
|---|
| 376 |  | 
|---|
| 377 | if (first<0) | 
|---|
| 378 | first=14; | 
|---|
| 379 | if (last<0) | 
|---|
| 380 | last=now.GetMagicPeriod(); | 
|---|
| 381 |  | 
|---|
| 382 | TH1F h[8]; | 
|---|
| 383 | TH2F h8; | 
|---|
| 384 |  | 
|---|
| 385 | MBinning binsp(last-first+1, first-0.5, last+0.5); | 
|---|
| 386 | MBinning binst(4*7, 0, 7); | 
|---|
| 387 | for (int i=0; i<8; i++) | 
|---|
| 388 | { | 
|---|
| 389 | binsp.Apply(h[i]); | 
|---|
| 390 | h[i].SetName(Form("H%d", i)); | 
|---|
| 391 | h[i].SetDirectory(0); | 
|---|
| 392 | } | 
|---|
| 393 |  | 
|---|
| 394 | MH::SetBinning(&h8, &binsp, &binst); | 
|---|
| 395 | h8.SetNameTitle("ObsTime", "Distribution of observation time per exposure"); | 
|---|
| 396 | h8.SetXTitle("Observation Period"); | 
|---|
| 397 | h8.SetYTitle("Obs. time per exposure [h]"); | 
|---|
| 398 | h8.SetZTitle("Counts"); | 
|---|
| 399 | h8.SetDirectory(0); | 
|---|
| 400 |  | 
|---|
| 401 | Int_t period = 0; | 
|---|
| 402 | MTime from; | 
|---|
| 403 |  | 
|---|
| 404 | while (1) | 
|---|
| 405 | { | 
|---|
| 406 | if (past.GetMagicPeriod()!=period) | 
|---|
| 407 | { | 
|---|
| 408 | period = past.GetMagicPeriod(); | 
|---|
| 409 |  | 
|---|
| 410 | if (period>first && period-1<=last) | 
|---|
| 411 | { | 
|---|
| 412 | TString a = from.GetSqlDateTime(); | 
|---|
| 413 | TString b = past.GetSqlDateTime(); | 
|---|
| 414 |  | 
|---|
| 415 | for (int i=0; i<8; i++) | 
|---|
| 416 | h[i].Fill(period-1, GetTime(serv, query[i], a, b)); | 
|---|
| 417 |  | 
|---|
| 418 | TArrayD arr(GetObsDist(serv, a, b)); | 
|---|
| 419 |  | 
|---|
| 420 | for (int i=0; i<arr.GetSize(); i++) | 
|---|
| 421 | h8.Fill(period-1, arr[i]); | 
|---|
| 422 | } | 
|---|
| 423 |  | 
|---|
| 424 | if (past>now) | 
|---|
| 425 | break; | 
|---|
| 426 |  | 
|---|
| 427 | from = past; | 
|---|
| 428 |  | 
|---|
| 429 | } | 
|---|
| 430 | past.SetMjd(past.GetMjd()+1); | 
|---|
| 431 | } | 
|---|
| 432 |  | 
|---|
| 433 | for (int i=0; i<h[0].GetNbinsX(); i++) | 
|---|
| 434 | h[0].SetBinError(i+1, 0.001); | 
|---|
| 435 |  | 
|---|
| 436 |  | 
|---|
| 437 | h[4].Add(&h[5]); | 
|---|
| 438 | h[6].Add(&h[7]); | 
|---|
| 439 |  | 
|---|
| 440 | // -------------------------------------------- | 
|---|
| 441 |  | 
|---|
| 442 | TCanvas &c0 = d.AddTab("ObsDist"); | 
|---|
| 443 | c0.SetFillColor(kWhite); | 
|---|
| 444 |  | 
|---|
| 445 | gPad->SetBorderMode(0); | 
|---|
| 446 | gPad->SetFrameBorderMode(0); | 
|---|
| 447 | gPad->SetFillColor(kWhite); | 
|---|
| 448 | gPad->SetRightMargin(0.01); | 
|---|
| 449 | //gPad->SetTopMargin(0.02); | 
|---|
| 450 | //gPad->SetLeftMargin(0.09); | 
|---|
| 451 | //gPad->SetBottomMargin(0.12); | 
|---|
| 452 | gPad->SetGridx(); | 
|---|
| 453 | gPad->SetGridy(); | 
|---|
| 454 | gPad->SetLogy(); | 
|---|
| 455 |  | 
|---|
| 456 | TH1 * p = h8.ProjectionY(); | 
|---|
| 457 |  | 
|---|
| 458 | p->SetYTitle("Counts"); | 
|---|
| 459 | p->SetDirectory(0); | 
|---|
| 460 | p->SetBit(kCanDelete); | 
|---|
| 461 | p->Draw(); | 
|---|
| 462 |  | 
|---|
| 463 | // -------------------------------------------- | 
|---|
| 464 |  | 
|---|
| 465 | TCanvas &c1 = d.AddTab("Hist"); | 
|---|
| 466 | c1.SetFillColor(kWhite); | 
|---|
| 467 | c1.Divide(2,2); | 
|---|
| 468 |  | 
|---|
| 469 | c1.cd(1); | 
|---|
| 470 |  | 
|---|
| 471 | gPad->SetBorderMode(0); | 
|---|
| 472 | gPad->SetFrameBorderMode(0); | 
|---|
| 473 | gPad->SetFillColor(kWhite); | 
|---|
| 474 | gPad->SetRightMargin(0.01); | 
|---|
| 475 | gPad->SetTopMargin(0.02); | 
|---|
| 476 | gPad->SetLeftMargin(0.09); | 
|---|
| 477 | gPad->SetBottomMargin(0.12); | 
|---|
| 478 | gPad->SetGridy(); | 
|---|
| 479 | gPad->SetPad(0, 0.5, 0.75, 1.0); | 
|---|
| 480 |  | 
|---|
| 481 | h[1].SetBit(TH1::kNoStats); | 
|---|
| 482 | // h[0].GetXaxis()->SetRangeUser(13.5, period+0.5); | 
|---|
| 483 | h[1].GetXaxis()->CenterTitle(); | 
|---|
| 484 | h[1].GetXaxis()->SetTitleSize(0.06); | 
|---|
| 485 | h[1].GetYaxis()->SetTitleSize(0.06); | 
|---|
| 486 | h[1].GetYaxis()->SetTitleOffset(0.7); | 
|---|
| 487 | h[1].GetXaxis()->SetLabelSize(0.06); | 
|---|
| 488 | h[1].GetYaxis()->SetLabelSize(0.06); | 
|---|
| 489 | h[1].GetXaxis()->SetNdivisions(550); | 
|---|
| 490 | h[1].SetYTitle("Time [h]"); | 
|---|
| 491 | h[1].SetFillColor(kWhite); | 
|---|
| 492 | h[1].SetLineColor(kBlack); | 
|---|
| 493 | h[1].DrawCopy(""); | 
|---|
| 494 |  | 
|---|
| 495 | h[2].SetLineColor(kBlack); | 
|---|
| 496 | h[2].SetFillColor(kBlack); | 
|---|
| 497 | h[2].DrawCopy("Bsame"); | 
|---|
| 498 |  | 
|---|
| 499 | h[3].SetLineColor(kBlue); | 
|---|
| 500 | h[3].SetFillColor(kBlue); | 
|---|
| 501 | h[3].DrawCopy("Bsame"); | 
|---|
| 502 |  | 
|---|
| 503 | h[4].SetLineColor(kRed); | 
|---|
| 504 | h[4].SetFillColor(kRed); | 
|---|
| 505 | h[4].DrawCopy("Bsame"); | 
|---|
| 506 |  | 
|---|
| 507 | h[5].SetLineColor(kGreen); | 
|---|
| 508 | h[5].SetFillColor(kGreen); | 
|---|
| 509 | h[5].DrawCopy("Bsame"); | 
|---|
| 510 |  | 
|---|
| 511 | h[6].SetLineColor(kRed+100); | 
|---|
| 512 | h[6].SetFillColor(kRed+100); | 
|---|
| 513 | h[6].DrawCopy("Bsame"); | 
|---|
| 514 |  | 
|---|
| 515 | h[7].SetLineColor(kGreen+100); | 
|---|
| 516 | h[7].SetFillColor(kGreen+100); | 
|---|
| 517 | h[7].DrawCopy("Bsame"); | 
|---|
| 518 |  | 
|---|
| 519 | h[0].SetMarkerSize(0); | 
|---|
| 520 | h[0].SetMarkerColor(15); | 
|---|
| 521 | h[0].SetLineWidth(3); | 
|---|
| 522 | h[0].SetLineColor(15); | 
|---|
| 523 | h[0].DrawCopy("EPsame"); | 
|---|
| 524 |  | 
|---|
| 525 | gPad->Update(); | 
|---|
| 526 | DrawYears(); | 
|---|
| 527 |  | 
|---|
| 528 | c1.cd(4); | 
|---|
| 529 |  | 
|---|
| 530 | gPad->SetBorderMode(0); | 
|---|
| 531 | gPad->SetFrameBorderMode(0); | 
|---|
| 532 | gPad->SetPad(0.75, 0, 1.0, 0.5); | 
|---|
| 533 |  | 
|---|
| 534 | DrawCake(h); | 
|---|
| 535 |  | 
|---|
| 536 | // -------------------------------------------- | 
|---|
| 537 |  | 
|---|
| 538 | TCanvas &cx = d.AddTab("All"); | 
|---|
| 539 | cx.SetBorderMode(0); | 
|---|
| 540 | cx.SetFrameBorderMode(0); | 
|---|
| 541 | cx.SetFillColor(kWhite); | 
|---|
| 542 | cx.Divide(9,5); | 
|---|
| 543 | cx.cd(1); | 
|---|
| 544 | DrawLegend(h); | 
|---|
| 545 |  | 
|---|
| 546 | for (int i=0; i<h[0].GetNbinsX(); i++) | 
|---|
| 547 | { | 
|---|
| 548 | const Int_t num = TMath::Nint(h[0].GetBinCenter(i+1)); | 
|---|
| 549 |  | 
|---|
| 550 | TCanvas &c = d.AddTab(Form("P%d", num)); | 
|---|
| 551 | c.SetBorderMode(0); | 
|---|
| 552 | c.SetFrameBorderMode(0); | 
|---|
| 553 | c.SetFillColor(kWhite); | 
|---|
| 554 |  | 
|---|
| 555 | c.cd(); | 
|---|
| 556 |  | 
|---|
| 557 | TPad *pad1 = new TPad(Form("Pad%da", num), "", 0.05, 0, 0.55, 1); | 
|---|
| 558 | pad1->SetBorderMode(0); | 
|---|
| 559 | pad1->SetFrameBorderMode(0); | 
|---|
| 560 | pad1->SetFillColor(kWhite); | 
|---|
| 561 | pad1->SetBit(kCanDelete); | 
|---|
| 562 | pad1->Draw(); | 
|---|
| 563 | pad1->cd(); | 
|---|
| 564 |  | 
|---|
| 565 | DrawCake(h, i+1, i+1); | 
|---|
| 566 |  | 
|---|
| 567 | if (i<4*8) | 
|---|
| 568 | { | 
|---|
| 569 | cx.cd(i+2); | 
|---|
| 570 | DrawCake(h, i+1, i+1); | 
|---|
| 571 | } | 
|---|
| 572 |  | 
|---|
| 573 | c.cd(); | 
|---|
| 574 |  | 
|---|
| 575 | TPad *pad2 = new TPad(Form("Pad%db", num), "", 0.6, 0.02, 1, 0.48); | 
|---|
| 576 | pad2->SetBorderMode(0); | 
|---|
| 577 | pad2->SetFrameBorderMode(0); | 
|---|
| 578 | pad2->SetFillColor(kWhite); | 
|---|
| 579 | pad2->SetBit(kCanDelete); | 
|---|
| 580 | pad2->SetGridx(); | 
|---|
| 581 | pad2->SetGridy(); | 
|---|
| 582 | pad2->SetRightMargin(0.01); | 
|---|
| 583 | pad2->Draw(); | 
|---|
| 584 | pad2->cd(); | 
|---|
| 585 |  | 
|---|
| 586 | TH1 * p = h8.ProjectionY(Form("Obs%d", num), i+1, i+1); | 
|---|
| 587 |  | 
|---|
| 588 | p->Rebin(2); | 
|---|
| 589 | p->SetBit(TH1::kNoStats); | 
|---|
| 590 | p->SetTitle(""); | 
|---|
| 591 | p->SetYTitle("Counts"); | 
|---|
| 592 | p->SetDirectory(0); | 
|---|
| 593 | p->SetBit(kCanDelete); | 
|---|
| 594 | p->Draw(); | 
|---|
| 595 |  | 
|---|
| 596 | /* | 
|---|
| 597 | c.cd(); | 
|---|
| 598 |  | 
|---|
| 599 | TPaveText *pave = new TPaveText(0.6, 0.52, 0.98, 0.98); | 
|---|
| 600 | pave->SetBorderSize(1); | 
|---|
| 601 | pave->AddText(Form("Period: %d", num))->SetTextAlign(22); | 
|---|
| 602 | pave->AddSeperator(); | 
|---|
| 603 | pave->AddText(Form("Start: %s", num)); | 
|---|
| 604 | pave->AddText(Form("End:   %s", num)); | 
|---|
| 605 | pave->SetBit(kCanDelete); | 
|---|
| 606 | pave->Draw(); | 
|---|
| 607 | */ | 
|---|
| 608 | } | 
|---|
| 609 |  | 
|---|
| 610 | c1.cd(2); | 
|---|
| 611 |  | 
|---|
| 612 | gPad->SetBorderMode(0); | 
|---|
| 613 | gPad->SetFrameBorderMode(0); | 
|---|
| 614 | gPad->SetRightMargin(0.01); | 
|---|
| 615 | gPad->SetTopMargin(0.02); | 
|---|
| 616 | gPad->SetLeftMargin(0.09); | 
|---|
| 617 | gPad->SetBottomMargin(0.12); | 
|---|
| 618 | gPad->SetPad(0, 0, 0.75, 0.5); | 
|---|
| 619 | gPad->SetGridy(); | 
|---|
| 620 |  | 
|---|
| 621 | h[1].Scale(0.01); | 
|---|
| 622 | h[0].Divide(&h[1]); | 
|---|
| 623 | h[2].Divide(&h[1]); | 
|---|
| 624 | h[3].Divide(&h[1]); | 
|---|
| 625 | h[4].Divide(&h[1]); | 
|---|
| 626 | h[5].Divide(&h[1]); | 
|---|
| 627 | h[6].Divide(&h[1]); | 
|---|
| 628 | h[7].Divide(&h[1]); | 
|---|
| 629 | h[1].Divide(&h[1]); | 
|---|
| 630 | h[1].Scale(100); | 
|---|
| 631 |  | 
|---|
| 632 | for (int i=0; i<h[0].GetNbinsX(); i++) | 
|---|
| 633 | h[0].SetBinError(i+1, 0.001); | 
|---|
| 634 |  | 
|---|
| 635 | h[1].GetXaxis()->SetNdivisions(550); | 
|---|
| 636 | h[1].SetYTitle("%"); | 
|---|
| 637 | h[1].SetXTitle("Period"); | 
|---|
| 638 | h[1].GetYaxis()->SetRangeUser(0, 100); | 
|---|
| 639 |  | 
|---|
| 640 | h[1].DrawCopy(); | 
|---|
| 641 | h[2].DrawCopy("same"); | 
|---|
| 642 | h[3].DrawCopy("same"); | 
|---|
| 643 | h[4].DrawCopy("same"); | 
|---|
| 644 | h[5].DrawCopy("same"); | 
|---|
| 645 | h[6].DrawCopy("same"); | 
|---|
| 646 | h[7].DrawCopy("same"); | 
|---|
| 647 | h[0].DrawCopy("same"); | 
|---|
| 648 | /* | 
|---|
| 649 | TLine l; | 
|---|
| 650 | l.SetLineColor(kWhite); | 
|---|
| 651 | l.SetLineWidth(1); | 
|---|
| 652 | l.SetLineStyle(kDotted); | 
|---|
| 653 | for (int i=10; i<95; i+=10) | 
|---|
| 654 | l.DrawLine(13.5, i, period+0.5, i); | 
|---|
| 655 | l.SetLineStyle(kSolid); | 
|---|
| 656 | l.DrawLine(13.5, 50, period+0.5, 50); | 
|---|
| 657 | */ | 
|---|
| 658 | gPad->Update(); | 
|---|
| 659 | DrawYears(); | 
|---|
| 660 |  | 
|---|
| 661 | c1.cd(3); | 
|---|
| 662 |  | 
|---|
| 663 | gPad->SetBorderMode(0); | 
|---|
| 664 | gPad->SetFrameBorderMode(0); | 
|---|
| 665 | gPad->SetPad(0.75, 0.5, 1.0, 1.0); | 
|---|
| 666 |  | 
|---|
| 667 | DrawLegend(h); | 
|---|
| 668 |  | 
|---|
| 669 | return kTRUE; | 
|---|
| 670 | } | 
|---|
| 671 |  | 
|---|
| 672 | int plotstat(Int_t first=-1, Int_t last=-1) | 
|---|
| 673 | { | 
|---|
| 674 | MSQLServer serv("sql.rc"); | 
|---|
| 675 | if (!serv.IsConnected()) | 
|---|
| 676 | { | 
|---|
| 677 | cout << "ERROR - Connection to database failed." << endl; | 
|---|
| 678 | return 0; | 
|---|
| 679 | } | 
|---|
| 680 |  | 
|---|
| 681 | cout << "plotstat" << endl; | 
|---|
| 682 | cout << "--------" << endl; | 
|---|
| 683 | cout << endl; | 
|---|
| 684 | cout << "Connected to " << serv.GetName() << endl; | 
|---|
| 685 | cout << endl; | 
|---|
| 686 |  | 
|---|
| 687 | MStatusDisplay *d = new MStatusDisplay; | 
|---|
| 688 | d->SetWindowName(serv.GetName()); | 
|---|
| 689 | d->SetTitle(serv.GetName()); | 
|---|
| 690 |  | 
|---|
| 691 | plot(*d, serv, first, last); | 
|---|
| 692 |  | 
|---|
| 693 | //d->SaveAsRoot("plotstat.root"); | 
|---|
| 694 | //d->SaveAsPS("plotstat.ps"); | 
|---|
| 695 |  | 
|---|
| 696 | return 1; | 
|---|
| 697 | } | 
|---|