Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JPlot1D.cc File Reference

General purpose plot program for 1D ROOT objects. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <cmath>
#include <memory>
#include "TROOT.h"
#include "TFile.h"
#include "TClass.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TKey.h"
#include "TStyle.h"
#include "TAttMarker.h"
#include "TAttLine.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TF1.h"
#include "TF2.h"
#include "THStack.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TGraphAsymmErrors.h"
#include "TMultiGraph.h"
#include "TProfile.h"
#include "TEllipse.h"
#include "TMarker.h"
#include "TLine.h"
#include "TLegend.h"
#include "TString.h"
#include "TRegexp.h"
#include "TText.h"
#include "JTools/JRange.hh"
#include "JROOT/JStyle.hh"
#include "JROOT/JCanvas.hh"
#include "JROOT/JMarkerAttributes.hh"
#include "JROOT/JLineAttributes.hh"
#include "JROOT/JLegend.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JRootObject.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JProperties.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

General purpose plot program for 1D ROOT objects.

The option -f corresponds to <file name>:<object name>.

Author
mdejong

Definition in file JPlot1D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 247 of file JPlot1D.cc.

248{
249 using namespace std;
250 using namespace JPP;
251
252 typedef JRange<double> JRange_t;
253
254 vector<JRootObjectID> inputFile;
255 string outputFile;
256 JCanvas canvas;
257 JStyle::JParameters parameters;
258 int stats;
259 JLegend legend;
260 JRange_t X;
261 JRange_t Y;
262 JRange_t Z;
263 JCounter logx;
264 JCounter logy;
265 bool logz;
266 char project;
267 string xLabel;
268 string yLabel;
269 JCounter drawLine;
270 int fillArea;
271 int lineWidth;
272 double markerSize;
273 string option;
274 set<char> grid;
275 bool batch;
276 string title;
277 map<string, int> Ndivisions;
278 size_t group;
279 int debug;
280 string xTimeFormat;
281
282 try {
283
284 JProperties properties = parameters.getProperties();
285
286 JParser<> zap("General purpose plot program for 1D ROOT objects.");
287
288 zap['f'] = make_field(inputFile, "<input file>:<object name>");
289 zap['o'] = make_field(outputFile, "graphics output") = "";
290 zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
291 zap['@'] = make_field(properties) = JPARSER::initialised();
292 zap['s'] = make_field(stats) = -1;
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") = "";
308 zap['G'] = make_field(grid, "grid lines [X][Y]") = JPARSER::initialised();
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";
313 zap['N'] = make_field(Ndivisions, "axis divisioning (e.g. \"X 505\")") = JPARSER::initialised();
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") = "";
316 zap['d'] = make_field(debug) = 0;
317
318 zap(argc, argv);
319 }
320 catch(const exception &error) {
321 FATAL(error.what() << endl);
322 }
323
324
325 gROOT->SetBatch(batch);
326
327 TApplication* tp = new TApplication("user", NULL, NULL);
328 TCanvas* cv = new TCanvas("c1", "c1", canvas.x, canvas.y);
329
330 if (!batch) {
331 ((TRootCanvas *) cv->GetCanvasImp())->Connect("CloseWindow()", "TApplication", tp, "Terminate()");
332 }
333
334 unique_ptr<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh(), parameters));
335
336 if (logy || logz) {
337 gStyle->SetTitleOffset(gStyle->GetTitleOffset() * 1.3, "Y");
338 }
339
340 gROOT->SetStyle("gplot");
341 gROOT->ForceStyle();
342
343 cv->SetFillStyle(4000);
344 cv->SetFillColor(kWhite);
345 cv->Divide(1,1);
346 cv->cd(1);
347
348
349 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
350 JLineAttributes ::getInstance().setLineWidth (lineWidth);
351
352
353 Double_t xmin = numeric_limits<double>::max();
354 Double_t xmax = numeric_limits<double>::lowest();
355
356 Double_t ymin = numeric_limits<double>::max();
357 Double_t ymax = numeric_limits<double>::lowest();
358
359
360 vector<JRootObject> listOfObjects;
361
362 const bool px = (project == 'x' || project == 'X'); // projection on x-axis of (2|3)D histogram
363 const bool py = (project == 'y' || project == 'Y'); // projection on y-axis of (2|3)D histogram
364 const bool pz = (project == 'z' || project == 'Z'); // projection on z-axis of 3D histogram
365
366 if (logz) {
367 logy = logz;
368 }
369
370 if (px) {
371 swap(Y, Z); // Y becomes range in TH2::ProjectionX() and Z becomes y-axis range
372 }
373
374 if (py) {
375 swap(X, Z); // X becomes range in TH2::ProjectionY()
376 swap(Y, X); // Y becomes x-axis range and Z becomes y-axis range
377 }
378
379 TH1* master = NULL;
380
381 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
382
383 DEBUG("Input: " << *input << endl);
384
385 TDirectory* dir = getDirectory(*input);
386
387 if (dir == NULL) {
388 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
389 continue;
390 }
391
392 const TRegexp regexp(input->getObjectName());
393
394 TIter iter(dir->GetListOfKeys());
395
396 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
397
398 const TString tag(key->GetName());
399
400 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
401
402 // option match
403
404 if (tag.Contains(regexp) && isTObject(key)) {
405
406 if (title == JName_t) {
407 title = key->GetName();
408 } else if (title == JTitle_t) {
409 title = key->GetTitle();
410 }
411
412 JRootObject object(key->ReadObj());
413
414 TAttMarker marker = JMarkerAttributes::getInstance().get(0);
415 TAttLine line = JLineAttributes ::getInstance().get(0);
416
417 if (group != 0) {
418 marker.SetMarkerColor(JMarkerAttributes::getInstance().get(listOfObjects.size()/group).GetMarkerColor());
419 }
420
421 if (drawLine == 1)
422 line = JLineAttributes::getInstance().get(listOfObjects.size());
423 else
424 line.SetLineColor(marker.GetMarkerColor());
425
426 // projections
427
428 try {
429
430 TProfile& h1 = dynamic_cast<TProfile&>(*object);
431
432 object = h1.ProjectionX();
433 }
434 catch(exception&) {}
435
436 try {
437
438 TH2& h2 = dynamic_cast<TH2&>(*object);
439
440 if (px) {
441
442 if (Z.is_valid())
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);
446 else
447 object = h2.ProjectionX(MAKE_CSTRING(h2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()),
448 1,
449 h2.GetYaxis()->GetNbins());
450
451 } else if (py) {
452
453 if (Z.is_valid())
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);
457 else
458 object = h2.ProjectionY(MAKE_CSTRING(h2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()),
459 1,
460 h2.GetXaxis()->GetNbins());
461
462 } else {
463
464 ERROR("For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
465
466 continue;
467 }
468 }
469 catch(exception&) {}
470
471 try {
472
473 TH3& h3 = dynamic_cast<TH3&>(*object);
474
475 if (px) {
476
477 object = h3.ProjectionX(MAKE_CSTRING(h3.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()));
478
479 } else if (py) {
480
481 object = h3.ProjectionY(MAKE_CSTRING(h3.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()));
482
483 } else if (pz) {
484
485 object = h3.ProjectionZ(MAKE_CSTRING(h3.GetName() << "_pz" << LABEL_TERMINATOR << listOfObjects.size()));
486
487 } else {
488
489 ERROR("For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
490
491 continue;
492 }
493 }
494 catch(exception&) {}
495
496 // colouring
497
498 try {
499 if (dynamic_cast<TMarker*>(object.get()) == NULL) {
500 dynamic_cast<TAttMarker&>(*object) = marker;
501 }
502 }
503 catch(exception&) {}
504
505 try {
506 if (dynamic_cast<TLine*>(object.get()) == NULL) {
507 dynamic_cast<TAttLine&> (*object) = line;
508 }
509 }
510 catch(exception&) {}
511
512 if (fillArea != 0) {
513
514 try {
515
516 TAttFill& fill = dynamic_cast<TAttFill&>(*object);
517
518 if (!isTAttLine(object) || fillArea < 0) {
519 fill.SetFillColor(marker.GetMarkerColor());
520 fill.SetFillStyle(abs(fillArea));
521 }
522 }
523 catch(exception&) {}
524 }
525
526 // set errors
527
528 if (drawLine) {
529
530 try {
531
532 TH1& h1 = dynamic_cast<TH1&>(*object);
533
534 for (int i = 1; i <= h1.GetNbinsX(); ++i) {
535 h1.SetBinError(i, 0.0);
536 }
537 }
538 catch(exception&) {}
539
540 try {
541
542 TGraphErrors& g1 = dynamic_cast<TGraphErrors&>(*object);
543
544 for (Int_t i = 0; i != g1.GetN(); ++i) {
545 g1.GetEX()[i] = 0.0;
546 g1.GetEY()[i] = 0.0;
547 }
548 }
549 catch(exception&) {}
550 }
551
552 // min-max
553
554 try {
555
556 TH1& h1 = dynamic_cast<TH1&>(*object);
557
558 h1.SetStats(stats != -1);
559
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());
564
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()));
569 }
570 }
571 }
572 catch(exception&) {}
573
574 try {
575
576 TGraph& g1 = dynamic_cast<TGraph&>(*object);
577
578 for (Int_t i = 0; i != g1.GetN(); ++i) {
579
580 xmin = min(xmin, g1.GetX()[i]);
581 xmax = max(xmax, g1.GetX()[i]);
582
583 if (!logy || g1.GetY()[i] > 0.0) {
584 ymin = min(ymin, g1.GetY()[i]);
585 ymax = max(ymax, g1.GetY()[i]);
586 }
587 }
588 }
589 catch(exception&) {}
590
591 try {
592
593 TGraphErrors& g1 = dynamic_cast<TGraphErrors&>(*object);
594
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]); }
598 }
599 }
600 catch(exception&) {}
601
602 try {
603
604 TMultiGraph& m1 = dynamic_cast<TMultiGraph&>(*object);
605
606 for (TIter i1(m1.GetListOfGraphs()); TGraph* g1 = dynamic_cast<TGraph*>(i1()); ) {
607
608 for (Int_t i = 0; i != g1->GetN(); ++i) {
609
610 xmin = min(xmin, g1->GetX()[i]);
611 xmax = max(xmax, g1->GetX()[i]);
612
613 if (!logy || g1->GetY()[i] > 0.0) {
614 ymin = min(ymin, g1->GetY()[i]);
615 ymax = max(ymax, g1->GetY()[i]);
616 }
617 }
618 }
619 }
620 catch(exception&) {}
621
622 try {
623
624 TF2& f2 = dynamic_cast<TF2&>(*object);
625 TF1* f1 = NULL;
626
627 TString formula = f2.GetExpFormula();
628 TString _z_ = TString::Format("%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
629
630 double __xmin;
631 double __xmax;
632 double __ymin;
633 double __ymax;
634
635 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
636
637 if (px) {
638
639 formula.ReplaceAll("y", _z_);
640
641 f1 = new TF1(MAKE_CSTRING(f2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()), formula);
642
643 f1->SetRange(__xmin, __xmax);
644
645 } else if (py) {
646
647 formula.ReplaceAll("x", _z_);
648 formula.ReplaceAll("y", "x");
649
650 f1 = new TF1(MAKE_CSTRING(f2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()), formula);
651
652 f1->SetRange(__ymin, __ymax);
653
654 } else {
655
656 ERROR("For 2D functions, use option option -P for projections or use JPlot2D" << endl);
657
658 continue;
659 }
660
661 DEBUG("TF1: " << f1->GetExpFormula() << endl);
662
663 f1->SetParameters(f2.GetParameters());
664
665 object = f1;
666 }
667 catch(exception&) {}
668
669 try {
670
671 TF1& f1 = dynamic_cast<TF1&>(*object);
672
673 double __xmin;
674 double __xmax;
675
676 f1.GetRange(__xmin, __xmax);
677
678 xmin = min(xmin, __xmin);
679 xmax = max(xmax, __xmax);
680 ymin = min(ymin, f1.GetMinimum());
681 ymax = max(ymax, f1.GetMaximum());
682 }
683 catch(exception&) {}
684
685 try {
686
687 THStack& hs = dynamic_cast<THStack&>(*object);
688
689 NOTICE("THStack" << endl);
690
691 unique_ptr<TIterator> iterator(hs.GetHists()->MakeIterator());
692
693 for (size_t index = 1; TObject* i = iterator->Next(); ++index) {
694
695 TH1& h1 = dynamic_cast<TH1&>(*i);
696
697 NOTICE("TH1[" << index << "] " << h1.GetName() << endl);
698
699 xmin = min(xmin, h1.GetXaxis()->GetXmin());
700 xmax = max(xmax, h1.GetXaxis()->GetXmax());
701
702 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
703 ymax = max(ymax, h1.GetMaximum());
704
705 h1.SetLineWidth(1);
706 h1.SetLineColor(kBlack);
707
708 h1.SetFillColor(JMarkerAttributes::getInstance().get(index).GetMarkerColor());
709 }
710 }
711 catch(exception&) {}
712
713 try {
714
715 TLine& h1 = dynamic_cast<TLine&>(*object);
716
717 xmin = min(xmin, h1.GetX1());
718 xmax = max(xmax, h1.GetX2());
719 ymin = min(ymin, h1.GetY1());
720 ymax = max(ymax, h1.GetY2());
721 }
722 catch(exception&) {}
723
724 // label
725
726 for (TString buffer[] = { object.getLabel(), input->getFilename().c_str(), "" }, *i = buffer; *i != ""; ++i) {
727
728 *i = (*i)(TRegexp("\\[.*\\]"));
729
730 if (i->Length() > 2) {
731 object.setLabel((*i)(1, i->Length() - 2));
732 }
733 }
734
735 DEBUG("Add object: " << tag << " with label <" << object.getLabel() << ">" << endl);
736
737 if (master == NULL) {
738 master = dynamic_cast<TH1*>(object.get());
739 }
740
741 listOfObjects.push_back(object);
742 }
743 }
744 }
745
746 if (listOfObjects.empty()) {
747 ERROR("Nothing to draw." << endl);
748 }
749
750 for (vector<JRootObject>::iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
751
752 // set line attributes of associated functions
753 // for single objects, change colour if same range else change style
754 // for multiple objecs, keep colour and change style
755
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());
760
761 TList list;
762
763 unique_ptr<TIterator> iterator;
764
765 if (h1 != NULL) {
766
767 iterator.reset(h1->GetListOfFunctions()->MakeIterator());
768
769 } else if (g1 != NULL) {
770
771 iterator.reset(g1->GetListOfFunctions()->MakeIterator());
772
773 } else if (m1 != NULL) {
774
775 for (TIter i1(m1->GetListOfGraphs()); TGraph* gi = dynamic_cast<TGraph*>(i1()); ) {
776 for (TIter i2(gi->GetListOfFunctions()); TF1* fi = dynamic_cast<TF1*>(i2()); ) {
777 list.Add(fi);
778 }
779 }
780
781 iterator.reset(list.MakeIterator());
782 }
783
784 if (iterator != NULL) {
785
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() };
788
789 for (int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*) iterator->Next(); ++nf) {
790
791 f1->GetRange(x1[1], x2[1]);
792 f1->SetNpx(5000);
793
794 dynamic_cast<TAttLine&>(*f1) = JLineAttributes::getInstance().get(0);
795
796 if (listOfObjects.size() == 1) {
797
798 if (x1[0] == x1[1] &&
799 x2[0] == x2[1])
800 ++nc; // change colour
801 else if (nf != 0)
802 ++ns; // change style
803
804 f1->SetLineStyle(JLineAttributes ::getInstance().get(ns).GetLineStyle());
805 f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).GetMarkerColor());
806
807 } else {
808
809 // keep colour of base object and accordingly modify line style.
810
811 f1->SetLineColor(ls->GetLineColor());
812 f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).GetLineStyle());
813 }
814
815 x1[0] = x1[1];
816 x2[0] = x2[1];
817
818 // set limits
819 /*
820 double __xmin;
821 double __xmax;
822
823 f1->GetRange(__xmin, __xmax);
824
825 ymin = min(ymin, f1->GetMinimum(__xmin, __xmax));
826 ymax = max(ymax, f1->GetMaximum(__xmin, __xmax));
827 */
828 }
829 }
830 }
831
832 // plot frame
833
834 if (X.is_valid()) {
835 xmin = X.getLowerLimit();
836 xmax = X.getUpperLimit();
837 }
838
839 if (Y.is_valid()) {
840 ymin = Y.getLowerLimit();
841 ymax = Y.getUpperLimit();
842 } else if (ymax > ymin) {
843 setRange(ymin, ymax, logy == 1);
844 }
845
846 if (logy > 1) {
847 ymin = pow(10.0, ymin);
848 ymax = pow(10.0, ymax);
849 }
850
851 cv->cd(1);
852
853 if (!listOfObjects.empty()) {
854
855 if (master == NULL) {
856
857 master = new TH1D(MASTER.c_str(), NULL, 1000, xmin, xmax);
858
859 master->SetStats(kFALSE);
860
861 for (Int_t i = 1; i <= master->GetXaxis()->GetNbins(); ++i) {
862 master->SetBinContent(i, ymin);
863 }
864 }
865 }
866
867 if (master == NULL) {
868
869 TText* p = new TText(0.5, 0.5, MAKE_CSTRING("No data"));
870
871 p->SetTextAlign(21);
872 p->SetTextAngle(45);
873 p->Draw();
874
875 } else {
876
877 if (logx) { gPad->SetLogx(); }
878 if (logy) { gPad->SetLogy(); }
879
880 master->SetTitle(title.c_str());
881
882 master->GetXaxis()->SetRangeUser(xmin, xmax);
883
884 if (logx > 1) { setLogarithmicX(master); }
885 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
886
887 if (logy > 1) { setLogarithmicY(master); }
888 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
889
890 master->SetMinimum(ymin);
891 master->SetMaximum(ymax);
892
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); }
895
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));
900
901 for (map<string, int>::const_iterator i = Ndivisions.begin(); i != Ndivisions.end(); ++i) {
902 master->SetNdivisions(i->second, i->first.c_str());
903 }
904
905 if (xTimeFormat != "") {
906
907 master->GetXaxis()->SetTimeDisplay(1);
908
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");
915 } else {
916 master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
917 }
918 }
919
920 master->Draw(option.c_str());
921 }
922
923 {
925
926 for (vector<JRootObject>::iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
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'); }
930 }
931 }
932 }
933
934 if (grid.count('x') || grid.count('X')) { gPad->SetGridx(); }
935 if (grid.count('y') || grid.count('Y')) { gPad->SetGridy(); }
936
937 if (stats != -1)
938 gStyle->SetOptStat(stats);
939 else
940 gStyle->SetOptFit(kFALSE);
941
942
943 for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
944
945 DEBUG("Draw " << (*i)->GetName() << ' ' << (*i)->GetTitle() << endl);
946
947 string buffer(option);
948
949 //if (!dynamic_cast<THStack*>(i->get())) {
950 // buffer += "SAMES";
951 //}
952
953 buffer += "SAME";
954
955 TF1* f1 = dynamic_cast<TF1*> (i->get());
956 TGraph* g1 = dynamic_cast<TGraph*> (i->get());
957 TMultiGraph* q1 = dynamic_cast<TMultiGraph*>(i->get());
958
959 if (f1 != NULL) {
960 f1->SetNpx(5000);
961 }
962
963 if (g1 != NULL) {
964 if (g1->GetN() > 1 && drawLine)
965 buffer += "L"; // drawing cut line
966 else if (fillArea == 0 ||
967 (dynamic_cast<TGraphErrors*> (g1) == NULL &&
968 dynamic_cast<TGraphAsymmErrors*>(g1) == NULL))
969 buffer += "P"; // drawing point(s)
970 }
971
972 if (q1 != NULL) {
973
974 for (TIter i1(q1->GetListOfGraphs()); TGraph* gi = dynamic_cast<TGraph*>(i1()); ) {
975
976 string zbuf = buffer;
977
978 if (gi->GetN() > 1 && drawLine)
979 zbuf += "L"; // drawing cut line
980 else
981 zbuf += "P"; // drawing point(s)
982
983 gi->Draw(zbuf.c_str());
984 }
985
986 } else {
987
988 (*i).Draw(buffer.c_str());
989 }
990 }
991
992 //gPad->RedrawAxis();
993
994 if (legend.is_valid()) {
995
996 if (group == 0) {
997 group = listOfObjects.size();
998 }
999
1000 Ssiz_t height = 0;
1001 Ssiz_t width = 1;
1002
1003 for (size_t i = 0; i < listOfObjects.size(); i += group) {
1004
1005 const JRootObject& object = listOfObjects[i];
1006
1007 if (is_legend(object.get())) {
1008 height += 1;
1009 width = max(width, getWidth(object.getLabel()));
1010 }
1011 }
1012
1013 TLegend* lg = getLegend(width, height, legend.location, legend.factor);
1014
1015 for (size_t i = 0; i < listOfObjects.size(); i += group) {
1016
1017 const JRootObject& object = listOfObjects[i];
1018
1019 if (is_legend(object.get())) {
1020 lg->AddEntry(object, " " + object.getLabel(), isTAttLine(object) ? "L" : isTAttFill(object) && fillArea != 0 ? "F" : "P");
1021 }
1022 }
1023
1024 lg->Draw();
1025 }
1026
1027 cv->Update();
1028
1029 if (outputFile != "") {
1030 cv->SaveAs(outputFile.c_str());
1031 }
1032
1033 if (!batch) {
1034 tp->Run();
1035 }
1036
1037 return (master != NULL ? 0 : 1);
1038}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
Utility class to parse parameter values.
Auxiliary data structure for TObject with a user defined label.
Auxiliary class to handle multiple boolean-like I/O.
Definition JParser.hh:423
Utility class to parse command line options.
Definition JParser.hh:1698
Data structure for size of TCanvas.
Definition JCanvas.hh:26
int y
number of pixels in Y
Definition JCanvas.hh:99
int x
number of pixels in X
Definition JCanvas.hh:98
Wrapper class around ROOT TStyle.
Definition JStyle.hh:24
Range of values.
Definition JRange.hh:42
const JPolynome f1(1.0, 2.0, 3.0)
Function.
const double xmax
const double xmin
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition JLocation.hh:247
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.
T pow(const T &x, const double y)
Power .
Definition JMath.hh:97
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.
Definition JLegend.hh:29
Type list.
Definition JTypeList.hh:23
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
JProperties getProperties()
Get properties of this class.
Definition JStyle.hh:46
Auxiliary data structure to list files in directory.