4 #include <onlmon/OnlMonClient.h>
5 #include <onlmon/OnlMonDB.h>
10 #include <TGraphErrors.h>
31 CanvasEditor( TCanvas* cv ):m_cv(cv)
32 {
if( m_cv ) m_cv->SetEditable(
true); }
36 {
if( m_cv ) m_cv->SetEditable(
false); }
39 TCanvas* m_cv =
nullptr;
44 auto transparent =
new TPad( (name+
"_transparent").c_str(),
"", 0, 0, 1, 1);
45 transparent->SetFillStyle(4000);
50 TPad* get_transparent_pad( TPad* parent,
const std::string& name,
bool clear =
true)
52 if( !parent )
return nullptr;
53 const std::string transparent_name = name+
"_transparent";
54 auto out =
dynamic_cast<TPad*
>( parent->FindObject( transparent_name.c_str() ) );
56 if( !
out ) std::cout <<
"get_transparent_pad - " << transparent_name <<
" not found" << std::endl;
57 if(
out && clear )
out->Clear(
"D");
63 [[maybe_unused]] TLine* vertical_line( TVirtualPad* pad, Double_t
x )
65 Double_t yMin = pad->GetUymin();
66 Double_t yMax = pad->GetUymax();
70 yMin = std::pow( 10, yMin );
71 yMax = std::pow( 10, yMax );
74 return new TLine( x, yMin, x, yMax );
78 [[maybe_unused]] TLine* horizontal_line( TVirtualPad* pad, Double_t
y )
80 Double_t xMin = pad->GetUxmin();
81 Double_t xMax = pad->GetUxmax();
85 xMin = std::pow( 10, xMin );
86 xMax = std::pow( 10, xMax );
89 return new TLine( xMin, y, xMax, y );
93 void divide_canvas( TCanvas* cv,
int ncol,
int nrow )
95 static constexpr
double max_height = 0.94;
97 cv->Divide( ncol, nrow );
98 for(
int i = 0;
i < ncol*nrow; ++
i )
100 auto pad = cv->GetPad(
i+1 );
106 const double ymin = max_height*(1. -
double(row+1)/nrow);
107 const double ymax = max_height*(1. -
double(row)/nrow);
108 pad->SetPad( xmin, ymin, xmax, ymax );
119 const auto tpotcalibref = getenv(
"TPOTCALIBREF");
127 std::cout <<
"TpotMon::TpotMon - TPOTCALIBREF environment variable not set. Reading reference histograms from: " <<
m_ref_histograms_filename << std::endl;
132 TDatime T0(2003, 01, 01, 00, 00, 00);
151 if(
Verbosity() ) std::cout <<
"TpotMonDraw::DrawDeadServer - invalid pad" << std::endl;
154 pad->SetPad(0,0,1,1);
164 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_time - invalid pad" << std::endl;
168 pad->SetPad( 0, 0.94, 1, 1 );
171 PrintRun.SetTextFont(62);
172 PrintRun.SetTextSize(0.6);
174 PrintRun.SetTextAlign(23);
176 std::ostringstream runnostream;
178 time_t evttime = cl->EventTime(
"CURRENT");
181 <<
ThisName <<
" Run " << cl->RunNumber()
182 <<
", Time: " << ctime(&evttime);
185 PrintRun.DrawText(0.5, 0.5, runnostream.str().c_str());
191 auto cv =
dynamic_cast<TCanvas*
>( gROOT->FindObject( name.c_str() ) );
193 if( cv && clear ) cv->Clear(
"D");
202 { std::cout <<
"TpotMonDraw::create_canvas - name: " << name << std::endl; }
208 if (name ==
"TPOT_counters")
212 auto cv =
new TCanvas(name.c_str(),
"TPOT event counters", -1, 0, xsize / 2, ysize);
213 gSystem->ProcessEvents();
214 divide_canvas( cv, 1, 1 );
215 create_transparent_pad(name);
216 cv->SetEditable(
false);
219 }
else if (name ==
"TPOT_detector_occupancy") {
222 auto cv =
new TCanvas(name.c_str(),
"TPOT detector occupancy", -1, 0, xsize / 2, ysize);
223 gSystem->ProcessEvents();
224 divide_canvas( cv, 1, 2 );
225 create_transparent_pad(name);
226 cv->SetEditable(
false);
230 }
else if (name ==
"TPOT_resist_occupancy") {
233 auto cv =
new TCanvas(name.c_str(),
"TPOT resist occupancy", -1, 0, xsize / 2, ysize);
234 gSystem->ProcessEvents();
235 divide_canvas( cv, 1, 2 );
236 create_transparent_pad(name);
237 cv->SetEditable(
false);
241 }
else if (name ==
"TPOT_adc_vs_sample") {
243 auto cv =
new TCanvas(name.c_str(),
"TpotMon adc vs sample", -1, 0, xsize / 2, ysize);
244 gSystem->ProcessEvents();
245 divide_canvas( cv, 4, 4 );
246 create_transparent_pad(name);
247 for(
int i = 0;
i < 16; ++
i )
249 cv->GetPad(
i+1)->SetLeftMargin(0.15);
250 cv->GetPad(
i+1)->SetRightMargin(0.02);
252 cv->SetEditable(
false);
256 }
else if (name ==
"TPOT_counts_vs_sample") {
258 auto cv =
new TCanvas(name.c_str(),
"TpotMon counts vs sample", -1, 0, xsize / 2, ysize);
259 gSystem->ProcessEvents();
260 divide_canvas( cv, 4, 4 );
261 create_transparent_pad(name);
262 for(
int i = 0;
i < 16; ++
i )
264 auto&& pad = cv->GetPad(
i+1);
265 pad->SetLeftMargin(0.15);
266 pad->SetRightMargin(0.02);
269 cv->SetEditable(
false);
273 }
else if (name ==
"TPOT_hit_charge") {
275 auto cv =
new TCanvas(name.c_str(),
"TpotMon hit charge", -1, 0, xsize / 2, ysize);
276 gSystem->ProcessEvents();
277 divide_canvas( cv, 4, 4 );
278 create_transparent_pad(name);
279 cv->SetEditable(
false);
283 }
else if (name ==
"TPOT_hit_multiplicity") {
285 auto cv =
new TCanvas(name.c_str(),
"TpotMon hit multiplicity", -1, 0, xsize / 2, ysize);
286 gSystem->ProcessEvents();
287 divide_canvas( cv, 4, 4 );
288 create_transparent_pad(name);
289 cv->SetEditable(
false);
293 }
else if (name ==
"TPOT_hit_vs_channel") {
295 auto cv =
new TCanvas(name.c_str(),
"TpotMon hit vs channel", -1, 0, xsize / 2, ysize);
296 gSystem->ProcessEvents();
297 divide_canvas( cv, 4, 4 );
298 create_transparent_pad(name);
299 cv->SetEditable(
false);
311 { std::cout <<
"TpotMonDraw::Draw - what: " << what << std::endl; }
323 std::cout <<
"TpotMonDraw::Draw - events: " << events <<
" valid events: " << valid_events << std::endl;
327 if( what ==
"ALL" || what ==
"TPOT_counters" )
333 if( what ==
"ALL" || what ==
"TPOT_detector_occupancy" )
339 if( what ==
"ALL" || what ==
"TPOT_resist_occupancy" )
345 if (what ==
"ALL" || what ==
"TPOT_adc_vs_sample")
351 CanvasEditor cv_edit(cv);
353 for(
int i = 0;
i < 16; ++
i )
356 auto&& pad = cv->GetPad(
i+1);
360 line->SetLineStyle(2);
361 line->SetLineColor(2);
362 line->SetLineWidth(2);
370 if (what ==
"ALL" || what ==
"TPOT_counts_vs_sample")
373 auto cv =
get_canvas(
"TPOT_counts_vs_sample");
376 std::cout <<
"TpotMonDraw::Draw - draw vertical lines" << std::endl;
377 CanvasEditor cv_edit(cv);
379 for(
int i = 0;
i < 16; ++
i )
382 auto&& pad = cv->GetPad(
i+1);
386 line->SetLineStyle(2);
387 line->SetLineColor(2);
388 line->SetLineWidth(2);
396 if (what ==
"ALL" || what ==
"TPOT_hit_charge")
402 if (what ==
"ALL" || what ==
"TPOT_hit_multiplicity")
408 if (what ==
"ALL" || what ==
"TPOT_hit_vs_channel")
414 CanvasEditor cv_edit(cv);
416 for(
int i = 0;
i < 16; ++
i )
419 auto&& pad = cv->GetPad(
i+1);
421 for(
const int&
channel:{64, 128, 196} )
424 line->SetLineStyle(2);
425 line->SetLineColor(1);
426 line->SetLineWidth(1);
436 std::cout <<
"TpotMonDraw::Draw - Unimplemented Drawing option: " << what << std::endl;
446 const int iret =
Draw(what);
447 if (iret)
return iret;
456 cl->CanvasToPng(cv, filename);
466 const int iret =
Draw(what);
467 if (iret)
return iret;
477 const auto pngfile = cl->htmlRegisterPage(*
this, cv->GetName(), Form(
"%lu",
i+1),
"png");
478 cl->CanvasToPng(cv, pngfile);
484 const std::string logfile = cl->htmlRegisterPage(*
this,
"EXPERTS/Log",
"log",
"html");
485 std::ofstream
out(logfile.c_str());
487 <<
"<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
490 <<
"<P>Some log file output would go here."
497 const std::string status = cl->htmlRegisterPage(*
this,
"EXPERTS/Status",
"status",
"html");
498 std::ofstream
out(status.c_str());
500 <<
"<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
503 <<
"<P>Some status output would go here."
506 cl->SaveLogFile(*
this);
516 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_counters" << std::endl;
523 auto transparent = get_transparent_pad( cv,
"TPOT_counters");
526 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_counters - no canvas" << std::endl;
530 CanvasEditor cv_edit(cv);
535 gPad->SetLeftMargin( 0.07 );
536 gPad->SetRightMargin( 0.15 );
537 m_counters->SetFillStyle(1001);
538 m_counters->SetFillColor(kYellow );
539 m_counters->DrawCopy(
"h" );
543 m_counters_ref->SetLineColor(2);
544 m_counters_ref->DrawCopy(
"hist same" );
560 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_detector_occupancy" << std::endl;
563 auto m_detector_occupancy_phi =
get_histogram(
"m_detector_occupancy_phi");
564 auto m_detector_occupancy_z =
get_histogram(
"m_detector_occupancy_z");
567 for(
const auto&
h:{m_detector_occupancy_phi,m_detector_occupancy_z} )
568 {
if(
h)
h->SetStats(0); }
570 auto cv =
get_canvas(
"TPOT_detector_occupancy");
571 auto transparent = get_transparent_pad( cv,
"TPOT_detector_occupancy");
574 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_detector_occupancy - no canvas" << std::endl;
578 CanvasEditor cv_edit(cv);
580 if( m_detector_occupancy_phi && m_detector_occupancy_z )
583 gPad->SetLeftMargin( 0.07 );
584 gPad->SetRightMargin( 0.15 );
585 m_detector_occupancy_z->DrawCopy(
"colz" );
589 gPad->SetLeftMargin( 0.07 );
590 gPad->SetRightMargin( 0.15 );
591 m_detector_occupancy_phi->DrawCopy(
"colz" );
609 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_resist_occupancy" << std::endl;
612 auto m_resist_occupancy_phi =
get_histogram(
"m_resist_occupancy_phi");
613 auto m_resist_occupancy_z =
get_histogram(
"m_resist_occupancy_z");
616 for(
const auto&
h:{m_resist_occupancy_phi,m_resist_occupancy_z} )
617 {
if(
h)
h->SetStats(0); }
619 auto cv =
get_canvas(
"TPOT_resist_occupancy");
620 auto transparent = get_transparent_pad( cv,
"TPOT_resist_occupancy");
623 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_resist_occupancy - no canvas" << std::endl;
627 CanvasEditor cv_edit(cv);
629 if( m_resist_occupancy_phi && m_resist_occupancy_z )
632 gPad->SetLeftMargin( 0.07 );
633 gPad->SetRightMargin( 0.15 );
634 m_resist_occupancy_z->DrawCopy(
"colz" );
638 gPad->SetLeftMargin( 0.07 );
639 gPad->SetRightMargin( 0.15 );
640 m_resist_occupancy_phi->DrawCopy(
"colz" );
660 auto text =
new TText();
671 return cl->getHisto(
"TPOTMON_0", name );
681 const auto hname = name +
"_" + detector_name;
684 { std::cout <<
"TpotMonDraw::get_histograms - " << hname << (
out[
i]?
" found":
" not found" ) << std::endl; }
701 const auto hname = name +
"_" + detector_name;
704 { std::cout <<
"TpotMonDraw::get_ref_histograms - " << hname << (
out[
i]?
" found":
" not found" ) << std::endl; }
717 for(
size_t i=0;
i<source.size(); ++
i)
729 if( !( m_counters && m_counters_ref ) )
return 0;
733 return full_events_ref > 0 ? full_events/full_events_ref : 0;
739 if( !source )
return nullptr;
740 auto destination =
static_cast<TH1*
>( source->Clone() );
741 destination->SetName( TString( source->GetName() )+
"_scaled" );
742 destination->Scale( scale );
749 if(
Verbosity() ) std::cout <<
"TpotMonDraw::draw_array - name: " << name << std::endl;
752 auto transparent = get_transparent_pad( cv, name);
756 CanvasEditor cv_edit(cv);
757 for(
size_t i = 0;
i < histograms.size(); ++
i )
762 if( options&DrawOptions::Colz ) histograms[
i]->DrawCopy(
"col" );
765 histograms[
i]->SetFillStyle(1001);
766 histograms[
i]->SetFillColor(kYellow );
767 histograms[
i]->DrawCopy(
"h" );
768 histograms[
i]->DrawCopy();
773 if( ref_histograms[i] )
775 ref_histograms[
i]->SetLineColor(2);
776 ref_histograms[
i]->Draw(
"hist same" );
779 gPad->SetBottomMargin(0.12);
780 if( options&DrawOptions::Logx ) gPad->SetLogx(
true );
781 if( options&DrawOptions::Logy && histograms[i]->GetEntries() > 0 ) gPad->SetLogy(
true );
782 if( options&DrawOptions::Logz ) gPad->SetLogz(
true );
797 for(
auto h:ref_histograms ) {
delete h; }