56 typedef JRange<double> JRange_t;
83 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
85 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
87 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
89 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t();
90 zap[
'y'] =
make_field(
Y,
"y-abscissa range") = JRange_t();
91 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t();
92 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
93 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
94 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
95 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
96 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
97 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
98 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
99 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
100 zap[
'O'] =
make_field(option,
"plotting option") =
"";
101 zap[
'B'] =
make_field(batch,
"batch processing");
102 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
104 zap[
'p'] =
make_field(palette,
"palette") = -1;
109 catch(
const exception &error) {
110 FATAL(error.what() << endl);
114 gROOT->SetBatch(batch);
116 TApplication* tp =
new TApplication(
"user", NULL, NULL);
117 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
119 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
122 gStyle->SetPalette(palette);
125 gROOT->SetStyle(
"gplot");
129 cv->SetFillStyle(4000);
130 cv->SetFillColor(kWhite);
136 Double_t xmin = numeric_limits<double>::max();
137 Double_t xmax = numeric_limits<double>::lowest();
138 Double_t ymin = numeric_limits<double>::max();
139 Double_t ymax = numeric_limits<double>::lowest();
140 Double_t zmin = numeric_limits<double>::max();
141 Double_t zmax = numeric_limits<double>::lowest();
149 DEBUG(
"Input: " << *input << endl);
154 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
158 const TRegexp regexp(input->getObjectName());
160 TIter iter(dir->GetListOfKeys());
162 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
164 const TString tag(key->GetName());
166 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
170 if (tag.Contains(regexp)) {
172 if (title == JName_t) {
173 title = key->GetName();
174 }
else if (title == JTitle_t) {
175 title = key->GetTitle();
178 JRootObject object(key->ReadObj());
182 TH3& h3 =
dynamic_cast<TH3&
>(*object);
184 object = h3.Project3D(project.c_str());
190 TH2& h2 =
dynamic_cast<TH2&
>(*object);
192 h2.SetStats(stats != -1);
194 xmin = min(xmin, h2.GetXaxis()->GetXmin());
195 xmax = max(xmax, h2.GetXaxis()->GetXmax());
196 ymin = min(ymin, h2.GetYaxis()->GetXmin());
197 ymax = max(ymax, h2.GetYaxis()->GetXmax());
198 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
199 zmax = max(zmax, h2.GetMaximum());
205 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
207 for (Int_t i = 0; i != g1.GetN(); ++i) {
208 xmin = min(xmin, g1.GetX()[i]);
209 xmax = max(xmax, g1.GetX()[i]);
210 ymin = min(ymin, g1.GetY()[i]);
211 ymax = max(ymax, g1.GetY()[i]);
217 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
228 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
230 for (Int_t i = 0; i != g2.GetN(); ++i) {
231 if (!logz || g2.GetZ()[i] > 0.0) {
232 xmin = min(xmin, g2.GetX()[i]);
233 xmax = max(xmax, g2.GetX()[i]);
234 ymin = min(ymin, g2.GetY()[i]);
235 ymax = max(ymax, g2.GetY()[i]);
236 zmin = min(zmin, g2.GetZ()[i]);
237 zmax = max(zmax, g2.GetZ()[i]);
241 if (Z != JRange_t()) {
242 g2.SetMinimum(Z.getLowerLimit());
243 g2.SetMaximum(Z.getUpperLimit());
250 TF2& f2 =
dynamic_cast<TF2&
>(*object);
252 f2.SetLineColor(kRed);
253 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
260 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
262 xmin = min(xmin, __xmin);
263 xmax = max(xmax, __xmax);
264 ymin = min(ymin, __ymin);
265 ymax = max(ymax, __ymax);
266 zmin = min(zmin, f2.GetMinimum());
267 zmax = max(zmax, f2.GetMaximum());
271 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
273 *i = (*i)(TRegexp(
"\\[.*\\]"));
275 if ((*i).Length() > 2) {
276 object.setLabel((*i)(1, (*i).Length() - 2));
280 if (dynamic_cast<TH2*> (
object.
get()) != NULL ||
281 dynamic_cast<TGraph*> (
object.
get()) != NULL ||
282 dynamic_cast<TGraph2D*>(
object.
get()) != NULL ||
283 dynamic_cast<TF2*> (
object.
get()) != NULL) {
285 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
288 master =
dynamic_cast<TH2*
>(
object.get());
291 listOfObjects.push_back(
object);
294 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
300 if (listOfObjects.empty()) {
301 ERROR(
"Nothing to draw." << endl);
308 if (option.find(
"COLZ") != string::npos ||
309 option.find(
"colz") != string::npos) {
310 gPad->SetRightMargin(0.20);
313 if (X != JRange_t()) {
314 xmin = X.getLowerLimit();
315 xmax = X.getUpperLimit();
318 if (
Y != JRange_t()) {
319 ymin =
Y.getLowerLimit();
320 ymax =
Y.getUpperLimit();
323 if (Z != JRange_t()) {
324 zmin = Z.getLowerLimit();
325 zmax = Z.getUpperLimit();
332 if (X != JRange_t() &&
335 master =
new TH2D(
"__H__", NULL,
336 100, X.getLowerLimit(), X.getUpperLimit(),
337 100,
Y.getLowerLimit(),
Y.getUpperLimit());
341 }
else if (xmin < xmax && ymin < ymax) {
343 master =
new TH2D(
"__H__", NULL,
351 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
361 if (logx) { gPad->SetLogx(); }
362 if (logy) { gPad->SetLogy(); }
363 if (logz) { gPad->SetLogz(); }
365 master->GetXaxis()->SetRangeUser(xmin, xmax);
366 master->GetYaxis()->SetRangeUser(ymin, ymax);
371 master->SetTitle(title.c_str());
376 if (xLabel !=
"") {
master->GetXaxis()->SetTitle(xLabel.c_str());
master->GetXaxis()->CenterTitle(
true); }
377 if (yLabel !=
"") {
master->GetYaxis()->SetTitle(yLabel.c_str());
master->GetYaxis()->CenterTitle(
true); }
378 if (zLabel !=
"") {
master->GetZaxis()->SetTitle(zLabel.c_str());
master->GetZaxis()->CenterTitle(
true); }
380 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
381 (logx > 1 && xmax-xmin < 2));
382 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
383 (logy > 1 && ymax-ymin < 2));
386 master->SetNdivisions(i->second, i->first.c_str());
389 DEBUG(
"Draw " <<
master->GetName() <<
' ' << option << endl);
391 master->Draw(option.c_str());
394 if (logx > 1 || logy > 1) {
396 if (dynamic_cast<TH2*>(i->get()) !=
master) {
412 gStyle->SetOptStat(stats);
414 gStyle->SetOptFit(kFALSE);
418 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
420 string buffer(option);
426 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
435 TGraph& g1 =
dynamic_cast<TGraph&
>(*(*i));
443 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
452 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
463 (*i)->Draw(buffer.c_str());
478 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
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.