256 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
258 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
260 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") =
JCanvas(500, 500);
263 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t::DEFAULT_RANGE();
264 zap[
'y'] =
make_field(Y,
"y-abscissa range") = JRange_t::DEFAULT_RANGE();
265 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t::DEFAULT_RANGE();
266 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
267 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
268 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
269 zap[
'P'] =
make_field(
project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
270 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
271 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
272 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
273 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
274 zap[
'O'] =
make_field(option,
"plotting option") =
"";
276 zap[
'B'] =
make_field(batch,
"batch processing");
277 zap[
'T'] =
make_field(title,
"graphics title ("
278 <<
"\"" << JName_t <<
"\" -> ROOT name; "
279 <<
"\"" << JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
281 zap[
'p'] =
make_field(palette,
"palette") = -1;
286 catch(
const exception &error) {
287 FATAL(error.what() << endl);
291 gROOT->SetBatch(batch);
293 TApplication* tp =
new TApplication(
"user", NULL, NULL);
294 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.
x, canvas.
y);
296 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
299 gStyle->SetPalette(palette);
302 gROOT->SetStyle(
"gplot");
306 cv->SetFillStyle(4000);
307 cv->SetFillColor(kWhite);
313 Double_t
xmin = numeric_limits<double>::max();
314 Double_t
xmax = numeric_limits<double>::lowest();
315 Double_t ymin = numeric_limits<double>::max();
316 Double_t ymax = numeric_limits<double>::lowest();
317 Double_t zmin = numeric_limits<double>::max();
318 Double_t zmax = numeric_limits<double>::lowest();
327 DEBUG(
"Input: " << *input << endl);
332 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
336 const TRegexp regexp(input->getObjectName());
338 TIter iter(dir->GetListOfKeys());
340 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
342 const TString tag(key->GetName());
344 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
348 if (tag.Contains(regexp) &&
isTObject(key)) {
350 if (title == JName_t) {
351 title = key->GetName();
352 }
else if (title == JTitle_t) {
353 title = key->GetTitle();
360 TH3& h3 =
dynamic_cast<TH3&
>(*object);
362 object = h3.Project3D(
project.c_str());
368 TH2& h2 =
dynamic_cast<TH2&
>(*object);
370 h2.SetStats(stats != -1);
372 xmin = min(
xmin, h2.GetXaxis()->GetXmin());
373 xmax = max(
xmax, h2.GetXaxis()->GetXmax());
374 ymin = min(ymin, h2.GetYaxis()->GetXmin());
375 ymax = max(ymax, h2.GetYaxis()->GetXmax());
376 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
377 zmax = max(zmax, h2.GetMaximum());
383 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
385 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
395 if (
dynamic_cast<TGraph*
>(i->get()) != NULL) {
406 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
408 for (Int_t i = 0; i != g2.GetN(); ++i) {
409 if (!logz || g2.GetZ()[i] > 0.0) {
412 ymin = min(ymin, g2.GetY()[i]);
413 ymax = max(ymax, g2.GetY()[i]);
414 zmin = min(zmin, g2.GetZ()[i]);
415 zmax = max(zmax, g2.GetZ()[i]);
428 TF2& f2 =
dynamic_cast<TF2&
>(*object);
430 f2.SetLineColor(kRed);
431 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
438 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
442 ymin = min(ymin, __ymin);
443 ymax = max(ymax, __ymax);
444 zmin = min(zmin, f2.GetMinimum());
445 zmax = max(zmax, f2.GetMaximum());
451 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
453 *i = (*i)(TRegexp(
"\\[.*\\]"));
455 if ((*i).Length() > 2) {
456 object.setLabel((*i)(1, (*i).Length() - 2));
460 if (
dynamic_cast<TH2*
> (
object.get()) != NULL ||
461 dynamic_cast<TGraph*
> (
object.get()) != NULL ||
462 dynamic_cast<TGraph2D*
>(
object.get()) != NULL ||
463 dynamic_cast<TEllipse*
>(
object.get()) != NULL ||
464 dynamic_cast<TLine*
> (
object.get()) != NULL ||
465 dynamic_cast<TText*
> (
object.get()) != NULL ||
466 dynamic_cast<TF2*
> (
object.get()) != NULL) {
468 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.
getLabel() <<
">" << endl);
470 if (master == NULL) {
472 master =
object.get();
475 listOfObjects.push_back(
object);
478 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
484 if (listOfObjects.empty()) {
485 ERROR(
"Nothing to draw." << endl);
492 if (option.find(
"COLZ") != string::npos ||
493 option.find(
"colz") != string::npos) {
494 gPad->SetRightMargin(0.20);
510 }
else if (zmax > zmin) {
514 if (!listOfObjects.empty()) {
516 if (master == NULL) {
518 master =
new TH2D(MASTER.c_str(), NULL,
522 master->SetStats(kFALSE);
526 if (master == NULL) {
528 TText* p =
new TText(0.5, 0.5,
"No data");
536 if (logx) { gPad->SetLogx(); }
537 if (logy) { gPad->SetLogy(); }
538 if (logz) { gPad->SetLogz(); }
540 master->SetTitle(title.c_str());
542 master->GetXaxis()->SetRangeUser(
xmin,
xmax);
543 master->GetYaxis()->SetRangeUser(ymin, ymax);
548 if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
549 if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
551 master->SetMinimum(zmin);
552 master->SetMaximum(zmax);
554 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
555 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
556 if (zLabel !=
"") { master->GetZaxis()->SetTitle(zLabel.c_str()); master->GetZaxis()->CenterTitle(
true); }
558 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(
xmax/
xmin) < 2) ||
560 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
561 (logy > 1 && ymax-ymin < 2));
564 master->SetNdivisions(i->second, i->first.c_str());
567 DEBUG(
"Draw " << master->GetName() <<
' ' << option << endl);
569 master->Draw(option.c_str());
572 if (logx > 1 || logy > 1) {
574 if (
dynamic_cast<TH2*
>(i->get()) != master) {
576 if (setLogX<TH2> (i->get())) {}
577 else if (setLogX<TF2> (i->get())) {}
578 else if (setLogX<TGraph2DErrors>(i->get())) {}
579 else if (setLogX<TGraph2D> (i->get())) {}
580 else if (setLogX<TGraphErrors> (i->get())) {}
581 else if (setLogX<TGraph> (i->get())) {}
582 else if (setLogX<TLine> (i->get())) {}
583 else if (setLogX<TEllipse> (i->get())) {}
586 if (setLogY<TH2> (i->get())) {}
587 else if (setLogY<TF2> (i->get())) {}
588 else if (setLogY<TGraph2DErrors>(i->get())) {}
589 else if (setLogY<TGraph2D> (i->get())) {}
590 else if (setLogY<TGraphErrors> (i->get())) {}
591 else if (setLogY<TGraph> (i->get())) {}
592 else if (setLogY<TLine> (i->get())) {}
593 else if (setLogY<TEllipse> (i->get())) {}
599 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
600 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
603 gStyle->SetOptStat(stats);
605 gStyle->SetOptFit(kFALSE);
610 if (i->get() != master) {
612 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
614 string buffer(option);
620 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
629 TGraph&
g1 =
dynamic_cast<TGraph&
>(*(*i));
637 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
646 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
657 (*i)->Draw(buffer.c_str());
673 return (master != NULL ? 0 : 1);
#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.
void setLogarithmicY(TList *list)
Make y-axis of objects in list logarithmic (e.g. after using log10()).
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
T & getInstance(const T &object)
Get static instance from temporary object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Type definition of range.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
JProperties getProperties()
Get properties of this class.