Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BbcMonDraw.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BbcMonDraw.cc
1 #include "BbcMonDraw.h"
2 
3 #include <onlmon/OnlMonClient.h>
4 
5 #include <TArc.h>
6 #include <TArrow.h>
7 #include <TAxis.h>
8 #include <TCanvas.h>
9 #include <TDatime.h>
10 #include <TF1.h>
11 #include <TGraph.h>
12 #include <TGraphErrors.h>
13 #include <TH1.h>
14 #include <TH2.h>
15 #include <TLatex.h>
16 #include <TLine.h>
17 #include <TPad.h>
18 #include <TPaveText.h>
19 #include <TROOT.h>
20 #include <TSpectrum.h>
21 #include <TStyle.h>
22 #include <TSystem.h>
23 #include <TText.h>
24 
25 #include <algorithm>
26 #include <cstring>
27 #include <ctime>
28 #include <fstream>
29 #include <iomanip>
30 #include <iostream>
31 #include <sstream>
32 #include <vector>
33 #include <chrono>
34 
35 #define DEBUG
36 #ifdef DEBUG
37 #define PRINT_DEBUG(x) std::cout<<x<<std::endl
38 #else
39 #define PRINT_DEBUG(x) {};
40 #endif
41 
42 #ifdef DEBUGNEW
43 #define ifdelete(x) if(x!=nullptr){ std::cout << "Delete " << #x << std::endl; delete x;x=nullptr;}
44 #define ifnew(t,x) {if(x!=nullptr){ std::cout << "Delete " << #x << std::endl; delete x;}std::cout << "New "<< #x << std::endl;x = new t;}
45 #else
46 #define ifdelete(x) if(x!=nullptr){ delete x;x=nullptr;}
47 #define ifnew(t,x) {if(x!=nullptr){ delete x;}x = new t;}
48 #endif
49 
50 // x position of trigger, scale factor and vtx mean
51 // static float xpos[3] = {0.30, 0.50, 0.75};
52 static float xpos[4] = {0.20, 0.35, 0.55, 0.75};
53 
55  : OnlMonDraw(name)
56 {
57  PRINT_DEBUG("In BbcMonDraw::BbcMonDraw()");
58  std::cout << "Done with BbcMonDraw::BbcMonDraw" << std::endl;
59  return;
60 }
61 
63 {
64  PRINT_DEBUG("In BbcMonDraw::~BbcMonDraw()");
65  // ifdelete( bbccalib );
66 
67  ifdelete( bbcStyle );
68 
69  // ------------------------------------------------------
70  // Canvas and Histogram
71 
74 
75  for (int i = 0; i < MAX_WARNING; i++)
76  {
78  ifdelete(ArcWarning[i]);
79  }
80 
81  // ------------------------------------------------------
82  // Graph for visualization
83 
84  // for the 1st Page
85 
86  for (int side = 0; side < nSIDE; side++)
87  {
88  ifdelete(TdcOver[side]);
89  ifdelete(LineTdcOver[side][0]);
90  ifdelete(LineTdcOver[side][1]);
91  ifdelete(BoxTdcOver[side]);
92 
93  for (int trig = 0; trig < nTRIGGER; trig++)
94  {
95  ifdelete(nHit[trig][side]);
96  ifdelete(LinenHit[trig][side][0]);
97  ifdelete(LinenHit[trig][side][1]);
98  ifdelete(BoxnHit[trig][side]);
99  }
100  }
102 
103  // for 2nd Page
104 
105  for (int side = 0; side < nSIDE; side++)
106  {
107  ifdelete(HitTime[side]);
108  ifdelete(LineHitTime[side][0]);
109  ifdelete(LineHitTime[side][1]);
110  ifdelete(ArrowHitTime[side]);
111  ifdelete(TextHitTime[side]);
112  ifdelete(FitHitTime[side]);
113  }
114 
121 
134 
139 
146 
147  ifdelete(Zvtx);
148  ifdelete(FitZvtx);
149  ifdelete(LineZvtx[0]);
150  ifdelete(LineZvtx[1]);
157 
158  ifdelete(ArmHit);
161 
162  // for 3rd Page
163  ifdelete(Adc);
167 
168  // for 4th Page
170  ifdelete(Zvtx);
173 
179 
180  // for (int i = 0; i < 4; i++)//need a look
181  for (int i = 0; i < 5; i++)
182  {
186  }
187  ifdelete( FitZvtx );
188  ifdelete( TextZvtxStatus[0] );
189  ifdelete( TextZvtxStatus[1] );
190 
191  for (int icv=0; icv<nCANVAS; icv++)
192  {
193  ifdelete( TC[icv] );
194  }
195 
197  ifdelete(tspec);
198 
199  return;
200 }
201 
203 {
204  PRINT_DEBUG("In BbcMonDraw::Init()");
205  TStyle *oldStyle = gStyle;
206  bbcStyle = new TStyle("bbcStyle", "BBC/MBD Online Monitor Style");
207  bbcStyle->SetOptStat(0);
208  bbcStyle->SetTitleH(0.075);
209  bbcStyle->SetTitleW(0.98);
210  bbcStyle->SetPalette(1);
211  bbcStyle->SetFrameBorderMode(0);
212  bbcStyle->SetPadBorderMode(0);
213  bbcStyle->SetCanvasBorderMode(0);
214  oldStyle->cd();
215 
216  // ------------------------------------------------------
217  // Canvas and Histogram
218 
219  memset(TC, 0, sizeof(TC));
220  memset(transparent, 0, sizeof(transparent));
221  memset(PadTop, 0, sizeof(PadTop));
222  memset(PaveWarning, 0, sizeof(PaveWarning));
223  memset(ArcWarning, 0, sizeof(ArcWarning));
224  memset(PadWarning, 0, sizeof(PadWarning));
225  memset(nPadWarning, 0, sizeof(nPadWarning));
226  // ------------------------------------------------------
227  // Graph for visualization
228 
229  // for the 1st Page
230  memset(TdcOver, 0, sizeof(TdcOver));
231  memset(PadTdcOver, 0, sizeof(PadTdcOver));
232  memset(LineTdcOver, 0, sizeof(LineTdcOver));
233  memset(BoxTdcOver, 0, sizeof(BoxTdcOver));
234  memset(FrameTdcOver, 0, sizeof(FrameTdcOver));
235  memset(PadnHit, 0, sizeof(PadnHit));
236  memset(nHit, 0, sizeof(nHit));
237  memset(LinenHit, 0, sizeof(LinenHit));
238  memset(BoxnHit, 0, sizeof(BoxnHit));
239  memset(FramenHit, 0, sizeof(FramenHit));
240 
241  // for 2nd Page
242 
243  memset(HitTime, 0, sizeof(HitTime));
244  memset(PadHitTime, 0, sizeof(PadHitTime));
245  memset(LineHitTime, 0, sizeof(LineHitTime));
246  memset(ArrowHitTime, 0, sizeof(ArrowHitTime));
247  memset(TextHitTime, 0, sizeof(TextHitTime));
248  memset(FitHitTime, 0, sizeof(FitHitTime));
249  memset(LineAvrHitTime, 0, sizeof(LineAvrHitTime));
250 
251  memset(LineNorthHitTime, 0, sizeof(LineNorthHitTime));
252  memset(LineSouthHitTime, 0, sizeof(LineSouthHitTime));
253 
254  memset(TextBbcSummaryHitTime, 0, sizeof(TextBbcSummaryHitTime));
256 
257  memset(LineZvtx, 0, sizeof(LineZvtx));
258 
259  memset(LineTzeroZvtx, 0, sizeof(LineTzeroZvtx));
260 
261  memset(TextZVertex, 0, sizeof(TextZVertex));
262  memset(TextZVertex_scale, 0, sizeof(TextZVertex_scale));
263  memset(TextZVertex_mean, 0, sizeof(TextZVertex_mean));
264 
265  FitZvtx = new TF1("FitZvtx", "gaus");
266  TextZvtxStatus[0] = new TLatex;
267  TextZvtxStatus[1] = new TLatex;
268 
269  tspec = new TSpectrum(5); // 5 peaks is enough - we have 4
270 
271  return 0;
272 }
273 
275 {
276  for (int i = 0; i < nWarning; i++)
277  {
279  ifdelete(ArcWarning[i]);
280  }
281  nWarning = 0;
282 
283  if (PaveWarnings)
284  {
285  PaveWarnings->Clear();
286  }
287  // if( PadWarnings )
288  // PaveWarnings->Draw();
289  return 0;
290 }
291 
292 int BbcMonDraw::Warning(TPad *pad, const float x, const float y, const int r, const std::string &msg)
293 {
294  static int brink = 1;
295  float x1, x2, y1, y2;
296 
297  x1 = pad->GetX1() * 0.97 + pad->GetX2() * 0.03;
298  x2 = pad->GetX1() * 0.03 + pad->GetX2() * 0.97;
299  // pave rises on top if error point is lower
300  if (y > pad->GetY1() * 0.5 + pad->GetY2() * 0.5)
301  {
302  y1 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.10;
303  y2 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.30;
304  }
305  else
306  {
307  y1 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.70;
308  y2 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.90;
309  }
310 
311  int newWarning = nWarning;
312  for (int i = 0; i < nWarning; i++)
313  {
314  if (PadWarning[i] == pad)
315  {
316  newWarning = i;
317  }
318  }
319 
320  ifnew(TArc(x, y, r), ArcWarning[newWarning]);
321  ArcWarning[newWarning]->SetLineWidth(r);
322  ArcWarning[newWarning]->SetLineColor(2);
323 
324  ifnew(TPaveText(x1, y1, x2, y2), PaveWarning[newWarning]);
325  PaveWarning[newWarning]->AddText(msg.c_str());
326  ArcWarning[newWarning]->SetLineColor(2 + 3 * brink);
327  PaveWarning[newWarning]->SetFillColor(5 + 5 * brink);
328  PaveWarning[newWarning]->SetTextColor(2);
329  PaveWarning[newWarning]->SetLineColor(2);
330  PaveWarning[newWarning]->SetLineWidth(2);
331 
332  if (newWarning == nWarning)
333  {
334  PadWarning[newWarning] = pad;
335  nPadWarning[newWarning] = 1;
336  nWarning++;
337  }
338  else
339  {
340  std::ostringstream wmsg;
341  wmsg << "... and other " << nPadWarning[newWarning] << " warnings";
342  nPadWarning[newWarning]++;
343  PaveWarning[newWarning]->AddText(wmsg.str().c_str());
344  wmsg.str("");
345  }
346  // PaveWarning[newWarning]->AddText( "Call BBC/MBD Expert. If this run is a PHYSICS run " );
347  PaveWarning[newWarning]->AddText("Do Quick-feed BBC/MBD");
348  PaveWarning[newWarning]->AddText("If it is NOT fixed by feed at PHYSICS run, call BBC/MBD experts");
349  // PaveWarning[newWarning]->AddText( "If it is NOT fixed by quick feed at PHYSICS run, conform to the BBC/MBD standing orders" );
350 
351  if (PaveWarnings)
352  {
353  PaveWarnings->AddText(msg.c_str());
354  }
355 
356  if (PadWarnings && PaveWarnings)
357  {
358  PaveWarnings->Draw();
359  }
360  // ArcWarning[newWarning]->Draw();
361  PaveWarning[newWarning]->Draw();
362 
363  // brink = 1 - brink;
364 
365  if (nWarning == MAX_WARNING - 2)
366  {
367  std::string bmsg = "Too Many Warnings";
368  Warning(pad, x, y, 0, bmsg);
369  bmsg.erase();
370  }
371 
372  return 0;
373 }
374 
376 {
377  PRINT_DEBUG("In BbcMonDraw::MakeCanvas()");
379  int xsize = cl->GetDisplaySizeX();
380  int ysize = cl->GetDisplaySizeY();
381 
382  if (name == "BbcMon1")
383  {
384  std::cout << "Creating Canvas BbcMon1..." << std::endl;
385 
386  TC[0] = new TCanvas("BbcMon1", "BBC/MBD Z-Vertex View for Shift crew", -1, 0, xsize / 2, ysize);
387 
388  // root is pathetic, whenever a new TCanvas is created root piles up
389  // 6kb worth of X11 events which need to be cleared with
390  // gSystem->ProcessEvents(), otherwise your process will grow and
391  // grow and grow but will not show a definitely lost memory leak
392  gSystem->ProcessEvents();
393 
394  TC[0]->cd();
395  PadTop[0] = new TPad("PadTop0", "PadTop0", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
396  PadZVertex = new TPad("PadZVertex", "PadZVertex", 0.00, 0.60, 1.00, 0.90, 0, 0, 0);
397  PadZVertexSummary = new TPad("PadZVertexSummary", "PadZVertexSummary", 0.00, 0.40, 1.00, 0.60, 0, 0, 0);
398  PadSouthHitMap = new TPad("PadSouthHitMap", "PadSouthHitMap", 0.00, 0.00, 0.495, 0.40, 0, 0, 0);
399  PadNorthHitMap = new TPad("PadNorthHitMap", "PadNorthHitMap", 0.505, 0.00, 1.0, 0.40, 0, 0, 0);
400  //PadTzeroZVertex = new TPad("PadTzeroZVertex", "PadTzeroZVertex", 0.00, 0.00, 1.00, 0.40, 0, 0, 0);
401 
402  PadTop[0]->Draw();
403  // PadZVertex->SetLogy();
404  PadZVertex->Draw();
405  //PadTzeroZVertex->Draw();
406  PadSouthHitMap->Draw();
407  PadNorthHitMap->Draw();
408  PadZVertexSummary->Draw();
409 
410  PadZVertexSummary->cd();
411 
412  // ifnew( TText, TextZVertexNotice );
413  // TextZVertexNotice->SetTextSize(0.08);
414  // TextZVertexNotice->SetText(0.05, 0.75, "< Z vertex deviation may NOT be due to BBC/MBD, don't page expert easily! >");
415 
416  // for (int i = 0; i < 4; i++)
417  for (int i = 0; i < 1; i++) // pp
418  {
419  ifnew(TText, TextZVertex[i]);
420  TextZVertex[i]->SetTextColor(bbc_onlmon::BBC_COLOR_ZVTX[i]);
421  // TextZVertex[i]->SetTextSize(0.15);
422  TextZVertex[i]->SetTextSize(0.08);
423 
424  ifnew(TText, TextZVertex_scale[i]);
425  ifnew(TText, TextZVertex_mean[i]);
427  TextZVertex_mean[i]->SetTextColor(bbc_onlmon::BBC_COLOR_ZVTX[i]);
428  TextZVertex_scale[i]->SetTextSize(0.08);
429  TextZVertex_mean[i]->SetTextSize(0.08);
430  }
431  /*chiu
432  TextZVertex[0]->SetText(xpos[0], 0.65, "Zbbc [BBLL1]"); // RUN11 pp
433  */
434  TC[0]->cd();
435  transparent[0] = new TPad("transparent3", "this does not show", 0, 0, 1, 1, 0, 0);
436  transparent[0]->SetFillStyle(4000);
437  transparent[0]->Draw();
438 
439  /*
440  ifnew(TLine(bbc_onlmon::BBC_MIN_REGULAR_ZVERTEX_MEAN, -6,
441  bbc_onlmon::BBC_MIN_REGULAR_ZVERTEX_MEAN, 16),
442  LineTzeroZvtx[0]);
443  ifnew(TLine(bbc_onlmon::BBC_MAX_REGULAR_ZVERTEX_MEAN, -6,
444  bbc_onlmon::BBC_MAX_REGULAR_ZVERTEX_MEAN, 16),
445  LineTzeroZvtx[1]);
446  ifnew(TLine(-200, bbc_onlmon::BBC_MIN_REGULAR_TDC1_MEAN - 5,
447  200, bbc_onlmon::BBC_MIN_REGULAR_TDC1_MEAN - 5),
448  LineTzeroZvtx[2]);
449  ifnew(TLine(-200, bbc_onlmon::BBC_MAX_REGULAR_TDC1_MEAN - 5,
450  200, bbc_onlmon::BBC_MAX_REGULAR_TDC1_MEAN - 5),
451  LineTzeroZvtx[3]);
452  ifnew(TText, TextTzeroZvtx);
453  */
454  }
455 
456  else if (name == "BbcMon2")
457  {
458  std::cout << "Creating Canvas BbcMon2..." << std::endl;
459 
460  TC[1] = new TCanvas("BbcMon2", "Beam status view for Shift crew", -xsize / 2, 0, xsize / 2, ysize);
461  gSystem->ProcessEvents();
462  TC[1]->cd();
463  PadTop[1] = new TPad("PadTop1", "PadTop1", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
464  PadTimeWave = new TPad("PadTimeWave", "PadTimeWave", 0.00, 0.30, 1.00, 0.90, 0, 0, 0);
465  PadSouthHitTime = new TPad("PadHitTimeSouth1", "PadHitTimeSouth1", 0.00, 0.00, 0.50, 0.30, 0, 0, 0);
466  PadNorthHitTime = new TPad("PadHitTimeNorth1", "PadHitTimeNorth1", 0.50, 0.00, 1.00, 0.30, 0, 0, 0);
467 
468  //PadArmHit = new TPad("PadArmHit", "PadArmHit", 0.50, 0.00, 1.00, 0.40, 0, 0, 0);
469  //PadBbcSummary = new TPad("PadBbcSummary", "PadBbcSummary", 0.00, 0.40, 1.00, 0.55, 0, 0, 0);
470  //PadAvrHitTime = new TPad("PadAvrHitTime", "PadAvrHitTime", 0.00, 0.00, 0.50, 0.40, 0, 0, 0);
471 
472  //PadArmHit->SetLogz();
473 
474  PadTop[1]->Draw();
475  if (PadTimeWave) PadTimeWave->Draw();
476  if (PadNorthHitTime) PadNorthHitTime->Draw();
477  if (PadSouthHitTime) PadSouthHitTime->Draw();
478  if (PadArmHit) PadArmHit->Draw();
479  if (PadBbcSummary) PadBbcSummary->Draw();
480  if (PadAvrHitTime) PadAvrHitTime->Draw();
481 
482  ifnew(TText, TextBbcSummaryHitTime[0]);
483  ifnew(TText, TextBbcSummaryHitTime[1]);
487  // TextBbcSummaryHitTime->SetTextSize(0.2);
488  TextBbcSummaryHitTime[0]->SetTextSize(0.2);
489  TextBbcSummaryHitTime[1]->SetTextSize(0.2);
490  TextBbcSummaryZvertex->SetTextSize(0.2);
491  TextBbcSummaryGlobalOffset[0]->SetTextSize(0.2);
492  TextBbcSummaryGlobalOffset[1]->SetTextSize(0.2);
493 
494  ifnew(TArc(10.5, 10.5, 4, 0, 360), ArcArmHit);
495  ArcArmHit->SetFillStyle(4000);
496  // ifnew( TArc(10.5, 10.5, 4), ArcArmHit );
497  ifnew(TText, TextArmHit);
498  TextArmHit->SetTextSize(0.08);
499  TextArmHit->SetText(10, 4, "Good region");
500 
501  // PadSouthHitTime = new TPad("PadSouthHitTime", "PadSouthHitTime", 0.00, 0.55, 0.50, 0.90, 0);
502  // PadNorthHitTime = new TPad("PadNorthHitTime", "PadNorthHitTime", 0.50, 0.55, 1.00, 0.90, 0);
503 
504  if (PadAvrHitTime)
505  {
508  LineAvrHitTime[0]);
511  LineAvrHitTime[1]);
512 
516  ArrowAvrHitTime->SetOption("<>");
517 
518  ifnew(TText, TextAvrHitTime);
519  TextAvrHitTime->SetTextSize(0.08);
520  TextAvrHitTime->SetText(bbc_onlmon::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
521 
522  LineAvrHitTime[0]->SetLineColor(9);
523  LineAvrHitTime[1]->SetLineColor(9);
524  ArrowAvrHitTime->SetLineColor(9);
525  TextAvrHitTime->SetTextColor(9);
526  }
527 
528  if (PadSouthHitTime)
529  {
532  LineSouthHitTime[0]);
535  LineSouthHitTime[1]);
536 
540  ArrowSouthHitTime->SetOption("<>");
541 
542  ifnew(TText, TextSouthHitTime);
543  TextSouthHitTime->SetTextSize(0.08);
544  TextSouthHitTime->SetText(bbc_onlmon::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
545 
546  LineSouthHitTime[0]->SetLineColor(9);
547  LineSouthHitTime[1]->SetLineColor(9);
548  ArrowSouthHitTime->SetLineColor(9);
549  TextSouthHitTime->SetTextColor(9);
550  }
551 
552  if (PadNorthHitTime)
553  {
556  LineNorthHitTime[0]);
559  LineNorthHitTime[1]);
560 
564  ArrowNorthHitTime->SetOption("<>");
565 
566  ifnew(TText, TextNorthHitTime);
567  TextNorthHitTime->SetTextSize(0.08);
568  TextNorthHitTime->SetText(bbc_onlmon::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
569 
570  LineNorthHitTime[0]->SetLineColor(9);
571  LineNorthHitTime[1]->SetLineColor(9);
572  ArrowNorthHitTime->SetLineColor(9);
573  TextNorthHitTime->SetTextColor(9);
574  }
575 
576  transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1, 0, 0);
577  transparent[1]->SetFillStyle(4000);
578  transparent[1]->Draw();
579  }
580 
581  else if (name == "BbcMon3")
582  {
583  std::cout << "Creating Canvas BbcMon3..." << std::endl;
584 
585  TC[2] = new TCanvas("BbcMon3", "BBC/MBD status view for Expert", -xsize / 2, 0, xsize / 2, ysize);
586  gSystem->ProcessEvents();
587  TC[2]->cd();
588 
589 
590  PadTop[2] = new TPad("PadTop0", "PadTop0", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
591  PadTdcOver[0] = new TPad("PadTdcOverSouth0", "PadTdcOverSouth0", 0.00, 0.30, 0.50, 0.60, 0, 0, 0);
592  PadTdcOver[1] = new TPad("PadTdcOverNorth1", "PadTdcOverNorth1", 0.50, 0.60, 1.00, 0.90, 0, 0, 0);
593  PadnHit[1] = new TPad("PadnHitNorth", "PadnHitNorth", 0.50, 0.03, 1.00, 0.30, 0, 0, 0);
594  PadnHit[0] = new TPad("PadnHitSouth", "PadnHitSouth", 0.00, 0.03, 0.50, 0.30, 0);
595  PadnHitStatus = new TPad("PadnHitStatus", "PadnHitStatus", 0.00, 0.00, 1.00, 0.03, 0, 0, 0);
596 
597  PadTop[2]->Draw();
598  for (int side = 0; side < nSIDE; side++)
599  {
600  PadTdcOver[side]->Draw();
601  PadnHit[side]->Draw();
602  PadnHitStatus->Draw();
603 
605  BoxnHit[0][side]->SetFillColor(5);
606  BoxnHit[0][side]->SetLineColor(3);
607 
609  BoxnHit[1][side]->SetFillColor(7);
610  BoxnHit[1][side]->SetLineColor(4);
611  }
612 
613  for (auto &side : BoxTdcOver)
614  {
616  side->SetFillColor(5);
617  side->SetLineColor(3);
618  }
619  ifnew(TText, TextnHitStatus);
620  TextnHitStatus->SetTextSize(0.7);
621  TextnHitStatus->SetText(0.05, 0.5, "Red Square : Collision Event / Blue Triangle : Laser Event");
622  transparent[2] = new TPad("transparent2", "this does not show", 0, 0, 1, 1, 0, 0);
623  transparent[2]->SetFillStyle(4000);
624  transparent[2]->Draw();
625  }
626 
627  //
628  // 4th Page
629  else if (name == "BbcMon4")
630  {
631  std::cout << "Creating Canvas BbcMon4..." << std::endl;
632 
633  // ifnew( TText, TextBbcSummaryTrigRate );
634  ifnew(TLatex, TextBbcSummaryTrigRate);
635  // TextBbcSummaryTrigRate->SetTextSize(0.109);
636  TextBbcSummaryTrigRate->SetTextSize(0.08);
637  // TextBbcSummaryTrigRate->SetTextSize(0.075);
638 
639  TC[3] = new TCanvas("BbcMon4", "Beam/Trigger status view for Shift clew", -1, 0, xsize / 2, ysize);
640  gSystem->ProcessEvents();
641  TC[3]->cd();
642 
643  PadTop[3] = new TPad("PadTop3", "PadTop3", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
644  PadTop[3]->Draw();
645 
646  PadHitTime[0] = new TPad("PadHitTimeSouth1", "PadHitTimeSouth1", 0.00, 0.60, 0.50, 0.90, 0, 0, 0);
647  PadHitTime[1] = new TPad("PadHitTimeNorth1", "PadHitTimeNorth1", 0.50, 0.60, 1.00, 0.90, 0, 0, 0);
648  PadHitTime[0]->SetLeftMargin(0.17);
649  PadHitTime[1]->SetLeftMargin(0.17);
650  PadHitTime[0]->Draw();
651  PadHitTime[1]->Draw();
652 
653  for (int side = 0; side < nSIDE; side++)
654  {
657 
660  ArrowHitTime[side]);
661  ArrowHitTime[side]->SetOption("<>");
662 
663  ifnew(TText, TextHitTime[side]);
664  TextHitTime[side]->SetTextSize(0.08);
665  TextHitTime[side]->SetText(bbc_onlmon::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
666 
667  LineHitTime[side][0]->SetLineColor(9);
668  LineHitTime[side][1]->SetLineColor(9);
669  ArrowHitTime[side]->SetLineColor(9);
670  TextHitTime[side]->SetTextColor(9);
671  }
672  PadZvtx = new TPad("PadZvtx", "PadZvtx", 0.00, 0.30, 0.50, 0.60, 0, 0, 0);
673 
674  // for Zvtx
675  if (PadZvtx)
676  {
677  PadZvtx->SetLeftMargin(0.17);
678  PadZvtx->Draw();
681  LineZvtx[0]);
684  LineZvtx[1]);
685 
688  ArrowZvtx);
689  ArrowZvtx->SetOption("<>");
690 
691  ifnew(TText, TextZvtx);
692  TextZvtx->SetTextSize(0.08);
693  TextZvtx->SetText(bbc_onlmon::BBC_MAX_REGULAR_ZVERTEX_MEAN, 10000, " good mean");
694  ifnew(TText, TextZvtxNorth);
695  TextZvtxNorth->SetTextSize(0.05);
696  TextZvtxNorth->SetText(130, 0, "North");
697  ifnew(TText, TextZvtxSouth);
698  TextZvtxSouth->SetTextSize(0.05);
699  TextZvtxSouth->SetText(-160, 0, "South");
700 
701  LineZvtx[0]->SetLineColor(9);
702  LineZvtx[1]->SetLineColor(9);
703  ArrowZvtx->SetLineColor(9);
704  TextZvtx->SetTextColor(9);
705  }
706 
707  PadChargeSum = new TPad("PadChargeSum", "PadCHargeSum", 0.50, 0.30, 1.00, 0.60, 0, 0, 0);
708  PadChargeSum->SetLogy();
709  PadChargeSum->Draw();
710 
711  ifnew(TText, TextNorthChargeSum);
712  // SetNDC(): this will use normalized coordinates (0-1/0-1) for drawing no matter what the histogram uses
713  TextNorthChargeSum->SetNDC();
714  TextNorthChargeSum->SetTextSize(0.08);
715  TextNorthChargeSum->SetText(0.3, 0.8, "--North"); // for p+p
716  TextNorthChargeSum->SetTextColor(4);
717 
718  ifnew(TText, TextSouthChargeSum);
719  // SetNDC(): this will use normalized coordinates (0-1/0-1) for drawing no matter what the histogram uses
720  TextSouthChargeSum->SetNDC();
721  TextSouthChargeSum->SetTextSize(0.08);
722  TextSouthChargeSum->SetText(0.6, 0.8, "--South"); // for p+p
723  TextSouthChargeSum->SetTextColor(2);
724 
725  PadAdc = new TPad("PadAdc", "PadAdc", 0.00, 0.00, 1.00, 0.30, 0, 0, 0);
726  PadAdc->SetLogz();
727  PadAdc->Draw();
728  transparent[3] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
729  transparent[3]->SetFillStyle(4000);
730  transparent[3]->Draw();
731 
732  // PadHitTime[1][0]->SetLogy();
733  // PadHitTime[1][1]->SetLogy();
734 
735  /*
736  ifnew( TPad("PadButton" , "PadButton" , 0.00, 0.70, 1.00, 0.90, 0), PadButton);
737  ifnew( TPad("PadMultiView" , "PadMultiView" , 0.10, 0.20, 1.00, 0.70, 0), PadMultiView);
738  ifnew( TPad("PadWarnings" , "PadWarnings" , 0.00, 0.00, 1.00, 0.20, 0), PadWarnings);
739  PadMultiView->Draw();
740  PadWarnings->Draw();
741  PadButton->Draw();
742  ifnew( TPaveText(0.05, 0.05, 0.95, 0.95) , PaveWarnings );
743  */
744 
745  // TC[3]->SetEditable(0);
746  }
747 
748  //
749 
750  /*
751  if ( ( strlen(name) < 1 || strcmp(name, "BBCMon1") == 0 ) ||
752  ( strlen(name) < 1 || strcmp(name, "BBCMon2") == 0 ) ||
753  ( strlen(name) < 1 || strcmp(name, "BBCMon3") == 0 ) ||
754  ( strlen(name) < 1 || strcmp(name, "BBCMon4") == 0 ) )
755  */
756  {
757  ifnew(TPaveText(0.05, 0.65, 0.70, 0.95), PaveTop);
758  PaveTop->AddText("BBC/MBD ONLINE MONITOR");
759  ifnew(TText, TextTop);
760  TextTop->SetTextSize(0.25);
761  }
762 
763  std::cout << "Initialize completed" << std::endl;
764 
765  return 0;
766 }
767 
769 {
770  PRINT_DEBUG("In BbcMonDraw::Draw()");
771  std::cout << what << std::endl;
772 
773  TStyle *oldStyle = gStyle;
774  bbcStyle->cd();
775 
776  if (!gROOT->FindObject("BbcMon1"))
777  {
778  PRINT_DEBUG("In BbcMonDraw::Draw(), BbcMon1");
779  TC[0] = nullptr;
780  if (what == "ALL" || what == "FIRST" || what == "BbcMon1" || what == "BbcMonitor")
781  {
782  MakeCanvas("BbcMon1");
783  }
784  }
785  if (!gROOT->FindObject("BbcMon2"))
786  {
787  PRINT_DEBUG("In BbcMonDraw::Draw(), BbcMon2");
788  TC[1] = nullptr;
789  if (what == "ALL" || what == "SECOND" || what == "BbcMon2" || what == "VertexMonitor")
790  {
791  MakeCanvas("BbcMon2");
792  }
793  }
794  if (!gROOT->FindObject("BbcMon3"))
795  {
796  TC[2] = nullptr;
797  if (what == "BbcMon3" || what == "BbcMonitor")
798  {
799  MakeCanvas("BbcMon3");
800  }
801  }
802  // 4th canvas
803  if (!gROOT->FindObject("BbcMon4"))
804  {
805  TC[3] = nullptr;
806  if (what == "BbcMon4" || what == "VertexMonitor")
807  {
808  MakeCanvas("BbcMon4");
809  }
810  }
811  // Histogram
812  TH2 *bbc_adc{nullptr};
813  TH2 *bbc_tdc{nullptr};
814  // TH2 *bbc_tdc_overflow;
815  // TH1 *bbc_tdc_overflow_each[nPMT_BBC];
816  //TH1 *bbc_nhit[nTRIGGER];
817  TH2 *bbc_tdc_armhittime{nullptr};
818  TH1 *bbc_zvertex{nullptr};
819  TH1 *bbc_zvertex_bbll1{nullptr};
820  TH1 *bbc_nevent_counter{nullptr};
821  TH2 *bbc_tzero_zvtx{nullptr};
822  TH1 *bbc_avr_hittime{nullptr};
823  TH1 *bbc_south_hittime{nullptr};
824  TH1 *bbc_north_hittime{nullptr};
825  TH1 *bbc_south_chargesum{nullptr};
826  TH1 *bbc_north_chargesum{nullptr};
827  TH1 *bbc_prescale_hist{nullptr};
828  TH2 *bbc_time_wave{nullptr};
829  TH2 *bbc_charge_wave{nullptr};
830  TH2 *bbc_south_hitmap{nullptr};
831  TH2 *bbc_north_hitmap{nullptr};
832 
833  ClearWarning();
834 
835  std::ostringstream otext;
837  std::string textok;
838  // std::ostringstream textok;
839  std::ostringstream name;
840 
841  // ---------------------------------------------------------------------------------
842  // get pointer for each histrams
843 
845 
846  PRINT_DEBUG("Start Getting Histogram");
847 
848  name << "bbc_tdc";
849  bbc_tdc = static_cast<TH2 *>(cl->getHisto("BBCMON_0",name.str().c_str()));
850  name.str("");
851 
852  /*
853  name << "bbc_tdc_overflow" ;
854  bbc_tdc_overflow = static_cast<TH2 *> (cl->getHisto("BBCMON_0",name.str().c_str()));
855  name.str("");
856 
857  for ( int i = 0 ; i < nPMT_BBC ; i++ )
858  {
859  name << "bbc_tdc_overflow_" << setw(3) << setfill('0') << i ;
860  bbc_tdc_overflow_each[i] = cl->getHisto("BBCMON_0",name.str().c_str());
861  name.str("");
862  }
863  */
864 
865  bbc_adc = static_cast<TH2 *>(cl->getHisto("BBCMON_0","bbc_adc"));
866  ifdelete(Adc);
867  for (int i = 0; i < nCANVAS; i++)
868  {
869  if (TC[i])
870  {
871  transparent[i]->Clear(); // clear dead server msg if it was printed before
872  }
873  }
874 
875  if (bbc_adc)
876  {
877  Adc = static_cast<TH2 *>(bbc_adc->Clone());
878  }
879  else
880  {
881  // here I assume server is dead and there must be a message saying so
882  std::cout << "SERVER IS DEAD, no bbc_adc" << std::endl;
883  for (auto &i : TC)
884  {
885  if (i)
886  {
887  i->cd();
888  i->Clear("D");
889  // DrawDeadServer(transparent[i]);
890  i->Update();
891  }
892  }
893  return -1;
894  }
895 
896  bbc_tdc_armhittime = static_cast<TH2 *>(cl->getHisto("BBCMON_0","bbc_tdc_armhittime"));
897  ifdelete(ArmHit);
898  ArmHit = static_cast<TH2 *>(bbc_tdc_armhittime->Clone());
899 
900  bbc_zvertex = cl->getHisto("BBCMON_0","bbc_zvertex");
901  ifdelete(Zvtx);
902  Zvtx = static_cast<TH1 *>(bbc_zvertex->Clone());
903 
904  bbc_zvertex_bbll1 = cl->getHisto("BBCMON_0","bbc_zvertex_bbll1");
906  Zvtx_bbll1 = static_cast<TH1 *>(bbc_zvertex_bbll1->Clone());
907 
908  bbc_nevent_counter = cl->getHisto("BBCMON_0","bbc_nevent_counter");
909 
910  bbc_tzero_zvtx = static_cast<TH2 *>(cl->getHisto("BBCMON_0","bbc_tzero_zvtx"));
912  TzeroZvtx = static_cast<TH2 *>(bbc_tzero_zvtx->Clone());
913 
914  bbc_avr_hittime = cl->getHisto("BBCMON_0","bbc_avr_hittime");
916  AvrHitTime = static_cast<TH1 *>(bbc_avr_hittime->Clone());
917 
918  bbc_north_hittime = cl->getHisto("BBCMON_0","bbc_north_hittime");
920  NorthHitTime = static_cast<TH1 *>(bbc_north_hittime->Clone());
921 
922  bbc_south_hittime = cl->getHisto("BBCMON_0","bbc_south_hittime");
924  SouthHitTime = static_cast<TH1 *>(bbc_south_hittime->Clone());
925 
926  bbc_south_chargesum = cl->getHisto("BBCMON_0","bbc_south_chargesum");
928  SouthChargeSum = static_cast<TH1 *>(bbc_south_chargesum->Clone());
929 
930  bbc_north_chargesum = cl->getHisto("BBCMON_0","bbc_north_chargesum");
932  NorthChargeSum = static_cast<TH1 *>(bbc_north_chargesum->Clone());
933 
934  bbc_prescale_hist = cl->getHisto("BBCMON_0","bbc_prescale_hist");
936  Prescale_hist = static_cast<TH1 *>(bbc_prescale_hist->Clone());
937 
938  bbc_time_wave = static_cast<TH2 *>( cl->getHisto("BBCMON_0","bbc_time_wave") );
940  TimeWave = static_cast<TH2 *>(bbc_time_wave->Clone());
941 
942  bbc_charge_wave = static_cast<TH2 *>( cl->getHisto("BBCMON_0","bbc_charge_wave") );
944  ChargeWave = static_cast<TH2 *>(bbc_charge_wave->Clone());
945 
946  bbc_south_hitmap = static_cast<TH2 *>( cl->getHisto("BBCMON_0","bbc_south_hitmap") );
948  SouthHitMap = static_cast<TH2 *>(bbc_south_hitmap->Clone());
949 
950  bbc_north_hitmap = static_cast<TH2 *>( cl->getHisto("BBCMON_0","bbc_north_hitmap") );
952  NorthHitMap = static_cast<TH2 *>(bbc_north_hitmap->Clone());
953 
954  PRINT_DEBUG("Start Creating graphs");
955 
956  // Create HitTime projection ------------------------------------------
957 
958  for (int side = 0; side < nSIDE; side++)
959  {
960  ifdelete(HitTime[side]);
961 
962  name << "FitHitTime" << bbc_onlmon::SIDE_Str[side];
963  HitTime[side] = bbc_tdc->ProjectionY(name.str().c_str(), side * 64, side * 64 + 63);
964  name.str("");
965 
966  name << bbc_onlmon::SIDE_Str[side] << " BBC/MBD TDC Distribution";
967  // name << bbc_onlmon::SIDE_Str[side] << " BBC/MBD TDC" << tdc << " Distribution(Trigger:BBLL1)" ; // Run14 AuAu 15GeV 2014.02.23
968  HitTime[side]->SetTitle(name.str().c_str());
969  ifnew(TF1(name.str().c_str(), "gaus"), FitHitTime[side]);
970  name.str("");
971  FitHitTime[side]->SetLineWidth(1); // 0.05 was used fro run3
972  FitHitTime[side]->SetLineColor(4);
973  }
974 
975  // Create ZVertex Fit
976 
977  ifnew(TF1("FitZvtx", "gaus"), FitZvtx);
978  ifnew(TF1("FitAvrHitTime", "gaus"), FitAvrHitTime);
979  ifnew(TF1("FitNorthHitTime", "gaus"), FitNorthHitTime);
980  ifnew(TF1("FitSouthHitTime", "gaus"), FitSouthHitTime);
981  FitZvtx->SetLineWidth(1); // 0.05 was used for run3
982  FitZvtx->SetLineColor(4);
983 
984  // ------------------------------------------------------------------------------
985  // making nHit TGraph
986 
987  double pmt[nPMT_1SIDE_BBC] = {0.};
988  double zero[nPMT_1SIDE_BBC] = {0.};
989  double nhitPmt[nTRIGGER][nSIDE][nPMT_1SIDE_BBC];
990  double nhit_total = bbc_nevent_counter->GetBinContent(2);
991  double nhit[nTRIGGER];
992  nhit[0] = bbc_nevent_counter->GetBinContent(2);
993  nhit[1] = bbc_nevent_counter->GetBinContent(3);
994 
995  for (int i = 0; i < nPMT_1SIDE_BBC; i++)
996  {
997  pmt[i] = i + 1;
998  // zero[i] = 0;
999  }
1000 
1001  PRINT_DEBUG("Creating nHit Graph");
1002 
1003  for (int side = 0; side < nSIDE; side++)
1004  {
1005  for (int trig = 0; trig < nTRIGGER; trig++)
1006  {
1007  for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1008  {
1009  if (nhit[trig] != 0)
1010  {
1011  // RUN12: to ignore laser rate for ch8, fiber is broken.
1012  if (side == 0 && trig == 1 && i == 7)
1013  {
1014  nhitPmt[trig][side][i] = 999;
1015  }
1016  else
1017  {
1018  //nhitPmt[trig][side][i] = bbc_nhit[trig]->GetBinContent(i + side * nPMT_1SIDE_BBC + 1) / nhit[trig];
1019  nhitPmt[trig][side][i] = 999;
1020  }
1021  }
1022  else
1023  {
1024  nhitPmt[trig][side][i] = 0;
1025  }
1026  }
1027  ifnew(TGraph(nPMT_1SIDE_BBC, pmt, nhitPmt[trig][side]), nHit[trig][side]);
1028  // nHit[trig][side]->GetXaxis()->SetTitleSize( 0.05);
1029  // nHit[trig][side]->GetYaxis()->SetTitleSize( 0.05);
1030  // nHit[trig][side]->GetXaxis()->SetTitleOffset(0.70);
1031  // nHit[trig][side]->GetYaxis()->SetTitleOffset(1.75);
1032  }
1033  }
1034  PRINT_DEBUG("Creating OverFlow Grapth");
1035 
1036  // Create TDC Overflow Graph
1037 
1038  double tdcOverMean[nSIDE][nPMT_1SIDE_BBC];
1039  double tdcOverErrY[nSIDE][nPMT_1SIDE_BBC];
1040  for (int iside = 0; iside < nSIDE; iside++)
1041  {
1042  for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1043  {
1044  tdcOverMean[iside][i] = 0.0;
1045  tdcOverErrY[iside][i] = 0.0;
1046  }
1047  }
1048 
1049  for (int side = 0; side < nSIDE; side++)
1050  {
1051  for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1052  {
1053  /*
1054  tdcOverMean[0][side][i] = bbc_tdc_overflow_each[0][i + side * nPMT_1SIDE_BBC]->GetMean() /
1055  bbccalib->getOverflow0()->getCalibPar(i)->getDeviation();
1056  tdcOverErrY[0][side][i] = bbc_tdc_overflow_each[0][i + side * nPMT_1SIDE_BBC]->GetRMS() /
1057  bbccalib->getOverflow0()->getCalibPar(i)->getDeviation();
1058 
1059  tdcOverMean[1][side][i] = bbc_tdc_overflow_each[1][i + side * nPMT_1SIDE_BBC]->GetMean() /
1060  bbccalib->getOverflow1()->getCalibPar(i)->getDeviation();
1061  tdcOverErrY[1][side][i] = bbc_tdc_overflow_each[1][i + side * nPMT_1SIDE_BBC]->GetRMS() /
1062  bbccalib->getOverflow1()->getCalibPar(i)->getDeviation();
1063  */
1064 
1065  ifnew(TGraphErrors(nPMT_1SIDE_BBC, pmt, tdcOverMean[side], zero,
1066  tdcOverErrY[side]),
1067  TdcOver[side]);
1068  }
1069  }
1070 
1071  // Redraw each Pad
1072 
1073  // ------------------------------------------------------------------------
1074  // Draw 1st Page
1075  // ------------------------------------------------------------------------
1076  std::ostringstream msg;
1077  PRINT_DEBUG("Drawing Graphs on Canvas");
1078 
1079  // Make TopPave
1080  time_t evttime = cl->EventTime("CURRENT");
1081 
1082  otext.str("");
1083  otext << "Run #" << cl->RunNumber();
1084  otext << " Events: " << nhit_total;
1085  otext << " Date:" << ctime(&evttime);
1086  text = otext.str();
1087  TextTop->SetText(0.01, 0.25, text.c_str());
1088 
1089  if (TC[0])
1090  {
1091  TC[0]->cd();
1092 
1093  PadTop[0]->cd();
1094  PaveTop->Draw();
1095  TextTop->Draw();
1096 
1097  PadZVertexSummary->cd();
1098 
1099  Zvtx->SetLineColor(4);
1100  Zvtx->SetFillColor(4);
1101 
1102  Zvtx_bbll1->SetLineColor(4);
1103  Zvtx_bbll1->SetFillColor(4);
1104 
1105  // Get Maximum at the inside of BBC which is 130cm from center;
1106  float maxEntries = 10;
1107 
1108  for (int i = 0; i < Zvtx->GetNbinsX(); i++)
1109  {
1110  if (fabs(Zvtx->GetBinCenter(i)) < 130)
1111  {
1112  if (maxEntries < Zvtx->GetBinContent(i + 1))
1113  {
1114  maxEntries = Zvtx->GetBinContent(i + 1);
1115  }
1116  }
1117  }
1118 
1119  // Fit No-Vertex Distribution
1120  FitZvtx->SetRange(-75, 75);
1121  FitZvtx->SetLineColor(7);
1122  //Zvtx->Fit("FitZvtx", "LRQ");
1123  Zvtx->Fit("FitZvtx", "R");
1124 
1125  // here we get the relative scaling right to put all on the same plot
1126  // the binning might be different, so we first find the bins corresponding to
1127  // +- 20cm and then get the Integral corrected for the binwidth
1128  // this is then used to get the histograms on the same scale
1129  /*
1130  int lowbin = Zvtx_zdc->GetXaxis()->FindBin(-20.);
1131  int hibin = Zvtx_zdc->GetXaxis()->FindBin(20.);
1132  double zdc_count = Zvtx_zdc->Integral(lowbin, hibin, "width");
1133  */
1134 
1135  /*
1136  int lowbin = Zvtx->GetXaxis()->FindBin(-20.);
1137  int hibin = Zvtx->GetXaxis()->FindBin(20.);
1138  double bbc_count = Zvtx->Integral(lowbin, hibin, "width");
1139  */
1140 
1141  // std::cout << "the ratio of integral (-30cm < ZVertex < 30cm) between BBLL1 without vtx cut and ZDC : " << bbc_count_novtx / zdc_count << std::endl ;
1142  // std::cout << "the ratio of integral (-30cm < ZVertex < 30cm) between BBLL1 without vtx cut and BBLL1 with BBCZ < |30cm| : " << bbc_count_novtx/bbc_count << std::endl ;
1143 
1144  // Draw ZVertex triggerd variable trigger
1145  Zvtx->SetMaximum(maxEntries * 1.05);
1146  Zvtx->SetTitle("BBC/MBD ZVertex (south<-->north)");
1147  // PadZVertex->DrawFrame(-160,0,160,maxEntries*1.05,"Bbc ZVertex (south<-->north)");
1148  // std::cout << "maxEntries " << maxEntries << std::endl;
1149  // Zvtx->Draw("hist");
1150  // Zvtx->Scale(bbc_count_novtx/bbc_count);
1151 
1152  // just in case the bbcll1 with vtx cut histo is empty
1153  // draw the novertex cut (happens during setup)
1154  if (Zvtx->GetEntries() > 0)
1155  {
1156  Zvtx->Draw("hist");
1157  }
1158  // trigger rate between BBCLL1 and Zvertex within +- BBC_ZVERTEX_CUT_FOR_TRIG_RATE
1159  // bbll1, zdc, bbll1_novtx
1160 
1161  float trig_rate[3], trig_rate_err[3];
1162  double nevent[3];
1163  memset(trig_rate, 0, sizeof(trig_rate));
1164  memset(trig_rate_err, 0, sizeof(trig_rate_err));
1165  memset(nevent, 0, sizeof(nevent));
1166 
1167  /*
1168  CalculateTriggerRates(trig_rate[0], trig_rate_err[0], nevent[0],
1169  trig_rate[1], trig_rate_err[1], nevent[1],
1170  trig_rate[2], trig_rate_err[2], nevent[2]);
1171  */
1172 
1173 /* chiu
1174  float sigma_zdc = 0.0;
1175  // float sigma_zdc_err = 0.0;
1176  float effic_bbc = 0.0;
1177  // float effic_bbc_err = 0.0;
1178  float beamInZdc = 0.0;
1179  // float beamInZdc_err = 0.0;
1180  float beamInBbc = 0.0;
1181  // float beamInBbc_err = 0.0;
1182 */
1183 
1184  /*
1185  BeamMonitoring( sigma_zdc, sigma_zdc_err, effic_bbc, effic_bbc_err,
1186  beamInZdc, beamInZdc_err, beamInBbc, beamInBbc_err);
1187  */
1188 
1189  /*chiu
1190  std::ostringstream trig_rate_text;
1191  trig_rate_text << " #sigma_{ZDC} = " << std::fixed << std::setprecision(3) << sigma_zdc
1192  << " #epsilon_{BBC} = " << effic_bbc
1193  << " {}^{beam in acceptance}_{ ZDC } = " << beamInZdc
1194  << " {}^{beam in acceptance}_{ BBC } = " << beamInBbc;
1195  TextBbcSummaryTrigRate->SetText(0.02, 0.05, trig_rate_text.str().c_str());
1196  trig_rate_text.str("");
1197  */
1198 
1199  // float xpos[3] = {0.1, 0.34, 0.58};
1200  // float xpos[3] = {0.30, 0.50, 0.75};
1201  // TextZVertexNotice->Draw();
1202 
1203  TH1 *Zvtx_array[4]; // with narrow
1204  // TH1 *Zvtx_array[3];
1205  Zvtx_array[0] = Zvtx;
1206  //Zvtx_array[1] = Zvtx;
1207  //Zvtx_array[2] = Zvtx;
1208  // Zvtx_array[1] = Zvtx_zdc;
1209 
1210  // Show status of ZVertex
1211  int i = 0;
1212 
1213  //TextZVertex[i]->Draw();
1214 
1215  // scale factor ---------------------------------------------------------------------
1216  // std::cout << " " << i << " " << Prescale_hist->GetBinContent(i + 1) << std::endl;
1217  otext.str("");
1218  // otext << "( "<< Prescale_hist->GetBinContent(i+1)<<" )";
1219  // otext << "( "<< Prescale_hist->GetBinContent(i+1)<<" )"<<" ";
1220  // otext << nevent[i] ;
1221  // otext.precision(8);
1222  otext << " ( " << Prescale_hist->GetBinContent(i + 1) << " ) "
1223  << " ";
1224  // otext << nevent[i]/Prescale_hist->GetBinContent(i+1) ;
1225  otext << Zvtx_array[i]->GetEntries();
1226 
1227  text = otext.str();
1228  TextZVertex_scale[i]->SetText(xpos[i], 0.50, text.c_str());
1229  //TextZVertex_scale[i]->Draw();
1230 
1231  // mean and RMS ---------------------------------------------------------------------
1232  otext.str("");
1233  otext << ((float) int(Zvtx_array[i]->GetMean() * 10)) / 10.0 << "cm ( "
1234  << ((float) int(Zvtx_array[i]->GetRMS() * 10)) / 10.0 << " cm) ";
1235  text = otext.str();
1236 
1237  TextZVertex_mean[i]->SetText(xpos[i], 0.25, text.c_str());
1238  //TextZVertex_mean[i]->Draw();
1239  // otext.precision(6);
1240 
1241  //TextZVertex[i]->Draw();
1242 
1243  /*
1244  TextZVertex_scale[i]->SetText(0.00, 0.50, "(Scale Fac.) #Evt.");
1245  TextZVertex_scale[i]->Draw();
1246  // TextZVertex_mean[i]->SetText(0.05, 0.25, "Vertex Mean (RMS)");
1247  TextZVertex_mean[i]->SetText(0.00, 0.25, "Vertex Mean (RMS)");
1248  TextZVertex_mean[i]->Draw();
1249  */
1250 
1251  // Draw Status
1252  otext.str("");
1253  otext << "Z_{All Trigs}^{Fit}= " << ((float) int(FitZvtx->GetParameter(1) * 10)) / 10.0 << " cm";
1254  // << " #pm " << ((float)int(FitZvtx->GetParError(1)*10))/10.0
1255  // << " #pm " << ((float)int(FitZvtx->GetParError(2)*10))/10.0
1256 
1257  text = otext.str();
1258  //TextZvtxStatus[0]->SetText(0.0, 0.85, text.c_str());
1259  TextZvtxStatus[0]->SetText(-230., maxEntries*0.8, text.c_str());
1260  TextZvtxStatus[0]->SetTextSize(0.10);
1261  TextZvtxStatus[0]->Draw();
1262 
1263  otext.str("");
1264  otext << "#sigma = " << int(FitZvtx->GetParameter(2)) << " cm";
1265  text = otext.str();
1266  TextZvtxStatus[1]->SetText(100., maxEntries*0.8, text.c_str());
1267  TextZvtxStatus[1]->SetTextSize(0.10);
1268  TextZvtxStatus[1]->Draw();
1269 
1270  //chiu TextBbcSummaryTrigRate->Draw();
1271 
1272  PadZVertex->cd();
1273 
1274  if (Zvtx_bbll1->GetEntries() > 0)
1275  {
1276  Zvtx_bbll1->GetXaxis()->SetRangeUser(-30,30);
1277  Zvtx_bbll1->Draw("hist");
1278  }
1279 
1280  /*
1281  // replaced with hitmap
1282  PadTzeroZVertex->cd();
1283  TzeroZvtx->Draw("colz");
1284 
1285  // insert line
1286  LineTzeroZvtx[0]->Draw();
1287  LineTzeroZvtx[1]->Draw();
1288  LineTzeroZvtx[2]->Draw();
1289  LineTzeroZvtx[3]->Draw();
1290 
1291  // insert text
1292  TextTzeroZvtx->SetText(10, 4, "Good region");
1293  TextTzeroZvtx->Draw();
1294  */
1295 
1296  double nevents = bbc_nevent_counter->GetBinContent(2);
1297  PadSouthHitMap->cd();
1298  SouthHitMap->Scale(1.0/nevents);
1299  SouthHitMap->Draw("colz");
1300 
1301  PadNorthHitMap->cd();
1302  NorthHitMap->Scale(1.0/nevents);
1303  NorthHitMap->Draw("colz");
1304  }
1305 
1306 
1307  // bbc_t0_pave->Draw("same");
1308 
1309  // ------------------------------------------------------------------------
1310  // Draw 2nd Page
1311  // ------------------------------------------------------------------------
1312  if (TC[1])
1313  {
1314  TC[1]->cd();
1315 
1316  PadTop[1]->cd();
1317  PaveTop->Draw();
1318  TextTop->Draw();
1319 
1320  if (PadAvrHitTime)
1321  {
1322  PadAvrHitTime->cd();
1323  AvrHitTime->Draw();
1324 
1325  float rangemin;
1326  float rangemax;
1327  int npeak = tspec->Search(AvrHitTime, 2, "goff"); // finds the highest peak, draws marker
1328  if (npeak < 3) // no center peak
1329  {
1330  AvrHitTime->Fit("FitAvrHitTime", "QN0L");
1331  rangemin = FitAvrHitTime->GetParameter(1) - FitAvrHitTime->GetParameter(2);
1332  rangemax = FitAvrHitTime->GetParameter(1) + FitAvrHitTime->GetParameter(2);
1333  }
1334  else
1335  {
1336  double *peakpos = tspec->GetPositionX();
1337  float centerpeak = peakpos[0];
1338  float sidepeak[2];
1339  if (peakpos[2] > peakpos[1])
1340  {
1341  sidepeak[0] = peakpos[1];
1342  sidepeak[1] = peakpos[2];
1343  }
1344  else
1345  {
1346  sidepeak[1] = peakpos[1];
1347  sidepeak[0] = peakpos[2];
1348  }
1349  rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
1350  rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
1351  }
1352 
1353  FitAvrHitTime->SetRange(rangemin, rangemax);
1354  AvrHitTime->Fit("FitAvrHitTime", "QRL");
1355  FitAvrHitTime->Draw("same");
1356 
1357  float height = AvrHitTime->GetMaximum();
1358  FitAvrHitTime->Draw("same");
1359 
1360  LineAvrHitTime[1]->SetY2(height);
1361  LineAvrHitTime[0]->SetY2(height);
1362  ArrowAvrHitTime->SetY1(height * 0.90);
1363  ArrowAvrHitTime->SetY2(height * 0.90);
1364  TextAvrHitTime->SetY(height * 0.88);
1365  LineAvrHitTime[0]->Draw();
1366  LineAvrHitTime[1]->Draw();
1367  ArrowAvrHitTime->Draw();
1368  TextAvrHitTime->Draw();
1369  }
1370 
1371  if (PadTimeWave)
1372  {
1373  PadTimeWave->cd();
1374  TimeWave->Draw("colz");
1375  }
1376 
1377  if (PadSouthHitTime)
1378  {
1379  PadSouthHitTime->cd();
1380  SouthHitTime->Draw();
1381  float rangemin;
1382  float rangemax;
1383  int npeak = tspec->Search(SouthHitTime, 2, "goff"); // finds the highest peak, draws marker
1384  if (npeak < 3) // no center peak
1385  {
1386  SouthHitTime->Fit("FitSouthHitTime", "QN0L");
1387  rangemin = FitSouthHitTime->GetParameter(1) - FitSouthHitTime->GetParameter(2);
1388  rangemax = FitSouthHitTime->GetParameter(1) + FitSouthHitTime->GetParameter(2);
1389  }
1390  else
1391  {
1392  double *peakpos = tspec->GetPositionX();
1393  float centerpeak = peakpos[0];
1394  float sidepeak[2];
1395  if (peakpos[2] > peakpos[1])
1396  {
1397  sidepeak[0] = peakpos[1];
1398  sidepeak[1] = peakpos[2];
1399  }
1400  else
1401  {
1402  sidepeak[1] = peakpos[1];
1403  sidepeak[0] = peakpos[2];
1404  }
1405  rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
1406  rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
1407  }
1408 
1409  FitSouthHitTime->SetRange(rangemin, rangemax);
1410  SouthHitTime->Fit("FitSouthHitTime", "QRL");
1411  FitSouthHitTime->Draw("same");
1412 
1413  FitSouthHitTime->Draw("same");
1414 
1415  /*
1416  // Lines to indicate good mean
1417  float height = SouthHitTime->GetMaximum();
1418  LineSouthHitTime[1]->SetY2(height);
1419  LineSouthHitTime[0]->SetY2(height);
1420  ArrowSouthHitTime->SetY1(height * 0.90);
1421  ArrowSouthHitTime->SetY2(height * 0.90);
1422  TextSouthHitTime->SetY(height * 0.88);
1423  LineSouthHitTime[0]->Draw();
1424  LineSouthHitTime[1]->Draw();
1425  ArrowSouthHitTime->Draw();
1426  TextSouthHitTime->Draw();
1427  */
1428  }
1429 
1430  if (PadNorthHitTime)
1431  {
1432  PadNorthHitTime->cd();
1433  NorthHitTime->Draw();
1434  float rangemin;
1435  float rangemax;
1436  int npeak = tspec->Search(NorthHitTime, 2, "goff"); // finds the highest peak, draws marker
1437  if (npeak < 3) // no center peak
1438  {
1439  NorthHitTime->Fit("FitNorthHitTime", "QN0L");
1440  rangemin = FitNorthHitTime->GetParameter(1) - FitNorthHitTime->GetParameter(2);
1441  rangemax = FitNorthHitTime->GetParameter(1) + FitNorthHitTime->GetParameter(2);
1442  }
1443  else
1444  {
1445  double *peakpos = tspec->GetPositionX();
1446  float centerpeak = peakpos[0];
1447  float sidepeak[2];
1448  if (peakpos[2] > peakpos[1])
1449  {
1450  sidepeak[0] = peakpos[1];
1451  sidepeak[1] = peakpos[2];
1452  }
1453  else
1454  {
1455  sidepeak[1] = peakpos[1];
1456  sidepeak[0] = peakpos[2];
1457  }
1458  rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
1459  rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
1460  }
1461 
1462  FitNorthHitTime->SetRange(rangemin, rangemax);
1463  NorthHitTime->Fit("FitNorthHitTime", "QRL");
1464  FitNorthHitTime->Draw("same");
1465 
1466  FitNorthHitTime->Draw("same");
1467 
1468  /*
1469  // Lines to indicate good mean
1470  float height = NorthHitTime->GetMaximum();
1471  LineNorthHitTime[1]->SetY2(height);
1472  LineNorthHitTime[0]->SetY2(height);
1473  ArrowNorthHitTime->SetY1(height * 0.90);
1474  ArrowNorthHitTime->SetY2(height * 0.90);
1475  TextNorthHitTime->SetY(height * 0.88);
1476  LineNorthHitTime[0]->Draw();
1477  LineNorthHitTime[1]->Draw();
1478  ArrowNorthHitTime->Draw();
1479  TextNorthHitTime->Draw();
1480  */
1481  }
1482 
1483  /*
1484  PadArmHit->cd();
1485  if (ArmHit)
1486  {
1487  ArmHit->Draw("colz");
1488  ArcArmHit->Draw();
1489  TextArmHit->Draw();
1490  }
1491  */
1492 
1493  if ( PadBbcSummary )
1494  {
1495  PadBbcSummary->cd();
1496  otext.str("");
1497  otext << "South:" << ((float) int(FitSouthHitTime->GetParameter(1) * 10)) / 10 << "[ns] ";
1498  otext << "North:" << ((float) int(FitNorthHitTime->GetParameter(1) * 10)) / 10 << "[ns] ";
1499  otext << "... ";
1500  if (bbc_onlmon::BBC_MIN_REGULAR_TDC0_MEAN < FitNorthHitTime->GetParameter(1) &&
1504  {
1505  // otext << "OK";
1506  textok = " OK";
1507  }
1508  else
1509  {
1510  textok = " ";
1512  {
1513  otext << "Too low statistics";
1514  }
1515  else
1516  {
1517  otext << "Change Global-Offset on V124";
1518  }
1519  }
1520  text = otext.str();
1521  TextBbcSummaryHitTime[0]->SetText(0.01, 0.75, text.c_str());
1522  TextBbcSummaryHitTime[0]->Draw();
1523  text = textok;
1524  // TextBbcSummaryHitTime[1]->SetText(0.65, 0.75, text.c_str() );
1525  TextBbcSummaryHitTime[1]->SetText(0.01, 0.75, text.c_str());
1526  TextBbcSummaryHitTime[1]->SetTextColor(3);
1527  TextBbcSummaryHitTime[1]->Draw();
1528  }
1529 
1530  // Global offset
1531  float delay = (bbc_onlmon::BBC_DEFAULT_OFFSET -
1532  ((FitNorthHitTime->GetParameter(1) + FitSouthHitTime->GetParameter(1)) * 0.5)); //[ns]
1533  otext.str("");
1534  otext << " Global offset : ";
1535  if (int(-2 * delay) == 0)
1536  {
1537  // otext << "need not to move ... OK";
1538  // otext << " ... OK";
1539  //textok = " ... OK";
1540  }
1541  else
1542  {
1543  //textok = " ";
1544  if (!(bbc_onlmon::BBC_MIN_REGULAR_TDC0_MEAN < FitNorthHitTime->GetParameter(1) &&
1548  {
1549  // otext << "Need to move " << int( -2*delay) << "count";
1550  otext << "Need to call BBC expert: " << int(-2 * delay) << "count shifted";
1551  }
1552  else
1553  {
1554  // otext << " ... OK";
1555  //textok = " OK";
1556  }
1557  }
1558 
1559 /*chiu
1560  // otext << "... )" ;
1561  text = otext.str();
1562  TextBbcSummaryGlobalOffset[0]->SetText(0.01, 0.50, text.c_str());
1563  TextBbcSummaryGlobalOffset[0]->Draw();
1564  text = textok;
1565  // TextBbcSummaryGlobalOffset[1]->SetText(0.35, 0.50, text.c_str() );
1566  TextBbcSummaryGlobalOffset[1]->SetText(0.01, 0.50, text.c_str());
1567  TextBbcSummaryGlobalOffset[1]->SetTextColor(3);
1568  TextBbcSummaryGlobalOffset[1]->Draw();
1569  // textok = " ";
1570 */
1571 
1572  // ZVertex
1573  /*
1574  otext.str("");
1575  otext << "Mean ZVertex:" << ((float)int(FitZvtx->GetParameter(1)*10)) / 10 << "[cm] ";
1576  if(Zvtx->GetEntries() > bbc_onlmon::BBC_MIN_WORNING_STATISTICS_FOR_ZVERTEX_MEAN ) {
1577  otext << "( sigma " << ((float)int(FitZvtx->GetParameter(2)*10)) / 10 << "cm)";
1578  }else{
1579  // otext << "( RMS " << ((float)int(Zvtx->GetRMS()*10)) / 10 << "cm)";
1580  }
1581  otext << " ... ";
1582  if ( bbc_onlmon::BBC_MIN_REGULAR_ZVERTEX_MEAN < FitZvtx->GetParameter(1) &&
1583  bbc_onlmon::BBC_MAX_REGULAR_ZVERTEX_MEAN > FitZvtx->GetParameter(1) )
1584  otext << "OK";
1585  else {
1586  if( bbc_onlmon::BBC_MIN_WORNING_STATISTICS_FOR_ZVERTEX_MEAN > Zvtx->GetEntries() )
1587  otext << "Too low statistics";
1588  else
1589  otext << "Ask SL to contact MCR";
1590  }
1591  text = otext.str();
1592  TextBbcSummaryZvertex->SetText(0.01, 0.25, text.c_str() );
1593  */
1594 
1595 /*chiu
1596  TextBbcSummaryZvertex->SetText(0.01, 0.25, "Shown data are triggered by BBLL1 |z|<130cm");
1597  TextBbcSummaryZvertex->Draw();
1598 */
1599  }
1600 
1601  // ------------------------------------------------------------------------
1602  // Draw 3rd Page
1603  // ------------------------------------------------------------------------
1604  if (TC[2])
1605  {
1606  TC[2]->cd();
1607 
1608  // -------------------------------------------------------------------------
1609  PadTop[2]->cd();
1610  PaveTop->Draw();
1611  TextTop->Draw();
1612 
1613  // TDC
1614 
1615  for (int side = 0; side < nSIDE; side++)
1616  {
1617  PadTdcOver[side]->cd();
1618  // ifdelete( FrameTdcOver[side] );
1619  FrameTdcOver[side] = TC[0]->DrawFrame(0.5, -5, 64.5, 5);
1620  // FrameTdcOver[side] = gPad->DrawFrame( 0.5, -5, 64.5, 5);
1621 
1622  std::cout << "FrameTdcOver[" << side << "] = " << (unsigned long) FrameTdcOver[side] << std::endl;
1623  BoxTdcOver[side]->Draw();
1624 
1625  name << bbc_onlmon::SIDE_Str[side] << " BBC/MBD TDC Distribution";
1626  FrameTdcOver[side]->SetTitle(name.str().c_str());
1627  name.str("");
1628 
1629  FrameTdcOver[side]->GetXaxis()->SetTitle("PMT Number");
1630  FrameTdcOver[side]->GetXaxis()->SetTitleSize(0.05);
1631  FrameTdcOver[side]->GetXaxis()->SetLabelSize(0.05);
1632  FrameTdcOver[side]->GetYaxis()->SetTitle("Deviation [#sigma]");
1633  FrameTdcOver[side]->GetYaxis()->SetTitleSize(0.07);
1634  FrameTdcOver[side]->GetYaxis()->SetTitleOffset(0.50);
1635  FrameTdcOver[side]->GetYaxis()->SetLabelSize(0.05);
1636  TdcOver[side]->SetMarkerStyle(21);
1637  TdcOver[side]->SetMarkerSize(0.5);
1638  TdcOver[side]->SetMarkerColor(2);
1639  TdcOver[side]->Draw("P");
1640 
1641  // Check Warning
1642  if (nhit[0] > 100)
1643  {
1644  for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1645  {
1646  if (tdcOverMean[side][i] == 0 && tdcOverErrY[side][i] == 0)
1647  {
1648  msg.str("");
1649  msg << "Stop the run (ch " << i + 1 << " is out of the range)";
1650  std::string wmsg = msg.str();
1651  Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
1652  wmsg.erase();
1653  msg.str("");
1654  }
1655  if (tdcOverMean[side][i] < bbc_onlmon::BBC_TDC_OVERFLOW_REGULAR_MIN)
1656  {
1657  msg.str("");
1658  msg << "ch " << i + 1 << " is too low ( " << std::fixed << std::setprecision(1) << tdcOverMean[side][i] << " #sigma)";
1659  std::string wmsg = msg.str();
1660  Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
1661  wmsg.erase();
1662  msg.str("");
1663  }
1664  if (tdcOverMean[side][i] > bbc_onlmon::BBC_TDC_OVERFLOW_REGULAR_MAX)
1665  {
1666  msg.str("");
1667  msg << "ch " << i + 1 << " is too high ( " << std::fixed << std::setprecision(1) << tdcOverMean[side][i] << " #sigma)";
1668  std::string wmsg = msg.str();
1669  Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
1670  wmsg.erase();
1671  msg.str("");
1672  }
1673  if (tdcOverMean[side][i] > bbc_onlmon::BBC_TDC_OVERFLOW_REGULAR_RMS_MAX)
1674  {
1675  msg.str("");
1676  msg << "ch " << i + 1 << " is too wide ( " << std::fixed << std::setprecision(1) << tdcOverErrY[side][i] << " #sigma)";
1677  std::string wmsg = msg.str();
1678  Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
1679  wmsg.erase();
1680  msg.str("");
1681  }
1682  }
1683  }
1684 
1685  PadnHit[side]->cd();
1686  // ifdelete( FramenHit[side] );
1687  // FramenHit[side] = TC[0]->DrawFrame( 0.5, 0, 64.5, 1);
1688  FramenHit[side] = gPad->DrawFrame(0.5, 0, 64.5, 1);
1689  BoxnHit[0][side]->Draw();
1690  BoxnHit[1][side]->Draw();
1691 
1692  name << bbc_onlmon::SIDE_Str[side] << " BBC/MBD number of Hit per Event";
1693  FramenHit[side]->SetTitle(name.str().c_str());
1694  name.str("");
1695 
1696  FramenHit[side]->GetXaxis()->SetTitle("PMT Number");
1697  FramenHit[side]->GetXaxis()->SetTitleSize(0.05);
1698  FramenHit[side]->GetXaxis()->SetLabelSize(0.05);
1699  FramenHit[side]->GetYaxis()->SetTitleSize(0.05);
1700  FramenHit[side]->GetYaxis()->SetLabelSize(0.05);
1701  nHit[0][side]->SetMarkerStyle(21);
1702  nHit[0][side]->SetMarkerSize(0.5);
1703  nHit[0][side]->SetMarkerColor(2);
1704  nHit[0][side]->Draw("P");
1705  nHit[1][side]->SetMarkerStyle(22);
1706  nHit[1][side]->SetMarkerSize(0.5);
1707  nHit[1][side]->SetMarkerColor(4);
1708  nHit[1][side]->Draw("P");
1709 
1710  for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1711  {
1712  if (nhit[0] > 100)
1713  {
1714  if (nhitPmt[0][side][i] < bbc_onlmon::BBC_nHIT_MB_MIN[side])
1715  {
1716  // RUN11: to ignore hit rate since ch29 before FEM input is dead.
1717  // RUN11: to ignore hit rate since the gain for ch40 is unstable.
1718  // if( (side==0)&&(i==29 || i==40))
1719  //{
1720  // if(i == 29){
1721  // std::cout << "ch29 : Ignore hit rate into ch29" << std::endl;
1722  // }
1723  // else {
1724  // std::cout << "ch40 : Ignore hit rate into ch40" << std::endl;
1725  // }
1726  // continue;
1727  // }
1728 
1729  msg.str("");
1730  msg << "Too low hit-rate into ch " << i + 1 << " ("
1731  << std::fixed << std::setprecision(2) << nhitPmt[0][side][i]
1732  << "/" << std::setprecision(0) << nhit[0] << "evt)";
1733  std::string wmsg = msg.str();
1734  Warning(PadnHit[side], i, nhitPmt[0][side][i], 1, wmsg);
1735  wmsg.erase();
1736  msg.str("");
1737  }
1738  if (nhitPmt[0][side][i] > bbc_onlmon::BBC_nHIT_MB_MAX[side])
1739  {
1740  msg.str("");
1741  msg << "Too high hit-rate into ch " << i + 1 << " ("
1742  << std::fixed << std::setprecision(2) << nhitPmt[0][side][i]
1743  << "/" << std::setprecision(0) << nhit[0] << "evt)";
1744  std::string wmsg = msg.str();
1745  Warning(PadnHit[side], i, nhitPmt[0][side][i], 1, wmsg);
1746  wmsg.erase();
1747  msg.str("");
1748  }
1749  }
1750 
1751  if (nhit[1] > 0)
1752  {
1753  if (nhitPmt[1][side][i] < bbc_onlmon::BBC_nHIT_LASER_MIN[side])
1754  {
1755  if (side == 0)
1756  {
1757  // RUN12: to ignore lack of laser rate, since fiber of ch7 is broken.
1758  if (i == 7)
1759  {
1760  std::cout << "ch7(S8) : Ignore hit rate of laser" << std::endl;
1761  continue;
1762  }
1763  msg.str("");
1764  msg << "Lack of laser's hit into ch " << i + 1 << " ("
1765  << std::fixed << std::setprecision(2) << nhitPmt[1][side][i]
1766  << "/" << std::setprecision(0) << nhit[1] << "evt)";
1767  std::string wmsg = msg.str();
1768  Warning(PadnHit[side], i, nhitPmt[1][side][i], 1, wmsg);
1769  wmsg.erase();
1770  msg.str("");
1771  }
1772  else // North
1773  {
1774  msg.str("");
1775  msg << "Lack of laser's hit into ch " << i + 1 << " ("
1776  << std::fixed << std::setprecision(2) << nhitPmt[1][side][i]
1777  << "/" << std::setprecision(0) << nhit[1] << "evt)";
1778  std::string wmsg = msg.str();
1779  Warning(PadnHit[side], i, nhitPmt[1][side][i], 1, wmsg);
1780  wmsg.erase();
1781  msg.str("");
1782  }
1783  }
1784  }
1785  }
1786  // if ( nhit[0] == 0 )
1787  // Warning( PadnHit[side], 1, 0, 1, "No Event" );
1788  // if ( nhit[1] == 0 )
1789  // Warning( PadnHit[side], 1, 0, 1, "No Laser Event" );
1790  }
1791 
1792  PadnHitStatus->cd();
1793  TextnHitStatus->Draw();
1794  }
1795 
1796  // std::cout << "Got Histgram Got-Pad 0" << std::endl;
1797 
1798  // ------------------------------------------------------------------------
1799  // Draw 4th Page
1800  // ------------------------------------------------------------------------
1801  bbcStyle->cd();
1802  if (TC[3])
1803  {
1804  PadTop[3]->cd();
1805  PaveTop->Draw();
1806  TextTop->Draw();
1807 
1808  for (int side = 0; side < nSIDE; side++)
1809  {
1810  PadHitTime[side]->cd();
1811 
1812  HitTime[side]->Draw();
1813  float rangemin;
1814  float rangemax;
1815  int npeak = tspec->Search(HitTime[side], 2, "goff"); // finds the highest peak, draws marker
1816  if (npeak < 3) // no center peak
1817  {
1819  HitTime[side]->Fit(FitHitTime[side]->GetName(), "QRNL");
1820  rangemax = std::min(bbc_onlmon::TDC_FIT_MAX,
1821  FitHitTime[side]->GetParameter(1) + FitHitTime[side]->GetParameter(2));
1822  rangemin = std::max(bbc_onlmon::TDC_FIT_MIN,
1823  FitHitTime[side]->GetParameter(1) - FitHitTime[side]->GetParameter(2));
1824  }
1825  else
1826  {
1827  double *peakpos = tspec->GetPositionX();
1828  float centerpeak = peakpos[0];
1829  float sidepeak[2];
1830  if (peakpos[2] > peakpos[1])
1831  {
1832  sidepeak[0] = peakpos[1];
1833  sidepeak[1] = peakpos[2];
1834  }
1835  else
1836  {
1837  sidepeak[1] = peakpos[1];
1838  sidepeak[0] = peakpos[2];
1839  }
1840  rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
1841  rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
1842  }
1843 
1844  FitHitTime[side]->SetRange(rangemin, rangemax);
1845 
1846  HitTime[side]->Fit(FitHitTime[side]->GetName(), "QRL");
1847  float height = HitTime[side]->GetMaximum();
1848  FitHitTime[side]->Draw("same");
1849 
1850  LineHitTime[side][1]->SetY2(height);
1851  LineHitTime[side][0]->SetY2(height);
1852  ArrowHitTime[side]->SetY1(height * 0.90);
1853  ArrowHitTime[side]->SetY2(height * 0.90);
1854  TextHitTime[side]->SetY(height * 0.88);
1855  LineHitTime[side][0]->Draw();
1856  LineHitTime[side][1]->Draw();
1857  ArrowHitTime[side]->Draw();
1858  TextHitTime[side]->Draw();
1859  }
1860  // PadWarnings->cd();
1861  // PaveWarnings->Draw();
1862 
1863  if (PadZvtx)
1864  {
1865  PadZvtx->cd();
1866  Zvtx->Draw();
1867  Zvtx->Fit("FitZvtx", "QN0L");
1868  FitZvtx->SetRange(FitZvtx->GetParameter(1) - FitZvtx->GetParameter(2) * 2,
1869  FitZvtx->GetParameter(1) + FitZvtx->GetParameter(2) * 2);
1870  Zvtx->Fit("FitZvtx", "QRL");
1871  FitZvtx->Draw("same");
1872 
1873  float height = Zvtx->GetMaximum();
1874  FitZvtx->Draw("same");
1875 
1876  LineZvtx[1]->SetY2(height);
1877  LineZvtx[0]->SetY2(height);
1878  ArrowZvtx->SetY1(height * 0.90);
1879  ArrowZvtx->SetY2(height * 0.90);
1880  TextZvtx->SetY(height * 0.88);
1881  LineZvtx[0]->Draw();
1882  LineZvtx[1]->Draw();
1883  ArrowZvtx->Draw();
1884  TextZvtx->Draw();
1885  TextZvtxNorth->Draw();
1886  TextZvtxSouth->Draw();
1887  }
1888 
1889  if (PadChargeSum)
1890  {
1891  PadChargeSum->cd();
1892  NorthChargeSum->SetLineColor(4);
1893  SouthChargeSum->SetLineColor(2);
1894  NorthChargeSum->Draw();
1895  SouthChargeSum->Draw("same");
1896 
1897  // float height = NorthChargeSum->GetMaximum();
1898  // TextNorthChargeSum->SetY( height*0.88);
1899  // TextSouthChargeSum->SetY( height*0.88);
1900  TextNorthChargeSum->SetTextColor(4);
1901  TextSouthChargeSum->SetTextColor(2);
1902  TextNorthChargeSum->Draw();
1903  TextSouthChargeSum->Draw();
1904  }
1905 
1906  if (PadAdc)
1907  {
1908  PadAdc->cd();
1909  Adc->Draw("colz");
1910  }
1911  } // TC[3]
1912 
1913  if (TC[0])
1914  {
1915  TC[0]->Update();
1916  }
1917  if (TC[1])
1918  {
1919  TC[1]->Update();
1920  }
1921  if (TC[2])
1922  {
1923  TC[2]->Update();
1924  }
1925  if (TC[3])
1926  {
1927  TC[3]->Update();
1928  }
1929 
1930  // std::cout << "Got Histgram Got-Pad 1" << std::endl;
1931 
1932  oldStyle->cd();
1933 
1934  //******************************************
1935  int iret = 0;
1936  // int idraw = 0;
1937  /*
1938  if (what == "ALL" || what == "FIRST")
1939  {
1940  iret += DrawFirst(what);
1941  idraw++;
1942  }
1943  if (what == "ALL" || what == "SECOND")
1944  {
1945  iret += DrawSecond(what);
1946  idraw++;
1947  }
1948  if (what == "ALL" || what == "HISTORY")
1949  {
1950  iret += DrawHistory(what);
1951  // idraw++;
1952  }
1953  */
1954 
1955  /*
1956  if (!idraw)
1957  {
1958  std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
1959  iret = -1;
1960  }
1961  */
1962 
1963  //******************************************
1964  return iret;
1965 }
1966 
1968 {
1969  PRINT_DEBUG("In BbcMonDraw::DrawFirst()");
1971  TH1 *bbcmon_hist1 = cl->getHisto("BBCMON_0","bbc_zvertex");
1972  TH2 *bbcmon_hist2 = (TH2*)cl->getHisto("BBCMON_0","bbc_tzero_zvtx");
1973 
1974  if (!gROOT->FindObject("BbcMon1"))
1975  {
1976  MakeCanvas("BbcMon1");
1977  }
1978  TC[0]->SetEditable(1);
1979  TC[0]->Clear("D");
1980  Pad[0]->cd();
1981  if (bbcmon_hist1)
1982  {
1983  bbcmon_hist1->DrawCopy();
1984  }
1985  else
1986  {
1988  TC[0]->SetEditable(0);
1989  return -1;
1990  }
1991 
1992  Pad[1]->cd();
1993  if (bbcmon_hist2)
1994  {
1995  bbcmon_hist2->DrawCopy();
1996  }
1997  TText PrintRun;
1998  PrintRun.SetTextFont(62);
1999  PrintRun.SetTextSize(0.04);
2000  PrintRun.SetNDC(); // set to normalized coordinates
2001  PrintRun.SetTextAlign(23); // center/top alignment
2002  std::ostringstream runnostream;
2003  std::string runstring;
2004  time_t evttime = cl->EventTime("CURRENT");
2005  // fill run number and event time into string
2006  runnostream << ThisName << "_1 Run " << cl->RunNumber()
2007  << ", Time: " << ctime(&evttime);
2008  runstring = runnostream.str();
2009  transparent[0]->cd();
2010  PrintRun.DrawText(0.5, 1., runstring.c_str());
2011  TC[0]->Update();
2012  TC[0]->Show();
2013  TC[0]->SetEditable(0);
2014  return 0;
2015 }
2016 
2018 {
2019  PRINT_DEBUG("In BbcMonDraw::DrawSecond()");
2020 
2022  TH1 *bbcmon_hist1 = cl->getHisto("BBCMON_0","bbc_zvertex");
2023  TH2 *bbcmon_hist2 = (TH2*)cl->getHisto("BBCMON_0","bbc_tzero_zvtx");
2024  if (!gROOT->FindObject("BbcMon2"))
2025  {
2026  MakeCanvas("BbcMon2");
2027  }
2028  TC[1]->SetEditable(1);
2029  TC[1]->Clear("D");
2030  Pad[2]->cd();
2031  if (bbcmon_hist1)
2032  {
2033  bbcmon_hist1->DrawCopy();
2034  }
2035  else
2036  {
2038  TC[1]->SetEditable(0);
2039  return -1;
2040  }
2041  Pad[3]->cd();
2042  if (bbcmon_hist2)
2043  {
2044  bbcmon_hist2->DrawCopy();
2045  }
2046  TText PrintRun;
2047  PrintRun.SetTextFont(62);
2048  PrintRun.SetTextSize(0.04);
2049  PrintRun.SetNDC(); // set to normalized coordinates
2050  PrintRun.SetTextAlign(23); // center/top alignment
2051  std::ostringstream runnostream;
2052  std::string runstring;
2053  time_t evttime = cl->EventTime("CURRENT");
2054 
2055  // fill run number and event time into string
2056  runnostream << ThisName << "_2 Run " << cl->RunNumber()
2057  << ", Time: " << ctime(&evttime);
2058  runstring = runnostream.str();
2059  transparent[1]->cd();
2060  PrintRun.DrawText(0.5, 1., runstring.c_str());
2061  TC[1]->Update();
2062  TC[1]->Show();
2063  TC[1]->SetEditable(0);
2064  return 0;
2065 }
2066 
2068 {
2069 
2071  int iret = Draw(what);
2072  if (iret) // on error no png files please
2073  {
2074  return iret;
2075  }
2076  int icnt = 0;
2077  for (TCanvas *canvas : TC)
2078  {
2079  if (canvas == nullptr)
2080  {
2081  continue;
2082  }
2083  icnt++;
2084  std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
2085  std::to_string(cl->RunNumber()) + "." + type;
2086  cl->CanvasToPng(canvas, filename);
2087  }
2088  return 0;
2089 }
2090 
2092 {
2093  int iret = Draw(what);
2094  if (iret) // on error no html output please
2095  {
2096  return iret;
2097  }
2098 
2100 
2101  int icnt = 0;
2102  for (TCanvas *canvas : TC)
2103  {
2104  if (canvas == nullptr)
2105  {
2106  continue;
2107  }
2108  icnt++;
2109  // Register the canvas png file to the menu and produces the png file.
2110  std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
2111  cl->CanvasToPng(canvas, pngfile);
2112  }
2113 
2114  // Now register also EXPERTS html pages, under the EXPERTS subfolder.
2115  // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
2116  // std::ofstream out(logfile.c_str());
2117  // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
2118  // << "</TITLE></HEAD>" << std::endl;
2119  // out << "<P>Some log file output would go here." << std::endl;
2120  // out.close();
2121 
2122  // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
2123  // std::ofstream out2(status.c_str());
2124  // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
2125  // << "</TITLE></HEAD>" << std::endl;
2126  // out2 << "<P>Some status output would go here." << std::endl;
2127  // out2.close();
2128 
2129  // cl->SaveLogFile(*this);
2130 
2131  return 0;
2132 }
2133 
2134 int BbcMonDraw::DrawHistory(const std::string & /* what */)
2135 {
2136  // you need to provide the following vectors
2137  // which are filled from the db
2138  std::vector<float> var;
2139  std::vector<float> varerr;
2140  std::vector<time_t> timestamp;
2141  /*chiu
2142  std::vector<int> runnumber;
2143  //std::string varname = "bbcmondummy";
2144  // this sets the time range from whihc values should be returned
2145  time_t begin = 0; // begin of time (1.1.1970)
2146  time_t end = time(nullptr); // current time (right NOW)
2147  int iret = dbvars->GetVar(begin, end, varname, timestamp, runnumber, var, varerr);
2148  if (iret)
2149  {
2150  std::cout << __PRETTY_FUNCTION__ << " Error in db access" << std::endl;
2151  return iret;
2152  }
2153  */
2154  if (!gROOT->FindObject("BbcMon3"))
2155  {
2156  MakeCanvas("BbcMon3");
2157  }
2158  // timestamps come sorted in ascending order
2159  float *x = new float[var.size()];
2160  float *y = new float[var.size()];
2161  float *ex = new float[var.size()];
2162  float *ey = new float[var.size()];
2163  // int n = var.size();
2164  for (unsigned int i = 0; i < var.size(); i++)
2165  {
2166  // std::cout << "timestamp: " << ctime(&timestamp[i])
2167  // << ", run: " << runnumber[i]
2168  // << ", var: " << var[i]
2169  // << ", varerr: " << varerr[i]
2170  // << std::endl;
2171  x[i] = timestamp[i] - TimeOffsetTicks;
2172  y[i] = var[i];
2173  ex[i] = 0;
2174  ey[i] = varerr[i];
2175  }
2176 
2177  /* need to implement history for BBC
2178  Pad[4]->cd(); // neeed to fix
2179  if (gr[0])
2180  {
2181  delete gr[0];
2182  }
2183  gr[0] = new TGraphErrors(n, x, y, ex, ey);
2184  gr[0]->SetMarkerColor(4);
2185  gr[0]->SetMarkerStyle(21);
2186  gr[0]->Draw("ALP");
2187  gr[0]->GetXaxis()->SetTimeDisplay(1);
2188  gr[0]->GetXaxis()->SetLabelSize(0.03);
2189  // the x axis labeling looks like crap
2190  // please help me with this, the SetNdivisions
2191  // don't do the trick
2192  gr[0]->GetXaxis()->SetNdivisions(-1006);
2193  gr[0]->GetXaxis()->SetTimeOffset(TimeOffsetTicks);
2194  gr[0]->GetXaxis()->SetTimeFormat("%Y/%m/%d %H:%M");
2195  */
2196  delete[] x;
2197  delete[] y;
2198  delete[] ex;
2199  delete[] ey;
2200 
2201  /*chiu
2202  varname = "bbcmoncount";
2203  iret = dbvars->GetVar(begin, end, varname, timestamp, runnumber, var, varerr);
2204  if (iret)
2205  {
2206  std::cout << __PRETTY_FUNCTION__ << " Error in db access" << std::endl;
2207  return iret;
2208  }
2209  */
2210  x = new float[var.size()];
2211  y = new float[var.size()];
2212  ex = new float[var.size()];
2213  ey = new float[var.size()];
2214  // n = var.size();
2215  for (unsigned int i = 0; i < var.size(); i++)
2216  {
2217  // std::cout << "timestamp: " << ctime(&timestamp[i])
2218  // << ", run: " << runnumber[i]
2219  // << ", var: " << var[i]
2220  // << ", varerr: " << varerr[i]
2221  // << std::endl;
2222  x[i] = timestamp[i] - TimeOffsetTicks;
2223  y[i] = var[i];
2224  ex[i] = 0;
2225  ey[i] = varerr[i];
2226  }
2227 
2228  /* Need to implement
2229  Pad[5]->cd();
2230  if (gr[1])
2231  {
2232  delete gr[1];
2233  }
2234  gr[1] = new TGraphErrors(n, x, y, ex, ey);
2235  gr[1]->SetMarkerColor(4);
2236  gr[1]->SetMarkerStyle(21);
2237  gr[1]->Draw("ALP");
2238  gr[1]->GetXaxis()->SetTimeDisplay(1);
2239  // TC[2]->Update();
2240  // h1->GetXaxis()->SetTimeDisplay(1);
2241  // h1->GetXaxis()->SetLabelSize(0.03);
2242  gr[1]->GetXaxis()->SetLabelSize(0.03);
2243  gr[1]->GetXaxis()->SetTimeOffset(TimeOffsetTicks);
2244  gr[1]->GetXaxis()->SetTimeFormat("%Y/%m/%d %H:%M");
2245  // h1->Draw();
2246  */
2247 
2248  delete[] x;
2249  delete[] y;
2250  delete[] ex;
2251  delete[] ey;
2252 
2253  TC[2]->Update();
2254  return 0;
2255 }
2256 
2257 int BbcMonDraw::DrawDeadServer(TPad *transparent_pad)
2258 {
2259  transparent_pad->cd();
2260  TText FatalMsg;
2261  FatalMsg.SetTextFont(62);
2262  FatalMsg.SetTextSize(0.1);
2263  FatalMsg.SetTextColor(4);
2264  FatalMsg.SetNDC(); // set to normalized coordinates
2265  FatalMsg.SetTextAlign(23); // center/top alignment
2266  FatalMsg.DrawText(0.5, 0.9, "BBCMONITOR");
2267  FatalMsg.SetTextAlign(22); // center/center alignment
2268  FatalMsg.DrawText(0.5, 0.5, "SERVER");
2269  FatalMsg.SetTextAlign(21); // center/bottom alignment
2270  FatalMsg.DrawText(0.5, 0.1, "DEAD");
2271  transparent_pad->Update();
2272  return 0;
2273 }
2274 
2275