56 typedef JRange<double> JRange_t;
87 JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
89 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
91 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
93 zap[
'L'] =
make_field(legend,
"position legend e.g. TR") =
"";
94 zap[
'x'] =
make_field(X,
"abscissa range") = JRange_t();
95 zap[
'y'] =
make_field(Y,
"ordinate range") = JRange_t();
96 zap[
'z'] =
make_field(Z,
"ordinate range of projection)") = JRange_t();
97 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
98 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis");
99 zap[
'Z'] =
make_field(logz,
"logarithmic y-axis; after projection");
100 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
101 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
102 zap[
'^'] =
make_field(yLabel,
"y-axis label") =
"";
105 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
106 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
107 zap[
'O'] =
make_field(option,
"plotting option") =
"";
109 zap[
'B'] =
make_field(batch,
"batch processing");
110 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
112 zap[
'g'] =
make_field(group,
"group colour codes of objects") = 1;
113 zap[
't'] =
make_field(xTimeFormat,
"set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") =
"";
118 catch(
const exception &error) {
119 FATAL(error.what() << endl);
123 gROOT->SetBatch(batch);
125 TApplication* tp =
new TApplication(
"user", NULL, NULL);
126 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
128 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
130 gROOT->SetStyle(
"gplot");
134 cv->SetFillStyle(4000);
135 cv->SetFillColor(kWhite);
144 Double_t xmin = +numeric_limits<double>::max();
145 Double_t xmax = -numeric_limits<double>::max();
147 Double_t ymin = +numeric_limits<double>::max();
148 Double_t ymax = -numeric_limits<double>::max();
153 const bool px = (project ==
'x' || project ==
'X');
154 const bool py = (project ==
'y' || project ==
'Y');
156 logy = (logy || logz);
171 DEBUG(
"Input: " << *input << endl);
176 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
180 const TRegexp regexp(input->getObjectName());
182 TIter iter(dir->GetListOfKeys());
184 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
186 const TString tag(key->GetName());
188 DEBUG(
"Key: " << tag <<
" match = " << tag.Index(regexp) <<
" (-1 /= OK)" << endl);
192 if (tag.Index(regexp) != -1) {
194 JRootObject object(key->ReadObj());
207 line.SetLineColor(marker.GetMarkerColor());
211 TProfile& h1 =
dynamic_cast<TProfile&
>(*object);
213 object = h1.ProjectionX();
219 TH2& h2 =
dynamic_cast<TH2&
>(*object);
225 h2.GetYaxis()->FindBin(Z.getLowerLimit()),
226 h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
230 h2.GetYaxis()->GetNbins());
236 h2.GetXaxis()->FindBin(Z.getLowerLimit()),
237 h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
241 h2.GetXaxis()->GetNbins());
245 ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
254 dynamic_cast<TAttMarker&
>(*object) = marker;
260 dynamic_cast<TAttLine&
> (*object) = line;
266 TH1& h1 =
dynamic_cast<TH1&
>(*object);
268 h1.SetStats(stats != -1);
270 xmin = min(xmin, h1.GetXaxis()->GetXmin());
271 xmax = max(xmax, h1.GetXaxis()->GetXmax());
273 ymin = min(ymin, h1.GetMinimum());
274 ymax = max(ymax, h1.GetMaximum());
277 for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
278 h1.SetBinError(i, 0.0);
282 TIterator*
iterator = h1.GetListOfFunctions()->MakeIterator();
284 for (
int n = 0; TF1* f1 = (TF1*) iterator->Next(); ) {
290 if (inputFile.size() == 1)
291 f1->SetLineColor(kRed);
293 f1->SetLineColor(h1.GetLineColor());
304 TAttFill& fill =
dynamic_cast<TAttFill&
>(*object);
306 fill.SetFillColor(marker.GetMarkerColor());
313 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
315 for (Int_t i = 0; i != g1.GetN(); ++i) {
317 xmin = min(xmin, g1.GetX()[i]);
318 xmax = max(xmax, g1.GetX()[i]);
320 if (!logy || g1.GetY()[i] > 0.0) {
321 ymin = min(ymin, g1.GetY()[i]);
322 ymax = max(ymax, g1.GetY()[i]);
332 THStack& hs =
dynamic_cast<THStack&
>(*object);
334 NOTICE(
"THStack" << endl);
336 TIterator* iterator = hs.GetHists()->MakeIterator();
338 for (
size_t index = 0;
TObject* i = iterator->Next(); ++index) {
340 TH1& h1 =
dynamic_cast<TH1&
>(*i);
342 NOTICE(
"TH1[" << index <<
"] " << h1.GetName() << endl);
344 xmin = min(xmin, h1.GetXaxis()->GetXmin());
345 xmax = max(xmax, h1.GetXaxis()->GetXmax());
347 ymin = min(ymin, h1.GetMinimum());
348 ymax = max(ymax, h1.GetMaximum());
351 h1.SetLineColor(kBlack);
360 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
362 *i = (*i)(TRegexp(
"\\[.*\\]"));
364 DEBUG(
"Label: <" << *i <<
">" << endl);
366 if (i->Length() > 2) {
367 object.setLabel((*i)(1, i->Length() - 2));
371 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
373 if (master == NULL) {
374 master =
dynamic_cast<TH1*
>(
object.get());
377 listOfObjects.push_back(
object);
382 if (listOfObjects.empty()) {
383 ERROR(
"Nothing to draw." << endl);
388 if (X != JRange_t()) {
389 xmin = X.getLowerLimit();
390 xmax = X.getUpperLimit();
393 if (Y != JRange_t()) {
394 ymin = Y.getLowerLimit();
395 ymax = Y.getUpperLimit();
402 if (master == NULL) {
404 if (X != JRange_t()) {
406 master =
new TH1D(
"__H__", NULL, 100, X.getLowerLimit(), X.getUpperLimit());
408 master->SetStats(kFALSE);
410 }
else if (xmin < xmax) {
412 master =
new TH1D(
"__H__", NULL, 100, xmin, xmax);
414 master->SetStats(kFALSE);
418 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
426 if (master != NULL) {
428 if (logx) { gPad->SetLogx(); }
429 if (logy) { gPad->SetLogy(); }
431 master->GetXaxis()->SetRangeUser(xmin, xmax);
437 master->SetTitle(title.c_str());
439 master->SetMinimum(ymin);
440 master->SetMaximum(ymax);
442 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
443 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
445 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
446 (logx > 1 && xmax-xmin < 2));
448 master->GetYaxis()->SetMoreLogLabels( logy && log10(ymax/ymin) < 2);
449 master->GetYaxis()->SetNoExponent ( logy && log10(ymax/ymin) < 2);
451 if (Ndivisions.first !=
"") {
452 master->SetNdivisions(Ndivisions.second, Ndivisions.first.c_str());
455 if (xTimeFormat !=
"") {
456 master->GetXaxis()->SetTimeDisplay(1);
457 master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
460 master->Draw(option.c_str());
467 TH1* h1 =
dynamic_cast<TH1*
>(i->get());
471 if (logx > 0 && h1 != master) {
475 TIter iter(h1->GetListOfFunctions());
477 const TRegexp key(
"x[^a-zA-Z]");
478 const TString rep(
"log10(x)");
480 for (TF1* f1; (f1 = (TF1*) iter.Next()) != NULL; ) {
482 TString formula(f1->GetExpFormula());
484 for (Ssiz_t pos = 0; (pos = formula.Index(key, pos)) != -1; pos += rep.Length()) {
485 formula.Replace(pos, 1, rep);
488 TF1 f2(f1->GetName(), formula);
490 f2.SetParameters(f1->GetParameters());
491 f2.SetRange(f1->GetXmin(), f1->GetXmax());
493 static_cast<TAttLine&
>(f2) = *f1;
497 if (f1->GetXmin() != 0.0 && f1->GetXmax() != 1.0)
498 f1->SetRange(pow(10.0,f1->GetXmin()), pow(10.0,f1->GetXmax()));
500 f1->SetRange(pow(10.0,xmin), pow(10.0,xmax));
506 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
507 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
510 gStyle->SetOptStat(stats);
512 gStyle->SetOptFit(kFALSE);
516 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
518 string buffer(option);
526 TGraph* p =
dynamic_cast<TGraph*
>(i->get());
529 if (p->GetN() > 1 && drawLine)
542 Ssiz_t height = listOfObjects.size();
546 width = max(width, i->getLabel().Length());
549 TLegend* lg =
new JLegend(width, height, legend);
552 lg->AddEntry(*i,
" " + i->getLabel(),
isTAttLine(*i) ?
"L" :
"LPF");
Utility class to parse command line options.
#define MAKE_CSTRING(A)
Make C-string.
Empty structure for specification of parser element that is initialised (i.e.
void setLogarithm(TAxis *axis)
Make axis logarithmic (e.g.
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
std::string getLabel(const JPDFType_t pdf)
Get PDF label.
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
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.