226{
229
231
236 int stats;
237 JRange_t X;
238 JRange_t Y;
239 JRange_t Z;
242 bool logz;
244 string xLabel;
245 string yLabel;
246 string zLabel;
248 int lineWidth;
249 double markerSize;
250 string option;
252 bool batch;
253 string title;
255 int palette;
257
258 try {
259
261
262 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
263
264 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
266 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") =
JCanvas(500, 500);
269 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t::DEFAULT_RANGE();
270 zap[
'y'] =
make_field(Y,
"y-abscissa range") = JRange_t::DEFAULT_RANGE();
271 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t::DEFAULT_RANGE();
272 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
273 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
274 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
275 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
276 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
277 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
278 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
279 zap[
'C'] =
make_field(drawLine,
"draw line (-C black-and-white -CC colour)");
280 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
281 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
282 zap[
'O'] =
make_field(option,
"plotting option") =
"";
284 zap[
'B'] =
make_field(batch,
"batch processing");
285 zap[
'T'] =
make_field(title,
"graphics title ("
286 << "\"" << JName_t << "\" -> ROOT name; "
287 << "\"" << JTitle_t << "\" -> ROOT title)") = "KM3NeT preliminary";
289 zap[
'p'] =
make_field(palette,
"palette") = -1;
291
292 zap(argc, argv);
293 }
294 catch(const exception &error) {
295 FATAL(error.what() << endl);
296 }
297
298
299 gROOT->SetBatch(batch);
300
301 TApplication* tp = new TApplication("user", NULL, NULL);
302 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.
x, canvas.
y);
303
304 if (!batch) {
305 ((TRootCanvas *) cv->GetCanvasImp())->Connect("CloseWindow()", "TApplication", tp, "Terminate()");
306 }
307
308 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
309
310 if (palette != -1) {
311 gStyle->SetPalette(palette);
312 }
313
314 gROOT->SetStyle("gplot");
315 gROOT->ForceStyle();
316
317
318 cv->SetFillStyle(4000);
319 cv->SetFillColor(kWhite);
320 cv->Divide(1,1);
321 cv->cd(1);
322
323
324 JMarkerAttributes::getInstance().setMarkerSize(markerSize);
325 JLineAttributes ::getInstance().setLineWidth (lineWidth);
326
327
328 Double_t xmin = numeric_limits<double>::max();
329 Double_t xmax = numeric_limits<double>::lowest();
330 Double_t ymin = numeric_limits<double>::max();
331 Double_t ymax = numeric_limits<double>::lowest();
332 Double_t zmin = numeric_limits<double>::max();
333 Double_t zmax = numeric_limits<double>::lowest();
334
336
337
338 JMaster master;
339
340 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
341
342 DEBUG(
"Input: " << *input << endl);
343
345
346 if (dir == NULL) {
347 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
348 continue;
349 }
350
351 const TRegexp regexp(input->getObjectName());
352
353 TIter iter(dir->GetListOfKeys());
354
355 for (TKey* key; (
key = (TKey*) iter.Next()) != NULL; ) {
356
357 const TString tag(
key->GetName());
358
359 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
360
361
362
363 if (tag.Contains(regexp) &&
isTObject(key)) {
364
365 if (title == JName_t) {
366 title =
key->GetName();
367 } else if (title == JTitle_t) {
368 title =
key->GetTitle();
369 }
370
372
373 try {
374
375 TH3& h3 = dynamic_cast<TH3&>(*object);
376
377 object = h3.Project3D(
project.c_str());
378 }
379 catch(exception&) {}
380
381 try {
382
383 TH2& h2 = dynamic_cast<TH2&>(*object);
384
385 h2.SetStats(stats != -1);
386
387 xmin = min(xmin, h2.GetXaxis()->GetXmin());
388 xmax = max(xmax, h2.GetXaxis()->GetXmax());
389 ymin = min(ymin, h2.GetYaxis()->GetXmin());
390 ymax = max(ymax, h2.GetYaxis()->GetXmax());
391 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
392 zmax = max(zmax, h2.GetMaximum());
393 }
394 catch(exception&) {}
395
396 try {
397
398 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
399
400 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
401 xmin = min(xmin,
g1.GetX()[i] - numeric_limits<float>::epsilon());
402 xmax = max(xmax,
g1.GetX()[i] + numeric_limits<float>::epsilon());
403 ymin = min(ymin,
g1.GetY()[i] - numeric_limits<float>::epsilon());
404 ymax = max(ymax,
g1.GetY()[i] + numeric_limits<float>::epsilon());
405 }
406
407 int ng = 0;
408
410 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
411 ++ng;
412 }
413 }
414
415 static_cast<TAttMarker&
>(
g1) = JMarkerAttributes::getInstance().get(ng);
416 }
417 catch(exception&) {}
418
419 try {
420
421 TGraph2D& g2 = dynamic_cast<TGraph2D&>(*object);
422
423 for (Int_t i = 0; i != g2.GetN(); ++i) {
424 if (!logz || g2.GetZ()[i] > 0.0) {
425 xmin = min(xmin, g2.GetX()[i]);
426 xmax = max(xmax, g2.GetX()[i]);
427 ymin = min(ymin, g2.GetY()[i]);
428 ymax = max(ymax, g2.GetY()[i]);
429 zmin = min(zmin, g2.GetZ()[i]);
430 zmax = max(zmax, g2.GetZ()[i]);
431 }
432 }
433
434 if (Z.is_valid()) {
435 g2.SetMinimum(Z.getLowerLimit());
436 g2.SetMaximum(Z.getUpperLimit());
437 }
438 }
439 catch(exception&) {}
440
441 try {
442
443 TF2& f2 = dynamic_cast<TF2&>(*object);
444
445 f2.SetLineColor(kRed);
446 f2.SetTitle((title + ";" + xLabel + ";" + yLabel + ";" + zLabel).c_str());
447
448 double __xmin;
449 double __xmax;
450 double __ymin;
451 double __ymax;
452
453 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
454
455 xmin = min(xmin, __xmin);
456 xmax = max(xmax, __xmax);
457 ymin = min(ymin, __ymin);
458 ymax = max(ymax, __ymax);
459 zmin = min(zmin, f2.GetMinimum());
460 zmax = max(zmax, f2.GetMaximum());
461 }
462 catch(exception&) {}
463
464
465
466 for (TString buffer[] = { object.getLabel(), input->getFilename().c_str(), "" }, *i = buffer; *i != ""; ++i) {
467
468 *i = (*i)(TRegexp("\\[.*\\]"));
469
470 if ((*i).Length() > 2) {
471 object.setLabel((*i)(1, (*i).Length() - 2));
472 }
473 }
474
475 if (dynamic_cast<TH2*> (object.get()) != NULL ||
476 dynamic_cast<TGraph2D*>(object.get()) != NULL ||
477 dynamic_cast<TF2*> (object.get()) != NULL) {
478
479 if (master == NULL) {
480 master = object.get();
481 }
482
483 } else if (dynamic_cast<TH1*> (object.get()) != NULL ||
484 dynamic_cast<TGraph*> (object.get()) != NULL) {
485
486 TAttMarker marker = *JMarkerAttributes::getInstance().next();
487 TAttLine line = JLineAttributes::getInstance().get(0);
488
489 if (drawLine == 1)
490 line = *JLineAttributes::getInstance().next();
491 else
492 line.SetLineColor(marker.GetMarkerColor());
493
494 if (dynamic_cast<TAttMarker*>(object.get()) != NULL) {
495 dynamic_cast<TAttMarker&>(*object) = marker;
496 }
497
498 if (dynamic_cast<TAttLine*> (object.get()) != NULL) {
499 dynamic_cast<TAttLine&> (*object) = line;
500 }
501
502
503
504
505 if (drawLine) {
506
507 try {
508
509 TH1& h1 = dynamic_cast<TH1&>(*object);
510
511 for (int i = 1; i <= h1.GetNbinsX(); ++i) {
512 h1.SetBinError(i, 0.0);
513 }
514 }
515 catch(exception&) {}
516
517 try {
518
519 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
520
521 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
524 }
525 }
526 catch(exception&) {}
527 }
528
529 } else if (dynamic_cast<TEllipse*>(object.get()) != NULL ||
530 dynamic_cast<TLine*> (object.get()) != NULL ||
531 dynamic_cast<TText*> (object.get()) != NULL) {
532
533 } else {
534
535 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
536
537 continue;
538 }
539
540 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.
getLabel() <<
">" << endl);
541
542 listOfObjects.push_back(object);
543 }
544 }
545 }
546
547 if (listOfObjects.empty()) {
548 ERROR(
"Nothing to draw." << endl);
549 }
550
551
552
553 cv->cd(1);
554
555 if (option.find("COLZ") != string::npos ||
556 option.find("colz") != string::npos) {
557 gPad->SetRightMargin(0.20);
558 }
559
560 if (X.is_valid()) {
561 xmin = X.getLowerLimit();
562 xmax = X.getUpperLimit();
563 }
564
565 if (Y.is_valid()) {
566 ymin = Y.getLowerLimit();
567 ymax = Y.getUpperLimit();
568 }
569
570 if (Z.is_valid()) {
571 zmin = Z.getLowerLimit();
572 zmax = Z.getUpperLimit();
573 } else if (zmax > zmin) {
575 }
576
577 if (!listOfObjects.empty()) {
578
579 if (master == NULL) {
580
581 master = new TH2D(MASTER.c_str(), NULL,
582 100, xmin, xmax,
583 100, ymin, ymax);
584
585 master->SetStats(kFALSE);
586 }
587 }
588
589 if (master == NULL) {
590
591 TText* p = new TText(0.5, 0.5, "No data");
592
593 p->SetTextAlign(21);
594 p->SetTextAngle(45);
595 p->Draw();
596
597 } else {
598
599 if (logx) { gPad->SetLogx(); }
600 if (logy) { gPad->SetLogy(); }
601 if (logz) { gPad->SetLogz(); }
602
603 master->SetTitle(title.c_str());
604
605 master->GetXaxis()->SetRangeUser(xmin, xmax);
606 master->GetYaxis()->SetRangeUser(ymin, ymax);
607
610
611 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
612 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
613
614 master->SetMinimum(zmin);
615 master->SetMaximum(zmax);
616
617 if (xLabel != "") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(true); }
618 if (yLabel != "") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(true); }
619 if (zLabel != "") { master->GetZaxis()->SetTitle(zLabel.c_str()); master->GetZaxis()->CenterTitle(true); }
620
621 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
622 (logx > 1 && xmax-xmin < 2));
623 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
624 (logy > 1 && ymax-ymin < 2));
625
627 master->SetNdivisions(i->second, i->first.c_str());
628 }
629
630 DEBUG(
"Draw " << master->GetName() <<
' ' << option << endl);
631
632 master->Draw(option.c_str());
633 }
634
635 if (logx > 1 || logy > 1) {
637 if (dynamic_cast<TH2*> (i->get()) != master &&
638 dynamic_cast<TGraph2D*>(i->get()) != master) {
639 if (logx > 1) {
640
641 if (setLogX<TH2> (i->get())) {}
642 else if (setLogX<TGraph2DErrors>(i->get())) {}
643 else if (setLogX<TGraph2D> (i->get())) {}
644 else if (setLogX<TF2> (i->get())) {}
645
646 else if (setLogX<TH1> (i->get())) {}
647 else if (setLogX<TGraphErrors> (i->get())) {}
648 else if (setLogX<TGraph> (i->get())) {}
649
650 else if (setLogX<TLine> (i->get())) {}
651 else if (setLogX<TEllipse> (i->get())) {}
652 }
653 if (logy > 1) {
654
655 if (setLogY<TH2> (i->get())) {}
656 else if (setLogY<TGraph2DErrors>(i->get())) {}
657 else if (setLogY<TGraph2D> (i->get())) {}
658 else if (setLogY<TF2> (i->get())) {}
659
660 else if (setLogY<TH1> (i->get())) {}
661 else if (setLogY<TGraphErrors> (i->get())) {}
662 else if (setLogY<TGraph> (i->get())) {}
663
664 else if (setLogY<TLine> (i->get())) {}
665 else if (setLogY<TEllipse> (i->get())) {}
666 }
667 }
668 }
669 }
670
671 if (grid.count('x') || grid.count('X')) { gPad->SetGridx(); }
672 if (grid.count('y') || grid.count('Y')) { gPad->SetGridy(); }
673
674 if (stats != -1)
675 gStyle->SetOptStat(stats);
676 else
677 gStyle->SetOptFit(kFALSE);
678
679
681
682 if (i->get() != master) {
683
684 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
685
686 string buffer(option);
687
688 buffer += "SAME";
689
690 try {
691
692 TH2& h2 = dynamic_cast<TH2&>(*(*i));
693
694 h2.SetMinimum(zmin);
695 h2.SetMaximum(zmax);
696 }
697 catch(exception&) {}
698
699 try {
700
701 TGraph&
g1 =
dynamic_cast<TGraph&
>(*(*i));
702
703 buffer = "P";
704 }
705 catch(exception&) {}
706
707 try {
708
709 TGraph2D& g2 = dynamic_cast<TGraph2D&>(*(*i));
710
711 g2.SetMinimum(zmin);
712 g2.SetMaximum(zmax);
713 }
714 catch(exception&) {}
715
716 try {
717
718 TF2& f2 = dynamic_cast<TF2&>(*(*i));
719
720 f2.SetNpx(1000);
721 f2.SetNpy(1000);
722
723
724
725
726 }
727 catch(exception&) {}
728
729 (*i)->Draw(buffer.c_str());
730 }
731 }
732
733
734
735 cv->Update();
736
739 }
740
741 if (!batch) {
742 tp->Run();
743 }
744
745 return (master != NULL ? 0 : 1);
746}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Double_t g1(const Double_t x)
Function.
Utility class to parse parameter values.
Auxiliary data structure for TObject with a user defined label.
Utility class to parse command line options.
Data structure for size of TCanvas.
int y
number of pixels in Y
int x
number of pixels in X
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.
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.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class to handle multiple boolean-like I/O.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
JProperties getProperties()
Get properties of this class.