Changeset 8212 for trunk/MagicSoft
- Timestamp:
- 11/03/06 10:53:45 (18 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8210 r8212 18 18 19 19 -*-*- END OF LINE -*-*- 20 21 2006/11/03 Thomas Bretz 22 23 * datacenter/macros/plotoptical.C, datacenter/macros/plotdb.C, 24 datacenter/macros/plotrundb.C: 25 - improved grouping 26 - added comments 27 28 20 29 21 30 2006/11/02 Daniela Dorner -
trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
r8186 r8212 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.3 1 2006-11-01 08:53:26 tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.32 2006-11-03 10:52:36 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 84 84 { 85 85 public: 86 // Possible constants to group-by (average) over a certain period 86 87 enum GroupBy_t 87 88 { … … 92 93 kGroupByWeek, 93 94 kGroupByMonth, 95 kGroupBySeason, 94 96 kGroupByYear 95 97 }; 98 96 99 private: 97 MSQLMagic &fServer; 98 99 MDataSet *fDataSet; 100 101 TString fPrimaryDate; 102 TString fPrimaryNumber; 103 TString fSecondary; 104 105 TString fRequestFrom; 106 TString fRequestTo; 107 Int_t fRequestPeriod; 100 MSQLMagic &fServer; // Reference to the sql-server class 101 102 MDataSet *fDataSet; // A possible dtaset to highlite single points 103 104 TString fPrimaryDate; // The name of the data we plot 105 TString fPrimaryNumber; // The corresponding name for the key number 106 TString fSecondary; // The value versus which the second plot is made 107 108 TString fRequestFrom; // Start of a requested date range 109 TString fRequestTo; // End of a requested date range 110 Int_t fRequestPeriod; // A possible requested period 108 111 109 112 Float_t fPlotMin; … … 113 116 Float_t fHistMax; 114 117 115 TString fDescription; 116 TString fNameTab; 117 118 TString fCondition; 119 GroupBy_t fGroupBy; 120 118 TString fDescription; // The description (title) of the plot 119 TString fNameTab; // The name of the tab in the display 120 121 TString fCondition; // An additional condition added to the query 122 GroupBy_t fGroupBy; // A possible Group-By flag 123 124 // -------------------------------------------------------------------------- 125 // 126 // Function to plot the result of the query 127 // 121 128 void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution) 122 129 { 130 // Enable all otions in the statistics box 123 131 gStyle->SetOptStat(111111); 124 132 125 133 TSQLRow *row; 126 134 135 // Create TGraph objects 127 136 TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph; 128 137 gt.SetNameTitle(name, Form("%s vs Time", name.Data())); … … 148 157 Int_t last = -1; 149 158 159 // Loop over the data 150 160 while ((row=res.Next())) 151 161 { 162 // Get all fields of this row 152 163 const char *date = (*row)[0]; 153 164 const char *zd = (*row)[1]; … … 158 169 continue; 159 170 171 // check if date is valid 160 172 MTime t(date); 161 173 if (!t.SetSqlDateTime(date)) 162 174 continue; 163 175 176 // check if it belongs to the requested MAGIC period 164 177 if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod) 165 178 continue; 166 179 180 // Get axis range 167 181 if (first<0) 168 182 first = TMath::Nint(TMath::Floor(t.GetMjd())); 169 183 last = TMath::Nint(TMath::Ceil(t.GetMjd())); 170 184 185 // Convert a possible key number into a integer 171 186 UInt_t seq = snum ? atoi(snum) : 0; 172 187 188 // convert primary and secondary value into floats 173 189 Float_t value = atof(val); 174 190 Float_t zenith = atof(zd); 175 191 192 // If a datset is given add the point to the special TGraphs 193 // used for highliting these dates 176 194 if (fDataSet) 177 195 { … … 189 207 } 190 208 209 // Add Data to TGraph 191 210 gt.SetPoint(gt.GetN(), t.GetAxisTime(), value); 192 211 gz.SetPoint(gz.GetN(), zenith, value); 193 212 213 // Set error-bar, if one 194 214 if (verr) 195 215 static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr)); … … 207 227 gROOT->SetSelectedPad(0); 208 228 229 // Create a TCanvas or open a new tab 209 230 TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab; 210 231 TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas; 232 // Set fillcolor, remove border and divide pad 211 233 c.SetFillColor(kWhite); 212 234 c.SetBorderMode(0); 213 235 c.Divide(1,2); 214 236 237 // Output mean and rms to console 215 238 cerr << setprecision(4) << setw(10) << title << ": "; 216 239 if (gt.GetN()==0) … … 228 251 229 252 TVirtualPad *pad = gPad; 253 254 // draw contants of pad 2 (counting starts at 0) 230 255 pad->cd(2); 231 256 gPad->SetBorderMode(0); … … 237 262 gPad->SetBottomMargin(0.08); 238 263 264 // format axis 239 265 TH1 *h = gt.GetHistogram(); 240 266 … … 246 272 h->GetXaxis()->SetLabelOffset(0.01); 247 273 274 // draw TGraph 248 275 gt.DrawClone("AP"); 249 276 if (gt0.GetN()>0) … … 252 279 gt1.DrawClone("P"); 253 280 281 // Add lines and text showing the MAGIC periods 254 282 TLine l; 255 283 TText t; … … 282 310 //gPad->SaveAs(Form("plotdb-%s.eps", title.Data())); 283 311 312 // Go back to first (upper) pad, format it and divide it again 284 313 pad->cd(1); 285 314 gPad->SetBorderMode(0); … … 288 317 289 318 TVirtualPad *pad2 = gPad; 319 320 // format left pad 290 321 pad2->cd(1); 291 322 gPad->SetBorderMode(0); … … 294 325 gPad->SetGridy(); 295 326 327 // Create histogram 296 328 const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50; 297 329 … … 299 331 hist.SetDirectory(0); 300 332 333 // Fill data into histogra, 301 334 for (int i=0; i<gt.GetN(); i++) 302 335 hist.Fill(gt.GetY()[i]); 303 336 337 // Format histogram 304 338 if (fDescription.IsNull()) 305 339 hist.SetXTitle(name); 306 340 hist.SetYTitle("Counts"); 307 341 342 // plot histogram 308 343 hist.DrawCopy(""); 309 344 345 // format right pad 310 346 pad2->cd(2); 311 347 gPad->SetBorderMode(0); … … 313 349 gPad->SetGridy(); 314 350 351 // format graph 315 352 TH1 *h2 = gz.GetHistogram(); 316 353 … … 318 355 h2->SetYTitle(name); 319 356 357 // draw graph 320 358 gz.DrawClone("AP"); 359 321 360 if (gz0.GetN()>0) 322 361 gz0.DrawClone("P"); … … 369 408 370 409 TString query="SELECT "; 371 query += valued; 410 switch (fGroupBy) 411 { 412 case kNone: 413 case kGroupByPrimary: 414 query += valued; 415 break; 416 case kGroupByHour: 417 query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 418 break; 419 case kGroupByNight: 420 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 421 break; 422 case kGroupByWeek: 423 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data()); 424 break; 425 case kGroupByMonth: 426 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 427 break; 428 case kGroupBySeason: 429 //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 430 break; 431 case kGroupByYear: 432 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 433 break; 434 } 435 372 436 if (fGroupBy==kNone) 373 437 { … … 395 459 } 396 460 397 switch (fGroupBy)398 {399 case kNone:400 case kGroupByPrimary:401 break;402 case kGroupByHour:403 query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data());404 break;405 case kGroupByNight:406 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data());407 break;408 case kGroupByWeek:409 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data());410 break;411 case kGroupByMonth:412 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data());413 break;414 case kGroupByYear:415 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data());416 break;417 }418 419 461 query += Form("FROM %s ", tabled.Data()); 420 462 … … 452 494 //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data()); 453 495 } 454 query += Form("ORDER BY %s ", fPrimaryDate.Data());496 query += Form("ORDER BY %s ", valued.Data()); 455 497 456 498 -
trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C
r8186 r8212 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1. 4 2006-11-01 08:53:26 tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.5 2006-11-03 10:52:36 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 28 28 ///////////////////////////////////////////////////////////////////////////// 29 29 // 30 // plotdb.C 31 // ======== 32 // 33 // This macro is used to read quality parameters from the DB and plot them. 34 // 35 // The parameters are from the following files: 36 // calib*.root:mean conversion factor, mean arrival time, rms arrival time 37 // (each parameter for inner and outer camera) 38 // signal*.root: mean pedestal rms (for inner and outer camera) 39 // star*.root: PSF, # of Muons, Effective OnTime, Muon rate, 40 // Ratio MC/Data(MuonSize) and mean number of islands 30 // plotoptical.C 31 // ============= 32 // 33 // This macro is used to read optical data from the DB and plot them. 41 34 // 42 35 // In the DB these values are stored in the tables Calibration and Star. 43 // 44 // Usage: 45 // .x plotdb.C --> all values in the DB are plotted 46 // You can chose are certain period: 47 // .x plotdb.C(25) --> all values from period 25 are plotted 36 // 37 // 38 // To plot the whole database simple use: 39 // .x plotdb.C+ 40 // 41 // Plot only data for one source. For the available sources see the database 42 // .x plotdb.C+("source") 43 // 44 // You can chose are certain MAGIC-period: 45 // .x plotdb.C+(25) --> all values from period 25 are plotted 46 // 47 // MAGIC periods correspond to one moon-phase and are defined as 48 // moon period-284. For details see MAstro::MoonPeriod and 49 // MAstro::MagicPeriod. 50 // 48 51 // or a time period from a certain date to a certain date 49 // .x plotdb.C ("2004-11-14 00:00:00", "2005-02-28 00:00:00")52 // .x plotdb.C+("2004-11-14 00:00:00", "2005-02-28 00:00:00") 50 53 // --> all values from 14.11.2004 0h to 28.2.2005 0h are plotted 51 // or all data, but with dataset data highlighted 52 // .x plotdb.C("dataset.txt") 53 // --> the sequences defined in dataset.txt are highlighted (blue:on, red:off) 54 // --> You can also add a dataset-name as last argument to one of the 55 // calls above 54 // .x plotdb.C+("2004-11-14 00:00:00", "2005-02-28 00:00:00", "source") 55 // --> all values from 14.11.2004 0h to 28.2.2005 0h of "source" are plotted 56 // 57 // 58 // For details of the plots produced see the function plotall() below. 59 // 60 // 61 // The plot title and axis-titles are created by: 62 // plot.SetDescription("Title;x", "TabName"); 63 // 64 // Drawing the plot is initiated by 65 // plot.Plot("OpticalData.fExposure", min, max, width); 66 // 67 // While OpticalData.fExposure can be any kind of variable to plot. 68 // min and max are the minimum and maximum of the histogram which is 69 // filled and width is the bin-width of this histogram. 70 // 71 // To group data (average) of a certain period use: 72 // plot.GroupBy(MPlot::kGroupByNight); 73 // before initiating the plot. 74 // 56 75 // 57 76 // Make sure, that database and password are corretly set in a resource … … 84 103 { 85 104 public: 105 // Possible constants to group-by (average) over a certain period 86 106 enum GroupBy_t 87 107 { … … 92 112 kGroupByWeek, 93 113 kGroupByMonth, 114 kGroupBySeason, 94 115 kGroupByYear 95 116 }; 117 96 118 private: 97 MSQLMagic &fServer; 98 99 MDataSet *fDataSet; 100 101 TString fPrimaryDate; 102 TString fPrimaryNumber; 103 TString fSecondary; 104 105 TString fRequestFrom; 106 TString fRequestTo; 107 Int_t fRequestPeriod; 119 MSQLMagic &fServer; // Reference to the sql-server class 120 121 MDataSet *fDataSet; // A possible dtaset to highlite single points 122 123 TString fPrimaryDate; // The name of the data we plot 124 TString fPrimaryNumber; // The corresponding name for the key number 125 TString fSecondary; // The value versus which the second plot is made 126 127 TString fRequestFrom; // Start of a requested date range 128 TString fRequestTo; // End of a requested date range 129 Int_t fRequestPeriod; // A possible requested period 108 130 109 131 Float_t fPlotMin; … … 113 135 Float_t fHistMax; 114 136 115 TString fDescription; 116 TString fNameTab; 117 118 TString fCondition; 119 GroupBy_t fGroupBy; 120 137 TString fDescription; // The description (title) of the plot 138 TString fNameTab; // The name of the tab in the display 139 140 TString fCondition; // An additional condition added to the query 141 GroupBy_t fGroupBy; // A possible Group-By flag 142 143 // -------------------------------------------------------------------------- 144 // 145 // Function to plot the result of the query 146 // 121 147 void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution) 122 148 { 149 // Enable all otions in the statistics box 123 150 gStyle->SetOptStat(111111); 124 151 125 152 TSQLRow *row; 126 153 154 // Create TGraph objects 127 155 TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph; 128 156 gt.SetNameTitle(name, Form("%s vs Time", name.Data())); … … 148 176 Int_t last = -1; 149 177 178 // Loop over the data 150 179 while ((row=res.Next())) 151 180 { 181 // Get all fields of this row 152 182 const char *date = (*row)[0]; 153 183 const char *zd = (*row)[1]; … … 158 188 continue; 159 189 190 // check if date is valid 160 191 MTime t(date); 161 192 if (!t.SetSqlDateTime(date)) 162 193 continue; 163 194 195 // check if it belongs to the requested MAGIC period 164 196 if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod) 165 197 continue; 166 198 199 // Get axis range 167 200 if (first<0) 168 201 first = TMath::Nint(TMath::Floor(t.GetMjd())); 169 202 last = TMath::Nint(TMath::Ceil(t.GetMjd())); 170 203 204 // Convert a possible key number into a integer 171 205 UInt_t seq = snum ? atoi(snum) : 0; 172 206 207 // convert primary and secondary value into floats 173 208 Float_t value = atof(val); 174 209 Float_t zenith = atof(zd); 175 210 211 // If a datset is given add the point to the special TGraphs 212 // used for highliting these dates 176 213 if (fDataSet) 177 214 { … … 189 226 } 190 227 228 // Add Data to TGraph 191 229 gt.SetPoint(gt.GetN(), t.GetAxisTime(), value); 192 230 gz.SetPoint(gz.GetN(), zenith, value); 193 231 232 // Set error-bar, if one 194 233 if (verr) 195 234 static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr)); … … 207 246 gROOT->SetSelectedPad(0); 208 247 248 // Create a TCanvas or open a new tab 209 249 TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab; 210 250 TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas; 251 // Set fillcolor, remove border and divide pad 211 252 c.SetFillColor(kWhite); 212 253 c.SetBorderMode(0); 213 254 c.Divide(1,2); 214 255 256 // Output mean and rms to console 215 257 cerr << setprecision(4) << setw(10) << title << ": "; 216 258 if (gt.GetN()==0) … … 228 270 229 271 TVirtualPad *pad = gPad; 272 273 // draw contants of pad 2 (counting starts at 0) 230 274 pad->cd(2); 231 275 gPad->SetBorderMode(0); … … 237 281 gPad->SetBottomMargin(0.08); 238 282 283 // format axis 239 284 TH1 *h = gt.GetHistogram(); 240 285 … … 246 291 h->GetXaxis()->SetLabelOffset(0.01); 247 292 293 // draw TGraph 248 294 gt.DrawClone("AP"); 249 295 if (gt0.GetN()>0) … … 252 298 gt1.DrawClone("P"); 253 299 300 // Add lines and text showing the MAGIC periods 254 301 TLine l; 255 302 TText t; … … 282 329 //gPad->SaveAs(Form("plotdb-%s.eps", title.Data())); 283 330 331 // Go back to first (upper) pad, format it and divide it again 284 332 pad->cd(1); 285 333 gPad->SetBorderMode(0); … … 288 336 289 337 TVirtualPad *pad2 = gPad; 338 339 // format left pad 290 340 pad2->cd(1); 291 341 gPad->SetBorderMode(0); … … 294 344 gPad->SetGridy(); 295 345 346 // Create histogram 296 347 const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50; 297 348 … … 299 350 hist.SetDirectory(0); 300 351 352 // Fill data into histogra, 301 353 for (int i=0; i<gt.GetN(); i++) 302 354 hist.Fill(gt.GetY()[i]); 303 355 356 // Format histogram 304 357 if (fDescription.IsNull()) 305 358 hist.SetXTitle(name); 306 359 hist.SetYTitle("Counts"); 307 360 361 // plot histogram 308 362 hist.DrawCopy(""); 309 363 364 // format right pad 310 365 pad2->cd(2); 311 366 gPad->SetBorderMode(0); … … 313 368 gPad->SetGridy(); 314 369 370 // format graph 315 371 TH1 *h2 = gz.GetHistogram(); 316 372 … … 318 374 h2->SetYTitle(name); 319 375 376 // draw graph 320 377 gz.DrawClone("AP"); 321 378 … … 375 432 376 433 TString query="SELECT "; 377 query += valued; 434 switch (fGroupBy) 435 { 436 case kNone: 437 case kGroupByPrimary: 438 query += valued; 439 break; 440 case kGroupByHour: 441 query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 442 break; 443 case kGroupByNight: 444 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 445 break; 446 case kGroupByWeek: 447 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data()); 448 break; 449 case kGroupByMonth: 450 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 451 break; 452 case kGroupBySeason: 453 //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 454 break; 455 case kGroupByYear: 456 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 457 break; 458 } 459 378 460 if (fGroupBy==kNone) 379 461 { … … 401 483 } 402 484 403 switch (fGroupBy)404 {405 case kNone:406 case kGroupByPrimary:407 break;408 case kGroupByHour:409 query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data());410 break;411 case kGroupByNight:412 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data());413 break;414 case kGroupByWeek:415 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data());416 break;417 case kGroupByMonth:418 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data());419 break;420 case kGroupByYear:421 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data());422 break;423 }424 425 485 query += Form("FROM %s ", tabled.Data()); 426 486 427 487 TString where(fCondition); 488 489 const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull(); 490 if (interval) 491 { 492 if (!where.IsNull()) 493 where += " AND "; 494 where += Form("%s BETWEEN '%s' AND '%s' ", 495 fPrimaryDate.Data(), fRequestFrom.Data(), fRequestTo.Data()); 496 } 428 497 429 498 if (!where.IsNull()) 430 499 where += " AND "; 431 432 500 where += fCondition; 433 501 where += " "; … … 448 516 //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data()); 449 517 } 450 query += Form("ORDER BY %s ", fPrimaryDate.Data()); 451 518 query += Form("ORDER BY %s ", valued.Data()); 452 519 453 520 // ------------------------------ … … 469 536 void plotall(MPlot &plot, TString source) 470 537 { 538 // Setup here the values for timestamp and secondary (upper/right) plot 471 539 plot.SetPrimaryDate("OpticalData.fTimestamp"); 472 540 plot.SetPrimaryNumber("OpticalData.fTimestamp"); 473 541 plot.SetSecondary("OpticalData.fZenithDistance"); 474 542 543 // This is the condition to take only the "ok" flagged data 544 // and to restrict the query to a given source (if any) 475 545 TString cond = "fStatusKEY=13"; 476 546 if (!source.IsNull()) … … 484 554 plot.SetCondition(cond); 485 555 556 // Plot exposure 486 557 plot.SetDescription("Exposure;T_{E} [s]", "Expo"); 487 558 plot.Plot("OpticalData.fExposure", 0, 900, 60); 488 559 560 // plot sky level 489 561 plot.SetDescription("Sky Level;B [s^{-1}]", "SkyLvl"); 490 562 plot.Plot("OpticalData.fSkyLevel/OpticalData.fExposure", 0, 5.0, 0.01); 491 563 564 // plot FWHM 492 565 plot.SetDescription("Full Width Half Maximum;FWHM [s^{-1}]", "Fwhm"); 493 566 plot.Plot("OpticalData.fFWHM/OpticalData.fExposure", 0, 0.05, 0.001); 494 567 568 // plot Aperture Radius 495 569 plot.SetDescription("Aperture Radius;R_{A}", "ApRad"); 496 570 plot.Plot("OpticalData.fApertureRadius", 0, 10, 1); 497 571 498 572 /* 499 plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s"); 500 plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure", 0, 0.2, 0.005); 501 502 plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}\\cdot s^{-1}", "MagErr/s"); 503 plot.Plot("OpticalData.fInstrumentalMagErr/OpticalData.fExposure", 0, 0.01, 0.0002); 504 573 // Plot instrumental magnitude 505 574 plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag"); 506 575 plot.Plot("OpticalData.fInstrumentalMag", 0, 30, 0.5); 507 576 577 // Plot error of instrumental magnitude 508 578 plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr"); 509 579 plot.Plot("OpticalData.fInstrumentalMagErr", 0, 1, 0.01); 510 580 */ 511 581 582 // Plot magnitude corrected for the exposure 512 583 plot.SetDescription("m_{1};m_{1}", "M1"); 513 584 plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2); 514 585 586 // Now take out all points named */BL from further queries 587 // And skip all sources the magnitude is not known 515 588 cond += " AND Object.fObjectName NOT LIKE '%/BL' AND NOT ISNULL(Object.fMagnitude) "; 516 589 plot.SetCondition(cond); 517 590 591 // Formula to calculate the extinction 518 592 TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)"); 519 ext += "+0.0028*fZenithDistance-0.08"; 520 593 // Add this to correct for the ZA dependancy 594 // ext += "+0.0028*fZenithDistance-0.08"; 595 596 // Group all data of one image together and plot extinction 521 597 plot.SetGroupBy(MPlot::kGroupByPrimary); 522 598 plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg"); 523 plot.Plot(ext/*Form("AVG(%s)", ext.Data())*/, 0.05, 1.2, 0.01); 524 599 plot.Plot(ext, 0.05, 1.2, 0.01); 600 601 // Group data hourly together and plot extinction 525 602 plot.SetGroupBy(MPlot::kGroupByHour); 526 603 plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour"); 527 plot.Plot(ext /*Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data())*/,528 0.5, 1.2, 0.01); 529 604 plot.Plot(ext, 0.5, 1.2, 0.01); 605 606 // Group data hourly together and plot extinction 530 607 plot.SetGroupBy(MPlot::kGroupByNight); 531 608 plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight"); 532 plot.Plot(ext/*Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data())*/, 533 0.5, 1.2, 0.01); 609 plot.Plot(ext, 0.5, 1.2, 0.01); 610 611 // Group data monthly together and plot extinction 612 plot.SetGroupBy(MPlot::kGroupByMonth); 613 plot.SetDescription("m_{1}-m_{true} (Extinction per Month);m_{1}-m_{true}", "ExtMonth"); 614 plot.Plot(ext, 0.5, 1.2, 0.01); 615 616 // Group data yearly together and plot extinction 617 plot.SetGroupBy(MPlot::kGroupByYear); 618 plot.SetDescription("m_{1}-m_{true} (Extinction per Year);m_{1}-m_{true}", "ExtYear"); 619 plot.Plot(ext, 0.5, 1.2, 0.01); 534 620 } 535 621 … … 556 642 557 643 MPlot plot(serv); 558 //plot.SetDataSet(dataset);644 // plot.SetDataSet(dataset); 559 645 plot.SetDisplay(d); 560 646 plot.SetRequestRange(from, to); 561 647 plotall(plot, source); 562 d->SaveAsRoot("plotoptical.root"); 563 d->SaveAsPS("plotoptical.ps"); 648 // Use this to create output plots automatically 649 // d->SaveAsRoot("plotoptical.root"); 650 // d->SaveAsPS("plotoptical.ps"); 564 651 565 652 return 1; … … 588 675 589 676 MPlot plot(serv); 590 //plot.SetDataSet(ds);677 // plot.SetDataSet(ds); 591 678 plot.SetDisplay(d); 592 679 plot.SetRequestRange("", ""); 593 680 plotall(plot, source); 594 d->SaveAsRoot("plotoptical.root"); 595 d->SaveAsPS("plotoptical.ps"); 681 // Use this to create output plots automatically 682 // d->SaveAsRoot("plotoptical.root"); 683 // d->SaveAsPS("plotoptical.ps"); 596 684 597 685 return 1; … … 620 708 621 709 MPlot plot(serv); 622 //plot.SetDataSet(dataset);710 // plot.SetDataSet(dataset); 623 711 plot.SetDisplay(d); 624 712 plot.SetRequestPeriod(period); 625 713 plotall(plot, source); 626 d->SaveAsRoot("plotoptical.root"); 627 d->SaveAsPS("plotoptical.ps"); 714 715 // Use this to create output plots automatically 716 // d->SaveAsRoot("plotoptical.root"); 717 // d->SaveAsPS("plotoptical.ps"); 628 718 629 719 return 1; -
trunk/MagicSoft/Mars/datacenter/macros/plotrundb.C
r8186 r8212 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1. 1 2006-11-01 08:54:04tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1.2 2006-11-03 10:52:36 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 84 84 { 85 85 public: 86 // Possible constants to group-by (average) over a certain period 86 87 enum GroupBy_t 87 88 { … … 92 93 kGroupByWeek, 93 94 kGroupByMonth, 95 kGroupBySeason, 94 96 kGroupByYear 95 97 }; 98 96 99 private: 97 MSQLMagic &fServer; 98 99 MDataSet *fDataSet; 100 101 TString fPrimaryDate; 102 TString fPrimaryNumber; 103 TString fSecondary; 104 105 TString fRequestFrom; 106 TString fRequestTo; 107 Int_t fRequestPeriod; 100 MSQLMagic &fServer; // Reference to the sql-server class 101 102 MDataSet *fDataSet; // A possible dtaset to highlite single points 103 104 TString fPrimaryDate; // The name of the data we plot 105 TString fPrimaryNumber; // The corresponding name for the key number 106 TString fSecondary; // The value versus which the second plot is made 107 108 TString fRequestFrom; // Start of a requested date range 109 TString fRequestTo; // End of a requested date range 110 Int_t fRequestPeriod; // A possible requested period 108 111 109 112 Float_t fPlotMin; … … 113 116 Float_t fHistMax; 114 117 115 TString fDescription; 116 TString fNameTab; 117 118 TString fCondition; 119 GroupBy_t fGroupBy; 120 118 TString fDescription; // The description (title) of the plot 119 TString fNameTab; // The name of the tab in the display 120 121 TString fCondition; // An additional condition added to the query 122 GroupBy_t fGroupBy; // A possible Group-By flag 123 124 // -------------------------------------------------------------------------- 125 // 126 // Function to plot the result of the query 127 // 121 128 void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution) 122 129 { 130 // Enable all otions in the statistics box 123 131 gStyle->SetOptStat(111111); 124 132 125 133 TSQLRow *row; 126 134 135 // Create TGraph objects 127 136 TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph; 128 137 gt.SetNameTitle(name, Form("%s vs Time", name.Data())); … … 148 157 Int_t last = -1; 149 158 159 // Loop over the data 150 160 while ((row=res.Next())) 151 161 { 162 // Get all fields of this row 152 163 const char *date = (*row)[0]; 153 164 const char *zd = (*row)[1]; … … 158 169 continue; 159 170 171 // check if date is valid 160 172 MTime t(date); 161 173 if (!t.SetSqlDateTime(date)) 162 174 continue; 163 175 176 // check if it belongs to the requested MAGIC period 164 177 if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod) 165 178 continue; 166 179 180 // Get axis range 167 181 if (first<0) 168 182 first = TMath::Nint(TMath::Floor(t.GetMjd())); 169 183 last = TMath::Nint(TMath::Ceil(t.GetMjd())); 170 184 185 // Convert a possible key number into a integer 171 186 UInt_t seq = snum ? atoi(snum) : 0; 172 187 188 // convert primary and secondary value into floats 173 189 Float_t value = atof(val); 174 190 Float_t zenith = atof(zd); 175 191 192 // If a datset is given add the point to the special TGraphs 193 // used for highliting these dates 176 194 if (fDataSet) 177 195 { … … 189 207 } 190 208 209 // Add Data to TGraph 191 210 gt.SetPoint(gt.GetN(), t.GetAxisTime(), value); 192 211 gz.SetPoint(gz.GetN(), zenith, value); 193 212 213 // Set error-bar, if one 194 214 if (verr) 195 215 static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr)); … … 207 227 gROOT->SetSelectedPad(0); 208 228 229 // Create a TCanvas or open a new tab 209 230 TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab; 210 231 TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas; 232 // Set fillcolor, remove border and divide pad 211 233 c.SetFillColor(kWhite); 212 234 c.SetBorderMode(0); 213 235 c.Divide(1,2); 214 236 237 // Output mean and rms to console 215 238 cerr << setprecision(4) << setw(10) << title << ": "; 216 239 if (gt.GetN()==0) … … 228 251 229 252 TVirtualPad *pad = gPad; 253 254 // draw contants of pad 2 (counting starts at 0) 230 255 pad->cd(2); 231 256 gPad->SetBorderMode(0); … … 237 262 gPad->SetBottomMargin(0.08); 238 263 264 // format axis 239 265 TH1 *h = gt.GetHistogram(); 240 266 … … 246 272 h->GetXaxis()->SetLabelOffset(0.01); 247 273 274 // draw TGraph 248 275 gt.DrawClone("AP"); 249 276 if (gt0.GetN()>0) … … 252 279 gt1.DrawClone("P"); 253 280 281 // Add lines and text showing the MAGIC periods 254 282 TLine l; 255 283 TText t; … … 282 310 //gPad->SaveAs(Form("plotdb-%s.eps", title.Data())); 283 311 312 // Go back to first (upper) pad, format it and divide it again 284 313 pad->cd(1); 285 314 gPad->SetBorderMode(0); … … 288 317 289 318 TVirtualPad *pad2 = gPad; 319 320 // format left pad 290 321 pad2->cd(1); 291 322 gPad->SetBorderMode(0); … … 294 325 gPad->SetGridy(); 295 326 327 // Create histogram 296 328 const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50; 297 329 … … 299 331 hist.SetDirectory(0); 300 332 333 // Fill data into histogra, 301 334 for (int i=0; i<gt.GetN(); i++) 302 335 hist.Fill(gt.GetY()[i]); 303 336 337 // Format histogram 304 338 if (fDescription.IsNull()) 305 339 hist.SetXTitle(name); 306 340 hist.SetYTitle("Counts"); 307 341 342 // plot histogram 308 343 hist.DrawCopy(""); 309 344 345 // format right pad 310 346 pad2->cd(2); 311 347 gPad->SetBorderMode(0); … … 313 349 gPad->SetGridy(); 314 350 351 // format graph 315 352 TH1 *h2 = gz.GetHistogram(); 316 353 … … 318 355 h2->SetYTitle(name); 319 356 357 // draw graph 320 358 gz.DrawClone("AP"); 359 321 360 if (gz0.GetN()>0) 322 361 gz0.DrawClone("P"); … … 369 408 370 409 TString query="SELECT "; 371 query += valued; 410 switch (fGroupBy) 411 { 412 case kNone: 413 case kGroupByPrimary: 414 query += valued; 415 break; 416 case kGroupByHour: 417 query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 418 break; 419 case kGroupByNight: 420 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 421 break; 422 case kGroupByWeek: 423 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data()); 424 break; 425 case kGroupByMonth: 426 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 427 break; 428 case kGroupBySeason: 429 //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 430 break; 431 case kGroupByYear: 432 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()); 433 break; 434 } 435 372 436 if (fGroupBy==kNone) 373 437 { … … 395 459 } 396 460 397 switch (fGroupBy)398 {399 case kNone:400 case kGroupByPrimary:401 break;402 case kGroupByHour:403 query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data());404 break;405 case kGroupByNight:406 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data());407 break;408 case kGroupByWeek:409 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data());410 break;411 case kGroupByMonth:412 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data());413 break;414 case kGroupByYear:415 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data());416 break;417 }418 419 461 query += Form("FROM %s ", tabled.Data()); 420 462 … … 449 491 //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data()); 450 492 } 451 query += Form("ORDER BY %s ", fPrimaryDate.Data());493 query += Form("ORDER BY %s ", valued.Data()); 452 494 453 495
Note:
See TracChangeset
for help on using the changeset viewer.