Jpp master_rocky-44-g75b7c4f75
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 "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 207 of file JPlot1D.cc.

208{
209 using namespace std;
210 using namespace JPP;
211
212 typedef JRange<double> JRange_t;
213
214 vector<JRootObjectID> inputFile;
215 string outputFile;
216 JCanvas canvas;
217 JStyle::JParameters parameters;
218 int stats;
219 JLegend legend;
220 JRange_t X;
221 JRange_t Y;
222 JRange_t Z;
223 JCounter logx;
224 bool logy;
225 bool logz;
226 char project;
227 string xLabel;
228 string yLabel;
229 JCounter drawLine;
230 int fillArea;
231 int lineWidth;
232 double markerSize;
233 string option;
234 set<char> grid;
235 bool batch;
236 string title;
237 map<string, int> Ndivisions;
238 size_t group;
239 int debug;
240 string xTimeFormat;
241
242 try {
243
244 JProperties properties = parameters.getProperties();
245
246 JParser<> zap("General purpose plot program for 1D ROOT objects.");
247
248 zap['f'] = make_field(inputFile, "<input file>:<object name>");
249 zap['o'] = make_field(outputFile, "graphics output") = "";
250 zap['w'] = make_field(canvas, "size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
251 zap['@'] = make_field(properties) = JPARSER::initialised();
252 zap['s'] = make_field(stats) = -1;
253 zap['L'] = make_field(legend, "position legend e.g. TR [factor]") = JLegend(), JLegend("TL"), JLegend("TR"), JLegend("BR"), JLegend("BL");
254 zap['x'] = make_field(X, "abscissa range") = JRange_t::DEFAULT_RANGE();
255 zap['y'] = make_field(Y, "ordinate range") = JRange_t::DEFAULT_RANGE();
256 zap['z'] = make_field(Z, "ordinate range of projection)") = JRange_t::DEFAULT_RANGE();
257 zap['X'] = make_field(logx, "logarithmic x-axis (-XX log10 axis)");
258 zap['Y'] = make_field(logy, "logarithmic y-axis");
259 zap['Z'] = make_field(logz, "logarithmic y-axis; after projection");
260 zap['P'] = make_field(project, "projection") = '\0', 'x', 'X', 'y', 'Y';
261 zap['>'] = make_field(xLabel, "x-axis label") = "";
262 zap['^'] = make_field(yLabel, "y-axis label") = "";
263 zap['C'] = make_field(drawLine, "draw line (-C black-and-white -CC colour)");
264 zap['F'] = make_field(fillArea, "fill area") = 0;
265 zap['l'] = make_field(lineWidth, "line width") = 2;
266 zap['S'] = make_field(markerSize, "marker size") = 1.0;
267 zap['O'] = make_field(option, "plotting option") = "";
268 zap['G'] = make_field(grid, "grid lines [X][Y]") = JPARSER::initialised();
269 zap['B'] = make_field(batch, "batch processing");
270 zap['T'] = make_field(title, "graphics title ("
271 << "\"" << JName_t << "\" -> ROOT name; "
272 << "\"" << JTitle_t << "\" -> ROOT title)") = "KM3NeT preliminary";
273 zap['N'] = make_field(Ndivisions, "axis divisioning (e.g. \"X 505\")") = JPARSER::initialised();
274 zap['g'] = make_field(group, "group colour codes of objects") = 1;
275 zap['t'] = make_field(xTimeFormat, "set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") = "";
276 zap['d'] = make_field(debug) = 0;
277
278 zap(argc, argv);
279 }
280 catch(const exception &error) {
281 FATAL(error.what() << endl);
282 }
283
284
285 gROOT->SetBatch(batch);
286
287 TApplication* tp = new TApplication("user", NULL, NULL);
288 TCanvas* cv = new TCanvas("c1", "c1", canvas.x, canvas.y);
289
290 unique_ptr<TStyle> gStyle(new JStyle("gplot", cv->GetWw(), cv->GetWh(), parameters));
291
292 if (logy || logz) {
293 gStyle->SetTitleOffset(gStyle->GetTitleOffset() * 1.3, "Y");
294 }
295
296 gROOT->SetStyle("gplot");
297 gROOT->ForceStyle();
298
299 cv->SetFillStyle(4000);
300 cv->SetFillColor(kWhite);
301 cv->Divide(1,1);
302 cv->cd(1);
303
304
305 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
306 JLineAttributes ::getInstance().setLineWidth (lineWidth);
307
308
309 Double_t xmin = numeric_limits<double>::max();
310 Double_t xmax = numeric_limits<double>::lowest();
311
312 Double_t ymin = numeric_limits<double>::max();
313 Double_t ymax = numeric_limits<double>::lowest();
314
315
316 vector<JRootObject> listOfObjects;
317
318 const bool px = (project == 'x' || project == 'X'); // projection on x-axis of (2|3)D histogram
319 const bool py = (project == 'y' || project == 'Y'); // projection on y-axis of (2|3)D histogram
320 const bool pz = (project == 'z' || project == 'Z'); // projection on z-axis of 3D histogram
321
322 logy = (logy || logz);
323
324 if (px) {
325 swap(Y, Z); // Y becomes range in TH2::ProjectionX() and Z becomes y-axis range
326 }
327
328 if (py) {
329 swap(X, Z); // X becomes range in TH2::ProjectionY()
330 swap(Y, X); // Y becomes x-axis range and Z becomes y-axis range
331 }
332
333 TH1* master = NULL;
334
335 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
336
337 DEBUG("Input: " << *input << endl);
338
339 TDirectory* dir = getDirectory(*input);
340
341 if (dir == NULL) {
342 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
343 continue;
344 }
345
346 const TRegexp regexp(input->getObjectName());
347
348 TIter iter(dir->GetListOfKeys());
349
350 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
351
352 const TString tag(key->GetName());
353
354 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
355
356 // option match
357
358 if (tag.Contains(regexp) && isTObject(key)) {
359
360 if (title == JName_t) {
361 title = key->GetName();
362 } else if (title == JTitle_t) {
363 title = key->GetTitle();
364 }
365
366 JRootObject object(key->ReadObj());
367
368 TAttMarker marker = JMarkerAttributes::getInstance().get(0);
369 TAttLine line = JLineAttributes ::getInstance().get(0);
370
371 if (group != 0) {
372 marker.SetMarkerColor(JMarkerAttributes::getInstance().get(listOfObjects.size()/group).GetMarkerColor());
373 }
374
375 if (drawLine == 1)
376 line = JLineAttributes::getInstance().get(listOfObjects.size());
377 else
378 line.SetLineColor(marker.GetMarkerColor());
379
380 // projections
381
382 try {
383
384 TProfile& h1 = dynamic_cast<TProfile&>(*object);
385
386 object = h1.ProjectionX();
387 }
388 catch(exception&) {}
389
390 try {
391
392 TH2& h2 = dynamic_cast<TH2&>(*object);
393
394 if (px) {
395
396 if (Z.is_valid())
397 object = h2.ProjectionX(MAKE_CSTRING(h2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()),
398 h2.GetYaxis()->FindBin(Z.getLowerLimit()),
399 h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
400 else
401 object = h2.ProjectionX(MAKE_CSTRING(h2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()),
402 1,
403 h2.GetYaxis()->GetNbins());
404
405 } else if (py) {
406
407 if (Z.is_valid())
408 object = h2.ProjectionY(MAKE_CSTRING(h2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()),
409 h2.GetXaxis()->FindBin(Z.getLowerLimit()),
410 h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
411 else
412 object = h2.ProjectionY(MAKE_CSTRING(h2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()),
413 1,
414 h2.GetXaxis()->GetNbins());
415
416 } else {
417
418 ERROR("For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
419
420 continue;
421 }
422 }
423 catch(exception&) {}
424
425 try {
426
427 TH3& h3 = dynamic_cast<TH3&>(*object);
428
429 if (px) {
430
431 object = h3.ProjectionX(MAKE_CSTRING(h3.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()));
432
433 } else if (py) {
434
435 object = h3.ProjectionY(MAKE_CSTRING(h3.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()));
436
437 } else if (pz) {
438
439 object = h3.ProjectionZ(MAKE_CSTRING(h3.GetName() << "_pz" << LABEL_TERMINATOR << listOfObjects.size()));
440
441 } else {
442
443 ERROR("For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
444
445 continue;
446 }
447 }
448 catch(exception&) {}
449
450 // colouring
451
452 try {
453 if (dynamic_cast<TMarker*>(object.get()) == NULL) {
454 dynamic_cast<TAttMarker&>(*object) = marker;
455 }
456 }
457 catch(exception&) {}
458
459 try {
460 if (dynamic_cast<TLine*>(object.get()) == NULL) {
461 dynamic_cast<TAttLine&> (*object) = line;
462 }
463 }
464 catch(exception&) {}
465
466 if (fillArea != 0) {
467
468 try {
469
470 TAttFill& fill = dynamic_cast<TAttFill&>(*object);
471
472 if (!isTAttLine(object) || fillArea < 0) {
473 fill.SetFillColor(marker.GetMarkerColor());
474 fill.SetFillStyle(abs(fillArea));
475 }
476 }
477 catch(exception&) {}
478 }
479
480 // set errors
481
482 if (drawLine) {
483
484 try {
485
486 TH1& h1 = dynamic_cast<TH1&>(*object);
487
488 for (int i = 1; i <= h1.GetNbinsX(); ++i) {
489 h1.SetBinError(i, 0.0);
490 }
491 }
492 catch(exception&) {}
493
494 try {
495
496 TGraphErrors& g1 = dynamic_cast<TGraphErrors&>(*object);
497
498 for (Int_t i = 0; i != g1.GetN(); ++i) {
499 g1.GetEX()[i] = 0.0;
500 g1.GetEY()[i] = 0.0;
501 }
502 }
503 catch(exception&) {}
504 }
505
506 // min-max
507
508 try {
509
510 TH1& h1 = dynamic_cast<TH1&>(*object);
511
512 h1.SetStats(stats != -1);
513
514 xmin = min(xmin, h1.GetXaxis()->GetXmin());
515 xmax = max(xmax, h1.GetXaxis()->GetXmax());
516 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
517 ymax = max(ymax, h1.GetMaximum());
518
519 if (!logy && h1.GetListOfFunctions() != NULL) {
520 for (unique_ptr<TIterator> iterator(h1.GetListOfFunctions()->MakeIterator()); TF1* f1 = (TF1*) iterator->Next(); ) {
521 ymin = min(ymin, f1->GetMinimum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
522 ymax = max(ymax, f1->GetMaximum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
523 }
524 }
525 }
526 catch(exception&) {}
527
528 try {
529
530 TGraph& g1 = dynamic_cast<TGraph&>(*object);
531
532 for (Int_t i = 0; i != g1.GetN(); ++i) {
533
534 xmin = min(xmin, g1.GetX()[i]);
535 xmax = max(xmax, g1.GetX()[i]);
536
537 if (!logy || g1.GetY()[i] > 0.0) {
538 ymin = min(ymin, g1.GetY()[i]);
539 ymax = max(ymax, g1.GetY()[i]);
540 }
541 }
542 }
543 catch(exception&) {}
544
545 try {
546
547 TGraphErrors& g1 = dynamic_cast<TGraphErrors&>(*object);
548
549 for (Int_t i = 0; i != g1.GetN(); ++i) {
550 if (!logy || g1.GetY()[i] - g1.GetEY()[i] > 0.0) { ymin = min(ymin, g1.GetY()[i] - g1.GetEY()[i]); }
551 if (!logy || g1.GetY()[i] + g1.GetEY()[i] > 0.0) { ymax = max(ymax, g1.GetY()[i] + g1.GetEY()[i]); }
552 }
553 }
554 catch(exception&) {}
555
556 try {
557
558 TMultiGraph& m1 = dynamic_cast<TMultiGraph&>(*object);
559
560 for (TIter i1(m1.GetListOfGraphs()); TGraph* g1 = dynamic_cast<TGraph*>(i1()); ) {
561
562 for (Int_t i = 0; i != g1->GetN(); ++i) {
563
564 xmin = min(xmin, g1->GetX()[i]);
565 xmax = max(xmax, g1->GetX()[i]);
566
567 if (!logy || g1->GetY()[i] > 0.0) {
568 ymin = min(ymin, g1->GetY()[i]);
569 ymax = max(ymax, g1->GetY()[i]);
570 }
571 }
572 }
573 }
574 catch(exception&) {}
575
576 try {
577
578 TF2& f2 = dynamic_cast<TF2&>(*object);
579 TF1* f1 = NULL;
580
581 TString formula = f2.GetExpFormula();
582 TString _z_ = TString::Format("%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
583
584 double __xmin;
585 double __xmax;
586 double __ymin;
587 double __ymax;
588
589 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
590
591 if (px) {
592
593 formula.ReplaceAll("y", _z_);
594
595 f1 = new TF1(MAKE_CSTRING(f2.GetName() << "_px" << LABEL_TERMINATOR << listOfObjects.size()), formula);
596
597 f1->SetRange(__xmin, __xmax);
598
599 } else if (py) {
600
601 formula.ReplaceAll("x", _z_);
602 formula.ReplaceAll("y", "x");
603
604 f1 = new TF1(MAKE_CSTRING(f2.GetName() << "_py" << LABEL_TERMINATOR << listOfObjects.size()), formula);
605
606 f1->SetRange(__ymin, __ymax);
607
608 } else {
609
610 ERROR("For 2D functions, use option option -P for projections or use JPlot2D" << endl);
611
612 continue;
613 }
614
615 DEBUG("TF1: " << f1->GetExpFormula() << endl);
616
617 f1->SetParameters(f2.GetParameters());
618
619 object = f1;
620 }
621 catch(exception&) {}
622
623 try {
624
625 TF1& f1 = dynamic_cast<TF1&>(*object);
626
627 double __xmin;
628 double __xmax;
629
630 f1.GetRange(__xmin, __xmax);
631
632 xmin = min(xmin, __xmin);
633 xmax = max(xmax, __xmax);
634 ymin = min(ymin, f1.GetMinimum());
635 ymax = max(ymax, f1.GetMaximum());
636 }
637 catch(exception&) {}
638
639 try {
640
641 THStack& hs = dynamic_cast<THStack&>(*object);
642
643 NOTICE("THStack" << endl);
644
645 unique_ptr<TIterator> iterator(hs.GetHists()->MakeIterator());
646
647 for (size_t index = 1; TObject* i = iterator->Next(); ++index) {
648
649 TH1& h1 = dynamic_cast<TH1&>(*i);
650
651 NOTICE("TH1[" << index << "] " << h1.GetName() << endl);
652
653 xmin = min(xmin, h1.GetXaxis()->GetXmin());
654 xmax = max(xmax, h1.GetXaxis()->GetXmax());
655
656 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
657 ymax = max(ymax, h1.GetMaximum());
658
659 h1.SetLineWidth(1);
660 h1.SetLineColor(kBlack);
661
662 h1.SetFillColor(JMarkerAttributes::getInstance().get(index).GetMarkerColor());
663 }
664 }
665 catch(exception&) {}
666
667 try {
668
669 TLine& h1 = dynamic_cast<TLine&>(*object);
670
671 xmin = min(xmin, h1.GetX1());
672 xmax = max(xmax, h1.GetX2());
673 ymin = min(ymin, h1.GetY1());
674 ymax = max(ymax, h1.GetY2());
675 }
676 catch(exception&) {}
677
678 // label
679
680 for (TString buffer[] = { object.getLabel(), input->getFilename().c_str(), "" }, *i = buffer; *i != ""; ++i) {
681
682 *i = (*i)(TRegexp("\\[.*\\]"));
683
684 if (i->Length() > 2) {
685 object.setLabel((*i)(1, i->Length() - 2));
686 }
687 }
688
689 DEBUG("Add object: " << tag << " with label <" << object.getLabel() << ">" << endl);
690
691 if (master == NULL) {
692 master = dynamic_cast<TH1*>(object.get());
693 }
694
695 listOfObjects.push_back(object);
696 }
697 }
698 }
699
700 if (listOfObjects.empty()) {
701 ERROR("Nothing to draw." << endl);
702 }
703
704 for (vector<JRootObject>::iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
705
706 // set line attributes of associated functions
707 // for single objects, change colour if same range else change style
708 // for multiple objecs, keep colour and change style
709
710 TH1* h1 = dynamic_cast<TH1*> (i->get());
711 TGraph* g1 = dynamic_cast<TGraph*> (i->get());
712 TMultiGraph* m1 = dynamic_cast<TMultiGraph*>(i->get());
713 TAttLine* ls = dynamic_cast<TAttLine*> (i->get());
714
715 TList list;
716
717 unique_ptr<TIterator> iterator;
718
719 if (h1 != NULL) {
720
721 iterator.reset(h1->GetListOfFunctions()->MakeIterator());
722
723 } else if (g1 != NULL) {
724
725 iterator.reset(g1->GetListOfFunctions()->MakeIterator());
726
727 } else if (m1 != NULL) {
728
729 for (TIter i1(m1->GetListOfGraphs()); TGraph* gi = dynamic_cast<TGraph*>(i1()); ) {
730 for (TIter i2(gi->GetListOfFunctions()); TF1* fi = dynamic_cast<TF1*>(i2()); ) {
731 list.Add(fi);
732 }
733 }
734
735 iterator.reset(list.MakeIterator());
736 }
737
738 if (iterator != NULL) {
739
740 Double_t x1[] = { numeric_limits<Double_t>::max(), numeric_limits<Double_t>::max() };
741 Double_t x2[] = { numeric_limits<Double_t>::lowest(), numeric_limits<Double_t>::lowest() };
742
743 for (int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*) iterator->Next(); ++nf) {
744
745 f1->GetRange(x1[1], x2[1]);
746 f1->SetNpx(5000);
747
748 dynamic_cast<TAttLine&>(*f1) = JLineAttributes::getInstance().get(0);
749
750 if (listOfObjects.size() == 1) {
751
752 if (x1[0] == x1[1] &&
753 x2[0] == x2[1])
754 ++nc; // change colour
755 else if (nf != 0)
756 ++ns; // change style
757
758 f1->SetLineStyle(JLineAttributes ::getInstance().get(ns).GetLineStyle());
759 f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).GetMarkerColor());
760
761 } else {
762
763 // keep colour of base object and accordingly modify line style.
764
765 f1->SetLineColor(ls->GetLineColor());
766 f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).GetLineStyle());
767 }
768
769 x1[0] = x1[1];
770 x2[0] = x2[1];
771
772 // set limits
773 /*
774 double __xmin;
775 double __xmax;
776
777 f1->GetRange(__xmin, __xmax);
778
779 ymin = min(ymin, f1->GetMinimum(__xmin, __xmax));
780 ymax = max(ymax, f1->GetMaximum(__xmin, __xmax));
781 */
782 }
783 }
784 }
785
786 // plot frame
787
788 if (X.is_valid()) {
789 xmin = X.getLowerLimit();
790 xmax = X.getUpperLimit();
791 }
792
793 if (Y.is_valid()) {
794 ymin = Y.getLowerLimit();
795 ymax = Y.getUpperLimit();
796 } else if (ymax > ymin) {
797 setRange(ymin, ymax, logy);
798 }
799
800 cv->cd(1);
801
802 if (!listOfObjects.empty()) {
803
804 if (master == NULL) {
805
806 master = new TH1D(MASTER.c_str(), NULL, 1000, xmin, xmax);
807
808 master->SetStats(kFALSE);
809
810 for (Int_t i = 1; i <= master->GetXaxis()->GetNbins(); ++i) {
811 master->SetBinContent(i, ymin);
812 }
813 }
814 }
815
816 if (master == NULL) {
817
818 TText* p = new TText(0.5, 0.5, MAKE_CSTRING("No data"));
819
820 p->SetTextAlign(21);
821 p->SetTextAngle(45);
822 p->Draw();
823
824 } else {
825
826 if (logx) { gPad->SetLogx(); }
827 if (logy) { gPad->SetLogy(); }
828
829 master->SetTitle(title.c_str());
830
831 master->GetXaxis()->SetRangeUser(xmin, xmax);
832
833 if (logx > 1) { setLogarithmicX(master); }
834
835 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
836
837 master->SetMinimum(ymin);
838 master->SetMaximum(ymax);
839
840 if (xLabel != "") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(true); }
841 if (yLabel != "") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(true); }
842
843 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
844 (logx > 1 && (xmax-xmin) < 2));
845
846 master->GetYaxis()->SetMoreLogLabels( logy && log10(ymax/ymin) < 2);
847 master->GetYaxis()->SetNoExponent ( logy && log10(ymax/ymin) < 2);
848
849 for (map<string, int>::const_iterator i = Ndivisions.begin(); i != Ndivisions.end(); ++i) {
850 master->SetNdivisions(i->second, i->first.c_str());
851 }
852
853 if (xTimeFormat != "") {
854
855 master->GetXaxis()->SetTimeDisplay(1);
856
857 if (xTimeFormat == "utc") {
858 master->GetXaxis()->SetTimeFormat("#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
859 master->GetXaxis()->SetTimeOffset(0.0, "gmt");
860 } else if (xTimeFormat == "UTC") {
861 master->GetXaxis()->SetTimeFormat("%d-%m-%y");
862 master->GetXaxis()->SetTimeOffset(0.0, "gmt");
863 } else {
864 master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
865 }
866 }
867
868 master->Draw(option.c_str());
869 }
870
871 if (logx > 1) {
872 for (vector<JRootObject>::iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
873 if (dynamic_cast<TH1*>(i->get()) != master) {
874 if (setLogX<TH1> (i->get())) {}
875 else if (setLogX<TF1> (i->get())) {}
876 else if (setLogX<TGraphErrors>(i->get())) {}
877 else if (setLogX<TGraph> (i->get())) {}
878 else if (setLogX<TMultiGraph> (i->get())) {}
879 else if (setLogX<TLine> (i->get())) {}
880 else if (setLogX<TEllipse> (i->get())) {}
881 }
882 }
883 }
884
885 if (grid.count('x') || grid.count('X')) { gPad->SetGridx(); }
886 if (grid.count('y') || grid.count('Y')) { gPad->SetGridy(); }
887
888 if (stats != -1)
889 gStyle->SetOptStat(stats);
890 else
891 gStyle->SetOptFit(kFALSE);
892
893
894 for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
895
896 DEBUG("Draw " << (*i)->GetName() << ' ' << (*i)->GetTitle() << endl);
897
898 string buffer(option);
899
900 //if (!dynamic_cast<THStack*>(i->get())) {
901 // buffer += "SAMES";
902 //}
903
904 buffer += "SAME";
905
906 TF1* f1 = dynamic_cast<TF1*> (i->get());
907 TGraph* g1 = dynamic_cast<TGraph*> (i->get());
908 TMultiGraph* q1 = dynamic_cast<TMultiGraph*>(i->get());
909
910 if (f1 != NULL) {
911 f1->SetNpx(5000);
912 }
913
914 if (g1 != NULL) {
915 if (g1->GetN() > 1 && drawLine)
916 buffer += "L"; // drawing cut line
917 else if (fillArea == 0 ||
918 (dynamic_cast<TGraphErrors*> (g1) == NULL &&
919 dynamic_cast<TGraphAsymmErrors*>(g1) == NULL))
920 buffer += "P"; // drawing point(s)
921 }
922
923 if (q1 != NULL) {
924
925 for (TIter i1(q1->GetListOfGraphs()); TGraph* gi = dynamic_cast<TGraph*>(i1()); ) {
926
927 string zbuf = buffer;
928
929 if (gi->GetN() > 1 && drawLine)
930 zbuf += "L"; // drawing cut line
931 else
932 zbuf += "P"; // drawing point(s)
933
934 gi->Draw(zbuf.c_str());
935 }
936
937 } else {
938
939 (*i).Draw(buffer.c_str());
940 }
941 }
942
943 //gPad->RedrawAxis();
944
945 if (legend.is_valid()) {
946
947 if (group == 0) {
948 group = listOfObjects.size();
949 }
950
951 Ssiz_t height = listOfObjects.size()/group;
952 Ssiz_t width = 1;
953
954 for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
955 width = max(width, getWidth(i->getLabel()));
956 }
957
958 TLegend* lg = getLegend(width, height, legend.location, legend.factor);
959
960 for (size_t i = 0; i < listOfObjects.size(); i += group) {
961
962 const JRootObject& object = listOfObjects[i];
963
964 if (dynamic_cast<TMarker*>(object.get()) == NULL &&
965 dynamic_cast<TLine*> (object.get()) == NULL &&
966 dynamic_cast<TText*> (object.get()) == NULL) {
967 lg->AddEntry(object, " " + object.getLabel(), isTAttLine(object) ? "L" : isTAttFill(object) && fillArea != 0 ? "F" : "P");
968 }
969 }
970
971 lg->Draw();
972 }
973
974 cv->Update();
975
976 if (outputFile != "") {
977 cv->SaveAs(outputFile.c_str());
978 }
979
980 if (!batch) {
981 tp->Run();
982 }
983
984 return (master != NULL ? 0 : 1);
985}
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:69
#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.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
bool isTAttLine(const TObject *object)
Get drawing option of object.
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
std::vector< size_t > ns
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:44
Auxiliary data structure to list files in directory.