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