269{
272
274
281 JRange_t X;
282 JRange_t Y;
283 JRange_t Z;
294 string option;
297 string title;
299 size_t group;
302
303 try {
304
306
307 JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
308
309 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
314 zap[
'L'] =
make_field(
legend,
"position legend e.g. TR [factor]") = JLegend(), JLegend(
"TL"), JLegend(
"TR"), JLegend(
"BR"), JLegend(
"BL");
315 zap[
'x'] =
make_field(X,
"abscissa range") = JRange_t::DEFAULT_RANGE();
316 zap[
'y'] =
make_field(Y,
"ordinate range") = JRange_t::DEFAULT_RANGE();
317 zap[
'z'] =
make_field(Z,
"ordinate range of projection)") = JRange_t::DEFAULT_RANGE();
318 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
321 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
332 <<
"\"" <<
JName_t <<
"\" -> ROOT name; "
333 <<
"\"" <<
JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
335 zap[
'g'] =
make_field(group,
"group colour codes of objects") = 1;
338
340 }
341 catch(const exception &error) {
343 }
344
345
347
350
352 ((
TRootCanvas *) cv->GetCanvasImp())->
Connect(
"CloseWindow()",
"TApplication", tp,
"Terminate()");
353 }
354
356
358 gStyle->SetTitleOffset(
gStyle->GetTitleOffset() * 1.3,
"Y");
359 }
360
361 gROOT->SetStyle(
"gplot");
363
364 cv->SetFillStyle(4000);
366 cv->Divide(1,1);
367 cv->cd(1);
368
369
370 JMarkerAttributes::getInstance().setMarkerSize(
markerSize);
371 JLineAttributes ::getInstance().setLineWidth (
lineWidth);
372
373
376
379
380
382
386
389 }
390
391 if (px) {
392 swap(Y, Z);
393 }
394
396 swap(X, Z);
397 swap(Y, X);
398 }
399
401
403
405
407
409 ERROR(
"File: " << input->getFullFilename() <<
" not opened." <<
endl);
410 continue;
411 }
412
414
416
418
419 const TString tag(
key->GetName());
420
422
423
424
426
428 title =
key->GetName();
430 title =
key->GetTitle();
431 }
432
434
435 TAttMarker marker = JMarkerAttributes::getInstance().get(0);
436 TAttLine line = JLineAttributes ::getInstance().get(0);
437
438 if (group > 1)
440 else
442
445 else
446 line.SetLineColor(marker.GetMarkerColor());
447
448
449
450 try {
451
453
454 object = h1.ProjectionX();
455 }
456 catch(exception&) {}
457
458 try {
459
460 TH2& h2 =
dynamic_cast<TH2&
>(*object);
461
462 if (px) {
463
464 if (Z.is_valid())
466 h2.GetYaxis()->FindBin(Z.getLowerLimit()),
467 h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
468 else
470 1,
471 h2.GetYaxis()->GetNbins());
472
474
475 if (Z.is_valid())
477 h2.GetXaxis()->FindBin(Z.getLowerLimit()),
478 h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
479 else
481 1,
482 h2.GetXaxis()->GetNbins());
483
484 } else {
485
486 ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" <<
endl);
487
488 continue;
489 }
490 }
491 catch(exception&) {}
492
493 try {
494
495 TH3&
h3 =
dynamic_cast<TH3&
>(*object);
496
497 if (px) {
498
500
502
504
506
508
509 } else {
510
511 ERROR(
"For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" <<
endl);
512
513 continue;
514 }
515 }
516 catch(exception&) {}
517
518
519
520 try {
521 if (
dynamic_cast<TMarker*
>(
object.get()) ==
NULL) {
523 }
524 }
525 catch(exception&) {}
526
527 try {
528 if (
dynamic_cast<TLine*
>(
object.get()) ==
NULL) {
529 dynamic_cast<TAttLine&
> (*object) = line;
530 }
531 }
532 catch(exception&) {}
533
535
536 try {
537
539
541 fill.SetFillColor(marker.GetMarkerColor());
543 }
544 }
545 catch(exception&) {}
546 }
547
548
549
551
552 try {
553
554 TH1& h1 =
dynamic_cast<TH1&
>(*object);
555
556 for (int i = 1; i <= h1.GetNbinsX(); ++i) {
557 h1.SetBinError(i, 0.0);
558 }
559 }
560 catch(exception&) {}
561
562 try {
563
564 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
565
566 for (
Int_t i = 0; i !=
g1.GetN(); ++i) {
569 }
570 }
571 catch(exception&) {}
572 }
573
574
575
576 try {
577
578 TH1& h1 =
dynamic_cast<TH1&
>(*object);
579
580 h1.SetStats(
stats != -1);
581
582 xmin = min(xmin, h1.GetXaxis()->GetXmin());
583 xmax = max(xmax, h1.GetXaxis()->GetXmax());
586
587 if (!
logy && h1.GetListOfFunctions() !=
NULL) {
589 ymin = min(
ymin, f1->GetMinimum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
590 ymax = max(
ymax, f1->GetMaximum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
591 }
592 }
593 }
594 catch(exception&) {}
595
596 try {
597
598 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
599
600 for (
Int_t i = 0; i !=
g1.GetN(); ++i) {
601
602 xmin = min(xmin,
g1.GetX()[i]);
603 xmax = max(xmax,
g1.GetX()[i]);
604
605 if (!
logy ||
g1.GetY()[i] > 0.0) {
608 }
609 }
610 }
611 catch(exception&) {}
612
613 try {
614
615 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
616
617 for (
Int_t i = 0; i !=
g1.GetN(); ++i) {
618 if (!
logy ||
g1.GetY()[i] -
g1.GetEY()[i] > 0.0) {
ymin = min(
ymin,
g1.GetY()[i] -
g1.GetEY()[i]); }
619 if (!
logy ||
g1.GetY()[i] +
g1.GetEY()[i] > 0.0) {
ymax = max(
ymax,
g1.GetY()[i] +
g1.GetEY()[i]); }
620 }
621 }
622 catch(exception&) {}
623
624 try {
625
627
628 for (
TIter i1(
m1.GetListOfGraphs()); TGraph*
g1 =
dynamic_cast<TGraph*
>(
i1()); ) {
629
630 for (
Int_t i = 0; i !=
g1->GetN(); ++i) {
631
632 xmin = min(xmin,
g1->GetX()[i]);
633 xmax = max(xmax,
g1->GetX()[i]);
634
635 if (!
logy ||
g1->GetY()[i] > 0.0) {
638 }
639 }
640 }
641 }
642 catch(exception&) {}
643
644 try {
645
646 TF2& f2 = dynamic_cast<TF2&>(*object);
648
649 TString formula = f2.GetExpFormula();
650 TString
_z_ = TString::Format(
"%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
651
656
658
659 if (px) {
660
661 formula.ReplaceAll(
"y",
_z_);
662
664
666
668
669 formula.ReplaceAll(
"x",
_z_);
670 formula.ReplaceAll("y", "x");
671
673
675
676 } else {
677
678 ERROR(
"For 2D functions, use option option -P for projections or use JPlot2D" <<
endl);
679
680 continue;
681 }
682
683 DEBUG(
"TF1: " << f1->GetExpFormula() <<
endl);
684
685 f1->SetParameters(f2.GetParameters());
686
687 object = f1;
688 }
689 catch(exception&) {}
690
691 try {
692
693 TF1& f1 = dynamic_cast<TF1&>(*object);
694
697
699
704 }
705 catch(exception&) {}
706
707 try {
708
710
712
714
716
717 TH1& h1 =
dynamic_cast<TH1&
>(*i);
718
719 NOTICE(
"TH1[" << index <<
"] " << h1.GetName() <<
endl);
720
721 xmin = min(xmin, h1.GetXaxis()->GetXmin());
722 xmax = max(xmax, h1.GetXaxis()->GetXmax());
723
726
727 h1.SetLineWidth(1);
729
730 h1.SetFillColor(JMarkerAttributes::getInstance().get(index).
GetMarkerColor());
731 }
732 }
733 catch(exception&) {}
734
735 try {
736
738
739 xmin = min(xmin, h1.GetX1());
740 xmax = max(xmax, h1.GetX2());
743 }
744 catch(exception&) {}
745
746
747
748 for (TString buffer[] = { object.getLabel(), input->getFilename().c_str(), "" }, *i = buffer; *i != ""; ++i) {
749
750 *i = (*i)(
TRegexp(
"\\[.*\\]"));
751
752 if (i->Length() > 2) {
753 object.setLabel((*i)(1, i->Length() - 2));
754 }
755 }
756
757 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.
getLabel() <<
">" <<
endl);
758
760 master =
dynamic_cast<TH1*
>(
object.get());
761 }
762
764 }
765 }
766 }
767
770 }
771
773
774
775
776
777
778 TH1* h1 =
dynamic_cast<TH1*
> (i->get());
779 TGraph*
g1 =
dynamic_cast<TGraph*
> (i->get());
782
784
786
788
789 iterator.reset(h1->GetListOfFunctions()->MakeIterator());
790
792
793 iterator.reset(
g1->GetListOfFunctions()->MakeIterator());
794
796
797 for (
TIter i1(
m1->GetListOfGraphs()); TGraph*
gi =
dynamic_cast<TGraph*
>(
i1()); ) {
798 for (
TIter i2(
gi->GetListOfFunctions()); TF1*
fi =
dynamic_cast<TF1*
>(
i2()); ) {
800 }
801 }
802
804 }
805
807
810
811 for (
int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*)
iterator->Next(); ++
nf) {
812
813 f1->GetRange(x1[1], x2[1]);
814 f1->SetNpx(5000);
815
816 dynamic_cast<TAttLine&
>(*f1) = JLineAttributes::getInstance().get(0);
817
819
820 if (x1[0] == x1[1] &&
821 x2[0] == x2[1])
822 ++nc;
824 ++ns;
825
826 f1->SetLineStyle(JLineAttributes ::getInstance().get(ns).
GetLineStyle());
827 f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).
GetMarkerColor());
828
829 } else {
830
831
832
833 f1->SetLineColor(
ls->GetLineColor());
834 f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).
GetLineStyle());
835 }
836
837 x1[0] = x1[1];
838 x2[0] = x2[1];
839
840
841
842
843
844
845
846
847
848
849
850 }
851 }
852 }
853
854
855
856 if (X.is_valid()) {
857 xmin = X.getLowerLimit();
858 xmax = X.getUpperLimit();
859 }
860
861 if (Y.is_valid()) {
862 ymin = Y.getLowerLimit();
863 ymax = Y.getUpperLimit();
866 }
867
871 }
872
873 DEBUG(
"plot frame " << xmin <<
' ' << xmax <<
' ' <<
ymin <<
' ' <<
ymax <<
endl);
874
875 cv->cd(1);
876
878
880
882
884
887 }
888
890 }
891 }
892
894
896
897 p->SetTextAlign(21);
898 p->SetTextAngle(45);
899 p->Draw();
900
901 } else {
902
903 if (logx) {
gPad->SetLogx(); }
905
906 master->SetTitle(title.c_str());
907
908 master->GetXaxis()->SetRangeUser(max(xmin,
master->GetXaxis()->GetXmin()),
909 min(xmax,
master->GetXaxis()->GetXmax()));
910
912 if (logx > 2) {
master->GetXaxis()->SetNoExponent(); }
913
915 if (
logy > 2) {
master->GetYaxis()->SetNoExponent(); }
916
919
922
923 master->GetXaxis()->SetMoreLogLabels((logx == 1 &&
log10(xmax/xmin) < 2) ||
924 (logx > 1 && (xmax-xmin) < 2));
927
929 master->SetNdivisions(i->second, i->first.c_str());
930 }
931
933
934 master->GetXaxis()->SetTimeDisplay(1);
935
937 master->GetXaxis()->SetTimeFormat(
"#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
938 master->GetXaxis()->SetTimeOffset(0.0,
"gmt");
940 master->GetXaxis()->SetTimeFormat(
"%d-%m-%y");
941 master->GetXaxis()->SetTimeOffset(0.0,
"gmt");
942 } else {
944 }
945 }
946
947 master->Draw(option.c_str());
948 }
949
950 {
952
954 if (
dynamic_cast<TH1*
>(i->get()) !=
master) {
955 if (logx > 1) { setLog<typelist> X(i->get(), 'X'); }
956 if (
logy > 1) { setLog<typelist> Y(i->get(),
'Y'); }
957 }
958 }
959 }
960
961 if (
grid.count(
'x') ||
grid.count(
'X')) {
gPad->SetGridx(); }
962 if (
grid.count(
'y') ||
grid.count(
'Y')) {
gPad->SetGridy(); }
963
966 else
968
969
971
972 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() <<
endl);
973
974 string buffer(option);
975
976
977
978
979
980 buffer += "SAME";
981
982 TF1* f1 = dynamic_cast<TF1*> (i->get());
983 TGraph*
g1 =
dynamic_cast<TGraph*
> (i->get());
985
987 f1->SetNpx(5000);
988 }
989
992 buffer += "L";
994 (
dynamic_cast<TGraphErrors*
> (
g1) ==
NULL &&
996 buffer += "P";
997 }
998
1000
1001 for (
TIter i1(
q1->GetListOfGraphs()); TGraph*
gi =
dynamic_cast<TGraph*
>(
i1()); ) {
1002
1003 string zbuf = buffer;
1004
1006 zbuf += "L";
1007 else
1008 zbuf += "P";
1009
1010 gi->Draw(zbuf.c_str());
1011 }
1012
1013 } else {
1014
1015 (*i).Draw(buffer.c_str());
1016 }
1017 }
1018
1019
1020
1022
1023 if (group == 0) {
1025 }
1026
1029
1031
1033
1035 height += 1;
1037 }
1038 }
1039
1041
1043
1045
1047 lg->AddEntry(
object,
" " +
object.
getLabel(),
isTAttLine(
object) || option.find(
"HIST") != string::npos || option.find(
"hist") != string::npos ?
"L" :
isTAttFill(object) &&
fillArea != 0 ?
"F" :
"P");
1048 }
1049 }
1050
1052 }
1053
1054 cv->Update();
1055
1058 }
1059
1061 tp->Run();
1062 }
1063
1065}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define MAKE_CSTRING(A)
Make C-string.
Double_t g1(const Double_t x)
Function.
Utility class to parse parameter values.
Auxiliary data structure for TObject with a user defined label.
Template definition of a multi-dimensional oscillation probability interpolation table.
Auxiliary class to handle multiple boolean-like I/O.
Utility class to parse command line options.
Data structure for size of TCanvas.
Wrapper class around ROOT TStyle.
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
void setLogarithmicX(TList *list)
Make x-axis of objects in list logarithmic (e.g. after using log10()).
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
bool isTAttFill(const TObject *object)
Get drawing option of object.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
void setLogarithmicY(TList *list)
Make y-axis of objects in list logarithmic (e.g. after using log10()).
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
bool isTAttLine(const TObject *object)
Get drawing option of object.
size_t getSize(T(&array)[N])
Get size of c-array.
T pow(const T &x, const double y)
Power .
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
TLegend * getLegend(const Int_t width, const Int_t height, const std::string option, const Double_t factor=1.0)
Get legend.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
JProperties getProperties()
Get properties of this class.
Auxiliary data structure to list files in directory.