63 typedef JRange<double> JRange_t;
94 JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
96 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
98 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
100 zap[
'L'] =
make_field(legend,
"position legend e.g. TR") =
"";
101 zap[
'x'] =
make_field(X,
"abscissa range") = JRange_t();
102 zap[
'y'] =
make_field(
Y,
"ordinate range") = JRange_t();
103 zap[
'z'] =
make_field(Z,
"ordinate range of projection)") = JRange_t();
104 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
105 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis");
106 zap[
'Z'] =
make_field(logz,
"logarithmic y-axis; after projection");
107 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
108 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
109 zap[
'^'] =
make_field(yLabel,
"y-axis label") =
"";
112 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
113 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
114 zap[
'O'] =
make_field(option,
"plotting option") =
"";
116 zap[
'B'] =
make_field(batch,
"batch processing");
117 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
119 zap[
'g'] =
make_field(group,
"group colour codes of objects") = 1;
120 zap[
't'] =
make_field(xTimeFormat,
"set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") =
"";
125 catch(
const exception &error) {
126 FATAL(error.what() << endl);
130 gROOT->SetBatch(batch);
132 TApplication* tp =
new TApplication(
"user", NULL, NULL);
133 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
135 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
137 gROOT->SetStyle(
"gplot");
141 cv->SetFillStyle(4000);
142 cv->SetFillColor(kWhite);
151 Double_t xmin = numeric_limits<double>::max();
152 Double_t xmax = numeric_limits<double>::lowest();
154 Double_t ymin = numeric_limits<double>::max();
155 Double_t ymax = numeric_limits<double>::lowest();
160 const bool px = (project ==
'x' || project ==
'X');
161 const bool py = (project ==
'y' || project ==
'Y');
163 logy = (logy || logz);
178 DEBUG(
"Input: " << *input << endl);
183 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
187 const TRegexp regexp(input->getObjectName());
189 TIter iter(dir->GetListOfKeys());
191 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
193 const TString tag(key->GetName());
195 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
199 if (tag.Contains(regexp)) {
201 if (title == JName_t) {
202 title = key->GetName();
203 }
else if (title == JTitle_t) {
204 title = key->GetTitle();
207 JRootObject object(key->ReadObj());
220 line.SetLineColor(marker.GetMarkerColor());
224 TProfile&
h1 =
dynamic_cast<TProfile&
>(*object);
226 object = h1.ProjectionX();
232 TH2& h2 =
dynamic_cast<TH2&
>(*object);
238 h2.GetYaxis()->FindBin(Z.getLowerLimit()),
239 h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
243 h2.GetYaxis()->GetNbins());
249 h2.GetXaxis()->FindBin(Z.getLowerLimit()),
250 h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
254 h2.GetXaxis()->GetNbins());
258 ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
267 dynamic_cast<TAttMarker&
>(*object) = marker;
273 dynamic_cast<TAttLine&
> (*object) = line;
279 TH1& h1 =
dynamic_cast<TH1&
>(*object);
281 h1.SetStats(stats != -1);
283 xmin = min(xmin, h1.GetXaxis()->GetXmin());
284 xmax = max(xmax, h1.GetXaxis()->GetXmax());
285 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
286 ymax = max(ymax, h1.GetMaximum());
289 for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
290 h1.SetBinError(i, 0.0);
300 TAttFill& fill =
dynamic_cast<TAttFill&
>(*object);
302 fill.SetFillColor(marker.GetMarkerColor());
309 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
311 for (Int_t i = 0; i != g1.GetN(); ++i) {
313 xmin = min(xmin, g1.GetX()[i]);
314 xmax = max(xmax, g1.GetX()[i]);
316 if (!logy || g1.GetY()[i] > 0.0) {
317 ymin = min(ymin, g1.GetY()[i]);
318 ymax = max(ymax, g1.GetY()[i]);
326 TGraphErrors& g1 =
dynamic_cast<TGraphErrors&
>(*object);
329 for (Int_t i = 0; i != g1.GetN(); ++i) {
334 for (Int_t i = 0; i != g1.GetN(); ++i) {
335 if (!logy || g1.GetY()[i] - g1.GetEY()[i] > 0.0) { ymin = min(ymin, g1.GetY()[i] - g1.GetEY()[i]); }
336 if (!logy || g1.GetY()[i] + g1.GetEY()[i] > 0.0) { ymax = max(ymax, g1.GetY()[i] + g1.GetEY()[i]); }
344 TMultiGraph& m1 =
dynamic_cast<TMultiGraph&
>(*object);
346 for (TIter i1(m1.GetListOfGraphs()); TGraph* g1 =
dynamic_cast<TGraph*
>(i1()); ) {
348 for (Int_t i = 0; i != g1->GetN(); ++i) {
350 xmin = min(xmin, g1->GetX()[i]);
351 xmax = max(xmax, g1->GetX()[i]);
353 if (!logy || g1->GetY()[i] > 0.0) {
354 ymin = min(ymin, g1->GetY()[i]);
355 ymax = max(ymax, g1->GetY()[i]);
364 TF1& f1 =
dynamic_cast<TF1&
>(*object);
369 f1.GetRange(__xmin, __xmax);
371 xmin = min(xmin, __xmin);
372 xmax = max(xmax, __xmax);
373 ymin = min(ymin, f1.GetMinimum());
374 ymax = max(ymax, f1.GetMaximum());
381 THStack& hs =
dynamic_cast<THStack&
>(*object);
383 NOTICE(
"THStack" << endl);
385 TIterator*
iterator = hs.GetHists()->MakeIterator();
387 for (
size_t index = 1;
TObject* i = iterator->Next(); ++index) {
389 TH1& h1 =
dynamic_cast<TH1&
>(*i);
391 NOTICE(
"TH1[" << index <<
"] " << h1.GetName() << endl);
393 xmin = min(xmin, h1.GetXaxis()->GetXmin());
394 xmax = max(xmax, h1.GetXaxis()->GetXmax());
396 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
397 ymax = max(ymax, h1.GetMaximum());
400 h1.SetLineColor(kBlack);
407 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
409 *i = (*i)(TRegexp(
"\\[.*\\]"));
411 DEBUG(
"Label: <" << *i <<
">" << endl);
413 if (i->Length() > 2) {
414 object.setLabel((*i)(1, i->Length() - 2));
418 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
421 master =
dynamic_cast<TH1*
>(
object.get());
424 listOfObjects.push_back(
object);
429 if (listOfObjects.empty()) {
430 ERROR(
"Nothing to draw." << endl);
435 TH1* h1 =
dynamic_cast<TH1*
> (i->get());
436 TGraph* g1 =
dynamic_cast<TGraph*
> (i->get());
437 TMultiGraph* m1 =
dynamic_cast<TMultiGraph*
>(i->get());
438 TAttLine* ls =
dynamic_cast<TAttLine*
> (i->get());
441 TIterator* iterator = NULL;
445 iterator = h1->GetListOfFunctions()->MakeIterator();
447 }
else if (g1 != NULL) {
449 iterator = g1->GetListOfFunctions()->MakeIterator();
451 }
else if (m1 != NULL) {
453 for (TIter i1(m1->GetListOfGraphs()); TGraph* gi =
dynamic_cast<TGraph*
>(i1()); ) {
454 for (TIter i2(gi->GetListOfFunctions()); TF1* fi =
dynamic_cast<TF1*
>(i2()); ) {
459 iterator = list.MakeIterator();
462 if (iterator != NULL) {
464 Double_t x1 = numeric_limits<Double_t>::max();
465 Double_t x2 = numeric_limits<Double_t>::lowest();
467 for (
int ns = 0, nc = 1; TF1* f1 = (TF1*) iterator->Next(); ) {
472 f1->GetRange(__x1, __x2);
477 if (listOfObjects.size() == 1) {
481 if (x1 != numeric_limits<Double_t>::max() &&
482 x2 != numeric_limits<Double_t>::lowest()) {
497 f1->SetLineColor(ls->GetLineColor());
504 f1->GetRange(__xmin, __xmax);
506 ymin = min(ymin, f1->GetMinimum(__xmin, __xmax));
507 ymax = max(ymax, f1->GetMaximum(__xmin, __xmax));
517 if (X != JRange_t()) {
518 xmin = X.getLowerLimit();
519 xmax = X.getUpperLimit();
522 if (
Y != JRange_t()) {
523 ymin =
Y.getLowerLimit();
524 ymax =
Y.getUpperLimit();
531 if (!listOfObjects.empty() &&
master == NULL) {
533 if (X != JRange_t()) {
535 master =
new TH1D(
"__H__", NULL, 100, X.getLowerLimit(), X.getUpperLimit());
539 }
else if (xmin < xmax) {
541 master =
new TH1D(
"__H__", NULL, 100, xmin, xmax);
549 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
557 if (logx) { gPad->SetLogx(); }
558 if (logy) { gPad->SetLogy(); }
560 master->GetXaxis()->SetRangeUser(xmin, xmax);
566 master->SetTitle(title.c_str());
571 if (xLabel !=
"") {
master->GetXaxis()->SetTitle(xLabel.c_str());
master->GetXaxis()->CenterTitle(
true); }
572 if (yLabel !=
"") {
master->GetYaxis()->SetTitle(yLabel.c_str());
master->GetYaxis()->CenterTitle(
true); }
574 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
575 (logx > 1 && (xmax-xmin) < 2));
577 master->GetYaxis()->SetMoreLogLabels( logy && log10(ymax/ymin) < 2);
578 master->GetYaxis()->SetNoExponent ( logy && log10(ymax/ymin) < 2);
580 if (Ndivisions.first !=
"") {
581 master->SetNdivisions(Ndivisions.second, Ndivisions.first.c_str());
584 if (xTimeFormat !=
"") {
585 master->GetXaxis()->SetTimeDisplay(1);
586 master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
589 master->Draw(option.c_str());
594 if (dynamic_cast<TH1*>(i->get()) !=
master) {
603 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
604 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
607 gStyle->SetOptStat(stats);
609 gStyle->SetOptFit(kFALSE);
614 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
616 string buffer(option);
624 TF1* f1 =
dynamic_cast<TF1*
> (i->get());
625 TGraph* g1 =
dynamic_cast<TGraph*
> (i->get());
626 TMultiGraph* q1 =
dynamic_cast<TMultiGraph*
>(i->get());
633 if (g1->GetN() > 1 && drawLine)
641 for (TIter i1(q1->GetListOfGraphs()); TGraph* gi =
dynamic_cast<TGraph*
>(i1()); ) {
643 string zbuf = buffer;
645 if (gi->GetN() > 1 && drawLine)
650 gi->Draw(zbuf.c_str());
655 (*i).Draw(buffer.c_str());
663 Ssiz_t height = listOfObjects.size();
667 width = max(width, i->getLabel().Length());
670 TLegend* lg =
getLegend(width, height, legend);
673 lg->AddEntry(*i,
" " + i->getLabel(),
isTAttLine(*i) ?
"L" :
"LPF");
Utility class to parse command line options.
void setLogarithmicX(TF1 *f1)
Make parameter x of function logarithmic (e.g. after filling with log10()).
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
then echo Test string reversed by master(hit< return > to continue)." JProcess -c "JEcho" -rC fi if (( 1 ))
#define MAKE_CSTRING(A)
Make C-string.
then for HISTOGRAM in h0 h1
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
bool isTAttLine(const TObject *object)
Get drawing option of TH1.
T & getInstance(const T &object)
Get static instance from temporary object.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
static const char LABEL_TERMINATOR
label terminator
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
TLegend * getLegend(const Int_t width, const Int_t height, const std::string option="TR")
Get legend.
Auxiliary class to handle multiple boolean-like I/O.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
#define DEBUG(A)
Message macros.
Double_t g1(const Double_t x)
Function.