Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LL1MonDraw.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LL1MonDraw.cc
1 #include "LL1MonDraw.h"
2 
3 #include <onlmon/OnlMonClient.h>
4 
5 #include <TAxis.h> // for TAxis
6 #include <TCanvas.h>
7 #include <TGraphErrors.h>
8 #include <TH1.h>
9 #include <TH2.h>
10 #include <TPad.h>
11 #include <TROOT.h>
12 #include <TSystem.h>
13 #include <TText.h>
14 #include <TStyle.h>
15 
16 #include <cstring> // for memset
17 #include <ctime>
18 #include <fstream>
19 #include <iostream> // for operator<<, basic_ostream, basic_os...
20 #include <sstream>
21 #include <vector> // for vector
22 
24  : OnlMonDraw(name)
25 {
26  return;
27 }
28 
30 {
31  return 0;
32 }
33 
35 {
37  int xsize = cl->GetDisplaySizeX();
38  int ysize = cl->GetDisplaySizeY();
39  gStyle->SetOptStat(0);
40  if (name == "LL1Mon1")
41  {
42  // xpos (-1) negative: do not draw menu bar
43  TC[0] = new TCanvas(name.c_str(), "ll1Mon Monitor", -1, 0, xsize/2, ysize/2);
44  TC[0]->SetTicks(1,1);
45  // root is pathetic, whenever a new TCanvas is created root piles up
46  // 6kb worth of X11 events which need to be cleared with
47  // gSystem->ProcessEvents(), otherwise your process will grow and
48  // grow and grow but will not show a definitely lost memory leak
49  gSystem->ProcessEvents();
50  for(int ipad=0; ipad<nPad1; ipad++){
51  Pad[ipad] = new TPad(Form("ll1pad%d",ipad),Form("ll1pad%d",ipad),padx1[ipad],pady1[ipad],padx2[ipad],pady2[ipad],0);
52  Pad[ipad]->Draw();
53  Pad[ipad]->SetTicks(1,1);
54  }
55  transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
56  transparent[0]->SetFillStyle(4000);
57  transparent[0]->Draw();
58  TC[0]->SetEditable(false);
59  }
60  else if (name == "LL1Mon2")
61  {
62  // xpos negative: do not draw menu bar
63  gStyle->SetOptStat(0);
64  TC[1] = new TCanvas(name.c_str(), "ll1Mon2 Monitor", -xsize / 2, 0, xsize / 2, ysize/2);
65  TC[1]->SetTicks(1,1);
66  gSystem->ProcessEvents();
67  // this one is used to plot the run number on the canvas
68  transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
69  transparent[1]->SetFillStyle(4000);
70  transparent[1]->Draw();
71  TC[1]->SetEditable(false);
72  }
73  else if (name == "LL1Mon3")
74  {
75  TC[2] = new TCanvas(name.c_str(), "ll1Mon3 Monitor", xsize / 2, 0, xsize / 2, ysize/2);
76  TC[2]->SetTicks(1,1);
77  gSystem->ProcessEvents();
78  // this one is used to plot the run number on the canvas
79  transparent[2] = new TPad("transparent2", "this does not show", 0, 0, 1, 1);
80  transparent[2]->SetFillStyle(4000);
81  transparent[2]->Draw();
82  TC[2]->SetEditable(0);
83  }
84  return 0;
85 }
86 
87 int LL1MonDraw::Draw(const std::string &what)
88 {
89  int iret = 0;
90  int idraw = 0;
91  if (what == "ALL" || what == "FIRST")
92  {
93  iret += DrawFirst(what);
94  idraw++;
95  }
96  if (what == "ALL" || what == "SECOND")
97  {
98  iret += DrawSecond(what);
99  idraw++;
100  }
101  if (what == "ALL" || what == "THIRD")
102  {
103  iret += DrawThird(what);
104  idraw++;
105  }
106  if (!idraw)
107  {
108  std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
109  iret = -1;
110  }
111  return iret;
112 }
113 
114 int LL1MonDraw::DrawFirst(const std::string & /* what */)
115 {
117  TH1 *h_nhit_n1 = cl->getHisto("LL1MON_0","h_nhit_n1");
118  TH1 *h_nhit_n2 = cl->getHisto("LL1MON_0","h_nhit_n2");
119  TH1 *h_nhit_s1 = cl->getHisto("LL1MON_0","h_nhit_s1");
120  TH1 *h_nhit_s2 = cl->getHisto("LL1MON_0","h_nhit_s2");
121  time_t evttime = cl->EventTime("CURRENT");
122  if (!gROOT->FindObject("LL1Mon1"))
123  {
124  MakeCanvas("LL1Mon1");
125  }
126  TC[0]->SetEditable(true);
127  TC[0]->Clear("D");
128  Pad[0]->cd();
129  if (h_nhit_n1)
130  {
131  h_nhit_n1->DrawCopy();
132  }
133  else
134  {
136  TC[0]->SetEditable(false);
137  return -1;
138  }
139  Pad[1]->cd();
140  h_nhit_n2->DrawCopy();
141  Pad[2]->cd();
142  h_nhit_s1->DrawCopy();
143  Pad[3]->cd();
144  h_nhit_s2->DrawCopy();
145 
146  TText PrintRun;
147  PrintRun.SetTextFont(62);
148  PrintRun.SetTextSize(0.04);
149  PrintRun.SetNDC(); // set to normalized coordinates
150  PrintRun.SetTextAlign(23); // center/top alignment
151  std::ostringstream runnostream;
152  std::string runstring;
153  // fill run number and event time into string
154  runnostream << ThisName << "_1 Run " << cl->RunNumber()
155  << ", Time: " << ctime(&evttime);
156  runstring = runnostream.str();
157  transparent[0]->cd();
158  PrintRun.DrawText(0.5, 1., runstring.c_str());
159  gStyle->SetOptStat(0);
160  TC[0]->Update();
161  TC[0]->SetTicks(1,1);
162  TC[0]->Show();
163  TC[0]->SetEditable(false);
164  return 0;
165 }
166 
167 int LL1MonDraw::DrawSecond(const std::string & /* what */)
168 {
170  TH2 *h_nhit_corr= (TH2D*) cl->getHisto("LL1MON_0","h_nhit_corr");
171  time_t evttime = cl->EventTime("CURRENT");
172  if (!gROOT->FindObject("LL1Mon2"))
173  {
174  MakeCanvas("LL1Mon2");
175  }
176  TC[1]->SetEditable(true);
177  TC[1]->Clear("D");
178  if (h_nhit_corr)
179  {
180  h_nhit_corr->Draw("colz");
181  }
182  else
183  {
185  TC[1]->SetEditable(false);
186  return -1;
187  }
188  TText PrintRun;
189  PrintRun.SetTextFont(62);
190  PrintRun.SetTextSize(0.04);
191  PrintRun.SetNDC(); // set to normalized coordinates
192  PrintRun.SetTextAlign(23); // center/top alignment
193  std::ostringstream runnostream;
194  std::string runstring;
195  // fill run number and event time into string
196  runnostream << ThisName << "_2 Run " << cl->RunNumber()
197  << ", Time: " << ctime(&evttime);
198  runstring = runnostream.str();
199  transparent[1]->cd();
200  PrintRun.DrawText(0.5, 1., runstring.c_str());
201  TC[1]->SetTicks(1,1);
202  TC[1]->Update();
203  TC[1]->Show();
204  TC[1]->SetEditable(false);
205  return 0;
206 }
207 
208 int LL1MonDraw::DrawThird(const std::string & /* what */)
209 {
211  TH2 *h_line_up= (TH2*) cl->getHisto("LL1MON_0","h_line_up");
212  time_t evttime = cl->EventTime("CURRENT");
213  if (!gROOT->FindObject("LL1Mon3"))
214  {
215  MakeCanvas("LL1Mon3");
216  }
217  TC[2]->SetEditable(true);
218  TC[2]->Clear("D");
219  gStyle->SetOptStat(0);
220  if (h_line_up)
221  {
222  h_line_up->Draw("colz");
223  }
224  else
225  {
227  TC[2]->SetEditable(false);
228  return -1;
229  }
230  TText PrintRun;
231  PrintRun.SetTextFont(62);
232  PrintRun.SetTextSize(0.04);
233  PrintRun.SetNDC(); // set to normalized coordinates
234  PrintRun.SetTextAlign(23); // center/top alignment
235  std::ostringstream runnostream;
236  std::string runstring;
237  // fill run number and event time into string
238  runnostream << ThisName << "_3 Run " << cl->RunNumber()
239  << ", Time: " << ctime(&evttime);
240  runstring = runnostream.str();
241  transparent[2]->cd();
242  PrintRun.DrawText(0.5, 1., runstring.c_str());
243  TC[2]->Update();
244  TC[2]->SetTicks(1,1);
245  TC[2]->Show();
246  TC[2]->SetEditable(false);
247  return 0;
248 }
249 
251 {
252 
254  int iret = Draw(what);
255  if (iret) // on error no png files please
256  {
257  return iret;
258  }
259  int icnt = 0;
260  for (TCanvas *canvas : TC)
261  {
262  if (canvas == nullptr)
263  {
264  continue;
265  }
266  icnt++;
267  std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
268  std::to_string(cl->RunNumber()) + "." + type;
269  cl->CanvasToPng(canvas, filename);
270  }
271  return 0;
272 }
273 
275 {
276  int iret = Draw(what);
277  if (iret) // on error no html output please
278  {
279  return iret;
280  }
281 
283 
284  int icnt = 0;
285  for (TCanvas *canvas : TC)
286  {
287  if (canvas == nullptr)
288  {
289  continue;
290  }
291  icnt++;
292  // Register the canvas png file to the menu and produces the png file.
293  std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
294  cl->CanvasToPng(canvas, pngfile);
295  }
296  // Now register also EXPERTS html pages, under the EXPERTS subfolder.
297 
298  // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
299  // std::ofstream out(logfile.c_str());
300  // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
301  // << "</TITLE></HEAD>" << std::endl;
302  // out << "<P>Some log file output would go here." << std::endl;
303  // out.close();
304 
305  // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
306  // std::ofstream out2(status.c_str());
307  // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
308  // << "</TITLE></HEAD>" << std::endl;
309  // out2 << "<P>Some status output would go here." << std::endl;
310  // out2.close();
311  // cl->SaveLogFile(*this);
312  return 0;
313 }