262 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
264 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
266 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") =
JCanvas(500, 500);
269 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t::DEFAULT_RANGE();
270 zap[
'y'] =
make_field(Y,
"y-abscissa range") = JRange_t::DEFAULT_RANGE();
271 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t::DEFAULT_RANGE();
272 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
273 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
274 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
275 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
276 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
277 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
278 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
279 zap[
'C'] =
make_field(drawLine,
"draw line (-C black-and-white -CC colour)");
280 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
281 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
282 zap[
'O'] =
make_field(option,
"plotting option") =
"";
284 zap[
'B'] =
make_field(batch,
"batch processing");
285 zap[
'T'] =
make_field(title,
"graphics title ("
286 <<
"\"" << JName_t <<
"\" -> ROOT name; "
287 <<
"\"" << JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
289 zap[
'p'] =
make_field(palette,
"palette") = -1;
294 catch(
const exception &error) {
295 FATAL(error.what() << endl);
299 gROOT->SetBatch(batch);
301 TApplication* tp =
new TApplication(
"user", NULL, NULL);
302 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.
x, canvas.
y);
305 ((TRootCanvas *) cv->GetCanvasImp())->Connect(
"CloseWindow()",
"TApplication", tp,
"Terminate()");
308 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
311 gStyle->SetPalette(palette);
314 gROOT->SetStyle(
"gplot");
318 cv->SetFillStyle(4000);
319 cv->SetFillColor(kWhite);
324 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
325 JLineAttributes ::getInstance().setLineWidth (lineWidth);
328 Double_t xmin = numeric_limits<double>::max();
329 Double_t xmax = numeric_limits<double>::lowest();
330 Double_t ymin = numeric_limits<double>::max();
331 Double_t ymax = numeric_limits<double>::lowest();
332 Double_t zmin = numeric_limits<double>::max();
333 Double_t zmax = numeric_limits<double>::lowest();
340 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
342 DEBUG(
"Input: " << *input << endl);
344 TDirectory* dir = getDirectory(*input);
347 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
351 const TRegexp regexp(input->getObjectName());
353 TIter iter(dir->GetListOfKeys());
355 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
357 const TString tag(key->GetName());
359 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
363 if (tag.Contains(regexp) && isTObject(key)) {
365 if (title == JName_t) {
366 title = key->GetName();
367 }
else if (title == JTitle_t) {
368 title = key->GetTitle();
375 TH3& h3 =
dynamic_cast<TH3&
>(*object);
377 object = h3.Project3D(project.c_str());
383 TH2& h2 =
dynamic_cast<TH2&
>(*object);
385 h2.SetStats(stats != -1);
387 xmin = min(xmin, h2.GetXaxis()->GetXmin());
388 xmax = max(xmax, h2.GetXaxis()->GetXmax());
389 ymin = min(ymin, h2.GetYaxis()->GetXmin());
390 ymax = max(ymax, h2.GetYaxis()->GetXmax());
391 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
392 zmax = max(zmax, h2.GetMaximum());
398 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
400 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
401 xmin = min(xmin,
g1.GetX()[i] - numeric_limits<float>::epsilon());
402 xmax = max(xmax,
g1.GetX()[i] + numeric_limits<float>::epsilon());
403 ymin = min(ymin,
g1.GetY()[i] - numeric_limits<float>::epsilon());
404 ymax = max(ymax,
g1.GetY()[i] + numeric_limits<float>::epsilon());
410 if (
dynamic_cast<TGraph*
>(i->get()) != NULL) {
415 static_cast<TAttMarker&
>(
g1) = JMarkerAttributes::getInstance().get(ng);
421 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
423 for (Int_t i = 0; i != g2.GetN(); ++i) {
424 if (!logz || g2.GetZ()[i] > 0.0) {
425 xmin = min(xmin, g2.GetX()[i]);
426 xmax = max(xmax, g2.GetX()[i]);
427 ymin = min(ymin, g2.GetY()[i]);
428 ymax = max(ymax, g2.GetY()[i]);
429 zmin = min(zmin, g2.GetZ()[i]);
430 zmax = max(zmax, g2.GetZ()[i]);
435 g2.SetMinimum(Z.getLowerLimit());
436 g2.SetMaximum(Z.getUpperLimit());
443 TF2& f2 =
dynamic_cast<TF2&
>(*object);
445 f2.SetLineColor(kRed);
446 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
453 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
455 xmin = min(xmin, __xmin);
456 xmax = max(xmax, __xmax);
457 ymin = min(ymin, __ymin);
458 ymax = max(ymax, __ymax);
459 zmin = min(zmin, f2.GetMinimum());
460 zmax = max(zmax, f2.GetMaximum());
466 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
468 *i = (*i)(TRegexp(
"\\[.*\\]"));
470 if ((*i).Length() > 2) {
471 object.setLabel((*i)(1, (*i).Length() - 2));
475 if (
dynamic_cast<TH2*
> (
object.get()) != NULL ||
476 dynamic_cast<TGraph2D*
>(
object.get()) != NULL ||
477 dynamic_cast<TF2*
> (
object.get()) != NULL) {
479 if (master == NULL) {
480 master =
object.get();
483 }
else if (
dynamic_cast<TH1*
> (
object.get()) != NULL ||
484 dynamic_cast<TGraph*
> (
object.get()) != NULL) {
486 TAttMarker marker = *JMarkerAttributes::getInstance().next();
487 TAttLine line = JLineAttributes::getInstance().get(0);
490 line = *JLineAttributes::getInstance().next();
492 line.SetLineColor(marker.GetMarkerColor());
494 if (
dynamic_cast<TAttMarker*
>(
object.get()) != NULL) {
495 dynamic_cast<TAttMarker&
>(*object) = marker;
498 if (
dynamic_cast<TAttLine*
> (
object.get()) != NULL) {
499 dynamic_cast<TAttLine&
> (*object) = line;
509 TH1& h1 =
dynamic_cast<TH1&
>(*object);
511 for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
512 h1.SetBinError(i, 0.0);
519 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
521 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
529 }
else if (
dynamic_cast<TEllipse*
>(
object.get()) != NULL ||
530 dynamic_cast<TLine*
> (
object.get()) != NULL ||
531 dynamic_cast<TText*
> (
object.get()) != NULL) {
535 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
540 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.getLabel() <<
">" << endl);
542 listOfObjects.push_back(
object);
547 if (listOfObjects.empty()) {
548 ERROR(
"Nothing to draw." << endl);
555 if (option.find(
"COLZ") != string::npos ||
556 option.find(
"colz") != string::npos) {
557 gPad->SetRightMargin(0.20);
561 xmin = X.getLowerLimit();
562 xmax = X.getUpperLimit();
566 ymin = Y.getLowerLimit();
567 ymax = Y.getUpperLimit();
571 zmin = Z.getLowerLimit();
572 zmax = Z.getUpperLimit();
573 }
else if (zmax > zmin) {
574 setRange(zmin, zmax, logz);
577 if (!listOfObjects.empty()) {
579 if (master == NULL) {
581 master =
new TH2D(MASTER.c_str(), NULL,
585 master->SetStats(kFALSE);
589 if (master == NULL) {
591 TText* p =
new TText(0.5, 0.5,
"No data");
599 if (logx) { gPad->SetLogx(); }
600 if (logy) { gPad->SetLogy(); }
601 if (logz) { gPad->SetLogz(); }
603 master->SetTitle(title.c_str());
605 master->GetXaxis()->SetRangeUser(xmin, xmax);
606 master->GetYaxis()->SetRangeUser(ymin, ymax);
608 if (logx > 1) { setLogarithmicX(master); }
609 if (logy > 1) { setLogarithmicY(master); }
611 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
612 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
614 master->SetMinimum(zmin);
615 master->SetMaximum(zmax);
617 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
618 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
619 if (zLabel !=
"") { master->GetZaxis()->SetTitle(zLabel.c_str()); master->GetZaxis()->CenterTitle(
true); }
621 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
622 (logx > 1 && xmax-xmin < 2));
623 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
624 (logy > 1 && ymax-ymin < 2));
627 master->SetNdivisions(i->second, i->first.c_str());
630 DEBUG(
"Draw " << master->GetName() <<
' ' << option << endl);
632 master->Draw(option.c_str());
635 if (logx > 1 || logy > 1) {
637 if (
dynamic_cast<TH2*
> (i->get()) != master &&
638 dynamic_cast<TGraph2D*
>(i->get()) != master) {
641 if (setLogX<TH2> (i->get())) {}
642 else if (setLogX<TGraph2DErrors>(i->get())) {}
643 else if (setLogX<TGraph2D> (i->get())) {}
644 else if (setLogX<TF2> (i->get())) {}
646 else if (setLogX<TH1> (i->get())) {}
647 else if (setLogX<TGraphErrors> (i->get())) {}
648 else if (setLogX<TGraph> (i->get())) {}
650 else if (setLogX<TLine> (i->get())) {}
651 else if (setLogX<TEllipse> (i->get())) {}
655 if (setLogY<TH2> (i->get())) {}
656 else if (setLogY<TGraph2DErrors>(i->get())) {}
657 else if (setLogY<TGraph2D> (i->get())) {}
658 else if (setLogY<TF2> (i->get())) {}
660 else if (setLogY<TH1> (i->get())) {}
661 else if (setLogY<TGraphErrors> (i->get())) {}
662 else if (setLogY<TGraph> (i->get())) {}
664 else if (setLogY<TLine> (i->get())) {}
665 else if (setLogY<TEllipse> (i->get())) {}
671 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
672 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
675 gStyle->SetOptStat(stats);
677 gStyle->SetOptFit(kFALSE);
682 if (i->get() != master) {
684 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
686 string buffer(option);
692 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
701 TGraph&
g1 =
dynamic_cast<TGraph&
>(*(*i));
709 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
718 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
729 (*i)->Draw(buffer.c_str());
745 return (master != NULL ? 0 : 1);