| 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, 07/2005 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2005 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | // MHRate | 
|---|
| 28 | // | 
|---|
| 29 | // Display information about software trigger rate | 
|---|
| 30 | // | 
|---|
| 31 | //////////////////////////////////////////////////////////////////////////// | 
|---|
| 32 | #include "MHRate.h" | 
|---|
| 33 |  | 
|---|
| 34 | #include <TCanvas.h> | 
|---|
| 35 | #include <TGaxis.h> | 
|---|
| 36 |  | 
|---|
| 37 | #include "MLog.h" | 
|---|
| 38 | #include "MLogManip.h" | 
|---|
| 39 |  | 
|---|
| 40 | #include "MParList.h" | 
|---|
| 41 |  | 
|---|
| 42 | #include "MTime.h" | 
|---|
| 43 | #include "MEventRate.h" | 
|---|
| 44 | #include "MPointingPos.h" | 
|---|
| 45 | #include "MBinning.h" | 
|---|
| 46 |  | 
|---|
| 47 | ClassImp(MHRate); | 
|---|
| 48 |  | 
|---|
| 49 | using namespace std; | 
|---|
| 50 |  | 
|---|
| 51 | void MHRate::ResetGraph(TGraph &g) const | 
|---|
| 52 | { | 
|---|
| 53 | g.Set(1); | 
|---|
| 54 | g.SetPoint(0, 0, 0); // Dummy Point | 
|---|
| 55 | g.SetEditable();     // Used as flag: First point? yes/no | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | void MHRate::InitGraph(TGraph &g) const | 
|---|
| 59 | { | 
|---|
| 60 | ResetGraph(g); | 
|---|
| 61 | g.SetMarkerStyle(kFullDotMedium); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | void MHRate::AddPoint(TGraph &g, Double_t x, Double_t y) const | 
|---|
| 65 | { | 
|---|
| 66 | if (g.IsEditable()) | 
|---|
| 67 | { | 
|---|
| 68 | g.RemovePoint(0); | 
|---|
| 69 | g.SetEditable(kFALSE); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | g.SetPoint(g.GetN(), x, y); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | // -------------------------------------------------------------------------- | 
|---|
| 76 | // | 
|---|
| 77 | // Setup histograms | 
|---|
| 78 | // | 
|---|
| 79 | MHRate::MHRate(const char *name, const char *title) | 
|---|
| 80 | : /*fTime(0),*/ fPointPos(0), fEvtRate(0) | 
|---|
| 81 | { | 
|---|
| 82 | fName  = name  ? name  : "MHRate"; | 
|---|
| 83 | fTitle = title ? title : "Graphs for rate data"; | 
|---|
| 84 |  | 
|---|
| 85 | // Init Graphs | 
|---|
| 86 | fRateTime.SetNameTitle("RateTime", "Rate vs Time"); | 
|---|
| 87 | fRateZd.SetNameTitle("RateZd", "Rate vs Zenith distance"); | 
|---|
| 88 | fRate.SetNameTitle("Rate", "Distribution of Rate"); | 
|---|
| 89 |  | 
|---|
| 90 | InitGraph(fRateTime); | 
|---|
| 91 |  | 
|---|
| 92 | fRateZd.SetXTitle("Zd [\\circ]"); | 
|---|
| 93 | fRateZd.SetYTitle("Rate [Hz]"); | 
|---|
| 94 |  | 
|---|
| 95 | fRate.SetXTitle("Rate [Hz]"); | 
|---|
| 96 | fRate.SetYTitle("Counts"); | 
|---|
| 97 |  | 
|---|
| 98 | fRate.SetDirectory(0); | 
|---|
| 99 | fRateZd.SetDirectory(0); | 
|---|
| 100 |  | 
|---|
| 101 | fRateZd.SetMarkerStyle(kFullDotMedium); | 
|---|
| 102 | fRateZd.SetBit(TH1::kNoStats); | 
|---|
| 103 |  | 
|---|
| 104 | MBinning b; | 
|---|
| 105 | b.SetEdges(120, 0, 1200); | 
|---|
| 106 | b.Apply(fRate); | 
|---|
| 107 |  | 
|---|
| 108 | b.SetEdgesASin(67, -0.005, 0.665); | 
|---|
| 109 | b.Apply(fRateZd); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | // -------------------------------------------------------------------------- | 
|---|
| 113 | // | 
|---|
| 114 | // Setup the Binning for the histograms automatically if the correct | 
|---|
| 115 | // instances of MBinning | 
|---|
| 116 | // | 
|---|
| 117 | Bool_t MHRate::SetupFill(const MParList *plist) | 
|---|
| 118 | { | 
|---|
| 119 | fEvtRate = (MEventRate*)plist->FindObject("MEventRate"); | 
|---|
| 120 | if (!fEvtRate) | 
|---|
| 121 | { | 
|---|
| 122 | *fLog << err << "MEventRate not found... abort." << endl; | 
|---|
| 123 | return kFALSE; | 
|---|
| 124 | } | 
|---|
| 125 | fPointPos = (MPointingPos*)plist->FindObject("MPointingPos"); | 
|---|
| 126 | if (!fPointPos) | 
|---|
| 127 | { | 
|---|
| 128 | *fLog << err << "MPointingPos not found... abort." << endl; | 
|---|
| 129 | return kFALSE; | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 | // Reset Graphs | 
|---|
| 133 | ResetGraph(fRateTime); | 
|---|
| 134 |  | 
|---|
| 135 | fCounter = 0; | 
|---|
| 136 | fMean    = 0; | 
|---|
| 137 | fLast    = MTime(); | 
|---|
| 138 |  | 
|---|
| 139 | return kTRUE; | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | // -------------------------------------------------------------------------- | 
|---|
| 143 | // | 
|---|
| 144 | // Fill the histograms with data from a MMuonCalibPar and | 
|---|
| 145 | // MMuonSearchPar container. | 
|---|
| 146 | // | 
|---|
| 147 | Bool_t MHRate::Fill(const MParContainer *par, const Stat_t w) | 
|---|
| 148 | { | 
|---|
| 149 | const MTime *t = dynamic_cast<const MTime*>(par); | 
|---|
| 150 | if (!t) | 
|---|
| 151 | { | 
|---|
| 152 | *fLog << err <<"MHRate::Fill - ERROR: MTime not given as argument... abort." << endl; | 
|---|
| 153 | return kERROR; | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | const Double_t rate = fEvtRate->GetRate(); | 
|---|
| 157 | if (rate<0) | 
|---|
| 158 | return kTRUE; | 
|---|
| 159 |  | 
|---|
| 160 | const Double_t tm   = t->GetAxisTime(); | 
|---|
| 161 |  | 
|---|
| 162 | if (fLast==MTime()) | 
|---|
| 163 | fLast = MTime(); | 
|---|
| 164 |  | 
|---|
| 165 | fMean += rate; | 
|---|
| 166 | fCounter++; | 
|---|
| 167 |  | 
|---|
| 168 | if ((double)*t > (double)fLast+5 && fCounter>0) | 
|---|
| 169 | { | 
|---|
| 170 | AddPoint(fRateTime, tm, fMean/fCounter); | 
|---|
| 171 | fMean     = 0; | 
|---|
| 172 | fCounter = 0; | 
|---|
| 173 | fLast = *t; | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | fRateZd.Fill(fPointPos->GetZd(), rate); | 
|---|
| 177 | fRate.Fill(rate); | 
|---|
| 178 |  | 
|---|
| 179 | return kTRUE; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | void MHRate::DrawGraph(TGraph &g, const char *y) const | 
|---|
| 183 | { | 
|---|
| 184 | // If this is set to early the plot remains empty in root 5.12/00 | 
|---|
| 185 | if (g.GetN()>0) | 
|---|
| 186 | g.SetMinimum(0); | 
|---|
| 187 |  | 
|---|
| 188 | // This is not done automatically anymore since root 5.12/00 | 
|---|
| 189 | // and it is necessary to force a proper update of the axis. | 
|---|
| 190 | TH1 *h = g.GetHistogram(); | 
|---|
| 191 | if (h) | 
|---|
| 192 | { | 
|---|
| 193 | delete h; | 
|---|
| 194 | g.SetHistogram(0); | 
|---|
| 195 | h = g.GetHistogram(); | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|
| 198 | if (h) | 
|---|
| 199 | { | 
|---|
| 200 | cout << "Y"; | 
|---|
| 201 | TAxis *axe = h->GetXaxis(); | 
|---|
| 202 | axe->SetLabelSize(0.033); | 
|---|
| 203 | axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT"); | 
|---|
| 204 | axe->SetTimeDisplay(1); | 
|---|
| 205 | axe->SetTitle("Time"); | 
|---|
| 206 | if (y) | 
|---|
| 207 | h->SetYTitle(y); | 
|---|
| 208 | } | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | // -------------------------------------------------------------------------- | 
|---|
| 212 | // | 
|---|
| 213 | // Update position of an axis on the right side of the histogram | 
|---|
| 214 | /* | 
|---|
| 215 | void MHRate::UpdateRightAxis(TGraph &g) const | 
|---|
| 216 | { | 
|---|
| 217 | TH1 &h = *g.GetHistogram(); | 
|---|
| 218 |  | 
|---|
| 219 | const Double_t max = h.GetMaximum(); | 
|---|
| 220 | if (max==0) | 
|---|
| 221 | return; | 
|---|
| 222 |  | 
|---|
| 223 | TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis"); | 
|---|
| 224 | if (!axis) | 
|---|
| 225 | return; | 
|---|
| 226 |  | 
|---|
| 227 | axis->SetX1(g.GetXaxis()->GetXmax()); | 
|---|
| 228 | axis->SetX2(g.GetXaxis()->GetXmax()); | 
|---|
| 229 | axis->SetY1(gPad->GetUymin()); | 
|---|
| 230 | axis->SetY2(gPad->GetUymax()); | 
|---|
| 231 | axis->SetWmax(max); | 
|---|
| 232 | } | 
|---|
| 233 | */ | 
|---|
| 234 | // -------------------------------------------------------------------------- | 
|---|
| 235 | // | 
|---|
| 236 | // Draw an axis on the right side of the histogram | 
|---|
| 237 | // | 
|---|
| 238 | /* | 
|---|
| 239 | void MHRate::DrawRightAxis(const char *title) const | 
|---|
| 240 | { | 
|---|
| 241 | TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(), | 
|---|
| 242 | gPad->GetUxmax(), gPad->GetUymax(), | 
|---|
| 243 | 0, 1, 510, "+L"); | 
|---|
| 244 | axis->SetName("RightAxis"); | 
|---|
| 245 | axis->SetTitle(title); | 
|---|
| 246 | axis->SetTitleOffset(0.9); | 
|---|
| 247 | axis->SetTextColor(kRed); | 
|---|
| 248 | axis->SetBit(kCanDelete); | 
|---|
| 249 | axis->Draw(); | 
|---|
| 250 | } | 
|---|
| 251 | */ | 
|---|
| 252 | // -------------------------------------------------------------------------- | 
|---|
| 253 | // | 
|---|
| 254 | // This displays the TGraph like you expect it to be (eg. time on the axis) | 
|---|
| 255 | // It should also make sure, that the displayed time always is UTC and | 
|---|
| 256 | // not local time... | 
|---|
| 257 | // | 
|---|
| 258 | void MHRate::Draw(Option_t *opt) | 
|---|
| 259 | { | 
|---|
| 260 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this); | 
|---|
| 261 | pad->SetBorderMode(0); | 
|---|
| 262 |  | 
|---|
| 263 | AppendPad(); | 
|---|
| 264 |  | 
|---|
| 265 | pad->Divide(2,2); | 
|---|
| 266 |  | 
|---|
| 267 | pad->cd(1); | 
|---|
| 268 | gPad->SetBorderMode(0); | 
|---|
| 269 | gPad->SetGridx(); | 
|---|
| 270 | gPad->SetGridy(); | 
|---|
| 271 | gPad->SetLogy(); | 
|---|
| 272 | fRate.Draw(); | 
|---|
| 273 | //fHumidity.Draw("AP"); | 
|---|
| 274 | //fTemperature.Draw("P"); | 
|---|
| 275 | //DrawRightAxis("T [\\circ C]"); | 
|---|
| 276 |  | 
|---|
| 277 | pad->cd(2); | 
|---|
| 278 | gPad->SetBorderMode(0); | 
|---|
| 279 | gPad->SetGridx(); | 
|---|
| 280 | gPad->SetGridy(); | 
|---|
| 281 | fRateTime.Draw("AP"); | 
|---|
| 282 | //fSolarRadiation.Draw("AP"); | 
|---|
| 283 |  | 
|---|
| 284 | pad->cd(3); | 
|---|
| 285 | gPad->SetBorderMode(0); | 
|---|
| 286 | gPad->SetGridx(); | 
|---|
| 287 | gPad->SetGridy(); | 
|---|
| 288 | fRateZd.Draw(); | 
|---|
| 289 |  | 
|---|
| 290 | if (pad->GetPad(4)) | 
|---|
| 291 | delete pad->GetPad(4); | 
|---|
| 292 |  | 
|---|
| 293 | /* | 
|---|
| 294 | pad->cd(4); | 
|---|
| 295 | gPad->SetBorderMode(0); | 
|---|
| 296 | gPad->SetGridx(); | 
|---|
| 297 | gPad->SetGridy(); | 
|---|
| 298 | fWindSpeed.Draw("AP");*/ | 
|---|
| 299 | } | 
|---|
| 300 |  | 
|---|
| 301 | void MHRate::Paint(Option_t *o) | 
|---|
| 302 | { | 
|---|
| 303 | DrawGraph(fRateTime, "f [Hz]"); | 
|---|
| 304 | /* | 
|---|
| 305 | gPad->cd(1); | 
|---|
| 306 |  | 
|---|
| 307 | if (gPad) | 
|---|
| 308 | { | 
|---|
| 309 | fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue); | 
|---|
| 310 | UpdateRightAxis(fTemperature); | 
|---|
| 311 | }*/ | 
|---|
| 312 | } | 
|---|