55 typedef JRange<double> JRange_t;
81 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
83 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
85 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
87 zap[
'x'] =
make_field(X,
"x-abscissa range") = JRange_t();
88 zap[
'y'] =
make_field(
Y,
"y-abscissa range") = JRange_t();
89 zap[
'z'] =
make_field(Z,
"ordinate range") = JRange_t();
90 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
91 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
92 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
93 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
94 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
95 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
96 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
97 zap[
'O'] =
make_field(option,
"plotting option") =
"";
98 zap[
'B'] =
make_field(batch,
"batch processing");
99 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
101 zap[
'p'] =
make_field(palette,
"palette") = -1;
106 catch(
const exception &error) {
107 FATAL(error.what() << endl);
111 gROOT->SetBatch(batch);
113 TApplication* tp =
new TApplication(
"user", NULL, NULL);
114 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
116 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
119 gStyle->SetPalette(palette);
122 gROOT->SetStyle(
"gplot");
126 cv->SetFillStyle(4000);
127 cv->SetFillColor(kWhite);
133 Double_t xmin = numeric_limits<double>::max();
134 Double_t xmax = numeric_limits<double>::lowest();
135 Double_t ymin = numeric_limits<double>::max();
136 Double_t ymax = numeric_limits<double>::lowest();
137 Double_t zmin = numeric_limits<double>::max();
138 Double_t zmax = numeric_limits<double>::lowest();
146 DEBUG(
"Input: " << *input << endl);
151 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
155 const TRegexp regexp(input->getObjectName());
157 TIter iter(dir->GetListOfKeys());
159 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
161 const TString tag(key->GetName());
163 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
167 if (tag.Contains(regexp)) {
169 if (title == JName_t) {
170 title = key->GetName();
171 }
else if (title == JTitle_t) {
172 title = key->GetTitle();
175 JRootObject object(key->ReadObj());
179 TH2& h2 =
dynamic_cast<TH2&
>(*object);
181 h2.SetStats(stats != -1);
183 xmin = min(xmin, h2.GetXaxis()->GetXmin());
184 xmax = max(xmax, h2.GetXaxis()->GetXmax());
185 ymin = min(ymin, h2.GetYaxis()->GetXmin());
186 ymax = max(ymax, h2.GetYaxis()->GetXmax());
187 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
188 zmax = max(zmax, h2.GetMaximum());
194 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
196 for (Int_t i = 0; i != g1.GetN(); ++i) {
197 xmin = min(xmin, g1.GetX()[i]);
198 xmax = max(xmax, g1.GetX()[i]);
199 ymin = min(ymin, g1.GetY()[i]);
200 ymax = max(ymax, g1.GetY()[i]);
206 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
217 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
219 for (Int_t i = 0; i != g2.GetN(); ++i) {
220 if (!logz || g2.GetZ()[i] > 0.0) {
221 xmin = min(xmin, g2.GetX()[i]);
222 xmax = max(xmax, g2.GetX()[i]);
223 ymin = min(ymin, g2.GetY()[i]);
224 ymax = max(ymax, g2.GetY()[i]);
225 zmin = min(zmin, g2.GetZ()[i]);
226 zmax = max(zmax, g2.GetZ()[i]);
230 if (Z != JRange_t()) {
231 g2.SetMinimum(Z.getLowerLimit());
232 g2.SetMaximum(Z.getUpperLimit());
239 TF2& f2 =
dynamic_cast<TF2&
>(*object);
241 f2.SetLineColor(kRed);
242 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
249 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
251 xmin = min(xmin, __xmin);
252 xmax = max(xmax, __xmax);
253 ymin = min(ymin, __ymin);
254 ymax = max(ymax, __ymax);
255 zmin = min(zmin, f2.GetMinimum());
256 zmax = max(zmax, f2.GetMaximum());
260 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
262 *i = (*i)(TRegexp(
"\\[.*\\]"));
264 if ((*i).Length() > 2) {
265 object.setLabel((*i)(1, (*i).Length() - 2));
269 if (dynamic_cast<TH2*> (
object.
get()) != NULL ||
270 dynamic_cast<TGraph*> (
object.
get()) != NULL ||
271 dynamic_cast<TGraph2D*>(
object.
get()) != NULL ||
272 dynamic_cast<TF2*> (
object.
get()) != NULL) {
274 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
277 master =
dynamic_cast<TH2*
>(
object.get());
280 listOfObjects.push_back(
object);
283 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
289 if (listOfObjects.empty()) {
290 ERROR(
"Nothing to draw." << endl);
297 if (option.find(
"COLZ") != string::npos ||
298 option.find(
"colz") != string::npos) {
299 gPad->SetRightMargin(0.20);
302 if (X != JRange_t()) {
303 xmin = X.getLowerLimit();
304 xmax = X.getUpperLimit();
307 if (
Y != JRange_t()) {
308 ymin =
Y.getLowerLimit();
309 ymax =
Y.getUpperLimit();
312 if (Z != JRange_t()) {
313 zmin = Z.getLowerLimit();
314 zmax = Z.getUpperLimit();
321 if (X != JRange_t() &&
324 master =
new TH2D(
"__H__", NULL,
325 100, X.getLowerLimit(), X.getUpperLimit(),
326 100,
Y.getLowerLimit(),
Y.getUpperLimit());
330 }
else if (xmin < xmax && ymin < ymax) {
332 master =
new TH2D(
"__H__", NULL,
340 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
350 if (logx) { gPad->SetLogx(); }
351 if (logy) { gPad->SetLogy(); }
352 if (logz) { gPad->SetLogz(); }
354 master->GetXaxis()->SetRangeUser(xmin, xmax);
355 master->GetYaxis()->SetRangeUser(ymin, ymax);
360 master->SetTitle(title.c_str());
365 if (xLabel !=
"") {
master->GetXaxis()->SetTitle(xLabel.c_str());
master->GetXaxis()->CenterTitle(
true); }
366 if (yLabel !=
"") {
master->GetYaxis()->SetTitle(yLabel.c_str());
master->GetYaxis()->CenterTitle(
true); }
367 if (zLabel !=
"") {
master->GetZaxis()->SetTitle(zLabel.c_str());
master->GetZaxis()->CenterTitle(
true); }
369 master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
370 (logx > 1 && xmax-xmin < 2));
371 master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
372 (logy > 1 && ymax-ymin < 2));
375 master->SetNdivisions(i->second, i->first.c_str());
378 DEBUG(
"Draw " <<
master->GetName() <<
' ' << option << endl);
380 master->Draw(option.c_str());
383 if (logx > 1 || logy > 1) {
385 if (dynamic_cast<TH2*>(i->get()) !=
master) {
401 gStyle->SetOptStat(stats);
403 gStyle->SetOptFit(kFALSE);
407 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
409 string buffer(option);
415 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
424 TGraph& g1 =
dynamic_cast<TGraph&
>(*(*i));
432 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
441 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
452 (*i)->Draw(buffer.c_str());
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.