286 JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
288 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
290 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") =
JCanvas(500, 500);
293 zap[
'L'] =
make_field(legend,
"position legend e.g. TR [factor]") = JLegend(), JLegend(
"TL"), JLegend(
"TR"), JLegend(
"BR"), JLegend(
"BL");
294 zap[
'x'] =
make_field(X,
"abscissa range") = JRange_t::DEFAULT_RANGE();
295 zap[
'y'] =
make_field(Y,
"ordinate range") = JRange_t::DEFAULT_RANGE();
296 zap[
'z'] =
make_field(Z,
"ordinate range of projection)") = JRange_t::DEFAULT_RANGE();
297 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
298 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
299 zap[
'Z'] =
make_field(logz,
"logarithmic y-axis; after projection");
300 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
301 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
302 zap[
'^'] =
make_field(yLabel,
"y-axis label") =
"";
303 zap[
'C'] =
make_field(drawLine,
"draw line (-C black-and-white -CC colour)");
304 zap[
'F'] =
make_field(fillArea,
"fill area") = 0;
305 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
306 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
307 zap[
'O'] =
make_field(option,
"plotting option") =
"";
309 zap[
'B'] =
make_field(batch,
"batch processing");
310 zap[
'T'] =
make_field(title,
"graphics title ("
311 <<
"\"" << JName_t <<
"\" -> ROOT name; "
312 <<
"\"" << JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
314 zap[
'g'] =
make_field(group,
"group colour codes of objects") = 1;
315 zap[
't'] =
make_field(xTimeFormat,
"set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") =
"";
320 catch(
const exception &error) {
321 FATAL(error.what() << endl);
325 gROOT->SetBatch(batch);
327 TApplication* tp =
new TApplication(
"user", NULL, NULL);
328 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.
x, canvas.
y);
331 ((TRootCanvas *) cv->GetCanvasImp())->Connect(
"CloseWindow()",
"TApplication", tp,
"Terminate()");
334 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
337 gStyle->SetTitleOffset(gStyle->GetTitleOffset() * 1.3,
"Y");
340 gROOT->SetStyle(
"gplot");
343 cv->SetFillStyle(4000);
344 cv->SetFillColor(kWhite);
349 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
350 JLineAttributes ::getInstance().setLineWidth (lineWidth);
353 Double_t xmin = numeric_limits<double>::max();
354 Double_t xmax = numeric_limits<double>::lowest();
356 Double_t ymin = numeric_limits<double>::max();
357 Double_t ymax = numeric_limits<double>::lowest();
362 const bool px = (project ==
'x' || project ==
'X');
363 const bool py = (project ==
'y' || project ==
'Y');
364 const bool pz = (project ==
'z' || project ==
'Z');
381 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
383 DEBUG(
"Input: " << *input << endl);
385 TDirectory* dir = getDirectory(*input);
388 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
392 const TRegexp regexp(input->getObjectName());
394 TIter iter(dir->GetListOfKeys());
396 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
398 const TString tag(key->GetName());
400 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
404 if (tag.Contains(regexp) && isTObject(key)) {
406 if (title == JName_t) {
407 title = key->GetName();
408 }
else if (title == JTitle_t) {
409 title = key->GetTitle();
414 TAttMarker marker = JMarkerAttributes::getInstance().get(0);
415 TAttLine line = JLineAttributes ::getInstance().get(0);
418 marker.SetMarkerColor(JMarkerAttributes::getInstance().get(listOfObjects.size()/group).GetMarkerColor());
422 line = JLineAttributes::getInstance().get(listOfObjects.size());
424 line.SetLineColor(marker.GetMarkerColor());
430 TProfile& h1 =
dynamic_cast<TProfile&
>(*object);
432 object = h1.ProjectionX();
438 TH2& h2 =
dynamic_cast<TH2&
>(*object);
443 object = h2.ProjectionX(
MAKE_CSTRING(h2.GetName() <<
"_px" << LABEL_TERMINATOR << listOfObjects.size()),
444 h2.GetYaxis()->FindBin(Z.getLowerLimit()),
445 h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
447 object = h2.ProjectionX(
MAKE_CSTRING(h2.GetName() <<
"_px" << LABEL_TERMINATOR << listOfObjects.size()),
449 h2.GetYaxis()->GetNbins());
454 object = h2.ProjectionY(
MAKE_CSTRING(h2.GetName() <<
"_py" << LABEL_TERMINATOR << listOfObjects.size()),
455 h2.GetXaxis()->FindBin(Z.getLowerLimit()),
456 h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
458 object = h2.ProjectionY(
MAKE_CSTRING(h2.GetName() <<
"_py" << LABEL_TERMINATOR << listOfObjects.size()),
460 h2.GetXaxis()->GetNbins());
464 ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
473 TH3& h3 =
dynamic_cast<TH3&
>(*object);
477 object = h3.ProjectionX(
MAKE_CSTRING(h3.GetName() <<
"_px" << LABEL_TERMINATOR << listOfObjects.size()));
481 object = h3.ProjectionY(
MAKE_CSTRING(h3.GetName() <<
"_py" << LABEL_TERMINATOR << listOfObjects.size()));
485 object = h3.ProjectionZ(
MAKE_CSTRING(h3.GetName() <<
"_pz" << LABEL_TERMINATOR << listOfObjects.size()));
489 ERROR(
"For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
499 if (
dynamic_cast<TMarker*
>(
object.get()) == NULL) {
500 dynamic_cast<TAttMarker&
>(*object) = marker;
506 if (
dynamic_cast<TLine*
>(
object.get()) == NULL) {
507 dynamic_cast<TAttLine&
> (*object) = line;
516 TAttFill& fill =
dynamic_cast<TAttFill&
>(*object);
518 if (!isTAttLine(
object) || fillArea < 0) {
519 fill.SetFillColor(marker.GetMarkerColor());
520 fill.SetFillStyle(abs(fillArea));
532 TH1& h1 =
dynamic_cast<TH1&
>(*object);
534 for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
535 h1.SetBinError(i, 0.0);
542 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
544 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
556 TH1& h1 =
dynamic_cast<TH1&
>(*object);
558 h1.SetStats(stats != -1);
560 xmin = min(xmin, h1.GetXaxis()->GetXmin());
561 xmax = max(xmax, h1.GetXaxis()->GetXmax());
562 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
563 ymax = max(ymax, h1.GetMaximum());
565 if (!logy && h1.GetListOfFunctions() != NULL) {
566 for (unique_ptr<TIterator>
iterator(h1.GetListOfFunctions()->MakeIterator()); TF1* f1 = (TF1*)
iterator->Next(); ) {
567 ymin = min(ymin, f1->GetMinimum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
568 ymax = max(ymax, f1->GetMaximum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
576 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
578 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
580 xmin = min(xmin,
g1.GetX()[i]);
581 xmax = max(xmax,
g1.GetX()[i]);
583 if (!logy ||
g1.GetY()[i] > 0.0) {
584 ymin = min(ymin,
g1.GetY()[i]);
585 ymax = max(ymax,
g1.GetY()[i]);
593 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
595 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
596 if (!logy ||
g1.GetY()[i] -
g1.GetEY()[i] > 0.0) { ymin = min(ymin,
g1.GetY()[i] -
g1.GetEY()[i]); }
597 if (!logy ||
g1.GetY()[i] +
g1.GetEY()[i] > 0.0) { ymax = max(ymax,
g1.GetY()[i] +
g1.GetEY()[i]); }
604 TMultiGraph& m1 =
dynamic_cast<TMultiGraph&
>(*object);
606 for (TIter i1(m1.GetListOfGraphs()); TGraph*
g1 =
dynamic_cast<TGraph*
>(i1()); ) {
608 for (Int_t i = 0; i !=
g1->GetN(); ++i) {
610 xmin = min(xmin,
g1->GetX()[i]);
611 xmax = max(xmax,
g1->GetX()[i]);
613 if (!logy ||
g1->GetY()[i] > 0.0) {
614 ymin = min(ymin,
g1->GetY()[i]);
615 ymax = max(ymax,
g1->GetY()[i]);
624 TF2& f2 =
dynamic_cast<TF2&
>(*object);
627 TString formula = f2.GetExpFormula();
628 TString _z_ = TString::Format(
"%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
635 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
639 formula.ReplaceAll(
"y", _z_);
641 f1 =
new TF1(
MAKE_CSTRING(f2.GetName() <<
"_px" << LABEL_TERMINATOR << listOfObjects.size()), formula);
643 f1->SetRange(__xmin, __xmax);
647 formula.ReplaceAll(
"x", _z_);
648 formula.ReplaceAll(
"y",
"x");
650 f1 =
new TF1(
MAKE_CSTRING(f2.GetName() <<
"_py" << LABEL_TERMINATOR << listOfObjects.size()), formula);
652 f1->SetRange(__ymin, __ymax);
656 ERROR(
"For 2D functions, use option option -P for projections or use JPlot2D" << endl);
661 DEBUG(
"TF1: " << f1->GetExpFormula() << endl);
663 f1->SetParameters(f2.GetParameters());
671 TF1& f1 =
dynamic_cast<TF1&
>(*object);
676 f1.GetRange(__xmin, __xmax);
678 xmin = min(xmin, __xmin);
679 xmax = max(xmax, __xmax);
680 ymin = min(ymin, f1.GetMinimum());
681 ymax = max(ymax, f1.GetMaximum());
687 THStack& hs =
dynamic_cast<THStack&
>(*object);
689 NOTICE(
"THStack" << endl);
691 unique_ptr<TIterator>
iterator(hs.GetHists()->MakeIterator());
695 TH1& h1 =
dynamic_cast<TH1&
>(*i);
697 NOTICE(
"TH1[" << index <<
"] " << h1.GetName() << endl);
699 xmin = min(xmin, h1.GetXaxis()->GetXmin());
700 xmax = max(xmax, h1.GetXaxis()->GetXmax());
702 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
703 ymax = max(ymax, h1.GetMaximum());
706 h1.SetLineColor(kBlack);
708 h1.SetFillColor(JMarkerAttributes::getInstance().get(index).GetMarkerColor());
715 TLine& h1 =
dynamic_cast<TLine&
>(*object);
717 xmin = min(xmin, h1.GetX1());
718 xmax = max(xmax, h1.GetX2());
719 ymin = min(ymin, h1.GetY1());
720 ymax = max(ymax, h1.GetY2());
726 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
728 *i = (*i)(TRegexp(
"\\[.*\\]"));
730 if (i->Length() > 2) {
731 object.setLabel((*i)(1, i->Length() - 2));
735 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.getLabel() <<
">" << endl);
737 if (master == NULL) {
738 master =
dynamic_cast<TH1*
>(
object.get());
741 listOfObjects.push_back(
object);
746 if (listOfObjects.empty()) {
747 ERROR(
"Nothing to draw." << endl);
756 TH1* h1 =
dynamic_cast<TH1*
> (i->get());
757 TGraph*
g1 =
dynamic_cast<TGraph*
> (i->get());
758 TMultiGraph* m1 =
dynamic_cast<TMultiGraph*
>(i->get());
759 TAttLine*
ls =
dynamic_cast<TAttLine*
> (i->get());
767 iterator.reset(h1->GetListOfFunctions()->MakeIterator());
769 }
else if (
g1 != NULL) {
771 iterator.reset(
g1->GetListOfFunctions()->MakeIterator());
773 }
else if (m1 != NULL) {
775 for (TIter i1(m1->GetListOfGraphs()); TGraph* gi =
dynamic_cast<TGraph*
>(i1()); ) {
776 for (TIter i2(gi->GetListOfFunctions()); TF1* fi =
dynamic_cast<TF1*
>(i2()); ) {
786 Double_t x1[] = { numeric_limits<Double_t>::max(), numeric_limits<Double_t>::max() };
787 Double_t x2[] = { numeric_limits<Double_t>::lowest(), numeric_limits<Double_t>::lowest() };
789 for (
int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*)
iterator->Next(); ++nf) {
791 f1->GetRange(x1[1], x2[1]);
794 dynamic_cast<TAttLine&
>(*f1) = JLineAttributes::getInstance().get(0);
796 if (listOfObjects.size() == 1) {
798 if (x1[0] == x1[1] &&
804 f1->SetLineStyle(JLineAttributes ::getInstance().get(ns).GetLineStyle());
805 f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).GetMarkerColor());
811 f1->SetLineColor(
ls->GetLineColor());
812 f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).GetLineStyle());
835 xmin = X.getLowerLimit();
836 xmax = X.getUpperLimit();
840 ymin = Y.getLowerLimit();
841 ymax = Y.getUpperLimit();
842 }
else if (ymax > ymin) {
843 setRange(ymin, ymax, logy == 1);
847 ymin = pow(10.0, ymin);
848 ymax = pow(10.0, ymax);
853 if (!listOfObjects.empty()) {
855 if (master == NULL) {
857 master =
new TH1D(MASTER.c_str(), NULL, 1000, xmin, xmax);
859 master->SetStats(kFALSE);
861 for (Int_t i = 1; i <= master->GetXaxis()->GetNbins(); ++i) {
862 master->SetBinContent(i, ymin);
867 if (master == NULL) {
869 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
877 if (logx) { gPad->SetLogx(); }
878 if (logy) { gPad->SetLogy(); }
880 master->SetTitle(title.c_str());
882 master->GetXaxis()->SetRangeUser(xmin, xmax);
884 if (logx > 1) { setLogarithmicX(master); }
885 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
887 if (logy > 1) { setLogarithmicY(master); }
888 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
890 master->SetMinimum(ymin);
891 master->SetMaximum(ymax);
893 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
894 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
896 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
897 (logx > 1 && (xmax-xmin) < 2));
898 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
899 (logy > 1 && (ymax-ymin) < 2));
902 master->SetNdivisions(i->second, i->first.c_str());
905 if (xTimeFormat !=
"") {
907 master->GetXaxis()->SetTimeDisplay(1);
909 if (xTimeFormat ==
"utc") {
910 master->GetXaxis()->SetTimeFormat(
"#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
911 master->GetXaxis()->SetTimeOffset(0.0,
"gmt");
912 }
else if (xTimeFormat ==
"UTC") {
913 master->GetXaxis()->SetTimeFormat(
"%d-%m-%y");
914 master->GetXaxis()->SetTimeOffset(0.0,
"gmt");
916 master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
920 master->Draw(option.c_str());
927 if (
dynamic_cast<TH1*
>(i->get()) != master) {
928 if (logx > 1) { setLog<typelist> X(i->get(),
'X'); }
929 if (logy > 1) { setLog<typelist> Y(i->get(),
'Y'); }
934 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
935 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
938 gStyle->SetOptStat(stats);
940 gStyle->SetOptFit(kFALSE);
943 for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
945 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
947 string buffer(option);
955 TF1* f1 =
dynamic_cast<TF1*
> (i->get());
956 TGraph*
g1 =
dynamic_cast<TGraph*
> (i->get());
957 TMultiGraph* q1 =
dynamic_cast<TMultiGraph*
>(i->get());
964 if (
g1->GetN() > 1 && drawLine)
966 else if (fillArea == 0 ||
967 (
dynamic_cast<TGraphErrors*
> (
g1) == NULL &&
968 dynamic_cast<TGraphAsymmErrors*
>(
g1) == NULL))
974 for (TIter i1(q1->GetListOfGraphs()); TGraph* gi =
dynamic_cast<TGraph*
>(i1()); ) {
976 string zbuf = buffer;
978 if (gi->GetN() > 1 && drawLine)
983 gi->Draw(zbuf.c_str());
988 (*i).Draw(buffer.c_str());
994 if (legend.is_valid()) {
997 group = listOfObjects.size();
1003 for (
size_t i = 0; i < listOfObjects.size(); i += group) {
1007 if (is_legend(
object.get())) {
1009 width = max(width, getWidth(
object.getLabel()));
1013 TLegend* lg = getLegend(width, height, legend.location, legend.factor);
1015 for (
size_t i = 0; i < listOfObjects.size(); i += group) {
1019 if (is_legend(
object.get())) {
1020 lg->AddEntry(
object,
" " +
object.getLabel(), isTAttLine(
object) ?
"L" : isTAttFill(
object) && fillArea != 0 ?
"F" :
"P");
1037 return (master != NULL ? 0 : 1);