257 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
259 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
261 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") =
JCanvas(500, 500);
264 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t::DEFAULT_RANGE();
265 zap[
'y'] =
make_field(Y,
"y-abscissa range") = JRange_t::DEFAULT_RANGE();
266 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t::DEFAULT_RANGE();
267 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
268 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
269 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
270 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
271 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
272 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
273 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
274 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
275 zap[
'O'] =
make_field(option,
"plotting option") =
"";
277 zap[
'B'] =
make_field(batch,
"batch processing");
278 zap[
'T'] =
make_field(title,
"graphics title ("
279 <<
"\"" << JName_t <<
"\" -> ROOT name; "
280 <<
"\"" << JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
282 zap[
'p'] =
make_field(palette,
"palette") = -1;
287 catch(
const exception &error) {
288 FATAL(error.what() << endl);
292 gROOT->SetBatch(batch);
294 TApplication* tp =
new TApplication(
"user", NULL, NULL);
295 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.
x, canvas.
y);
298 ((TRootCanvas *) cv->GetCanvasImp())->Connect(
"CloseWindow()",
"TApplication", tp,
"Terminate()");
301 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
304 gStyle->SetPalette(palette);
307 gROOT->SetStyle(
"gplot");
311 cv->SetFillStyle(4000);
312 cv->SetFillColor(kWhite);
316 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
318 Double_t xmin = numeric_limits<double>::max();
319 Double_t xmax = numeric_limits<double>::lowest();
320 Double_t ymin = numeric_limits<double>::max();
321 Double_t ymax = numeric_limits<double>::lowest();
322 Double_t zmin = numeric_limits<double>::max();
323 Double_t zmax = numeric_limits<double>::lowest();
330 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
332 DEBUG(
"Input: " << *input << endl);
334 TDirectory* dir = getDirectory(*input);
337 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
341 const TRegexp regexp(input->getObjectName());
343 TIter iter(dir->GetListOfKeys());
345 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
347 const TString tag(key->GetName());
349 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
353 if (tag.Contains(regexp) && isTObject(key)) {
355 if (title == JName_t) {
356 title = key->GetName();
357 }
else if (title == JTitle_t) {
358 title = key->GetTitle();
365 TH3& h3 =
dynamic_cast<TH3&
>(*object);
367 object = h3.Project3D(project.c_str());
373 TH2& h2 =
dynamic_cast<TH2&
>(*object);
375 h2.SetStats(stats != -1);
377 xmin = min(xmin, h2.GetXaxis()->GetXmin());
378 xmax = max(xmax, h2.GetXaxis()->GetXmax());
379 ymin = min(ymin, h2.GetYaxis()->GetXmin());
380 ymax = max(ymax, h2.GetYaxis()->GetXmax());
381 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
382 zmax = max(zmax, h2.GetMaximum());
388 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
390 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
391 xmin = min(xmin,
g1.GetX()[i] - numeric_limits<float>::epsilon());
392 xmax = max(xmax,
g1.GetX()[i] + numeric_limits<float>::epsilon());
393 ymin = min(ymin,
g1.GetY()[i] - numeric_limits<float>::epsilon());
394 ymax = max(ymax,
g1.GetY()[i] + numeric_limits<float>::epsilon());
400 if (
dynamic_cast<TGraph*
>(i->get()) != NULL) {
405 static_cast<TAttMarker&
>(
g1) = JMarkerAttributes::getInstance().get(ng);
411 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
413 for (Int_t i = 0; i != g2.GetN(); ++i) {
414 if (!logz || g2.GetZ()[i] > 0.0) {
415 xmin = min(xmin, g2.GetX()[i]);
416 xmax = max(xmax, g2.GetX()[i]);
417 ymin = min(ymin, g2.GetY()[i]);
418 ymax = max(ymax, g2.GetY()[i]);
419 zmin = min(zmin, g2.GetZ()[i]);
420 zmax = max(zmax, g2.GetZ()[i]);
425 g2.SetMinimum(Z.getLowerLimit());
426 g2.SetMaximum(Z.getUpperLimit());
433 TF2& f2 =
dynamic_cast<TF2&
>(*object);
435 f2.SetLineColor(kRed);
436 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
443 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
445 xmin = min(xmin, __xmin);
446 xmax = max(xmax, __xmax);
447 ymin = min(ymin, __ymin);
448 ymax = max(ymax, __ymax);
449 zmin = min(zmin, f2.GetMinimum());
450 zmax = max(zmax, f2.GetMaximum());
456 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
458 *i = (*i)(TRegexp(
"\\[.*\\]"));
460 if ((*i).Length() > 2) {
461 object.setLabel((*i)(1, (*i).Length() - 2));
465 if (
dynamic_cast<TH2*
> (
object.get()) != NULL ||
466 dynamic_cast<TGraph*
> (
object.get()) != NULL ||
467 dynamic_cast<TGraph2D*
>(
object.get()) != NULL ||
468 dynamic_cast<TEllipse*
>(
object.get()) != NULL ||
469 dynamic_cast<TLine*
> (
object.get()) != NULL ||
470 dynamic_cast<TText*
> (
object.get()) != NULL ||
471 dynamic_cast<TF2*
> (
object.get()) != NULL) {
473 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.getLabel() <<
">" << endl);
475 if (master == NULL) {
477 master =
object.get();
480 listOfObjects.push_back(
object);
483 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
489 if (listOfObjects.empty()) {
490 ERROR(
"Nothing to draw." << endl);
497 if (option.find(
"COLZ") != string::npos ||
498 option.find(
"colz") != string::npos) {
499 gPad->SetRightMargin(0.20);
503 xmin = X.getLowerLimit();
504 xmax = X.getUpperLimit();
508 ymin = Y.getLowerLimit();
509 ymax = Y.getUpperLimit();
513 zmin = Z.getLowerLimit();
514 zmax = Z.getUpperLimit();
515 }
else if (zmax > zmin) {
516 setRange(zmin, zmax, logz);
519 if (!listOfObjects.empty()) {
521 if (master == NULL) {
523 master =
new TH2D(MASTER.c_str(), NULL,
527 master->SetStats(kFALSE);
531 if (master == NULL) {
533 TText* p =
new TText(0.5, 0.5,
"No data");
541 if (logx) { gPad->SetLogx(); }
542 if (logy) { gPad->SetLogy(); }
543 if (logz) { gPad->SetLogz(); }
545 master->SetTitle(title.c_str());
547 master->GetXaxis()->SetRangeUser(xmin, xmax);
548 master->GetYaxis()->SetRangeUser(ymin, ymax);
550 if (logx > 1) { setLogarithmicX(master); }
551 if (logy > 1) { setLogarithmicY(master); }
553 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
554 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
556 master->SetMinimum(zmin);
557 master->SetMaximum(zmax);
559 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
560 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
561 if (zLabel !=
"") { master->GetZaxis()->SetTitle(zLabel.c_str()); master->GetZaxis()->CenterTitle(
true); }
563 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
564 (logx > 1 && xmax-xmin < 2));
565 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
566 (logy > 1 && ymax-ymin < 2));
569 master->SetNdivisions(i->second, i->first.c_str());
572 DEBUG(
"Draw " << master->GetName() <<
' ' << option << endl);
574 master->Draw(option.c_str());
577 if (logx > 1 || logy > 1) {
579 if (
dynamic_cast<TH2*
>(i->get()) != master) {
581 if (setLogX<TH2> (i->get())) {}
582 else if (setLogX<TF2> (i->get())) {}
583 else if (setLogX<TGraph2DErrors>(i->get())) {}
584 else if (setLogX<TGraph2D> (i->get())) {}
585 else if (setLogX<TGraphErrors> (i->get())) {}
586 else if (setLogX<TGraph> (i->get())) {}
587 else if (setLogX<TLine> (i->get())) {}
588 else if (setLogX<TEllipse> (i->get())) {}
591 if (setLogY<TH2> (i->get())) {}
592 else if (setLogY<TF2> (i->get())) {}
593 else if (setLogY<TGraph2DErrors>(i->get())) {}
594 else if (setLogY<TGraph2D> (i->get())) {}
595 else if (setLogY<TGraphErrors> (i->get())) {}
596 else if (setLogY<TGraph> (i->get())) {}
597 else if (setLogY<TLine> (i->get())) {}
598 else if (setLogY<TEllipse> (i->get())) {}
604 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
605 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
608 gStyle->SetOptStat(stats);
610 gStyle->SetOptFit(kFALSE);
615 if (i->get() != master) {
617 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
619 string buffer(option);
625 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
634 TGraph&
g1 =
dynamic_cast<TGraph&
>(*(*i));
642 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
651 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
662 (*i)->Draw(buffer.c_str());
678 return (master != NULL ? 0 : 1);