57 typedef JRange<double> JRange_t;
85 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
87 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
89 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
91 zap[
'x'] =
make_field(
X,
"x-abscissa range") = JRange_t();
92 zap[
'y'] =
make_field(
Y,
"y-abscissa range") = JRange_t();
93 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t();
94 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
95 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
96 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
97 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
98 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
99 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
100 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
101 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
102 zap[
'O'] =
make_field(option,
"plotting option") =
"";
104 zap[
'B'] =
make_field(batch,
"batch processing");
105 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
107 zap[
'p'] =
make_field(palette,
"palette") = -1;
112 catch(
const exception &error) {
113 FATAL(error.what() << endl);
117 gROOT->SetBatch(batch);
119 TApplication* tp =
new TApplication(
"user", NULL, NULL);
120 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
122 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
125 gStyle->SetPalette(palette);
128 gROOT->SetStyle(
"gplot");
132 cv->SetFillStyle(4000);
133 cv->SetFillColor(kWhite);
139 Double_t xmin = numeric_limits<double>::max();
140 Double_t xmax = numeric_limits<double>::lowest();
141 Double_t ymin = numeric_limits<double>::max();
142 Double_t ymax = numeric_limits<double>::lowest();
143 Double_t zmin = numeric_limits<double>::max();
144 Double_t zmax = numeric_limits<double>::lowest();
152 DEBUG(
"Input: " << *input << endl);
157 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
161 const TRegexp regexp(input->getObjectName());
163 TIter iter(dir->GetListOfKeys());
165 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
167 const TString tag(key->GetName());
169 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
173 if (tag.Contains(regexp)) {
175 if (title == JName_t) {
176 title = key->GetName();
177 }
else if (title == JTitle_t) {
178 title = key->GetTitle();
181 JRootObject object(key->ReadObj());
185 TH3& h3 =
dynamic_cast<TH3&
>(*object);
187 object = h3.Project3D(project.c_str());
193 TH2& h2 =
dynamic_cast<TH2&
>(*object);
195 h2.SetStats(stats != -1);
197 xmin = min(xmin, h2.GetXaxis()->GetXmin());
198 xmax = max(xmax, h2.GetXaxis()->GetXmax());
199 ymin = min(ymin, h2.GetYaxis()->GetXmin());
200 ymax = max(ymax, h2.GetYaxis()->GetXmax());
201 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
202 zmax = max(zmax, h2.GetMaximum());
208 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
210 for (Int_t i = 0; i != g1.GetN(); ++i) {
211 xmin = min(xmin, g1.GetX()[i] - numeric_limits<float>::epsilon());
212 xmax = max(xmax, g1.GetX()[i] + numeric_limits<float>::epsilon());
213 ymin = min(ymin, g1.GetY()[i] - numeric_limits<float>::epsilon());
214 ymax = max(ymax, g1.GetY()[i] + numeric_limits<float>::epsilon());
220 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
231 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
233 for (Int_t i = 0; i != g2.GetN(); ++i) {
234 if (!logz || g2.GetZ()[i] > 0.0) {
235 xmin = min(xmin, g2.GetX()[i]);
236 xmax = max(xmax, g2.GetX()[i]);
237 ymin = min(ymin, g2.GetY()[i]);
238 ymax = max(ymax, g2.GetY()[i]);
239 zmin = min(zmin, g2.GetZ()[i]);
240 zmax = max(zmax, g2.GetZ()[i]);
244 if (Z != JRange_t()) {
245 g2.SetMinimum(Z.getLowerLimit());
246 g2.SetMaximum(Z.getUpperLimit());
253 TF2& f2 =
dynamic_cast<TF2&
>(*object);
255 f2.SetLineColor(kRed);
256 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
263 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
265 xmin = min(xmin, __xmin);
266 xmax = max(xmax, __xmax);
267 ymin = min(ymin, __ymin);
268 ymax = max(ymax, __ymax);
269 zmin = min(zmin, f2.GetMinimum());
270 zmax = max(zmax, f2.GetMaximum());
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 if (dynamic_cast<TH2*> (
object.
get()) != NULL ||
284 dynamic_cast<TGraph*> (
object.
get()) != NULL ||
285 dynamic_cast<TGraph2D*>(
object.
get()) != NULL ||
286 dynamic_cast<TF2*> (
object.
get()) != NULL) {
288 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
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);
316 if (
X != JRange_t()) {
317 xmin =
X.getLowerLimit();
318 xmax =
X.getUpperLimit();
321 if (
Y != JRange_t()) {
322 ymin =
Y.getLowerLimit();
323 ymax =
Y.getUpperLimit();
326 if (Z != JRange_t()) {
327 zmin = Z.getLowerLimit();
328 zmax = Z.getUpperLimit();
335 if (
X != JRange_t() &&
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 DEBUG(
"Draw " <<
master->GetName() <<
' ' << option << endl);
394 master->Draw(option.c_str());
397 if (logx > 1 || logy > 1) {
399 if (dynamic_cast<TH2*>(i->get()) !=
master) {
414 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
415 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
418 gStyle->SetOptStat(stats);
420 gStyle->SetOptFit(kFALSE);
424 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
426 string buffer(option);
432 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
441 TGraph& g1 =
dynamic_cast<TGraph&
>(*(*i));
449 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
458 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
469 (*i)->Draw(buffer.c_str());
484 return (
master != NULL ? 0 : 1);
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.
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
T & getInstance(const T &object)
Get static instance from temporary object.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
then break fi done getCenter read X Y Z let X
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.
void setLogarithmicY(TF2 *f2)
Make parameter y of function logarithmic (e.g. after filling with log10()).
#define DEBUG(A)
Message macros.
Double_t g1(const Double_t x)
Function.