82 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
84 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
86 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
91 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
92 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
93 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
94 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
95 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
96 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
97 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
98 zap[
'O'] =
make_field(option,
"plotting option") =
"";
99 zap[
'B'] =
make_field(batch,
"batch processing");
100 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
102 zap[
'p'] =
make_field(palette,
"palette") = -1;
107 catch(
const exception &error) {
108 FATAL(error.what() << endl);
112 gROOT->SetBatch(batch);
114 TApplication* tp =
new TApplication(
"user", NULL, NULL);
115 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
117 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
120 gStyle->SetPalette(palette);
123 gROOT->SetStyle(
"gplot");
127 cv->SetFillStyle(4000);
128 cv->SetFillColor(kWhite);
134 lineAttributes.push_back(TAttLine(kBlack, 1, lineWidth));
135 lineAttributes.push_back(TAttLine(kRed, 1, lineWidth));
136 lineAttributes.push_back(TAttLine(kBlue, 1, lineWidth));
137 lineAttributes.push_back(TAttLine(kGreen, 1, lineWidth));
138 lineAttributes.push_back(TAttLine(kMagenta, 1, lineWidth));
139 lineAttributes.push_back(TAttLine(kYellow, 1, lineWidth));
140 lineAttributes.push_back(TAttLine(kCyan, 1, lineWidth));
143 Double_t xmin = +numeric_limits<double>::max();
144 Double_t xmax = -numeric_limits<double>::max();
145 Double_t ymin = +numeric_limits<double>::max();
146 Double_t ymax = -numeric_limits<double>::max();
147 Double_t zmin = +numeric_limits<double>::max();
148 Double_t zmax = -numeric_limits<double>::max();
156 DEBUG(
"Input: " << *input << endl);
161 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
165 const TRegexp regexp(input->getObjectName());
167 TIter iter(dir->GetListOfKeys());
169 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
171 const TString tag(key->GetName());
173 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
177 if (tag.Contains(regexp)) {
179 if (title == JName_t) {
180 title = key->GetName();
181 }
else if (title == JTitle_t) {
182 title = key->GetTitle();
185 JRootObject object(key->ReadObj());
189 dynamic_cast<TAttLine&
>(*object) = lineAttributes[listOfObjects.size() % lineAttributes.size()];
195 TH2& h2 =
dynamic_cast<TH2&
>(*object);
197 h2.SetStats(stats != -1);
199 xmin = min(xmin, h2.GetXaxis()->GetXmin());
200 xmax = max(xmax, h2.GetXaxis()->GetXmax());
201 ymin = min(ymin, h2.GetYaxis()->GetXmin());
202 ymax = max(ymax, h2.GetYaxis()->GetXmax());
203 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
204 zmax = max(zmax, h2.GetMaximum());
210 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
212 for (Int_t i = 0; i != g1.GetN(); ++i) {
214 xmin = min(xmin, g1.GetX()[i]);
215 xmax = max(xmax, g1.GetX()[i]);
216 ymin = min(ymin, g1.GetY()[i]);
217 ymax = max(ymax, g1.GetY()[i]);
223 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
234 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
236 for (Int_t i = 0; i != g2.GetN(); ++i) {
238 if (!logy || g2.GetZ()[i] > 0.0) {
239 xmin = min(xmin, g2.GetX()[i]);
240 xmax = max(xmax, g2.GetX()[i]);
241 ymin = min(ymin, g2.GetY()[i]);
242 ymax = max(ymax, g2.GetY()[i]);
243 zmin = min(zmin, g2.GetZ()[i]);
244 zmax = max(zmax, g2.GetZ()[i]);
249 g2.SetMinimum(Z.getLowerLimit());
250 g2.SetMaximum(Z.getUpperLimit());
259 TF2& f2 =
dynamic_cast<TF2&
>(*object);
261 f2.SetLineColor(kRed);
262 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
264 if (xmin != +numeric_limits<double>::max() &&
265 xmax != -numeric_limits<double>::max() &&
266 ymin != +numeric_limits<double>::max() &&
267 ymax != -numeric_limits<double>::max()) {
268 zmin = min(zmin, f2.GetMinimum(xmin, xmax, ymin, ymax));
269 zmax = max(zmax, f2.GetMaximum(xmin, xmax, ymin, ymax));
274 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
276 *i = (*i)(TRegexp(
"\\[.*\\]"));
278 if ((*i).Length() > 2) {
279 object.setLabel((*i)(1, (*i).Length() - 2));
283 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
285 if (dynamic_cast<TH2*> (
object.
get()) != NULL ||
286 dynamic_cast<TGraph*> (
object.
get()) != NULL ||
287 dynamic_cast<TGraph2D*>(
object.
get()) != NULL ||
288 dynamic_cast<TF2*> (
object.
get()) != NULL) {
291 master =
dynamic_cast<TH2*
>(
object.get());
294 listOfObjects.push_back(
object);
297 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
303 if (listOfObjects.empty()) {
304 ERROR(
"Nothing to draw." << endl);
311 if (option.find(
"COLZ") != string::npos ||
312 option.find(
"colz") != string::npos) {
313 gPad->SetRightMargin(0.20);
317 xmin = X.getLowerLimit();
318 xmax = X.getUpperLimit();
322 ymin = Y.getLowerLimit();
323 ymax = Y.getUpperLimit();
327 zmin = Z.getLowerLimit();
328 zmax = Z.getUpperLimit();
338 master =
new TH2D(
"__H__", NULL,
339 100, X.getLowerLimit(), X.getUpperLimit(),
340 100, Y.getLowerLimit(), Y.getUpperLimit());
344 }
else if (xmin < xmax && ymin < ymax) {
346 master =
new TH2D(
"__H__", NULL,
354 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
364 if (logx) { gPad->SetLogx(); }
365 if (logy) { gPad->SetLogy(); }
366 if (logz) { gPad->SetLogz(); }
368 master->GetXaxis()->SetRangeUser(xmin, xmax);
369 master->GetYaxis()->SetRangeUser(ymin, ymax);
374 master->SetTitle(title.c_str());
379 if (xLabel !=
"") {
master->GetXaxis()->SetTitle(xLabel.c_str());
master->GetXaxis()->CenterTitle(
true); }
380 if (yLabel !=
"") {
master->GetYaxis()->SetTitle(yLabel.c_str());
master->GetYaxis()->CenterTitle(
true); }
381 if (zLabel !=
"") {
master->GetZaxis()->SetTitle(zLabel.c_str());
master->GetZaxis()->CenterTitle(
true); }
383 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
384 (logx > 1 && xmax-xmin < 2));
385 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
386 (logy > 1 && ymax-ymin < 2));
389 master->SetNdivisions(i->second, i->first.c_str());
392 master->Draw(option.c_str());
395 if (logx > 1 || logy > 1) {
399 TH2* h2 =
dynamic_cast<TH2*
>(i->get());
401 if (h2 != NULL && h2 !=
master) {
409 gStyle->SetOptStat(stats);
411 gStyle->SetOptFit(kFALSE);
415 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
417 string buffer(option);
423 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
432 TGraph& g1 =
dynamic_cast<TGraph&
>(*(*i));
440 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
449 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
451 f2.SetRange(xmin, ymin, zmin,
456 (*i)->Draw(buffer.c_str());
Utility class to parse command line options.
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.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
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
JRange< Double_t > JRange_t
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.