50 typedef JRange<double> JRange_t;
75 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
77 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
79 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
81 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t();
82 zap[
'y'] =
make_field(Y,
"y-abscissa range") = JRange_t();
83 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t();
84 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
85 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
86 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
87 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
88 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
89 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
90 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
91 zap[
'O'] =
make_field(option,
"plotting option") =
"";
92 zap[
'B'] =
make_field(batch,
"batch processing");
93 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
95 zap[
'p'] =
make_field(palette,
"palette") = 53;
100 catch(
const exception &error) {
101 FATAL(error.what() << endl);
105 gROOT->SetBatch(batch);
107 TApplication* tp =
new TApplication(
"user", NULL, NULL);
108 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
110 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
112 gStyle->SetPalette(palette);
114 gROOT->SetStyle(
"gplot");
118 cv->SetFillStyle(4000);
119 cv->SetFillColor(kWhite);
125 lineAttributes.push_back(TAttLine(kBlack, 1, lineWidth));
126 lineAttributes.push_back(TAttLine(kRed, 1, lineWidth));
127 lineAttributes.push_back(TAttLine(kBlue, 1, lineWidth));
128 lineAttributes.push_back(TAttLine(kGreen, 1, lineWidth));
129 lineAttributes.push_back(TAttLine(kMagenta, 1, lineWidth));
130 lineAttributes.push_back(TAttLine(kYellow, 1, lineWidth));
131 lineAttributes.push_back(TAttLine(kCyan, 1, lineWidth));
134 Double_t xmin = +numeric_limits<double>::max();
135 Double_t xmax = -numeric_limits<double>::max();
136 Double_t ymin = +numeric_limits<double>::max();
137 Double_t ymax = -numeric_limits<double>::max();
138 Double_t zmin = +numeric_limits<double>::max();
139 Double_t zmax = -numeric_limits<double>::max();
147 DEBUG(
"Input: " << *input << endl);
152 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
156 const TRegexp regexp(input->getObjectName());
158 TIter iter(dir->GetListOfKeys());
160 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
162 const TString tag(key->GetName());
164 DEBUG(
"Key: " << tag <<
" match = " << tag.Index(regexp) <<
" (-1 /= OK)" << endl);
168 if (tag.Index(regexp) != -1) {
170 JRootObject object(key->ReadObj());
174 dynamic_cast<TAttLine&
>(*object) = lineAttributes[listOfObjects.size() % lineAttributes.size()];
180 TH2& h2 =
dynamic_cast<TH2&
>(*object);
182 h2.SetStats(stats != -1);
184 xmin = min(xmin, h2.GetXaxis()->GetXmin());
185 xmax = max(xmax, h2.GetXaxis()->GetXmax());
186 ymin = min(ymin, h2.GetYaxis()->GetXmin());
187 ymax = max(ymax, h2.GetYaxis()->GetXmax());
188 zmin = min(zmin, h2.GetMinimum());
189 zmax = max(zmax, h2.GetMaximum());
195 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
197 for (Int_t i = 0; i != g1.GetN(); ++i) {
199 xmin = min(xmin, g1.GetX()[i]);
200 xmax = max(xmax, g1.GetX()[i]);
201 ymin = min(ymin, g1.GetY()[i]);
202 ymax = max(ymax, g1.GetY()[i]);
208 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
219 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
221 for (Int_t i = 0; i != g2.GetN(); ++i) {
223 if (!logy || g2.GetZ()[i] > 0.0) {
224 xmin = min(xmin, g2.GetX()[i]);
225 xmax = max(xmax, g2.GetX()[i]);
226 ymin = min(ymin, g2.GetY()[i]);
227 ymax = max(ymax, g2.GetY()[i]);
228 zmin = min(zmin, g2.GetZ()[i]);
229 zmax = max(zmax, g2.GetZ()[i]);
233 if (Z != JRange_t()) {
234 g2.SetMinimum(Z.getLowerLimit());
235 g2.SetMaximum(Z.getUpperLimit());
245 TF2& f2 =
dynamic_cast<TF2&
>(*object);
247 f2.SetLineColor(kRed);
248 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
252 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
254 *i = (*i)(TRegexp(
"\\[.*\\]"));
256 if ((*i).Length() > 2) {
257 object.setLabel((*i)(1, (*i).Length() - 2));
261 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
263 if (dynamic_cast<TH2*> (
object.
get()) != NULL ||
264 dynamic_cast<TGraph*> (
object.
get()) != NULL ||
265 dynamic_cast<TGraph2D*>(
object.
get()) != NULL ||
266 dynamic_cast<TF2*> (
object.
get()) != NULL) {
268 if (master == NULL) {
269 master =
dynamic_cast<TH2*
>(
object.get());
272 listOfObjects.push_back(
object);
275 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
281 if (listOfObjects.empty()) {
282 ERROR(
"Nothing to draw." << endl);
289 if (option.find(
"COLZ") != string::npos ||
290 option.find(
"colz") != string::npos) {
291 gPad->SetRightMargin(0.20);
294 if (X != JRange_t()) {
295 xmin = X.getLowerLimit();
296 xmax = X.getUpperLimit();
299 if (Y != JRange_t()) {
300 ymin = Y.getLowerLimit();
301 ymax = Y.getUpperLimit();
304 if (Z != JRange_t()) {
305 zmin = Z.getLowerLimit();
306 zmax = Z.getUpperLimit();
311 if (master == NULL) {
313 if (X != JRange_t() &&
316 master =
new TH2D(
"__H__", NULL,
317 100, X.getLowerLimit(), X.getUpperLimit(),
318 100, Y.getLowerLimit(), Y.getUpperLimit());
320 master->SetStats(kFALSE);
322 }
else if (xmin < xmax && ymin < ymax) {
324 master =
new TH2D(
"__H__", NULL,
328 master->SetStats(kFALSE);
332 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
340 if (master != NULL) {
342 if (logx) { gPad->SetLogx(); }
343 if (logy) { gPad->SetLogy(); }
344 if (logz) { gPad->SetLogz(); }
346 master->GetXaxis()->SetRangeUser(xmin, xmax);
347 master->GetYaxis()->SetRangeUser(ymin, ymax);
352 master->SetTitle(title.c_str());
354 master->SetMinimum(zmin);
355 master->SetMaximum(zmax);
357 if (xLabel !=
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
358 if (yLabel !=
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
359 if (zLabel !=
"") { master->GetZaxis()->SetTitle(zLabel.c_str()); master->GetZaxis()->CenterTitle(
true); }
361 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
362 (logx > 1 && xmax-xmin < 2));
363 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
364 (logy > 1 && ymax-ymin < 2));
366 if (Ndivisions.first !=
"") {
367 master->SetNdivisions(Ndivisions.second, Ndivisions.first.c_str());
370 master->Draw(option.c_str());
373 if (logx > 1 || logy > 1) {
377 TH2* h2 =
dynamic_cast<TH2*
>(i->get());
379 if (h2 != NULL && h2 != master) {
387 gStyle->SetOptStat(stats);
389 gStyle->SetOptFit(kFALSE);
393 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
395 string buffer(option);
401 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
410 TGraph& g1 =
dynamic_cast<TGraph&
>(*(*i));
418 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
427 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
429 f2.SetRange(xmin, ymin, zmin,
434 (*i)->Draw(buffer.c_str());
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.
T & getInstance(const T &object)
Get static instance from temporary object.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
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.