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