Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ZdcMonDraw.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ZdcMonDraw.cc
1 #include "ZdcMonDraw.h"
2 
3 #include <onlmon/OnlMonClient.h>
4 #include <onlmon/OnlMonDB.h>
5 
6 #include <TAxis.h> // for TAxis
7 #include <TCanvas.h>
8 #include <TDatime.h>
9 #include <TGraphErrors.h>
10 #include <TH1.h>
11 #include <TPad.h>
12 #include <TROOT.h>
13 #include <TSystem.h>
14 #include <TText.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  if (name == "ZdcMon1")
40  {
41  // xpos (-1) negative: do not draw menu bar
42  TC[0] = new TCanvas(name.c_str(), "ZdcMon Example Monitor", -1, 0, xsize / 2, ysize);
43  // root is pathetic, whenever a new TCanvas is created root piles up
44  // 6kb worth of X11 events which need to be cleared with
45  // gSystem->ProcessEvents(), otherwise your process will grow and
46  // grow and grow but will not show a definitely lost memory leak
47  gSystem->ProcessEvents();
48  Pad[0] = new TPad("zdcpad1", "who needs this?", 0.1, 0.5, 0.9, 0.9, 0);
49  Pad[1] = new TPad("zdcpad2", "who needs this?", 0.1, 0.05, 0.9, 0.45, 0);
50  Pad[0]->Draw();
51  Pad[1]->Draw();
52  // this one is used to plot the run number on the canvas
53  transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
54  transparent[0]->SetFillStyle(4000);
55  transparent[0]->Draw();
56  TC[0]->SetEditable(false);
57  }
58  else if (name == "ZdcMon2")
59  {
60  // xpos negative: do not draw menu bar
61  TC[1] = new TCanvas(name.c_str(), "ZdcMon2 Example Monitor", -xsize / 2, 0, xsize / 2, ysize);
62  gSystem->ProcessEvents();
63  Pad[2] = new TPad("zdcpad3", "who needs this?", 0.1, 0.5, 0.9, 0.9, 0);
64  Pad[3] = new TPad("zdcpad4", "who needs this?", 0.1, 0.05, 0.9, 0.45, 0);
65  Pad[2]->Draw();
66  Pad[3]->Draw();
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  return 0;
74 }
75 
76 int ZdcMonDraw::Draw(const std::string &what)
77 {
78  int iret = 0;
79  int idraw = 0;
80  if (what == "ALL" || what == "FIRST")
81  {
82  iret += DrawFirst(what);
83  idraw++;
84  }
85  if (what == "ALL" || what == "SECOND")
86  {
87  iret += DrawSecond(what);
88  idraw++;
89  }
90  if (!idraw)
91  {
92  std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
93  iret = -1;
94  }
95  return iret;
96 }
97 
98 int ZdcMonDraw::DrawFirst(const std::string & /* what */)
99 {
101  TH1 *zdc_adc_south = cl->getHisto("ZDCMON_0","zdc_adc_south");
102  TH1 *zdc_adc_north = cl->getHisto("ZDCMON_0","zdc_adc_north");
103  if (!gROOT->FindObject("ZdcMon1"))
104  {
105  MakeCanvas("ZdcMon1");
106  }
107  TC[0]->SetEditable(true);
108  TC[0]->Clear("D");
109  Pad[0]->cd();
110  gPad->SetLogy();
111  gPad->SetLogx();
112  if (zdc_adc_south)
113  {
114  zdc_adc_south->Scale(1/zdc_adc_south->Integral(), "width");
115  zdc_adc_south->DrawCopy();
116  }
117  else
118  {
120  TC[0]->SetEditable(false);
121  return -1;
122  }
123  Pad[1]->cd();
124  gPad->SetLogy();
125  gPad->SetLogx();
126  if (zdc_adc_north)
127  {
128  zdc_adc_north->Scale(1/zdc_adc_north->Integral(), "width");
129  zdc_adc_north->DrawCopy();
130  }
131  TText PrintRun;
132  PrintRun.SetTextFont(62);
133  PrintRun.SetTextSize(0.04);
134  PrintRun.SetNDC(); // set to normalized coordinates
135  PrintRun.SetTextAlign(23); // center/top alignment
136  std::ostringstream runnostream;
137  std::string runstring;
138  time_t evttime = cl->EventTime("CURRENT");
139  // fill run number and event time into string
140  runnostream << ThisName << "_1 Run " << cl->RunNumber()
141  << ", Time: " << ctime(&evttime);
142  runstring = runnostream.str();
143  transparent[0]->cd();
144  PrintRun.DrawText(0.5, 1., runstring.c_str());
145  TC[0]->Update();
146  TC[0]->Show();
147  TC[0]->SetEditable(false);
148  return 0;
149 }
150 
151 int ZdcMonDraw::DrawSecond(const std::string & /* what */)
152 {
154  TH1 *zdc_adc_south = cl->getHisto("ZDCMON_0","zdc_adc_south");
155  TH1 *zdc_adc_north = cl->getHisto("ZDCMON_0","zdc_adc_north");
156  if (!gROOT->FindObject("ZdcMon2"))
157  {
158  MakeCanvas("ZdcMon2");
159  }
160  TC[1]->SetEditable(true);
161  TC[1]->Clear("D");
162  Pad[2]->cd();
163  if (zdc_adc_south)
164  {
165  zdc_adc_south->DrawCopy();
166  }
167  else
168  {
170  TC[1]->SetEditable(false);
171  return -1;
172  }
173  Pad[3]->cd();
174  if (zdc_adc_north)
175  {
176  zdc_adc_north->DrawCopy();
177  }
178  TText PrintRun;
179  PrintRun.SetTextFont(62);
180  PrintRun.SetTextSize(0.04);
181  PrintRun.SetNDC(); // set to normalized coordinates
182  PrintRun.SetTextAlign(23); // center/top alignment
183  std::ostringstream runnostream;
184  std::string runstring;
185  time_t evttime = cl->EventTime("CURRENT");
186  // fill run number and event time into string
187  runnostream << ThisName << "_2 Run " << cl->RunNumber()
188  << ", Time: " << ctime(&evttime);
189  runstring = runnostream.str();
190  transparent[1]->cd();
191  PrintRun.DrawText(0.5, 1., runstring.c_str());
192  TC[1]->Update();
193  TC[1]->Show();
194  TC[1]->SetEditable(false);
195  return 0;
196 }
197 
199 {
200 
202  int iret = Draw(what);
203  if (iret) // on error no png files please
204  {
205  return iret;
206  }
207  int icnt = 0;
208  for (TCanvas *canvas : TC)
209  {
210  if (canvas == nullptr)
211  {
212  continue;
213  }
214  icnt++;
215  std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
216  std::to_string(cl->RunNumber()) + "." + type;
217  cl->CanvasToPng(canvas, filename);
218  }
219  return 0;
220 }
221 
223 {
224  int iret = Draw(what);
225  if (iret) // on error no html output please
226  {
227  return iret;
228  }
229 
231 
232  // Register the 1st canvas png file to the menu and produces the png file.
233  std::string pngfile = cl->htmlRegisterPage(*this, "First Canvas", "1", "png");
234  cl->CanvasToPng(TC[0], pngfile);
235 
236  // idem for 2nd canvas.
237  pngfile = cl->htmlRegisterPage(*this, "Second Canvas", "2", "png");
238  cl->CanvasToPng(TC[1], pngfile);
239  // Now register also EXPERTS html pages, under the EXPERTS subfolder.
240 
241  std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
242  std::ofstream out(logfile.c_str());
243  out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
244  << "</TITLE></HEAD>" << std::endl;
245  out << "<P>Some log file output would go here." << std::endl;
246  out.close();
247 
248  std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
249  std::ofstream out2(status.c_str());
250  out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
251  << "</TITLE></HEAD>" << std::endl;
252  out2 << "<P>Some status output would go here." << std::endl;
253  out2.close();
254  cl->SaveLogFile(*this);
255  return 0;
256 }