261 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
263 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
265 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") =
JCanvas(500, 500);
268 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t::DEFAULT_RANGE();
269 zap[
'y'] =
make_field(Y,
"y-abscissa range") = JRange_t::DEFAULT_RANGE();
270 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t::DEFAULT_RANGE();
271 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
272 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
273 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
274 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
275 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
276 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
277 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
278 zap[
'C'] =
make_field(drawLine,
"draw line (-C black-and-white -CC colour)");
279 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
280 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
281 zap[
'O'] =
make_field(option,
"plotting option") =
"";
283 zap[
'B'] =
make_field(batch,
"batch processing");
284 zap[
'T'] =
make_field(title,
"graphics title ("
285 <<
"\"" << JName_t <<
"\" -> ROOT name; "
286 <<
"\"" << JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
288 zap[
'p'] =
make_field(palette,
"palette") = -1;
293 catch(
const exception &error) {
294 FATAL(error.what() << endl);
298 gROOT->SetBatch(batch);
300 TApplication* tp =
new TApplication(
"user", NULL, NULL);
301 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.
x, canvas.
y);
304 ((TRootCanvas *) cv->GetCanvasImp())->Connect(
"CloseWindow()",
"TApplication", tp,
"Terminate()");
307 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
310 gStyle->SetPalette(palette);
313 gROOT->SetStyle(
"gplot");
317 cv->SetFillStyle(4000);
318 cv->SetFillColor(kWhite);
323 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
324 JLineAttributes ::getInstance().setLineWidth (lineWidth);
327 Double_t xmin = numeric_limits<double>::max();
328 Double_t xmax = numeric_limits<double>::lowest();
329 Double_t ymin = numeric_limits<double>::max();
330 Double_t ymax = numeric_limits<double>::lowest();
331 Double_t zmin = numeric_limits<double>::max();
332 Double_t zmax = numeric_limits<double>::lowest();
339 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
341 DEBUG(
"Input: " << *input << endl);
343 TDirectory* dir = getDirectory(*input);
346 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
350 const TRegexp regexp(input->getObjectName());
352 TIter iter(dir->GetListOfKeys());
354 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
356 const TString tag(key->GetName());
358 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
362 if (tag.Contains(regexp) && isTObject(key)) {
364 if (title == JName_t) {
365 title = key->GetName();
366 }
else if (title == JTitle_t) {
367 title = key->GetTitle();
374 TH3& h3 =
dynamic_cast<TH3&
>(*object);
376 object = h3.Project3D(project.c_str());
382 TH2& h2 =
dynamic_cast<TH2&
>(*object);
384 h2.SetStats(stats != -1);
386 xmin = min(xmin, h2.GetXaxis()->GetXmin());
387 xmax = max(xmax, h2.GetXaxis()->GetXmax());
388 ymin = min(ymin, h2.GetYaxis()->GetXmin());
389 ymax = max(ymax, h2.GetYaxis()->GetXmax());
390 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
391 zmax = max(zmax, h2.GetMaximum());
397 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
399 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
400 xmin = min(xmin,
g1.GetX()[i] - numeric_limits<float>::epsilon());
401 xmax = max(xmax,
g1.GetX()[i] + numeric_limits<float>::epsilon());
402 ymin = min(ymin,
g1.GetY()[i] - numeric_limits<float>::epsilon());
403 ymax = max(ymax,
g1.GetY()[i] + numeric_limits<float>::epsilon());
409 if (
dynamic_cast<TGraph*
>(i->get()) != NULL) {
414 static_cast<TAttMarker&
>(
g1) = JMarkerAttributes::getInstance().get(ng);
420 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
422 for (Int_t i = 0; i != g2.GetN(); ++i) {
423 if (!logz || g2.GetZ()[i] > 0.0) {
424 xmin = min(xmin, g2.GetX()[i]);
425 xmax = max(xmax, g2.GetX()[i]);
426 ymin = min(ymin, g2.GetY()[i]);
427 ymax = max(ymax, g2.GetY()[i]);
428 zmin = min(zmin, g2.GetZ()[i]);
429 zmax = max(zmax, g2.GetZ()[i]);
434 g2.SetMinimum(Z.getLowerLimit());
435 g2.SetMaximum(Z.getUpperLimit());
442 TF2& f2 =
dynamic_cast<TF2&
>(*object);
444 f2.SetLineColor(kRed);
445 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
452 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
454 xmin = min(xmin, __xmin);
455 xmax = max(xmax, __xmax);
456 ymin = min(ymin, __ymin);
457 ymax = max(ymax, __ymax);
458 zmin = min(zmin, f2.GetMinimum());
459 zmax = max(zmax, f2.GetMaximum());
465 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
467 *i = (*i)(TRegexp(
"\\[.*\\]"));
469 if ((*i).Length() > 2) {
470 object.setLabel((*i)(1, (*i).Length() - 2));
474 if (
dynamic_cast<TH2*
> (
object.get()) != NULL ||
475 dynamic_cast<TGraph2D*
>(
object.get()) != NULL ||
476 dynamic_cast<TF2*
> (
object.get()) != NULL) {
478 if (master == NULL) {
479 master =
object.get();
482 }
else if (
dynamic_cast<TH1*
> (
object.get()) != NULL ||
483 dynamic_cast<TGraph*
> (
object.get()) != NULL) {
485 TAttMarker marker = *JMarkerAttributes::getInstance().next();
486 TAttLine line = JLineAttributes::getInstance().get(0);
489 line = *JLineAttributes::getInstance().next();
491 line.SetLineColor(marker.GetMarkerColor());
493 if (
dynamic_cast<TAttMarker*
>(
object.get()) != NULL) {
494 dynamic_cast<TAttMarker&
>(*object) = marker;
497 if (
dynamic_cast<TAttLine*
> (
object.get()) != NULL) {
498 dynamic_cast<TAttLine&
> (*object) = line;
508 TH1& h1 =
dynamic_cast<TH1&
>(*object);
510 for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
511 h1.SetBinError(i, 0.0);
518 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
520 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
528 }
else if (
dynamic_cast<TEllipse*
>(
object.get()) != NULL ||
529 dynamic_cast<TLine*
> (
object.get()) != NULL ||
530 dynamic_cast<TText*
> (
object.get()) != NULL) {
534 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
539 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.getLabel() <<
">" << endl);
541 listOfObjects.push_back(
object);
546 if (listOfObjects.empty()) {
547 ERROR(
"Nothing to draw." << endl);
554 if (option.find(
"COLZ") != string::npos ||
555 option.find(
"colz") != string::npos) {
556 gPad->SetRightMargin(0.20);
560 xmin = X.getLowerLimit();
561 xmax = X.getUpperLimit();
565 ymin = Y.getLowerLimit();
566 ymax = Y.getUpperLimit();
570 zmin = Z.getLowerLimit();
571 zmax = Z.getUpperLimit();
572 }
else if (zmax > zmin) {
573 setRange(zmin, zmax, logz);
576 if (!listOfObjects.empty()) {
578 if (master == NULL) {
580 master =
new TH2D(MASTER.c_str(), NULL,
584 master->SetStats(kFALSE);
588 if (master == NULL) {
590 TText* p =
new TText(0.5, 0.5,
"No data");
598 if (logx) { gPad->SetLogx(); }
599 if (logy) { gPad->SetLogy(); }
600 if (logz) { gPad->SetLogz(); }
602 master->SetTitle(title.c_str());
604 master->GetXaxis()->SetRangeUser(xmin, xmax);
605 master->GetYaxis()->SetRangeUser(ymin, ymax);
607 if (logx > 1) { setLogarithmicX(master); }
608 if (logy > 1) { setLogarithmicY(master); }
610 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
611 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
613 master->SetMinimum(zmin);
614 master->SetMaximum(zmax);
616 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
617 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
618 if (zLabel !=
"") { master->GetZaxis()->SetTitle(zLabel.c_str()); master->GetZaxis()->CenterTitle(
true); }
620 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
621 (logx > 1 && xmax-xmin < 2));
622 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
623 (logy > 1 && ymax-ymin < 2));
626 master->SetNdivisions(i->second, i->first.c_str());
629 DEBUG(
"Draw " << master->GetName() <<
' ' << option << endl);
631 master->Draw(option.c_str());
634 if (logx > 1 || logy > 1) {
636 if (
dynamic_cast<TH2*
> (i->get()) != master &&
637 dynamic_cast<TGraph2D*
>(i->get()) != master) {
640 if (setLogX<TH2> (i->get())) {}
641 else if (setLogX<TGraph2DErrors>(i->get())) {}
642 else if (setLogX<TGraph2D> (i->get())) {}
643 else if (setLogX<TF2> (i->get())) {}
645 else if (setLogX<TH1> (i->get())) {}
646 else if (setLogX<TGraphErrors> (i->get())) {}
647 else if (setLogX<TGraph> (i->get())) {}
649 else if (setLogX<TLine> (i->get())) {}
650 else if (setLogX<TEllipse> (i->get())) {}
654 if (setLogY<TH2> (i->get())) {}
655 else if (setLogY<TGraph2DErrors>(i->get())) {}
656 else if (setLogY<TGraph2D> (i->get())) {}
657 else if (setLogY<TF2> (i->get())) {}
659 else if (setLogY<TH1> (i->get())) {}
660 else if (setLogY<TGraphErrors> (i->get())) {}
661 else if (setLogY<TGraph> (i->get())) {}
663 else if (setLogY<TLine> (i->get())) {}
664 else if (setLogY<TEllipse> (i->get())) {}
670 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
671 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
674 gStyle->SetOptStat(stats);
676 gStyle->SetOptFit(kFALSE);
681 if (i->get() != master) {
683 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
685 string buffer(option);
691 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
700 TGraph&
g1 =
dynamic_cast<TGraph&
>(*(*i));
708 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
717 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
728 (*i)->Draw(buffer.c_str());
744 return (master != NULL ? 0 : 1);