Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SepdMonDraw.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SepdMonDraw.cc
1 #include "SepdMonDraw.h"
2 
3 #include <onlmon/OnlMonClient.h>
4 
5 #include <TAxis.h> // for TAxis
6 #include <TCanvas.h>
7 #include <TGraphErrors.h>
8 #include <TH1.h>
9 #include <TLegend.h>
10 #include <TLine.h>
11 #include <TPad.h>
12 #include <TProfile.h>
13 #include <TROOT.h>
14 #include <TSystem.h>
15 #include <TText.h>
16 
17 #include <cstring> // for memset
18 #include <ctime>
19 #include <fstream>
20 #include <iostream> // for operator<<, basic_ostream, basic_os...
21 #include <sstream>
22 #include <vector> // for vector
23 
25  : OnlMonDraw(name)
26 {
27  return;
28 }
29 
31 {
32  return 0;
33 }
34 
36 {
38  int xsize = cl->GetDisplaySizeX();
39  int ysize = cl->GetDisplaySizeY();
40  if (name == "SepdMon1")
41  {
42  // xpos (-1) negative: do not draw menu bar
43  TC[0] = new TCanvas(name.c_str(), "SepdMon Example Monitor", 1200, 600);
44  // root is pathetic, whenever a new TCanvas is created root piles up
45  // 6kb worth of X11 events which need to be cleared with
46  // gSystem->ProcessEvents(), otherwise your process will grow and
47  // grow and grow but will not show a definitely lost memory leak
48  gSystem->ProcessEvents();
49  Pad[0] = new TPad("sepdpad0", "Left", 0., 0., 0.5, 1);
50  Pad[1] = new TPad("sepdpad1", "Right", 0.5, 0., 1, 1);
51  Pad[0]->Draw();
52  Pad[1]->Draw();
53  // this one is used to plot the run number on the canvas
54  transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
55  transparent[0]->SetFillStyle(4000);
56  transparent[0]->Draw();
57  TC[0]->SetEditable(false);
58  }
59  else if (name == "SepdMon2")
60  {
61  // xpos negative: do not draw menu bar
62  TC[1] = new TCanvas(name.c_str(), "SepdMon2 Example Monitor", 1200, 600);
63  gSystem->ProcessEvents();
64  Pad[2] = new TPad("sepdpad2", "Left", 0., 0., 0.5, 1);
65  Pad[3] = new TPad("sepdpad3", "Right", 0.5, 0., 1, 1);
66  Pad[2]->Draw();
67  Pad[3]->Draw();
68  // this one is used to plot the run number on the canvas
69  transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
70  transparent[1]->SetFillStyle(4000);
71  transparent[1]->Draw();
72  TC[1]->SetEditable(false);
73  }
74  /*
75  else if (name == "SepdMon3")
76  {
77  }
78  */
79  else if (name == "SepdMon4")
80  {
81  TC[3] = new TCanvas(name.c_str(), "SepdMon3 Waveform Info", xsize / 3, 0, xsize / 3, ysize * 0.9);
82  gSystem->ProcessEvents();
83  Pad[6] = new TPad("hcalpad6", "who needs this?", 0.0, 0.6, 1.0, 0.95, 0);
84  Pad[7] = new TPad("hcalpad7", "who needs this?", 0.0, 0.3, 1.0, 0.6, 0);
85  Pad[8] = new TPad("hcalpad8", "who needs this?", 0.0, 0.0, 1.0, 0.3, 0);
86  Pad[6]->Draw();
87  Pad[7]->Draw();
88  Pad[8]->Draw();
89  // this one is used to plot the run number on the canvas
90  transparent[3] = new TPad("transparent3", "this does not show", 0, 0, 1, 1);
91  transparent[3]->SetFillStyle(4000);
92  transparent[3]->Draw();
93  TC[3]->SetEditable(0);
94  }
95  else if (name == "SepdMon5")
96  {
97  // xpos negative: do not draw menu bar
98  TC[4] = new TCanvas(name.c_str(), "HCAL Packet Information", 2 * xsize / 3, 0, 2 * xsize / 3, ysize * 0.9);
99  gSystem->ProcessEvents();
100  Pad[10] = new TPad("pad10", "packet event check", 0.0, 0.6, 1.0 / 2, 0.95, 0);
101  Pad[11] = new TPad("pad11", "packet size", 0.0, 0.3, 1.0 / 2, 0.6, 0);
102  Pad[12] = new TPad("pad12", "packet channels", 0.0, 0.0, 1.0 / 2, 0.3, 0);
103  Pad[13] = new TPad("pad13", "event number offset", 0.5, 0.6, 1.0, 0.95, 0);
104  // pad 14 and 15 side by side from left to right for correlation
105  // Pad[14] = new TPad("pad14", "correlation0", 0.5, 0.3, 0.75, 0.6, 0);
106  // Pad[15] = new TPad("pad15", "correlation1", 0.75, 0.3, 1.0, 0.6, 0);
107 
108  Pad[10]->Draw();
109  Pad[11]->Draw();
110  Pad[12]->Draw();
111  Pad[13]->Draw();
112  //Pad[14]->Draw();
113  //Pad[15]->Draw();
114  // this one is used to plot the run number on the canvas
115  transparent[4] = new TPad("transparent1", "this does not show", 0, 0, 1., 1);
116  transparent[4]->SetFillStyle(4000);
117  transparent[4]->Draw();
118 
119  // packet warnings
120  warning[1] = new TPad("warning1", "packet warnings", 0.5, 0, 1, 0.2);
121  warning[1]->SetFillStyle(4000);
122  warning[1]->Draw();
123  TC[4]->SetEditable(0);
124  }
125  return 0;
126 }
127 
129 {
130  int iret = 0;
131  int idraw = 0;
132  if (what == "ALL" || what == "FIRST")
133  {
134  iret += DrawFirst(what);
135  idraw++;
136  }
137  if (what == "ALL" || what == "SECOND")
138  {
139  iret += DrawSecond(what);
140  idraw++;
141  }
142  /*
143  if (what == "ALL" || what == "THIRD")
144  {
145  iret += DrawThird(what);
146  idraw++;
147  }
148  */
149  if (what == "ALL" || what == "FOURTH")
150  {
151  iret += DrawFourth(what);
152  idraw++;
153  }
154  if (what == "ALL" || what == "FIFTH")
155  {
156  iret += DrawFifth(what);
157  idraw++;
158  }
159 
160  /*
161  if (what == "ALL" || what == "HISTORY")
162  {
163  iret += DrawHistory(what);
164  idraw++;
165  }
166  */
167  if (!idraw)
168  {
169  std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
170  iret = -1;
171  }
172  return iret;
173 }
174 
175 int SepdMonDraw::DrawFirst(const std::string & /* what */)
176 {
178  TH2 *h_ADC0_s = (TH2 *) cl->getHisto("SEPDMON_0", "h_ADC0_s");
179  TH2 *h_ADC0_n = (TH2 *) cl->getHisto("SEPDMON_0", "h_ADC0_n");
180  TH2 *h_ADC_s = (TH2 *) cl->getHisto("SEPDMON_0", "h_ADC_s");
181  TH2 *h_ADC_n = (TH2 *) cl->getHisto("SEPDMON_0", "h_ADC_n");
182  TH2 *h_hits0_s = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits0_s");
183  TH2 *h_hits0_n = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits0_n");
184  TH2 *h_hits_s = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits_s");
185  TH2 *h_hits_n = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits_n");
186  time_t evttime = cl->EventTime("CURRENT");
187 
188  if (!gROOT->FindObject("SepdMon1"))
189  {
190  MakeCanvas("SepdMon1");
191  }
192  TC[0]->SetEditable(true);
193  TC[0]->Clear("D");
194 
195  if (!h_ADC0_s)
196  {
198  TC[0]->SetEditable(false);
199  return -1;
200  }
201 
202  int nbinsx0 = h_ADC0_s->GetNbinsX();
203  int nbinsy0 = h_ADC0_s->GetNbinsY();
204  int nbinsx = h_ADC_s->GetNbinsX();
205  int nbinsy = h_ADC_s->GetNbinsY();
206 
207  for (int ibx = 0; ibx < nbinsx0; ibx++)
208  {
209  for (int iby = 0; iby < nbinsy0; iby++)
210  {
211  double con = h_ADC0_s->GetBinContent(ibx + 1, iby + 1);
212  double div = h_hits0_s->GetBinContent(ibx + 1, iby + 1);
213  h_ADC0_s->SetBinContent(ibx + 1, iby + 1, con / div);
214  con = h_ADC0_n->GetBinContent(ibx + 1, iby + 1);
215  div = h_hits0_n->GetBinContent(ibx + 1, iby + 1);
216  h_ADC0_n->SetBinContent(ibx + 1, iby + 1, con / div);
217  }
218  }
219 
220  for (int ibx = 0; ibx < nbinsx; ibx++)
221  {
222  for (int iby = 0; iby < nbinsy; iby++)
223  {
224  double con = h_ADC_s->GetBinContent(ibx + 1, iby + 1);
225  double div = h_hits_s->GetBinContent(ibx + 1, iby + 1);
226  h_ADC_s->SetBinContent(ibx + 1, iby + 1, con / div);
227  con = h_ADC_n->GetBinContent(ibx + 1, iby + 1);
228  div = h_hits_n->GetBinContent(ibx + 1, iby + 1);
229  h_ADC_n->SetBinContent(ibx + 1, iby + 1, con / div);
230  }
231  }
232  gStyle->SetOptStat(0);
233  Pad[0]->cd();
234  h_ADC0_s->Draw("COLZPOL");
235  h_ADC_s->Draw("COLZPOL same");
236  Pad[1]->cd();
237  h_ADC0_n->Draw("COLZPOL");
238  h_ADC_n->Draw("COLZPOL same");
239 
240  TText PrintRun;
241  PrintRun.SetTextFont(62);
242  PrintRun.SetTextSize(0.04);
243  PrintRun.SetNDC(); // set to normalized coordinates
244  PrintRun.SetTextAlign(23); // center/top alignment
245  std::ostringstream runnostream;
246  std::string runstring;
247  // fill run number and event time into string
248  runnostream << ThisName << "_1 Run " << cl->RunNumber()
249  << ", Time: " << ctime(&evttime);
250  runstring = runnostream.str();
251  transparent[0]->cd();
252  PrintRun.DrawText(0.5, 1., runstring.c_str());
253  TC[0]->Update();
254  TC[0]->Show();
255  TC[0]->SetEditable(false);
256  return 0;
257 }
258 
259 int SepdMonDraw::DrawSecond(const std::string & /* what */)
260 {
262  TH2 *h_hits0_s = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits0_s");
263  TH2 *h_hits0_n = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits0_n");
264  TH2 *h_hits_s = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits_s");
265  TH2 *h_hits_n = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits_n");
266 
267  TH1 *h_event = cl->getHisto("SEPDMON_0", "h_event");
268  time_t evttime = cl->EventTime("CURRENT");
269 
270  if (!gROOT->FindObject("SepdMon2"))
271  {
272  MakeCanvas("SepdMon2");
273  }
274  if (!h_hits0_s)
275  {
277  TC[0]->SetEditable(false);
278  return -1;
279  }
280  int nevt = h_event->GetEntries();
281  h_hits0_s->Scale(1. / nevt);
282  h_hits_s->Scale(1. / nevt);
283  h_hits0_n->Scale(1. / nevt);
284  h_hits_n->Scale(1. / nevt);
285  gStyle->SetOptStat(0);
286  TC[1]->SetEditable(true);
287  TC[1]->Clear("D");
288  Pad[2]->cd();
289  h_hits0_s->Draw("COLZPOL");
290  h_hits_s->Draw("COLZPOL same");
291  Pad[3]->cd();
292  h_hits0_n->Draw("COLZPOL");
293  h_hits_n->Draw("COLZPOL same");
294  TText PrintRun;
295  PrintRun.SetTextFont(62);
296  PrintRun.SetTextSize(0.04);
297  PrintRun.SetNDC(); // set to normalized coordinates
298  PrintRun.SetTextAlign(23); // center/top alignment
299  std::ostringstream runnostream;
300  std::string runstring;
301  // fill run number and event time into string
302  runnostream << ThisName << "_2 Run " << cl->RunNumber()
303  << ", Time: " << ctime(&evttime);
304  runstring = runnostream.str();
305  transparent[1]->cd();
306  PrintRun.DrawText(0.5, 1., runstring.c_str());
307  TC[1]->Update();
308  TC[1]->Show();
309  TC[1]->SetEditable(false);
310  return 0;
311 }
312 
313 int SepdMonDraw::DrawThird(const std::string & /* what */)
314 {
316  TH2 *h_ADC_corr = (TH2 *) cl->getHisto("SEPDMON_0", "h_ADC_corr");
317  TH2 *h_hits_corr = (TH2 *) cl->getHisto("SEPDMON_0", "h_hits_corr");
318  time_t evttime = cl->EventTime("CURRENT");
319  if (!gROOT->FindObject("SepdMon3"))
320  {
321  MakeCanvas("SepdMon3");
322  }
323  if (!h_ADC_corr)
324  {
326  TC[0]->SetEditable(false);
327  return -1;
328  }
329  TC[2]->SetEditable(true);
330  TC[2]->Clear("D");
331  Pad[4]->cd();
332  h_ADC_corr->Draw("COLZ");
333  Pad[5]->cd();
334  h_hits_corr->Draw("COLZ");
335  TText PrintRun;
336  PrintRun.SetTextFont(62);
337  PrintRun.SetTextSize(0.04);
338  PrintRun.SetNDC(); // set to normalized coordinates
339  PrintRun.SetTextAlign(23); // center/top alignment
340  std::ostringstream runnostream;
341  std::string runstring;
342  // fill run number and event time into string
343  runnostream << ThisName << "_2 Run " << cl->RunNumber()
344  << ", Time: " << ctime(&evttime);
345  runstring = runnostream.str();
346  transparent[1]->cd();
347  PrintRun.DrawText(0.5, 1., runstring.c_str());
348  TC[2]->Update();
349  TC[2]->Show();
350  TC[2]->SetEditable(false);
351  return 0;
352 }
353 
354 int SepdMonDraw::DrawFourth(const std::string & /* what */)
355 {
357 
358  TH1F *h_waveform_time = (TH1F *) cl->getHisto("SEPDMON_0", "h1_waveform_time");
359  TH1F *h_waveform_pedestal = (TH1F *) cl->getHisto("SEPDMON_0", "h1_waveform_pedestal");
360  TH2F *h2_sepd_waveform = (TH2F *) cl->getHisto("SEPDMON_0", "h2_sepd_waveform");
361 
362  if (!gROOT->FindObject("SepdMon4"))
363  {
364  MakeCanvas("SepdMon4");
365  }
366 
367  TC[3]->SetEditable(1);
368  TC[3]->Clear("D");
369  Pad[6]->cd();
370  if (!h2_sepd_waveform || !h_waveform_time || !h_waveform_pedestal)
371  {
372  //cout which one is not found
373  if (!h2_sepd_waveform) std::cout << "h2_sepd_waveform not found" << std::endl;
374  if (!h_waveform_time) std::cout << "h_waveform_time not found" << std::endl;
375  if (!h_waveform_pedestal) std::cout << "h_waveform_pedestal not found" << std::endl;
377  TC[3]->SetEditable(0);
378  return -1;
379  }
380 
381  Pad[6]->cd();
382  gStyle->SetTitleFontSize(0.03);
383  float ymaxp = h2_sepd_waveform->ProfileX()->GetMaximum();
384  h2_sepd_waveform->GetYaxis()->SetRangeUser(0, ymaxp * 20);
385 
386  h2_sepd_waveform->Draw("colz");
387 
388  float tsize = 0.06;
389  h2_sepd_waveform->GetXaxis()->SetNdivisions(510, kTRUE);
390  h2_sepd_waveform->GetXaxis()->SetTitle("Sample #");
391  h2_sepd_waveform->GetYaxis()->SetTitle("Waveform [ADC]");
392  h2_sepd_waveform->GetXaxis()->SetLabelSize(tsize);
393  h2_sepd_waveform->GetYaxis()->SetLabelSize(tsize);
394  h2_sepd_waveform->GetXaxis()->SetTitleSize(tsize);
395  h2_sepd_waveform->GetYaxis()->SetTitleSize(tsize);
396  h2_sepd_waveform->GetXaxis()->SetTitleOffset(1.2);
397  h2_sepd_waveform->GetYaxis()->SetTitleOffset(0.75);
398  gPad->SetLogz();
399  gPad->SetBottomMargin(0.16);
400  gPad->SetLeftMargin(0.2);
401  gPad->SetRightMargin(0.05);
402  gPad->SetLeftMargin(0.15);
403  gStyle->SetOptStat(0);
404  gStyle->SetPalette(57);
405  gPad->SetTicky();
406  gPad->SetTickx();
407 
408  TText PrintRun;
409  PrintRun.SetTextFont(62);
410  PrintRun.SetTextSize(0.03);
411  PrintRun.SetNDC(); // set to normalized coordinates
412  PrintRun.SetTextAlign(23); // center/top alignment
413  std::ostringstream runnostream;
414  std::string runstring;
415  time_t evttime = getTime();
416  // fill run number and event time into string
417  runnostream << ThisName << ": Pulse fitting, Run" << cl->RunNumber()
418  << ", Time: " << ctime(&evttime);
419  runstring = runnostream.str();
420  transparent[3]->cd();
421  PrintRun.DrawText(0.5, 0.99, runstring.c_str());
422 
423  Pad[7]->cd();
424 
425  gStyle->SetTitleFontSize(0.06);
426 
427  float tsize2 = 0.08;
428  h_waveform_time->Draw("hist");
429  h_waveform_time->GetXaxis()->SetNdivisions(510, kTRUE);
430  h_waveform_time->GetXaxis()->SetTitle("Sample #");
431  h_waveform_time->GetYaxis()->SetTitle("Towers");
432  h_waveform_time->GetXaxis()->SetLabelSize(tsize2);
433  h_waveform_time->GetYaxis()->SetLabelSize(tsize2);
434  h_waveform_time->GetXaxis()->SetTitleSize(tsize2);
435  h_waveform_time->GetYaxis()->SetTitleSize(tsize2);
436  h_waveform_time->GetXaxis()->SetTitleOffset(1.0);
437  h_waveform_time->GetYaxis()->SetTitleOffset(0.85);
438  gPad->SetTopMargin(0.06);
439  gPad->SetBottomMargin(0.18);
440  gPad->SetRightMargin(0.05);
441  gPad->SetLeftMargin(0.2);
442  gStyle->SetOptStat(0);
443  gPad->SetTicky();
444  gPad->SetTickx();
445 
446  Pad[8]->cd();
447 
448  gStyle->SetTitleFontSize(0.06);
449 
450  h_waveform_pedestal->Draw("hist");
451  h_waveform_pedestal->GetXaxis()->SetNdivisions(510, kTRUE);
452  h_waveform_pedestal->GetXaxis()->SetTitle("ADC Pedistal");
453  h_waveform_pedestal->GetYaxis()->SetTitle("Towers");
454  h_waveform_pedestal->GetXaxis()->SetLabelSize(tsize2);
455  h_waveform_pedestal->GetYaxis()->SetLabelSize(tsize2);
456  h_waveform_pedestal->GetXaxis()->SetTitleSize(tsize2);
457  h_waveform_pedestal->GetYaxis()->SetTitleSize(tsize2);
458  h_waveform_pedestal->GetXaxis()->SetTitleOffset(0.9);
459  h_waveform_pedestal->GetYaxis()->SetTitleOffset(0.85);
460  gPad->SetTopMargin(0.06);
461  gPad->SetBottomMargin(0.18);
462  gPad->SetRightMargin(0.05);
463  gPad->SetLeftMargin(0.2);
464  gStyle->SetOptStat(0);
465  gPad->SetTicky();
466  gPad->SetTickx();
467 
468  TC[3]->Update();
469  TC[3]->Show();
470  TC[3]->SetEditable(0);
471 
472  return 0;
473 }
474 int SepdMonDraw::DrawFifth(const std::string & /* what */)
475 {
477 
478  TH1F *h1_packet_number = (TH1F *) cl->getHisto("SEPDMON_0", "h1_packet_number");
479  TH1F *h1_packet_length = (TH1F *) cl->getHisto("SEPDMON_0", "h1_packet_length");
480  TH1F *h1_packet_chans = (TH1F *) cl->getHisto("SEPDMON_0", "h1_packet_chans");
481  TH1F *h1_packet_event = (TH1F *) cl->getHisto("SEPDMON_0", "h1_packet_event");
482 
483  if (!gROOT->FindObject("SepdMon5"))
484  {
485  MakeCanvas("SepdMon5");
486  }
487  TC[4]->SetEditable(1);
488  TC[4]->Clear("D");
489 
490  if (!h1_packet_number || !h1_packet_length || !h1_packet_chans || !h1_packet_event)
491  {
492  // print out which is not found
493  if (!h1_packet_number) std::cout << "h1_packet_number not found" << std::endl;
494  if (!h1_packet_length) std::cout << "h1_packet_length not found" << std::endl;
495  if (!h1_packet_chans) std::cout << "h1_packet_chans not found" << std::endl;
496  if (!h1_packet_event) std::cout << "h1_packet_event not found" << std::endl;
497 
499  TC[5]->SetEditable(0);
500  return -1;
501  }
502 
503  // int maxbin = h1_packet_event->GetMaximumBin();
504  int maxy = h1_packet_event->GetMaximum();
505  // substract all none zero bin by maxy
506  for (int i = 1; i <= h1_packet_event->GetNbinsX(); i++)
507  {
508  if (h1_packet_event->GetBinContent(i) != 0)
509  {
510  h1_packet_event->SetBinContent(i, h1_packet_event->GetBinContent(i) - maxy);
511  }
512  }
513 
514  // find the x range for h1_packet_number
515  double xmin = h1_packet_number->GetXaxis()->GetXmin();
516  double xmax = h1_packet_number->GetXaxis()->GetXmax();
517 
518  TLine *one = new TLine(xmin, 1, xmax, 1);
519  one->SetLineStyle(7);
520 
521  TLine *goodSize = new TLine(xmin, 3991, xmax, 3991);
522  goodSize->SetLineStyle(7);
523 
524  TLine *goodChans = new TLine(xmin, 128, xmax, 128);
525  goodChans->SetLineStyle(7);
526 
527  float param = 0.95;
528 
529  TLegend *leg = new TLegend(0.3, 0.16, 0.95, 0.4);
530  leg->SetFillStyle(0);
531  leg->SetBorderSize(0);
532 
533  TLine *warnLineOne = new TLine(xmin, param * 1, xmax, param * 1);
534  warnLineOne->SetLineStyle(7);
535  warnLineOne->SetLineColor(2);
536 
537  leg->AddEntry(warnLineOne, "95% Threshold", "l");
538 
539  TLine *warnLineSize = new TLine(xmin, param * 3991., xmax, param * 3991.);
540  warnLineSize->SetLineStyle(7);
541  warnLineSize->SetLineColor(2);
542 
543  TLine *warnLineChans = new TLine(xmin, param * 128., xmax, param * 128.);
544  warnLineChans->SetLineStyle(7);
545  warnLineChans->SetLineColor(2);
546 
547  Pad[10]->cd();
548  float tsize = 0.08;
549  h1_packet_number->GetYaxis()->SetRangeUser(0.0, 1.3);
550  h1_packet_number->Draw("hist");
551  one->Draw("same");
552  warnLineOne->Draw("same");
553  h1_packet_number->GetXaxis()->SetNdivisions(510, kTRUE);
554  h1_packet_number->GetXaxis()->SetTitle("Packet #");
555  h1_packet_number->GetYaxis()->SetTitle("% Of Events Present");
556  h1_packet_number->GetXaxis()->SetLabelSize(tsize - 0.01);
557  h1_packet_number->GetYaxis()->SetLabelSize(tsize - 0.01);
558  h1_packet_number->GetXaxis()->SetTitleSize(tsize - 0.01);
559  h1_packet_number->GetYaxis()->SetTitleSize(tsize - 0.01);
560  h1_packet_number->GetXaxis()->SetTitleOffset(1);
561  gPad->SetBottomMargin(0.16);
562  gPad->SetLeftMargin(0.16);
563  gPad->SetRightMargin(0.05);
564  gPad->SetLeftMargin(0.15);
565  gStyle->SetOptStat(0);
566  gPad->SetTicky();
567  gPad->SetTickx();
568 
569  Pad[11]->cd();
570  h1_packet_length->Draw("hist");
571  h1_packet_length->GetYaxis()->SetRangeUser(0, 6500);
572  goodSize->Draw("same");
573  warnLineSize->Draw("same");
574  leg->Draw("same");
575  h1_packet_length->GetXaxis()->SetNdivisions(510, kTRUE);
576  h1_packet_length->GetXaxis()->SetTitle("Packet #");
577  h1_packet_length->GetYaxis()->SetTitle("Average Packet Size");
578  h1_packet_length->GetXaxis()->SetLabelSize(tsize - .01);
579  h1_packet_length->GetYaxis()->SetLabelSize(tsize);
580  h1_packet_length->GetXaxis()->SetTitleSize(tsize - .01);
581  h1_packet_length->GetYaxis()->SetTitleSize(tsize);
582  h1_packet_length->GetXaxis()->SetTitleOffset(1);
583  h1_packet_length->GetYaxis()->SetTitleOffset(0.8);
584  gPad->SetBottomMargin(0.16);
585  gPad->SetLeftMargin(0.16);
586  gPad->SetRightMargin(0.05);
587  gPad->SetLeftMargin(0.15);
588  gStyle->SetOptStat(0);
589  gPad->SetTicky();
590  gPad->SetTickx();
591 
592  Pad[12]->cd();
593  h1_packet_chans->Draw("hist");
594  h1_packet_chans->GetYaxis()->SetRangeUser(0, 212);
595  goodChans->Draw("same");
596  warnLineChans->Draw("same");
597  h1_packet_chans->GetXaxis()->SetNdivisions(510, kTRUE);
598  h1_packet_chans->GetXaxis()->SetTitle("Packet #");
599  h1_packet_chans->GetYaxis()->SetTitle("Average # of Channels");
600  h1_packet_chans->GetXaxis()->SetLabelSize(tsize - .01);
601  h1_packet_chans->GetYaxis()->SetLabelSize(tsize);
602  h1_packet_chans->GetXaxis()->SetTitleSize(tsize - .01);
603  h1_packet_chans->GetYaxis()->SetTitleSize(tsize);
604  h1_packet_chans->GetXaxis()->SetTitleOffset(0.8);
605  h1_packet_chans->GetYaxis()->SetTitleOffset(0.8);
606  gPad->SetBottomMargin(0.16);
607  gPad->SetLeftMargin(0.16);
608  gPad->SetRightMargin(0.05);
609  gPad->SetLeftMargin(0.15);
610  gStyle->SetOptStat(0);
611  gPad->SetTicky();
612  gPad->SetTickx();
613 
614  Pad[13]->cd();
615  h1_packet_event->Draw("hist");
616  double ymax = h1_packet_event->GetMaximum();
617  double ymin = h1_packet_event->GetMinimum();
618 
619  h1_packet_event->GetYaxis()->SetRangeUser(ymin - 0.3 * (ymax - ymin + 30), ymax + 0.3 * (ymax - ymin + 30));
620  h1_packet_event->GetXaxis()->SetTitle("Packet #");
621  h1_packet_event->GetYaxis()->SetTitle("clock offset");
622  h1_packet_event->GetXaxis()->SetLabelSize(tsize - .01);
623  h1_packet_event->GetYaxis()->SetLabelSize(tsize);
624  h1_packet_event->GetXaxis()->SetTitleSize(tsize - .01);
625  h1_packet_event->GetYaxis()->SetTitleSize(tsize);
626  h1_packet_event->GetXaxis()->SetTitleOffset(0.8);
627  h1_packet_event->GetYaxis()->SetTitleOffset(1.2);
628  gPad->SetBottomMargin(0.16);
629  gPad->SetLeftMargin(0.2);
630  gPad->SetRightMargin(0.05);
631  gPad->SetLeftMargin(0.2);
632  gStyle->SetOptStat(0);
633  gPad->SetTicky();
634  gPad->SetTickx();
635 
636 
637  // draw the warning here:
638 
639  warning[1]->cd();
640 
641  std::vector<int> badPackets;
642  std::vector<std::string> whatswrong;
643  for (int i = 1; i <= 6; i++)
644  {
645  bool missing = false;
646  bool badnumber = false;
647  bool badlength = false;
648  bool badchans = false;
649  if (h1_packet_number->GetBinContent(i) == 0)
650  {
651  missing = true;
652  }
653  if (h1_packet_number->GetBinContent(i) < param)
654  {
655  badnumber = true;
656  }
657  if (h1_packet_length->GetBinContent(i) < param * 3991.)
658  {
659  badlength = true;
660  }
661  if (h1_packet_chans->GetBinContent(i) < param * 128.)
662  {
663  badchans = true;
664  }
665  if (badnumber || badlength || badchans || missing)
666  {
667  badPackets.push_back((int) h1_packet_number->GetBinCenter(i));
668  std::string reason = "";
669  if (missing)
670  {
671  reason += "packet lost! ";
672  }
673  else
674  {
675  if (badnumber)
676  {
677  reason += "some events are missing, ";
678  }
679  if (badlength)
680  {
681  reason += "too short, ";
682  }
683  if (badchans)
684  {
685  reason += "too few channels, ";
686  }
687  // remove the last two characters
688  reason = reason.substr(0, reason.size() - 2);
689  reason += ".";
690  }
691  whatswrong.push_back(reason);
692  }
693  }
694  bool mismatch = false;
695  for (int i = 1; i <= h1_packet_event->GetNbinsX(); i++)
696  {
697  if (h1_packet_event->GetBinContent(i) != 0)
698  {
699  mismatch = true;
700  }
701  }
702  // draw the mismatch warning on the pad
703  TText mismatchWarn;
704  mismatchWarn.SetTextFont(62);
705  mismatchWarn.SetTextSize(0.06);
706  mismatchWarn.SetTextColor(2);
707  mismatchWarn.SetNDC();
708  mismatchWarn.SetTextAlign(23);
709  if (mismatch)
710  {
711  mismatchWarn.DrawText(0.5, 0.95, "Packet misaligned!");
712  }
713 
714  mismatchWarn.SetTextColor(1);
715  mismatchWarn.SetTextSize(0.05);
716 
717  // draw the bad packet warning here
718  TText PacketWarn;
719  PacketWarn.SetTextFont(62);
720  PacketWarn.SetTextSize(0.04);
721  PacketWarn.SetTextColor(1);
722  PacketWarn.SetNDC();
723  PacketWarn.SetTextAlign(23);
724  PacketWarn.DrawText(0.5, 0.75, "Bad Packets:");
725  for (int i = 0; i < (int) badPackets.size(); i++)
726  {
727  PacketWarn.DrawText(0.5, 0.7 - 0.05 * i, Form("%i: %s", badPackets[i], whatswrong[i].c_str()));
728  }
729 
730  TText PrintRun;
731  PrintRun.SetTextFont(62);
732  PrintRun.SetTextSize(0.02);
733  PrintRun.SetNDC(); // set to normalized coordinates
734  PrintRun.SetTextAlign(23); // center/top alignment
735  std::ostringstream runnostream;
736  std::string runstring;
737  std::ostringstream runnostream2;
738  time_t evttime = getTime();
739  // fill run number and event time into string
740 
741  runnostream << "Packet Information";
742  runnostream2 << " Run " << cl->RunNumber() << ", Time: " << ctime(&evttime);
743  transparent[4]->cd();
744 
745  runstring = runnostream.str();
746  PrintRun.DrawText(0.5, .99, runstring.c_str());
747 
748  runstring = runnostream2.str();
749  PrintRun.DrawText(0.5, .966, runstring.c_str());
750  TC[4]->Update();
751  TC[4]->Show();
752  TC[4]->SetEditable(0);
753  // if (save) TC[5]->SaveAs("plots/packets.pdf");
754  return 0;
755 }
756 
758 {
760  int iret = Draw(what);
761  if (iret) // on error no png files please
762  {
763  return iret;
764  }
765  int icnt = 0;
766  for (TCanvas *canvas : TC)
767  {
768  if (canvas == nullptr)
769  {
770  continue;
771  }
772  icnt++;
773  std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
774  std::to_string(cl->RunNumber()) + "." + type;
775  cl->CanvasToPng(canvas, filename);
776  }
777  return 0;
778 }
779 
781 {
782  int iret = Draw(what);
783  if (iret) // on error no html output please
784  {
785  return iret;
786  }
787 
789  int icnt = 0;
790  for (TCanvas *canvas : TC)
791  {
792  if (canvas == nullptr)
793  {
794  continue;
795  }
796  icnt++;
797  // Register the canvas png file to the menu and produces the png file.
798  std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
799  cl->CanvasToPng(canvas, pngfile);
800  }
801 
802  // Now register also EXPERTS html pages, under the EXPERTS subfolder.
803 
804  // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
805  // std::ofstream out(logfile.c_str());
806  // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
807  // << "</TITLE></HEAD>" << std::endl;
808  // out << "<P>Some log file output would go here." << std::endl;
809  // out.close();
810 
811  // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
812  // std::ofstream out2(status.c_str());
813  // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
814  // << "</TITLE></HEAD>" << std::endl;
815  // out2 << "<P>Some status output would go here." << std::endl;
816  // out2.close();
817  // cl->SaveLogFile(*this);
818  return 0;
819 }
820 
822 {
824  time_t currtime = 0;
825 
826  currtime = cl->EventTime("CURRENT");
827  return currtime;
828 }