Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HcalMonDraw.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HcalMonDraw.cc
1 #include "HcalMonDraw.h"
2 
3 #include <onlmon/OnlMonClient.h>
4 
5 #include <TAxis.h> // for TAxis
6 #include <TButton.h>
7 #include <TCanvas.h>
8 #include <TGraphErrors.h>
9 #include <TH1.h>
10 #include <TH2.h>
11 #include <TH2D.h>
12 #include <TLegend.h>
13 #include <TLine.h>
14 #include <TPad.h>
15 #include <TProfile.h>
16 #include <TQObject.h>
17 #include <TROOT.h>
18 #include <TStyle.h>
19 #include <TSystem.h>
20 #include <TText.h>
21 
22 #include <cstring> // for memset
23 #include <ctime>
24 #include <fstream>
25 #include <iostream> // for operator<<, basic_ostream, basic_os...
26 #include <sstream>
27 #include <vector> // for vector
28 
30  : OnlMonDraw(name)
31 {
32  // if name start with O prefix = "OHCALMON"
33  // if name start with I prefix = "IHCALMON"
34  if (ThisName[0] == 'O')
35  {
36  prefix = "OHCALMON";
37  }
38  else if (ThisName[0] == 'I')
39  {
40  prefix = "IHCALMON";
41  }
42  else
43  {
44  std::cout << "HcalMonDraw::HcalMonDraw() ERROR: name does not start with O or I " << ThisName << std::endl;
45  exit(1);
46  }
47  return;
48 }
49 
51 {
52  hcalStyle = new TStyle("hcalStyle", "hcalStyle");
53 
54  Int_t font = 42; // Helvetica
55  hcalStyle->SetLabelFont(font, "x");
56  hcalStyle->SetTitleFont(font, "x");
57  hcalStyle->SetLabelFont(font, "y");
58  hcalStyle->SetTitleFont(font, "y");
59  hcalStyle->SetLabelFont(font, "z");
60  hcalStyle->SetTitleFont(font, "z");
61  hcalStyle->SetOptStat(0);
62  hcalStyle->SetPadTickX(1);
63  hcalStyle->SetPadTickY(1);
64  gROOT->SetStyle("hcalStyle");
65  gROOT->ForceStyle();
66 
67  return 0;
68 }
69 
71 {
73  int xsize = cl->GetDisplaySizeX();
74  int ysize = cl->GetDisplaySizeY();
75  if (name == "HcalMon1")
76  {
77  // xpos (-1) negative: do not draw menu bar
78  TC[0] = new TCanvas(name.c_str(), "Hcal Towers", xsize / 3, 0, xsize / 3, ysize * 0.9);
79  // root is pathetic, whenever a new TCanvas is created root piles up
80  // 6kb worth of X11 events which need to be cleared with
81  // gSystem->ProcessEvents(), otherwise your process will grow and
82  // grow and grow but will not show a definitely lost memory leak
83  gSystem->ProcessEvents();
84  Pad[0] = new TPad("hist", "On the top", 0., 0.2, 1., 1.);
85  Pad[0]->Draw();
86  // Pad[1]->Draw();
87  // this one is used to plot the run number on the canvas
88  transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
89  transparent[0]->SetFillStyle(4000);
90  transparent[0]->Draw();
91 
92  // warning
93  warning[0] = new TPad("warning0", "this does not show", 0, 0, 0.9, 0.2);
94  warning[0]->SetFillStyle(4000);
95  warning[0]->Draw();
96 
97  TC[0]->SetEditable(0);
98  }
99  else if (name == "HcalMon2")
100  {
101  // xpos negative: do not draw menu bar
102  TC[1] = new TCanvas(name.c_str(), "Hcal Sector Running Mean", xsize / 3, 0, xsize / 3, ysize * 0.9);
103  gSystem->ProcessEvents();
104  Pad[2] = new TPad("hcalpad3", "who needs this?", 0.0, 0.0, 1, 0.92, 0);
105  // Pad[3] = new TPad("hcalpad4", "who needs this?", 0.1, 0.05, 0.9, 0.45, 0);
106  Pad[2]->Draw();
107  // Pad[3]->Draw();
108  // this one is used to plot the run number on the canvas
109  transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
110  transparent[1]->SetFillStyle(4000);
111  transparent[1]->Draw();
112  TC[1]->SetEditable(0);
113  }
114  else if (name == "HcalMon3")
115  {
116  TC[3] = new TCanvas(name.c_str(), "HcalMon3 Waveform Info", xsize / 3, 0, xsize / 3, ysize * 0.9);
117  gSystem->ProcessEvents();
118  Pad[6] = new TPad("hcalpad6", "who needs this?", 0.0, 0.6, 1.0, 0.95, 0);
119  Pad[7] = new TPad("hcalpad7", "who needs this?", 0.0, 0.3, 1.0, 0.6, 0);
120  Pad[8] = new TPad("hcalpad8", "who needs this?", 0.0, 0.0, 1.0, 0.3, 0);
121  Pad[6]->Draw();
122  Pad[7]->Draw();
123  Pad[8]->Draw();
124  // this one is used to plot the run number on the canvas
125  transparent[3] = new TPad("transparent3", "this does not show", 0, 0, 1, 1);
126  transparent[3]->SetFillStyle(4000);
127  transparent[3]->Draw();
128  TC[3]->SetEditable(0);
129  }
130  else if (name == "HcalMon4")
131  {
132  // xpos negative: do not draw menu bar
133  TC[5] = new TCanvas(name.c_str(), "HCAL Packet Information", 2 * xsize / 3, 0, 2 * xsize / 3, ysize * 0.9);
134  gSystem->ProcessEvents();
135  Pad[10] = new TPad("pad10", "packet event check", 0.0, 0.6, 1.0 / 2, 0.95, 0);
136  Pad[11] = new TPad("pad11", "packet size", 0.0, 0.3, 1.0 / 2, 0.6, 0);
137  Pad[12] = new TPad("pad12", "packet channels", 0.0, 0.0, 1.0 / 2, 0.3, 0);
138  Pad[13] = new TPad("pad13", "event number offset", 0.5, 0.6, 1.0, 0.95, 0);
139  // pad 14 and 15 side by side from left to right for correlation
140  Pad[14] = new TPad("pad14", "correlation0", 0.5, 0.3, 0.75, 0.6, 0);
141  Pad[15] = new TPad("pad15", "correlation1", 0.75, 0.3, 1.0, 0.6, 0);
142 
143  Pad[10]->Draw();
144  Pad[11]->Draw();
145  Pad[12]->Draw();
146  Pad[13]->Draw();
147  Pad[14]->Draw();
148  Pad[15]->Draw();
149  // this one is used to plot the run number on the canvas
150  transparent[5] = new TPad("transparent1", "this does not show", 0, 0, 1., 1);
151  transparent[5]->SetFillStyle(4000);
152  transparent[5]->Draw();
153 
154  // packet warnings
155  warning[1] = new TPad("warning1", "packet warnings", 0.5, 0, 1, 0.2);
156  warning[1]->SetFillStyle(4000);
157  warning[1]->Draw();
158  TC[5]->SetEditable(0);
159  }
160  else if (name == "HcalMon5")
161  {
162  TC[6] = new TCanvas(name.c_str(), "HcalMon5 Trigger Info", xsize / 2, 0, xsize / 2, ysize * 0.9);
163  gSystem->ProcessEvents();
164  Pad[16] = new TPad("hcalpad16", "who needs this?", 0.0, 0.3, 0.5, 0.95, 0);
165  Pad[17] = new TPad("hcalpad17", "who needs this?", 0.5, 0.3, 1.0, 0.90, 0);
166  Pad[18] = new TPad("hcalpad18", "who needs this?", 0.0, 0.0, 1.0, 0.3, 0);
167  Pad[16]->Draw();
168  Pad[17]->Draw();
169  Pad[18]->Draw();
170  // this one is used to plot the run number on the canvas
171  transparent[6] = new TPad("transparent6", "this does not show", 0, 0, 1, 1);
172  transparent[6]->SetFillStyle(4000);
173  transparent[6]->Draw();
174  TC[6]->SetEditable(0);
175  }
176  else if (name == "HcalPopUp")
177  {
178  TC[4] = new TCanvas(name.c_str(), "!!!DO NOT CLOSE!!! OR THE CODE WILL CRASH!!!!", 2 * xsize / 3, 0.05, xsize / 2, 2 * ysize / 3);
179  gSystem->ProcessEvents();
180  Pad[9] = new TPad("hcalpad9", "for single tower running mean", 0.0, 0.0, 1, 0.92, 0);
181  Pad[9]->Draw();
182  transparent[4] = new TPad("transparent4", "this does not show", 0, 0, 1, 1);
183  transparent[4]->SetFillStyle(4000);
184  transparent[4]->Draw();
185  TC[4]->SetEditable(0);
186  }
187  return 0;
188 }
189 
191 {
192  int iret = 0;
193  int idraw = 0;
194  if (what == "ALL" || what == "FIRST")
195  {
196  iret += DrawFirst(what);
197  idraw++;
198  }
199  if (what == "ALL" || what == "SECOND")
200  {
201  iret += DrawSecond(what);
202  idraw++;
203  }
204  if (what == "ALL" || what == "THIRD")
205  {
206  iret += DrawThird(what);
207  idraw++;
208  }
209  if (what == "ALL" || what == "FOURTH")
210  {
211  iret += DrawFourth(what);
212  idraw++;
213  }
214  if (what == "ALL" || what == "FIFTH")
215  {
216  iret += DrawFifth(what);
217  idraw++;
218  }
219  if (!idraw)
220  {
221  std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
222  iret = -1;
223  }
224  return iret;
225 }
226 
227 int HcalMonDraw::DrawFirst(const std::string& /* what */)
228 {
230 
231  char HCALMON_0[100];
232  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
233  char HCALMON_1[100];
234  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
235 
236  TH2D* hist1 = (TH2D*) cl->getHisto(HCALMON_0, "h2_hcal_rm");
237  TH2F* h2_hcal_mean = (TH2F*) cl->getHisto(HCALMON_0, "h2_hcal_mean");
238  TH1F* h_event = (TH1F*) cl->getHisto(HCALMON_0, "h_event");
239  TH2F* h2_hcal_hits = (TH2F*) cl->getHisto(HCALMON_0, "h2_hcal_hits");
240  TH2F* hist1_1 = (TH2F*) cl->getHisto(HCALMON_1, "h2_hcal_rm");
241  TH2F* h2_hcal_mean_1 = (TH2F*) cl->getHisto(HCALMON_1, "h2_hcal_mean");
242  TH1D* h_event_1 = (TH1D*) cl->getHisto(HCALMON_1, "h_event");
243  TH2F* h2_hcal_hits_1 = (TH2F*) cl->getHisto(HCALMON_1, "h2_hcal_hits");
244 
245  if (!gROOT->FindObject("HcalMon1"))
246  {
247  MakeCanvas("HcalMon1");
248  }
249  if (!hist1)
250  {
252  TC[0]->SetEditable(0);
253  return -1;
254  }
255 
256  h2_hcal_mean->Scale(1. / h_event->GetEntries());
257  h2_hcal_hits->Scale(1. / h_event->GetEntries());
258  hist1->Divide(h2_hcal_mean);
259 
260  h2_hcal_mean_1->Scale(1. / h_event_1->GetEntries());
261  h2_hcal_hits_1->Scale(1. / h_event_1->GetEntries());
262  hist1_1->Divide(h2_hcal_mean_1);
263 
264  hist1->Add(hist1_1);
265  h2_hcal_mean->Add(h2_hcal_mean_1);
266  h2_hcal_hits->Add(h2_hcal_hits_1);
267  // h_event->Add(h_event_1);
268 
269  // h2_hcal_mean->Scale(1. / h_event->GetEntries());
270  // hist1->Divide(h2_hcal_mean);
271 
272  TC[0]->SetEditable(1);
273  TC[0]->Clear("D");
274  Pad[0]->cd();
275 
276  hist1->GetXaxis()->SetTitle("eta index");
277  hist1->GetYaxis()->SetTitle("phi index");
278  hist1->GetXaxis()->CenterTitle();
279  hist1->GetYaxis()->CenterTitle();
280  hist1->GetXaxis()->SetNdivisions(24);
281  hist1->GetYaxis()->SetNdivisions(232);
282 
283  float tsize = 0.025;
284  hist1->GetXaxis()->SetLabelSize(tsize);
285  hist1->GetYaxis()->SetLabelSize(tsize);
286  hist1->GetZaxis()->SetLabelSize(tsize);
287  hist1->GetXaxis()->SetTitleSize(tsize);
288  hist1->GetYaxis()->SetTitleSize(tsize);
289  hist1->GetXaxis()->SetTickLength(0.02);
290 
291  hist1->GetZaxis()->SetRangeUser(0, 2);
292 
293  TLine* line_sector[32];
294  for (int i_line = 0; i_line < 32; i_line++)
295  {
296  line_sector[i_line] = new TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
297  line_sector[i_line]->SetLineColor(1);
298  line_sector[i_line]->SetLineWidth(4);
299  line_sector[i_line]->SetLineStyle(1);
300  }
301  TLine* line_board1 = new TLine(8, 0, 8, 64);
302  line_board1->SetLineColor(1);
303  line_board1->SetLineWidth(4);
304  line_board1->SetLineStyle(1);
305  TLine* line_board2 = new TLine(16, 0, 16, 64);
306  line_board2->SetLineColor(1);
307  line_board2->SetLineWidth(4);
308  line_board2->SetLineStyle(1);
309 
310  TLine* line_iphi[64];
311  for (int i_line = 0; i_line < 64; i_line++)
312  {
313  line_iphi[i_line] = new TLine(0, (i_line + 1), 24, (i_line + 1));
314  line_iphi[i_line]->SetLineColor(1);
315  line_iphi[i_line]->SetLineWidth(1);
316  line_iphi[i_line]->SetLineStyle(1);
317  }
318  TLine* line_ieta[64];
319  for (int i_line = 0; i_line < 24; i_line++)
320  {
321  line_ieta[i_line] = new TLine((i_line + 1), 0, (i_line + 1), 64);
322  line_ieta[i_line]->SetLineColor(1);
323  line_ieta[i_line]->SetLineWidth(1);
324  line_ieta[i_line]->SetLineStyle(1);
325  }
326 
327  gPad->SetTopMargin(0.08);
328  gPad->SetBottomMargin(0.07);
329  gPad->SetLeftMargin(0.08);
330  gPad->SetRightMargin(0.11);
331 
332  hist1->Draw("colz");
333  for (int i_line = 0; i_line < 32; i_line++)
334  {
335  line_sector[i_line]->Draw();
336  }
337  line_board1->Draw();
338  line_board2->Draw();
339 
340  for (int i_line = 0; i_line < 64; i_line++)
341  {
342  line_iphi[i_line]->Draw();
343  }
344  for (int i_line = 0; i_line < 24; i_line++)
345  {
346  line_ieta[i_line]->Draw();
347  }
348 
349  Int_t palette[3] = {1, 8, 2};
350  hcalStyle->SetPalette(3, palette);
351  gROOT->SetStyle("hcalStyle");
352  gROOT->ForceStyle();
353  gStyle->SetPalette(3, palette);
354  double_t levels[4] = {0, 0.9, 1.1, 2};
355  hist1->SetContour(4, levels);
356 
357  FindHotTower(warning[0], hist1);
358  TText PrintRun;
359  PrintRun.SetTextFont(62);
360  PrintRun.SetTextSize(0.03);
361  PrintRun.SetNDC(); // set to normalized coordinates
362  PrintRun.SetTextAlign(23); // center/top alignment
363  std::ostringstream runnostream;
364  std::ostringstream runnostream2;
365  std::string runstring;
366  time_t evttime = getTime();
367  // fill run number and event time into string
368  runnostream << ThisName << ": tower running mean divided by template";
369  runnostream2 << "Run" << cl->RunNumber() << ", Time: " << ctime(&evttime);
370  transparent[0]->cd();
371  runstring = runnostream.str();
372  PrintRun.DrawText(0.5, 0.99, runstring.c_str());
373  runstring = runnostream2.str();
374  PrintRun.DrawText(0.5, 0.966, runstring.c_str());
375  // make a TButton at bottom left to pop up a window with average ADC for all tower
376  TButton* but1 = new TButton("Draw Template", "", 0.01, 0.01, 0.5, 0.05);
377  but1->SetName("avgenergy");
378  TC[0]->cd();
379  but1->Draw();
380  TButton* but2 = new TButton("Draw Multiplicity", "", 0.51, 0.01, 0.99, 0.05);
381  but2->SetName("hitmap");
382  but2->Draw();
383 
384  // this connects the clicks on TCavas to the HandleEvent method that makes a pop up window
385  // and display the running mean history of the tower correponding to the bin you click on
386  TC[0]->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HcalMonDraw", this,
387  "HandleEvent(int,int,int,TObject*)");
388 
389  TC[0]->Update();
390  TC[0]->Show();
391 
392  TC[0]->SetEditable(0);
393 
394  // TC[0]->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TCanvas", TC[0],
395  // "Paint()");
396  return 0;
397 }
398 
399 int HcalMonDraw::DrawSecond(const std::string& /* what */)
400 {
401  const int Nsector = 32;
403 
404  char HCALMON_0[100];
405  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
406  char HCALMON_1[100];
407  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
408 
409  TH1F* h_sectorAvg_total = (TH1F*) cl->getHisto(HCALMON_0, "h_sectorAvg_total");
410  TH1F* h_event = (TH1F*) cl->getHisto(HCALMON_0, "h_event");
411  TH1F* h_sectorAvg_total_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_sectorAvg_total");
412  TH1F* h_event_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_event");
413  TH1F* h_rm_sectorAvg[Nsector];
414  TH1F* h_rm_sectorAvg_1[Nsector];
415  for (int ih = 0; ih < Nsector; ih++)
416  {
417  h_rm_sectorAvg[ih] = (TH1F*) cl->getHisto(HCALMON_0, Form("h_rm_sectorAvg_s%d", ih));
418  h_rm_sectorAvg_1[ih] = (TH1F*) cl->getHisto(HCALMON_1, Form("h_rm_sectorAvg_s%d", ih));
419  h_rm_sectorAvg[ih]->Add(h_rm_sectorAvg_1[ih]);
420  }
421 
422  if (!gROOT->FindObject("HcalMon2"))
423  {
424  MakeCanvas("HcalMon2");
425  }
426 
427  TC[1]->SetEditable(1);
428  TC[1]->Clear("D");
429  Pad[2]->cd();
430  if (!h_rm_sectorAvg[0] || !h_event || !h_sectorAvg_total)
431  {
433  TC[1]->SetEditable(0);
434  return -1;
435  }
436 
437  h_sectorAvg_total->Scale(1. / h_event->GetEntries());
438  h_sectorAvg_total_1->Scale(1. / h_event_1->GetEntries());
439  h_sectorAvg_total->Add(h_sectorAvg_total_1);
440 
441  for (int ih = 0; ih < Nsector; ih++)
442  {
443  h_rm_sectorAvg[ih]->Scale(1. / h_sectorAvg_total->GetBinContent(ih + 1));
444  for (int ib = 1; ib < h_rm_sectorAvg[ih]->GetNbinsX(); ib++)
445  {
446  h_rm_sectorAvg[ih]->SetBinContent(ib, ih + h_rm_sectorAvg[ih]->GetBinContent(ib));
447  }
448  }
449 
450  gStyle->SetTitleFontSize(0.03);
451 
452  gStyle->SetOptStat(0);
453 
454  TH1F* frame = new TH1F("frame", "", 100, 0, 100);
455  frame->Draw("AXIS");
456  frame->GetXaxis()->SetTitle("time");
457  frame->GetYaxis()->SetTitle("sector running mean / template + sector #");
458  frame->GetXaxis()->CenterTitle();
459  frame->GetYaxis()->CenterTitle();
460  // frame->GetXaxis()->SetNdivisions(20);
461  // frame->GetYaxis()->SetNdivisions(232);
462  float tsize = 0.03;
463  frame->GetXaxis()->SetLabelSize(tsize);
464  frame->GetYaxis()->SetLabelSize(tsize);
465  frame->GetXaxis()->SetTitleSize(tsize);
466  frame->GetYaxis()->SetTitleSize(tsize);
467 
468  frame->GetXaxis()->SetRangeUser(0, 100);
469  frame->GetYaxis()->SetRangeUser(0, 32.75);
470 
471  gPad->SetTickx();
472  gPad->SetTicky();
473  gPad->SetTopMargin(0.01);
474 
475  for (int ih = 0; ih < Nsector; ih++)
476  {
477  h_rm_sectorAvg[ih]->Draw("same hist ][");
478  }
479 
480  TText PrintRun;
481  PrintRun.SetTextFont(62);
482  PrintRun.SetTextSize(0.03);
483  PrintRun.SetNDC(); // set to normalized coordinates
484  PrintRun.SetTextAlign(23); // center/top alignment
485  std::ostringstream runnostream;
486  std::string runstring;
487  time_t evttime = getTime();
488  // fill run number and event time into string
489  runnostream << ThisName << "_running mean, Run" << cl->RunNumber()
490  << ", Time: " << ctime(&evttime);
491  runstring = runnostream.str();
492  transparent[1]->cd();
493  PrintRun.DrawText(0.5, 1., runstring.c_str());
494  TC[1]->Update();
495  TC[1]->Show();
496  TC[1]->SetEditable(0);
497  return 0;
498 }
499 
500 int HcalMonDraw::DrawThird(const std::string& /* what */)
501 {
503 
504  char HCALMON_0[100];
505  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
506  char HCALMON_1[100];
507  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
508  // TH1F* h_waveform_twrAvg = (TH1F*) cl->getHisto(HCALMON_0, "h_waveform_twrAvg");
509  TH1F* h_waveform_time = (TH1F*) cl->getHisto(HCALMON_0, "h_waveform_time");
510  TH1F* h_waveform_pedestal = (TH1F*) cl->getHisto(HCALMON_0, "h_waveform_pedestal");
511  TH2F* h2_hcal_waveform = (TH2F*) cl->getHisto(HCALMON_0, "h2_hcal_waveform");
512  // TH1F* hwaveform_twrAvg_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_waveform_twrAvg");
513  TH1F* hwaveform_time_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_waveform_time");
514  TH1F* hwaveform_pedestal_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_waveform_pedestal");
515  TH2F* h2_hcal_waveform_1 = (TH2F*) cl->getHisto(HCALMON_1, "h2_hcal_waveform");
516 
517  if (!gROOT->FindObject("HcalMon3"))
518  {
519  MakeCanvas("HcalMon3");
520  }
521 
522  TC[3]->SetEditable(1);
523  TC[3]->Clear("D");
524  Pad[6]->cd();
525  if (!h2_hcal_waveform || !h_waveform_time || !h_waveform_pedestal)
526  {
528  TC[3]->SetEditable(0);
529  return -1;
530  }
531 
532  // h_waveform_twrAvg->Add(hwaveform_twrAvg_1);
533  h_waveform_time->Add(hwaveform_time_1);
534  h_waveform_pedestal->Add(hwaveform_pedestal_1);
535  h2_hcal_waveform->Add(h2_hcal_waveform_1);
536 
537  Pad[6]->cd();
538  gStyle->SetTitleFontSize(0.03);
539  float ymaxp = h2_hcal_waveform->ProfileX()->GetMaximum();
540  h2_hcal_waveform->GetYaxis()->SetRangeUser(0, ymaxp * 20);
541 
542  h2_hcal_waveform->Draw("colz");
543 
544  float tsize = 0.06;
545  h2_hcal_waveform->GetXaxis()->SetNdivisions(510, kTRUE);
546  h2_hcal_waveform->GetXaxis()->SetTitle("Sample #");
547  h2_hcal_waveform->GetYaxis()->SetTitle("Waveform [ADC]");
548  h2_hcal_waveform->GetXaxis()->SetLabelSize(tsize);
549  h2_hcal_waveform->GetYaxis()->SetLabelSize(tsize);
550  h2_hcal_waveform->GetXaxis()->SetTitleSize(tsize);
551  h2_hcal_waveform->GetYaxis()->SetTitleSize(tsize);
552  h2_hcal_waveform->GetXaxis()->SetTitleOffset(1.2);
553  h2_hcal_waveform->GetYaxis()->SetTitleOffset(0.75);
554  gPad->SetLogz();
555  gPad->SetBottomMargin(0.16);
556  gPad->SetLeftMargin(0.2);
557  gPad->SetRightMargin(0.05);
558  gPad->SetLeftMargin(0.15);
559  gStyle->SetOptStat(0);
560  gStyle->SetPalette(57);
561  gPad->SetTicky();
562  gPad->SetTickx();
563 
564  TText PrintRun;
565  PrintRun.SetTextFont(62);
566  PrintRun.SetTextSize(0.03);
567  PrintRun.SetNDC(); // set to normalized coordinates
568  PrintRun.SetTextAlign(23); // center/top alignment
569  std::ostringstream runnostream;
570  std::string runstring;
571  time_t evttime = getTime();
572  // fill run number and event time into string
573  runnostream << ThisName << ": Pulse fitting, Run" << cl->RunNumber()
574  << ", Time: " << ctime(&evttime);
575  runstring = runnostream.str();
576  transparent[3]->cd();
577  PrintRun.DrawText(0.5, 0.99, runstring.c_str());
578 
579  Pad[7]->cd();
580 
581  gStyle->SetTitleFontSize(0.06);
582 
583  float tsize2 = 0.08;
584  h_waveform_time->Draw("hist");
585  h_waveform_time->GetXaxis()->SetNdivisions(510, kTRUE);
586  h_waveform_time->GetXaxis()->SetTitle("Sample #");
587  h_waveform_time->GetYaxis()->SetTitle("Towers");
588  h_waveform_time->GetXaxis()->SetLabelSize(tsize2);
589  h_waveform_time->GetYaxis()->SetLabelSize(tsize2);
590  h_waveform_time->GetXaxis()->SetTitleSize(tsize2);
591  h_waveform_time->GetYaxis()->SetTitleSize(tsize2);
592  h_waveform_time->GetXaxis()->SetTitleOffset(1.0);
593  h_waveform_time->GetYaxis()->SetTitleOffset(0.85);
594  gPad->SetTopMargin(0.06);
595  gPad->SetBottomMargin(0.18);
596  gPad->SetRightMargin(0.05);
597  gPad->SetLeftMargin(0.2);
598  gStyle->SetOptStat(0);
599  gPad->SetTicky();
600  gPad->SetTickx();
601 
602  Pad[8]->cd();
603 
604  gStyle->SetTitleFontSize(0.06);
605 
606  h_waveform_pedestal->Draw("hist");
607  h_waveform_pedestal->GetXaxis()->SetNdivisions(510, kTRUE);
608  h_waveform_pedestal->GetXaxis()->SetTitle("ADC Pedistal");
609  h_waveform_pedestal->GetYaxis()->SetTitle("Towers");
610  h_waveform_pedestal->GetXaxis()->SetLabelSize(tsize2);
611  h_waveform_pedestal->GetYaxis()->SetLabelSize(tsize2);
612  h_waveform_pedestal->GetXaxis()->SetTitleSize(tsize2);
613  h_waveform_pedestal->GetYaxis()->SetTitleSize(tsize2);
614  h_waveform_pedestal->GetXaxis()->SetTitleOffset(0.9);
615  h_waveform_pedestal->GetYaxis()->SetTitleOffset(0.85);
616  gPad->SetTopMargin(0.06);
617  gPad->SetBottomMargin(0.18);
618  gPad->SetRightMargin(0.05);
619  gPad->SetLeftMargin(0.2);
620  gStyle->SetOptStat(0);
621  gPad->SetTicky();
622  gPad->SetTickx();
623 
624  TC[3]->Update();
625  TC[3]->Show();
626  TC[3]->SetEditable(0);
627 
628  return 0;
629 }
630 
631 int HcalMonDraw::DrawFourth(const std::string& /* what */)
632 {
634 
635  char HCALMON_0[100];
636  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
637  char HCALMON_1[100];
638  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
639  TH1F* h1_packet_number = (TH1F*) cl->getHisto(HCALMON_0, "h1_packet_number");
640  TH1F* h1_packet_length = (TH1F*) cl->getHisto(HCALMON_0, "h1_packet_length");
641  TH1F* h1_packet_chans = (TH1F*) cl->getHisto(HCALMON_0, "h1_packet_chans");
642  TH1F* h1_packet_event = (TH1F*) cl->getHisto(HCALMON_0, "h1_packet_event");
643  TH1F* h_event = (TH1F*) cl->getHisto(HCALMON_0, "h_event");
644  TH2F* h2_hcal_correlation = (TH2F*) cl->getHisto(HCALMON_0, "h2_hcal_correlation");
645 
646  TH1F* h1_packet_number_1 = (TH1F*) cl->getHisto(HCALMON_1, "h1_packet_number");
647  TH1F* h1_packet_length_1 = (TH1F*) cl->getHisto(HCALMON_1, "h1_packet_length");
648  TH1F* h1_packet_chans_1 = (TH1F*) cl->getHisto(HCALMON_1, "h1_packet_chans");
649  TH1F* h1_packet_event_1 = (TH1F*) cl->getHisto(HCALMON_1, "h1_packet_event");
650  TH2F* h2_hcal_correlation_1 = (TH2F*) cl->getHisto(HCALMON_1, "h2_hcal_correlation");
651  TH1F* h_event_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_event");
652 
653  if (!gROOT->FindObject("HcalMon4"))
654  {
655  MakeCanvas("HcalMon4");
656  }
657 
658  TC[5]->SetEditable(1);
659  TC[5]->Clear("D");
660 
661  if (!h1_packet_number || !h1_packet_length || !h1_packet_chans || !h_event || !h1_packet_event || !h2_hcal_correlation)
662  {
663  // print out which is not found
664  if (!h1_packet_number) std::cout << "h1_packet_number not found" << std::endl;
665  if (!h1_packet_length) std::cout << "h1_packet_length not found" << std::endl;
666  if (!h1_packet_chans) std::cout << "h1_packet_chans not found" << std::endl;
667  if (!h_event) std::cout << "h_event not found" << std::endl;
668  if (!h1_packet_event) std::cout << "h1_packet_event not found" << std::endl;
669  if (!h2_hcal_correlation) std::cout << "h2_hcal_correlation not found" << std::endl;
670 
672  TC[5]->SetEditable(0);
673  return -1;
674  }
675  // h1_packet_number->Scale(1. / h_event->GetEntries());
676  // h1_packet_length->Scale(1. / h_event->GetEntries());
677  // h1_packet_chans->Scale(1. / h_event->GetEntries());
678 
679  // h1_packet_number_1->Scale(1. / h_event_1->GetEntries());
680  // h1_packet_length_1->Scale(1. / h_event_1->GetEntries());
681  // h1_packet_chans_1->Scale(1. / h_event_1->GetEntries());
682 
683  h1_packet_number->Add(h1_packet_number_1);
684  h1_packet_length->Add(h1_packet_length_1);
685  h1_packet_chans->Add(h1_packet_chans_1);
686 
687  // int maxbin = h1_packet_event->GetMaximumBin();
688  int maxy = h1_packet_event->GetMaximum();
689  // substract all none zero bin by maxy
690  for (int i = 1; i <= h1_packet_event->GetNbinsX(); i++)
691  {
692  if (h1_packet_event->GetBinContent(i) != 0)
693  {
694  h1_packet_event->SetBinContent(i, h1_packet_event->GetBinContent(i) - maxy);
695  }
696  }
697  int maxy1 = h1_packet_event_1->GetMaximum();
698  for (int i = 1; i <= h1_packet_event_1->GetNbinsX(); i++)
699  {
700  if (h1_packet_event_1->GetBinContent(i) != 0)
701  {
702  h1_packet_event_1->SetBinContent(i, h1_packet_event_1->GetBinContent(i) - maxy1);
703  }
704  }
705 
706  /*
707  if (maxbin < 3|| maxbin > 6){
708  //substract bin 1,2 ,7 8 by maxy
709  h1_packet_event->SetBinContent(1, h1_packet_event->GetBinContent(1) - maxy);
710  h1_packet_event->SetBinContent(2, h1_packet_event->GetBinContent(2) - maxy);
711  h1_packet_event->SetBinContent(7, h1_packet_event->GetBinContent(7) - maxy);
712  h1_packet_event->SetBinContent(8, h1_packet_event->GetBinContent(8) - maxy);
713 
714  h1_packet_event_1->SetBinContent(3, h1_packet_event_1->GetBinContent(3) - maxy1);
715  h1_packet_event_1->SetBinContent(4, h1_packet_event_1->GetBinContent(4) - maxy1);
716  h1_packet_event_1->SetBinContent(5, h1_packet_event_1->GetBinContent(5) - maxy1);
717  h1_packet_event_1->SetBinContent(6, h1_packet_event_1->GetBinContent(6) - maxy1);
718  }
719  else{
720  //substract bin 3,4,5,6 by maxy
721  h1_packet_event->SetBinContent(3, h1_packet_event->GetBinContent(3) - maxy);
722  h1_packet_event->SetBinContent(4, h1_packet_event->GetBinContent(4) - maxy);
723  h1_packet_event->SetBinContent(5, h1_packet_event->GetBinContent(5) - maxy);
724  h1_packet_event->SetBinContent(6, h1_packet_event->GetBinContent(6) - maxy);
725 
726  h1_packet_event_1->SetBinContent(1, h1_packet_event_1->GetBinContent(1) - maxy1);
727  h1_packet_event_1->SetBinContent(2, h1_packet_event_1->GetBinContent(2) - maxy1);
728  h1_packet_event_1->SetBinContent(7, h1_packet_event_1->GetBinContent(7) - maxy1);
729  h1_packet_event_1->SetBinContent(8, h1_packet_event_1->GetBinContent(8) - maxy1);
730  }
731  */
732  h1_packet_event->Add(h1_packet_event_1);
733 
734  // find the x range for h1_packet_number
735  double xmin = h1_packet_number->GetXaxis()->GetXmin();
736  double xmax = h1_packet_number->GetXaxis()->GetXmax();
737 
738  TLine* one = new TLine(xmin, 1, xmax, 1);
739  one->SetLineStyle(7);
740 
741  TLine* goodSize = new TLine(xmin, 5981, xmax, 5981);
742  goodSize->SetLineStyle(7);
743 
744  TLine* goodChans = new TLine(xmin, 192, xmax, 192);
745  goodChans->SetLineStyle(7);
746 
747  // float param = 0.75;
748  float param = 0.95;
749 
750  TLegend* leg = new TLegend(0.3, 0.16, 0.95, 0.4);
751  leg->SetFillStyle(0);
752  leg->SetBorderSize(0);
753 
754  TLine* warnLineOne = new TLine(xmin, param * 1, xmax, param * 1);
755  warnLineOne->SetLineStyle(7);
756  warnLineOne->SetLineColor(2);
757 
758  leg->AddEntry(warnLineOne, "95% Threshold", "l");
759 
760  TLine* warnLineSize = new TLine(xmin, param * 5981., xmax, param * 5981.);
761  warnLineSize->SetLineStyle(7);
762  warnLineSize->SetLineColor(2);
763 
764  TLine* warnLineChans = new TLine(xmin, param * 192., xmax, param * 192.);
765  warnLineChans->SetLineStyle(7);
766  warnLineChans->SetLineColor(2);
767 
768  Pad[10]->cd();
769  float tsize = 0.08;
770  h1_packet_number->GetYaxis()->SetRangeUser(0.0, 1.3);
771  h1_packet_number->Draw("hist");
772  // std::vector<std::vector<int>> badPackets;
773  // badPackets.push_back(getBadPackets(h1_packet_number, 0, param));
774  one->Draw("same");
775  warnLineOne->Draw("same");
776  h1_packet_number->GetXaxis()->SetNdivisions(510, kTRUE);
777  h1_packet_number->GetXaxis()->SetTitle("Packet #");
778  h1_packet_number->GetYaxis()->SetTitle("% Of Events Present");
779  h1_packet_number->GetXaxis()->SetLabelSize(tsize - 0.01);
780  h1_packet_number->GetYaxis()->SetLabelSize(tsize - 0.01);
781  h1_packet_number->GetXaxis()->SetTitleSize(tsize - 0.01);
782  h1_packet_number->GetYaxis()->SetTitleSize(tsize - 0.01);
783  h1_packet_number->GetXaxis()->SetTitleOffset(1);
784  gPad->SetBottomMargin(0.16);
785  gPad->SetLeftMargin(0.16);
786  gPad->SetRightMargin(0.05);
787  gPad->SetLeftMargin(0.15);
788  gStyle->SetOptStat(0);
789  gPad->SetTicky();
790  gPad->SetTickx();
791 
792  Pad[11]->cd();
793  h1_packet_length->Draw("hist");
794  h1_packet_length->GetYaxis()->SetRangeUser(0, 6500);
795  // badPackets.push_back(getBadPackets(h1_packet_length, 1, param));
796  goodSize->Draw("same");
797  warnLineSize->Draw("same");
798  leg->Draw("same");
799  h1_packet_length->GetXaxis()->SetNdivisions(510, kTRUE);
800  h1_packet_length->GetXaxis()->SetTitle("Packet #");
801  h1_packet_length->GetYaxis()->SetTitle("Average Packet Size");
802  h1_packet_length->GetXaxis()->SetLabelSize(tsize - .01);
803  h1_packet_length->GetYaxis()->SetLabelSize(tsize);
804  h1_packet_length->GetXaxis()->SetTitleSize(tsize - .01);
805  h1_packet_length->GetYaxis()->SetTitleSize(tsize);
806  h1_packet_length->GetXaxis()->SetTitleOffset(1);
807  h1_packet_length->GetYaxis()->SetTitleOffset(0.8);
808  gPad->SetBottomMargin(0.16);
809  gPad->SetLeftMargin(0.16);
810  gPad->SetRightMargin(0.05);
811  gPad->SetLeftMargin(0.15);
812  gStyle->SetOptStat(0);
813  gPad->SetTicky();
814  gPad->SetTickx();
815 
816  Pad[12]->cd();
817  h1_packet_chans->Draw("hist");
818  h1_packet_chans->GetYaxis()->SetRangeUser(0, 212);
819  // badPackets.push_back(getBadPackets(h1_packet_chans, 2, param));
820  goodChans->Draw("same");
821  warnLineChans->Draw("same");
822  h1_packet_chans->GetXaxis()->SetNdivisions(510, kTRUE);
823  h1_packet_chans->GetXaxis()->SetTitle("Packet #");
824  h1_packet_chans->GetYaxis()->SetTitle("Average # of Channels");
825  h1_packet_chans->GetXaxis()->SetLabelSize(tsize - .01);
826  h1_packet_chans->GetYaxis()->SetLabelSize(tsize);
827  h1_packet_chans->GetXaxis()->SetTitleSize(tsize - .01);
828  h1_packet_chans->GetYaxis()->SetTitleSize(tsize);
829  h1_packet_chans->GetXaxis()->SetTitleOffset(0.8);
830  h1_packet_chans->GetYaxis()->SetTitleOffset(0.8);
831  gPad->SetBottomMargin(0.16);
832  gPad->SetLeftMargin(0.16);
833  gPad->SetRightMargin(0.05);
834  gPad->SetLeftMargin(0.15);
835  gStyle->SetOptStat(0);
836  gPad->SetTicky();
837  gPad->SetTickx();
838 
839  Pad[13]->cd();
840  h1_packet_event->Draw("hist");
841  double ymax = h1_packet_event->GetMaximum();
842  double ymin = h1_packet_event->GetMinimum();
843 
844  h1_packet_event->GetYaxis()->SetRangeUser(ymin - 0.3 * (ymax - ymin + 30), ymax + 0.3 * (ymax - ymin + 30));
845  h1_packet_event->GetXaxis()->SetTitle("Packet #");
846  h1_packet_event->GetYaxis()->SetTitle("clock offset");
847  h1_packet_event->GetXaxis()->SetLabelSize(tsize - .01);
848  h1_packet_event->GetYaxis()->SetLabelSize(tsize);
849  h1_packet_event->GetXaxis()->SetTitleSize(tsize - .01);
850  h1_packet_event->GetYaxis()->SetTitleSize(tsize);
851  h1_packet_event->GetXaxis()->SetTitleOffset(0.8);
852  h1_packet_event->GetYaxis()->SetTitleOffset(1.2);
853  gPad->SetBottomMargin(0.16);
854  gPad->SetLeftMargin(0.2);
855  gPad->SetRightMargin(0.05);
856  gPad->SetLeftMargin(0.2);
857  gStyle->SetOptStat(0);
858  gPad->SetTicky();
859  gPad->SetTickx();
860 
861  Pad[14]->cd();
862  h2_hcal_correlation->Draw("colz");
863  ymax = h2_hcal_correlation->ProfileX()->GetMaximum();
864  xmax = h2_hcal_correlation->ProfileY()->GetMaximum();
865  h2_hcal_correlation->GetYaxis()->SetRangeUser(0, ymax * 1.2);
866  h2_hcal_correlation->GetXaxis()->SetRangeUser(0, xmax * 1.2);
867  h2_hcal_correlation->GetXaxis()->SetNdivisions(510, kTRUE);
868  h2_hcal_correlation->GetYaxis()->SetNdivisions(510, kTRUE);
869  h2_hcal_correlation->GetXaxis()->SetTitle("Total West OHCal Energy[a.u.]");
870  h2_hcal_correlation->GetYaxis()->SetTitle("Total West IHCal Energy[a.u.]");
871  h2_hcal_correlation->GetXaxis()->SetLabelSize(0);
872  h2_hcal_correlation->GetYaxis()->SetLabelSize(0);
873  h2_hcal_correlation->GetXaxis()->SetTitleSize(tsize - .02);
874  h2_hcal_correlation->GetYaxis()->SetTitleSize(tsize - .02);
875  h2_hcal_correlation->GetXaxis()->SetTitleOffset(0.8);
876  h2_hcal_correlation->GetYaxis()->SetTitleOffset(0.8);
877  gPad->SetBottomMargin(0.16);
878  gPad->SetLeftMargin(0.2);
879  gPad->SetRightMargin(0.03);
880  gPad->SetLeftMargin(0.2);
881  gStyle->SetOptStat(0);
882  gPad->SetTicky();
883  gPad->SetTickx();
884 
885  Pad[15]->cd();
886  h2_hcal_correlation_1->Draw("colz");
887  ymax = h2_hcal_correlation_1->ProfileX()->GetMaximum();
888  xmax = h2_hcal_correlation_1->ProfileY()->GetMaximum();
889  h2_hcal_correlation_1->GetYaxis()->SetRangeUser(0, ymax * 1.2);
890  h2_hcal_correlation_1->GetXaxis()->SetRangeUser(0, xmax * 1.2);
891  h2_hcal_correlation_1->GetXaxis()->SetNdivisions(510, kTRUE);
892  h2_hcal_correlation_1->GetYaxis()->SetNdivisions(510, kTRUE);
893  h2_hcal_correlation_1->GetXaxis()->SetTitle("Total East OHCal Energy[a.u.]");
894  h2_hcal_correlation_1->GetYaxis()->SetTitle("Total East IHCal Energy[a.u.]");
895  h2_hcal_correlation_1->GetXaxis()->SetLabelSize(0);
896  h2_hcal_correlation_1->GetYaxis()->SetLabelSize(0);
897  h2_hcal_correlation_1->GetXaxis()->SetTitleSize(tsize - .02);
898  h2_hcal_correlation_1->GetYaxis()->SetTitleSize(tsize - .02);
899  h2_hcal_correlation_1->GetXaxis()->SetTitleOffset(0.8);
900  h2_hcal_correlation_1->GetYaxis()->SetTitleOffset(0.8);
901  gPad->SetBottomMargin(0.16);
902  gPad->SetLeftMargin(0.2);
903  gPad->SetRightMargin(0.05);
904  gPad->SetLeftMargin(0.2);
905  gStyle->SetOptStat(0);
906  gPad->SetTicky();
907  gPad->SetTickx();
908 
909 
910  // draw the warning here:
911  warning[1]->cd();
912  std::vector<int> badPackets;
913  std::vector<std::string> whatswrong;
914  for (int i = 1; i <= 8; i++)
915  {
916  bool missing = false;
917  bool badnumber = false;
918  bool badlength = false;
919  bool badchans = false;
920  if (h1_packet_number->GetBinContent(i) == 0)
921  {
922  missing = true;
923  }
924  if (h1_packet_number->GetBinContent(i) < param)
925  {
926  badnumber = true;
927  }
928  if (h1_packet_length->GetBinContent(i) < param * 5981.)
929  {
930  badlength = true;
931  }
932  if (h1_packet_chans->GetBinContent(i) < param * 192.)
933  {
934  badchans = true;
935  }
936  if (badnumber || badlength || badchans || missing)
937  {
938  badPackets.push_back((int) h1_packet_number->GetBinCenter(i));
939  std::string reason = "";
940  if (missing)
941  {
942  reason += "packet lost! ";
943  }
944  else
945  {
946  if (badnumber)
947  {
948  reason += "some events are missing, ";
949  }
950  if (badlength)
951  {
952  reason += "too short, ";
953  }
954  if (badchans)
955  {
956  reason += "too few channels, ";
957  }
958  // remove the last two characters
959  reason = reason.substr(0, reason.size() - 2);
960  reason += ".";
961  }
962  whatswrong.push_back(reason);
963  }
964  }
965  bool westmismatch = false;
966  bool eastmismatch = false;
967  for (int i = 1; i <= h1_packet_event->GetNbinsX(); i++)
968  {
969  if (h1_packet_event->GetBinContent(i) != 0)
970  {
971  if (i < 3 || i > 6)
972  {
973  westmismatch = true;
974  }
975  else
976  {
977  eastmismatch = true;
978  }
979  }
980  }
981  // draw the mismatch warning on the pad
982  TText mismatchWarn;
983  mismatchWarn.SetTextFont(62);
984  mismatchWarn.SetTextSize(0.06);
985  mismatchWarn.SetTextColor(2);
986  mismatchWarn.SetNDC();
987  mismatchWarn.SetTextAlign(23);
988  if (westmismatch)
989  {
990  mismatchWarn.DrawText(0.5, 0.95, "West misaligned!");
991  }
992  if (eastmismatch)
993  {
994  mismatchWarn.DrawText(0.5, 0.9, "East misaligned!");
995  }
996  mismatchWarn.SetTextColor(1);
997  mismatchWarn.SetTextSize(0.05);
998  if (westmismatch || eastmismatch)
999  {
1000  // mismatchWarn.DrawText(0.5, 0.7, "Restart the run and see if this persists.");
1001  // draw a line for seperation
1002  TLine* line = new TLine(0., 0.8, 1., 0.8);
1003  line->SetLineColor(1);
1004  line->SetLineStyle(1);
1005  line->SetLineWidth(10);
1006  line->Draw("same");
1007  }
1008 
1009  // draw the bad packet warning here
1010  TText PacketWarn;
1011  PacketWarn.SetTextFont(62);
1012  PacketWarn.SetTextSize(0.04);
1013  PacketWarn.SetTextColor(1);
1014  PacketWarn.SetNDC();
1015  PacketWarn.SetTextAlign(23);
1016  PacketWarn.DrawText(0.5, 0.75, "Bad Packets:");
1017  for (int i = 0; i < (int) badPackets.size(); i++)
1018  {
1019  PacketWarn.DrawText(0.5, 0.7 - 0.05 * i, Form("%i: %s", badPackets[i], whatswrong[i].c_str()));
1020  }
1021  if ((int) badPackets.size() > 0 && (h_event->GetEntries() > 1000 || h_event_1->GetEntries() > 1000))
1022  {
1023  PacketWarn.SetTextSize(0.04);
1024  PacketWarn.DrawText(0.5, 0.7 - 0.05 * (int) badPackets.size(), "Check with HCal experts.");
1025  }
1026  TText PrintRun;
1027  PrintRun.SetTextFont(62);
1028  PrintRun.SetTextSize(0.02);
1029  PrintRun.SetNDC(); // set to normalized coordinates
1030  PrintRun.SetTextAlign(23); // center/top alignment
1031  std::ostringstream runnostream;
1032  std::string runstring;
1033  std::ostringstream runnostream2;
1034  time_t evttime = getTime();
1035  // fill run number and event time into string
1036 
1037  runnostream << "Packet Information";
1038  runnostream2 << " Run " << cl->RunNumber() << ", Time: " << ctime(&evttime);
1039  transparent[5]->cd();
1040 
1041  runstring = runnostream.str();
1042  PrintRun.DrawText(0.5, .99, runstring.c_str());
1043 
1044  runstring = runnostream2.str();
1045  PrintRun.DrawText(0.5, .966, runstring.c_str());
1046  TC[5]->Update();
1047  TC[5]->Show();
1048  TC[5]->SetEditable(0);
1049  // if (save) TC[5]->SaveAs("plots/packets.pdf");
1050  return 0;
1051 }
1052 
1053 int HcalMonDraw::FindHotTower(TPad* warningpad, TH2* hhit)
1054 {
1055  int nhott = 0;
1056  int ndeadt = 0;
1057  int displaylimit = 15;
1058  // get histogram
1059  std::ostringstream hottowerlist;
1060  std::ostringstream deadtowerlist;
1061  float hot_threshold = 1.33;
1062  float dead_threshold = 0.66;
1063 
1064  for (int ieta = 0; ieta < 24; ieta++)
1065  {
1066  for (int iphi = 0; iphi < 64; iphi++)
1067  {
1068  double nhit = hhit->GetBinContent(ieta + 1, iphi + 1);
1069 
1070  if (nhit > hot_threshold)
1071  {
1072  if (nhott <= displaylimit)
1073  hottowerlist << " (" << ieta << "," << iphi << ")";
1074  nhott++;
1075  }
1076 
1077  if (nhit < dead_threshold)
1078  {
1079  if (ndeadt <= displaylimit)
1080  deadtowerlist << " (" << ieta << "," << iphi << ")";
1081  ndeadt++;
1082  }
1083  }
1084  }
1085 
1086  if (nhott > displaylimit)
1087  hottowerlist << "... " << nhott << " total";
1088  if (ndeadt > displaylimit)
1089  deadtowerlist << "... " << ndeadt << " total";
1090 
1091  // draw warning here
1092  warningpad->cd();
1093  TText Warn;
1094  Warn.SetTextFont(62);
1095  Warn.SetTextSize(0.06);
1096  Warn.SetTextColor(2);
1097  Warn.SetNDC();
1098  Warn.SetTextAlign(23);
1099  Warn.DrawText(0.5, 1, "Hot towers:");
1100  Warn.DrawText(0.5, 0.9, hottowerlist.str().c_str());
1101 
1102  Warn.SetTextColor(4);
1103  Warn.SetTextAlign(22);
1104  Warn.DrawText(0.5, 0.7, "Dead towers:");
1105  Warn.DrawText(0.5, 0.6, deadtowerlist.str().c_str());
1106 
1107  warningpad->Update();
1108  return 0;
1109 }
1110 
1111 // int HcalMonDraw::DrawSecond(const std::string & /* what */)
1112 /*
1113 {
1114  OnlMonClient *cl = OnlMonClient::instance();
1115  TH2D* hist1 = (TH2D*)cl->getHisto("h2_hcal_rm");
1116 
1117  if (!gROOT->FindObject("HcalMon2"))
1118  {
1119  MakeCanvas("HcalMon2");
1120  }
1121 
1122 
1123  TC[1]->SetEditable(1);
1124  TC[1]->Clear("D");
1125  Pad[2]->cd();
1126  if (!hist1)
1127  {
1128  DrawDeadServer(transparent[1]);
1129  TC[1]->SetEditable(0);
1130  return -1;
1131  }
1132 
1133 
1134 
1135  gStyle->SetTitleFontSize(0.03);
1136 
1137  gStyle->SetOptStat(0);
1138  gStyle->SetPalette(57);
1139 
1140 
1141  hist1->GetXaxis()->SetTitle("ieta");
1142  hist1->GetYaxis()->SetTitle("iphi");
1143  hist1->GetXaxis()->SetTitleSize(0.025);
1144  hist1->GetYaxis()->SetTitleSize(0.025);
1145  hist1->GetXaxis()->CenterTitle();
1146  hist1->GetYaxis()->CenterTitle();
1147  hist1->GetXaxis()->SetNdivisions(24);
1148  hist1->GetYaxis()->SetNdivisions(232);
1149  hist1->GetXaxis()->SetLabelSize(0.02);
1150  hist1->GetYaxis()->SetLabelSize(0.02);
1151  hist1->GetZaxis()->SetLabelSize(0.018);
1152 
1153 
1154  TLine *line_sector[32];
1155  for(int i_line=0;i_line<32;i_line++)
1156  {
1157  line_sector[i_line] = new TLine(0,(i_line+1)*2,24,(i_line+1)*2);
1158  line_sector[i_line]->SetLineColor(1);
1159  line_sector[i_line]->SetLineWidth(1.2);
1160  line_sector[i_line]->SetLineStyle(1);
1161  }
1162  TLine *line_board1 = new TLine(8,0,8,64);
1163  line_board1->SetLineColor(1);
1164  line_board1->SetLineWidth(1.2);
1165  line_board1->SetLineStyle(1);
1166  TLine *line_board2 = new TLine(16,0,16,64);
1167  line_board2->SetLineColor(1);
1168  line_board2->SetLineWidth(1.2);
1169  line_board2->SetLineStyle(1);
1170 
1171  gPad->SetTopMargin(0.04);
1172  gPad->SetBottomMargin(0.06);
1173  gPad->SetLeftMargin(0.06);
1174  gPad->SetRightMargin(0.11);
1175  gPad->SetTickx();
1176  gPad->SetTicky();
1177 
1178  hist1->Draw("colz");
1179  for(int i_line=0;i_line<32;i_line++)
1180  {
1181  line_sector[i_line]->Draw();
1182  }
1183  line_board1->Draw();
1184  line_board2->Draw();
1185 
1186  TText PrintRun;
1187  PrintRun.SetTextFont(62);
1188  PrintRun.SetTextSize(0.03);
1189  PrintRun.SetNDC(); // set to normalized coordinates
1190  PrintRun.SetTextAlign(23); // center/top alignment
1191  std::ostringstream runnostream;
1192  std::string runstring;
1193  time_t evttime = getTime();
1194  // fill run number and event time into string
1195  runnostream << ThisName << "_running mean, Run" << cl->RunNumber()
1196  << ", Time: " << ctime(&evttime);
1197  runstring = runnostream.str();
1198  transparent[1]->cd();
1199  PrintRun.DrawText(0.5, 1., runstring.c_str());
1200  TC[1]->Update();
1201  TC[1]->Show();
1202  TC[1]->SetEditable(0);
1203  return 0;
1204 }
1205 */
1206 
1207 /* currently not using the hits 2D plot
1208 int HcalMonDraw::DrawDeadServer(TPad *transparentpad)
1209 {
1210  transparentpad->cd();
1211  TText FatalMsg;
1212  FatalMsg.SetTextFont(62);
1213  FatalMsg.SetTextSize(0.1);
1214  FatalMsg.SetTextColor(4);
1215  FatalMsg.SetNDC(); // set to normalized coordinates
1216  FatalMsg.SetTextAlign(23); // center/top alignment
1217  FatalMsg.DrawText(0.5, 0.9, "HCAL MONITOR");
1218  FatalMsg.SetTextAlign(22); // center/center alignment
1219  FatalMsg.DrawText(0.5, 0.5, "SERVER");
1220  FatalMsg.SetTextAlign(21); // center/bottom alignment
1221  FatalMsg.DrawText(0.5, 0.1, "DEAD");
1222  transparentpad->Update();
1223  return 0;
1224 }
1225 */
1226 
1228 {
1229 
1231  int iret = Draw(what);
1232  if (iret) // on error no png files please
1233  {
1234  return iret;
1235  }
1236  int icnt = 0;
1237  for (TCanvas *canvas : TC)
1238  {
1239  if (canvas == nullptr)
1240  {
1241  continue;
1242  }
1243  icnt++;
1244  std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
1245  std::to_string(cl->RunNumber()) + "." + type;
1246  cl->CanvasToPng(canvas, filename);
1247  }
1248  return 0;
1249 }
1250 
1252 {
1253  int iret = Draw(what);
1254  if (iret) // on error no html output please
1255  {
1256  return iret;
1257  }
1258 
1260  int icnt = 0;
1261  for (TCanvas *canvas : TC)
1262  {
1263  if (canvas == nullptr)
1264  {
1265  continue;
1266  }
1267  icnt++;
1268  // Register the canvas png file to the menu and produces the png file.
1269  std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
1270  cl->CanvasToPng(canvas, pngfile);
1271  }
1272 
1273  // Now register also EXPERTS html pages, under the EXPERTS subfolder.
1274 
1275  // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
1276  // std::ofstream out(logfile.c_str());
1277  // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
1278  // << "</TITLE></HEAD>" << std::endl;
1279  // out << "<P>Some log file output would go here." << std::endl;
1280  // out.close();
1281 
1282  // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
1283  // std::ofstream out2(status.c_str());
1284  // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
1285  // << "</TITLE></HEAD>" << std::endl;
1286  // out2 << "<P>Some status output would go here." << std::endl;
1287  // out2.close();
1288  // cl->SaveLogFile(*this);
1289  return 0;
1290 }
1291 
1292 // this is a method that draw the tower average energy
1294 {
1296  char HCALMON_0[100];
1297  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
1298  char HCALMON_1[100];
1299  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
1300 
1301  TH2D* h2_hcal_mean = (TH2D*) cl->getHisto(HCALMON_0, "h2_hcal_mean");
1302  // TH1F* h_event = (TH1F*) cl->getHisto(HCALMON_0, "h_event");
1303  // TH2D* h2_hcal_mean_1 = (TH2D*) cl->getHisto(HCALMON_1, "h2_hcal_mean");
1304  // TH1F* h_event_1 = (TH1F*) cl->getHisto(HCALMON_1, "h_event");
1305 
1306  if (!gROOT->FindObject("HcalPopUp"))
1307  {
1308  MakeCanvas("HcalPopUp");
1309  }
1310  if (!h2_hcal_mean)
1311  {
1313  TC[4]->SetEditable(0);
1314  return;
1315  }
1316 
1317  // h2_hcal_mean->Scale(1. / h_event->GetEntries());
1318  // h2_hcal_mean_1->Scale(1. / h_event_1->GetEntries());
1319  // h2_hcal_mean->Add(h2_hcal_mean_1);
1320 
1321  TC[4]->SetEditable(1);
1322  TC[4]->Clear("D");
1323  Pad[9]->cd();
1324 
1325  gPad->SetLogz();
1326  gStyle->SetOptStat(0);
1327  gStyle->SetPalette(57);
1328  h2_hcal_mean->GetXaxis()->SetTitle("eta index");
1329  h2_hcal_mean->GetYaxis()->SetTitle("phi index");
1330  h2_hcal_mean->SetTitle("Tower Average Energy[ADC]");
1331  h2_hcal_mean->Draw("COLZ");
1332  // lines
1333  TLine* line_sector[32];
1334  for (int i_line = 0; i_line < 32; i_line++)
1335  {
1336  line_sector[i_line] = new TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
1337  line_sector[i_line]->SetLineColor(1);
1338  line_sector[i_line]->SetLineWidth(4);
1339  line_sector[i_line]->SetLineStyle(1);
1340  }
1341  TLine* line_board1 = new TLine(8, 0, 8, 64);
1342  line_board1->SetLineColor(1);
1343  line_board1->SetLineWidth(4);
1344  line_board1->SetLineStyle(1);
1345  TLine* line_board2 = new TLine(16, 0, 16, 64);
1346  line_board2->SetLineColor(1);
1347  line_board2->SetLineWidth(4);
1348  line_board2->SetLineStyle(1);
1349 
1350  for (int i_line = 0; i_line < 32; i_line++)
1351  {
1352  line_sector[i_line]->Draw();
1353  }
1354  line_board1->Draw();
1355  line_board2->Draw();
1356 
1357  TC[4]->Update();
1358  TC[4]->Show();
1359  TC[4]->SetEditable(0);
1360 }
1361 
1362 // this is a method that draw the tower hit map
1364 {
1366  char HCALMON_0[100];
1367  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
1368  char HCALMON_1[100];
1369  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
1370 
1371  TH2D* h2_hcal_hits = (TH2D*) cl->getHisto(HCALMON_0, "h2_hcal_hits");
1372 
1373  if (!gROOT->FindObject("HcalPopUp"))
1374  {
1375  MakeCanvas("HcalPopUp");
1376  }
1377  if (!h2_hcal_hits)
1378  {
1380  TC[4]->SetEditable(0);
1381  return;
1382  }
1383 
1384  TC[4]->SetEditable(1);
1385  TC[4]->Clear("D");
1386  Pad[9]->cd();
1387  gPad->SetLogz(0);
1388  gStyle->SetOptStat(0);
1389  gStyle->SetPalette(57);
1390  h2_hcal_hits->GetXaxis()->SetTitle("eta index");
1391  h2_hcal_hits->GetYaxis()->SetTitle("phi index");
1392  h2_hcal_hits->SetTitle("Average Multiplicity");
1393  h2_hcal_hits->Draw("COLZ");
1394  // lines
1395  TLine* line_sector[32];
1396  for (int i_line = 0; i_line < 32; i_line++)
1397  {
1398  line_sector[i_line] = new TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
1399  line_sector[i_line]->SetLineColor(1);
1400  line_sector[i_line]->SetLineWidth(4);
1401  line_sector[i_line]->SetLineStyle(1);
1402  }
1403  TLine* line_board1 = new TLine(8, 0, 8, 64);
1404  line_board1->SetLineColor(1);
1405  line_board1->SetLineWidth(4);
1406  line_board1->SetLineStyle(1);
1407  TLine* line_board2 = new TLine(16, 0, 16, 64);
1408  line_board2->SetLineColor(1);
1409  line_board2->SetLineWidth(4);
1410  line_board2->SetLineStyle(1);
1411 
1412  for (int i_line = 0; i_line < 32; i_line++)
1413  {
1414  line_sector[i_line]->Draw();
1415  }
1416  line_board1->Draw();
1417  line_board2->Draw();
1418  TC[4]->Update();
1419  TC[4]->Show();
1420  TC[4]->SetEditable(0);
1421 }
1422 
1423 // this is the method to idetify which bin you are clicking on and make the pop up window of TH1
1424 void HcalMonDraw::HandleEvent(int event, int x, int y, TObject* selected)
1425 {
1426  if (event == 1)
1427  {
1428  char HCALMON_0[100];
1429  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
1430  char HCALMON_1[100];
1431  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
1432  // printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n", "a",
1433  // event, x, y, selected->IsA()->GetName());
1434  // std::cout << "selected->GetName()=" << selected->GetName() << std::endl;
1435 
1436  if (strcmp(selected->GetName(), "avgenergy") == 0)
1437  {
1438  DrawTowerAvg();
1439  return;
1440  }
1441  if (strcmp(selected->GetName(), "hitmap") == 0)
1442  {
1443  DrawHitMap();
1444  return;
1445  }
1446 
1447  double xx = Pad[0]->AbsPixeltoX(x);
1448  double xhis = Pad[0]->PadtoX(xx);
1449  int binx = (int) xhis;
1450  double yy = Pad[0]->AbsPixeltoY(y);
1451  double yhis = Pad[0]->PadtoY(yy);
1452  int biny = (int) yhis;
1453  // printf("ieta=%d, iphi=%d \n", binx, biny);
1454  if (binx < 0 || binx > 23) return;
1455  if (biny < 0 || biny > 63) return;
1456 
1458 
1459  TH1F* h_rm_tower = (TH1F*) cl->getHisto(HCALMON_0, Form("h_rm_tower_%d_%d", binx, biny));
1460  TH1F* h_rm_tower_1 = (TH1F*) cl->getHisto(HCALMON_1, Form("h_rm_tower_%d_%d", binx, biny));
1461  if (!gROOT->FindObject("HcalPopUp"))
1462  {
1463  MakeCanvas("HcalPopUp");
1464  }
1465 
1466  if (!h_rm_tower || !h_rm_tower_1)
1467  {
1469  TC[4]->SetEditable(0);
1470  return;
1471  }
1472  h_rm_tower->Add(h_rm_tower_1);
1473  h_rm_tower->SetXTitle("Time");
1474  h_rm_tower->SetYTitle("Running Mean");
1475 
1476  TC[4]->SetEditable(1);
1477  TC[4]->Clear("D");
1478  Pad[9]->cd();
1479  gStyle->SetOptStat(0);
1480  h_rm_tower->Draw();
1481  TC[4]->Update();
1482  TC[4]->Show();
1483  TC[4]->SetEditable(0);
1484  }
1485 }
1486 
1487 
1488 int HcalMonDraw::DrawFifth(const std::string& /* what */)
1489 {
1491 
1492  char HCALMON_0[100];
1493  sprintf(HCALMON_0, "%s_%i", prefix.c_str(), 0);
1494  char HCALMON_1[100];
1495  sprintf(HCALMON_1, "%s_%i", prefix.c_str(), 1);
1496  TH2F* h2_hcal_hits_trig = (TH2F*) cl->getHisto(HCALMON_0, "h2_hcal_hits_trig");
1497  TH2F* h2_hcal_hits = (TH2F*) cl->getHisto(HCALMON_0, "h2_hcal_hits");
1498  TH1F* h_hcal_trig = (TH1F*) cl->getHisto(HCALMON_0, "h_hcal_trig");
1499  TH2F* h_caloPack_gl1_clock_diff = (TH2F*) cl->getHisto(HCALMON_0, "h_caloPack_gl1_clock_diff");
1500 
1501 
1502  if (!gROOT->FindObject("HcalMon5"))
1503  {
1504  MakeCanvas("HcalMon5");
1505  }
1506 
1507  TC[6]->SetEditable(1);
1508  TC[6]->Clear("D");
1509  Pad[16]->cd();
1510  if (!h2_hcal_hits_trig || !h2_hcal_hits || !h_hcal_trig || !h_caloPack_gl1_clock_diff)
1511  {
1513  TC[6]->SetEditable(0);
1514  return -1;
1515  }
1516 
1517 
1518  Pad[16]->cd();
1519  gStyle->SetTitleFontSize(0.03);
1520 
1521  h2_hcal_hits->Draw("colz");
1522 
1523  float tsize = 0.06;
1524  h2_hcal_hits->GetXaxis()->SetNdivisions(510, kTRUE);
1525  h2_hcal_hits->GetXaxis()->SetTitle("No trigger req ieta");
1526  h2_hcal_hits->GetYaxis()->SetTitle("iphi");
1527  h2_hcal_hits->GetXaxis()->SetLabelSize(tsize);
1528  h2_hcal_hits->GetYaxis()->SetLabelSize(tsize);
1529  h2_hcal_hits->GetXaxis()->SetTitleSize(tsize);
1530  h2_hcal_hits->GetYaxis()->SetTitleSize(tsize);
1531  h2_hcal_hits->GetXaxis()->SetTitleOffset(1.2);
1532  h2_hcal_hits->GetYaxis()->SetTitleOffset(0.75);
1533  gPad->SetLogz();
1534  gPad->SetBottomMargin(0.16);
1535  gPad->SetLeftMargin(0.2);
1536  gPad->SetRightMargin(0.05);
1537  gPad->SetLeftMargin(0.15);
1538  gStyle->SetOptStat(0);
1539  gStyle->SetPalette(57);
1540  gPad->SetTicky();
1541  gPad->SetTickx();
1542 
1543  TText PrintRun;
1544  PrintRun.SetTextFont(62);
1545  PrintRun.SetTextSize(0.03);
1546  PrintRun.SetNDC(); // set to normalized coordinates
1547  PrintRun.SetTextAlign(23); // center/top alignment
1548  std::ostringstream runnostream;
1549  std::string runstring;
1550  time_t evttime = getTime();
1551  // fill run number and event time into string
1552  runnostream << ThisName << ": Pulse fitting, Run" << cl->RunNumber()
1553  << ", Time: " << ctime(&evttime);
1554  runstring = runnostream.str();
1555  transparent[3]->cd();
1556  PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1557 
1558  Pad[17]->cd();
1559 
1560  gStyle->SetTitleFontSize(0.06);
1561 
1562  float tsize2 = 0.08;
1563  h2_hcal_hits_trig->Draw("colz");
1564  h2_hcal_hits_trig->GetXaxis()->SetNdivisions(510, kTRUE);
1565  h2_hcal_hits_trig->GetXaxis()->SetTitle("trigger req ieta");
1566  h2_hcal_hits_trig->GetYaxis()->SetTitle("iphi");
1567  h2_hcal_hits_trig->GetXaxis()->SetLabelSize(tsize2);
1568  h2_hcal_hits_trig->GetYaxis()->SetLabelSize(tsize2);
1569  h2_hcal_hits_trig->GetXaxis()->SetTitleSize(tsize2);
1570  h2_hcal_hits_trig->GetYaxis()->SetTitleSize(tsize2);
1571  h2_hcal_hits_trig->GetXaxis()->SetTitleOffset(1.0);
1572  h2_hcal_hits_trig->GetYaxis()->SetTitleOffset(0.85);
1573  gPad->SetTopMargin(0.06);
1574  gPad->SetBottomMargin(0.18);
1575  gPad->SetRightMargin(0.05);
1576  gPad->SetLeftMargin(0.2);
1577  gStyle->SetOptStat(0);
1578  gPad->SetTicky();
1579  gPad->SetTickx();
1580 
1581  Pad[18]->cd();
1582 
1583  gStyle->SetTitleFontSize(0.06);
1584 
1585  h_hcal_trig->Draw("hist");
1586  h_hcal_trig->GetXaxis()->SetNdivisions(510, kTRUE);
1587  h_hcal_trig->GetXaxis()->SetTitle("trigger index");
1588  h_hcal_trig->GetYaxis()->SetTitle("events");
1589  h_hcal_trig->GetXaxis()->SetLabelSize(tsize2);
1590  h_hcal_trig->GetYaxis()->SetLabelSize(tsize2);
1591  h_hcal_trig->GetXaxis()->SetTitleSize(tsize2);
1592  h_hcal_trig->GetYaxis()->SetTitleSize(tsize2);
1593  h_hcal_trig->GetXaxis()->SetTitleOffset(0.9);
1594  h_hcal_trig->GetYaxis()->SetTitleOffset(0.85);
1595  gPad->SetTopMargin(0.06);
1596  gPad->SetBottomMargin(0.18);
1597  gPad->SetRightMargin(0.05);
1598  gPad->SetLeftMargin(0.2);
1599  gStyle->SetOptStat(0);
1600  gPad->SetTicky();
1601  gPad->SetTickx();
1602 
1603  TC[6]->Update();
1604  TC[6]->Show();
1605  TC[6]->SetEditable(0);
1606 
1607  return 0;
1608 }
1609 
1610 
1611 
1613 {
1615  time_t currtime = cl->EventTime("CURRENT");
1616  return currtime;
1617 }