10 #include "TApplication.h"
14 #include "TAttMarker.h"
20 #include "TGraphErrors.h"
22 #include "TGraph2DErrors.h"
51 inline bool setLogX(
TObject*
object)
55 T* p =
dynamic_cast<T*
>(object);
74 inline bool setLogY(
TObject*
object)
78 T* p =
dynamic_cast<T*
>(object);
90 const std::string MASTER =
"__H__";
92 const char*
const JName_t =
"?";
93 const char*
const JTitle_t =
"%";
103 int main(
int argc,
char **argv)
108 typedef JRange<double> JRange_t;
136 JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
138 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
140 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
142 zap[
'x'] =
make_field(
X,
"x-abscissa range") = JRange_t();
143 zap[
'y'] =
make_field(
Y,
"y-abscissa range") = JRange_t();
144 zap[
'z'] =
make_field(
Z,
"ordinate range") = JRange_t();
145 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
146 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis (-YY log10 axis)");
147 zap[
'Z'] =
make_field(logz,
"logarithmic z-axis");
148 zap[
'P'] =
make_field(project,
"projection") =
"",
"xy",
"yx",
"xz",
"zx",
"yz",
"zy";
149 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
150 zap[
'<'] =
make_field(yLabel,
"y-axis label") =
"";
151 zap[
'^'] =
make_field(zLabel,
"z-axis label") =
"";
152 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
153 zap[
'O'] =
make_field(option,
"plotting option") =
"";
155 zap[
'B'] =
make_field(batch,
"batch processing");
156 zap[
'T'] =
make_field(title,
"title") =
"KM3NeT preliminary";
158 zap[
'p'] =
make_field(palette,
"palette") = -1;
163 catch(
const exception &error) {
164 FATAL(error.what() << endl);
168 gROOT->SetBatch(batch);
170 TApplication* tp =
new TApplication(
"user", NULL, NULL);
171 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
173 JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
176 gStyle->SetPalette(palette);
179 gROOT->SetStyle(
"gplot");
183 cv->SetFillStyle(4000);
184 cv->SetFillColor(kWhite);
190 Double_t xmin = numeric_limits<double>::max();
191 Double_t xmax = numeric_limits<double>::lowest();
192 Double_t ymin = numeric_limits<double>::max();
193 Double_t ymax = numeric_limits<double>::lowest();
194 Double_t zmin = numeric_limits<double>::max();
195 Double_t zmax = numeric_limits<double>::lowest();
203 DEBUG(
"Input: " << *input << endl);
208 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
212 const TRegexp regexp(input->getObjectName());
214 TIter iter(dir->GetListOfKeys());
216 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
218 const TString tag(key->GetName());
220 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
224 if (tag.Contains(regexp) &&
isTObject(key)) {
226 if (title == JName_t) {
227 title = key->GetName();
228 }
else if (title == JTitle_t) {
229 title = key->GetTitle();
232 JRootObject object(key->ReadObj());
236 TH3& h3 =
dynamic_cast<TH3&
>(*object);
238 object = h3.Project3D(project.c_str());
244 TH2& h2 =
dynamic_cast<TH2&
>(*object);
246 h2.SetStats(stats != -1);
248 xmin = min(xmin, h2.GetXaxis()->GetXmin());
249 xmax = max(xmax, h2.GetXaxis()->GetXmax());
250 ymin = min(ymin, h2.GetYaxis()->GetXmin());
251 ymax = max(ymax, h2.GetYaxis()->GetXmax());
252 zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
253 zmax = max(zmax, h2.GetMaximum());
259 TGraph&
g1 =
dynamic_cast<TGraph&
>(*object);
261 for (Int_t i = 0; i != g1.GetN(); ++i) {
262 xmin = min(xmin, g1.GetX()[i] - numeric_limits<float>::epsilon());
263 xmax = max(xmax, g1.GetX()[i] + numeric_limits<float>::epsilon());
264 ymin = min(ymin, g1.GetY()[i] - numeric_limits<float>::epsilon());
265 ymax = max(ymax, g1.GetY()[i] + numeric_limits<float>::epsilon());
271 if (dynamic_cast<TGraph*>(i->get()) != NULL) {
282 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*object);
284 for (Int_t i = 0; i != g2.GetN(); ++i) {
285 if (!logz || g2.GetZ()[i] > 0.0) {
286 xmin = min(xmin, g2.GetX()[i]);
287 xmax = max(xmax, g2.GetX()[i]);
288 ymin = min(ymin, g2.GetY()[i]);
289 ymax = max(ymax, g2.GetY()[i]);
290 zmin = min(zmin, g2.GetZ()[i]);
291 zmax = max(zmax, g2.GetZ()[i]);
295 if (
Z != JRange_t()) {
296 g2.SetMinimum(
Z.getLowerLimit());
297 g2.SetMaximum(
Z.getUpperLimit());
304 TF2& f2 =
dynamic_cast<TF2&
>(*object);
306 f2.SetLineColor(kRed);
307 f2.SetTitle((title +
";" + xLabel +
";" + yLabel +
";" + zLabel).c_str());
314 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
316 xmin = min(xmin, __xmin);
317 xmax = max(xmax, __xmax);
318 ymin = min(ymin, __ymin);
319 ymax = max(ymax, __ymax);
320 zmin = min(zmin, f2.GetMinimum());
321 zmax = max(zmax, f2.GetMaximum());
325 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++i) {
327 *i = (*i)(TRegexp(
"\\[.*\\]"));
329 if ((*i).Length() > 2) {
330 object.setLabel((*i)(1, (*i).Length() - 2));
334 if (dynamic_cast<TH2*> (
object.
get()) != NULL ||
335 dynamic_cast<TGraph*> (
object.
get()) != NULL ||
336 dynamic_cast<TGraph2D*>(
object.
get()) != NULL ||
337 dynamic_cast<TEllipse*>(
object.
get()) != NULL ||
338 dynamic_cast<TLine*> (
object.
get()) != NULL ||
339 dynamic_cast<TF2*> (
object.
get()) != NULL) {
341 DEBUG(
"Add object: " << tag <<
" with label " <<
object.
getLabel() << endl);
344 master =
dynamic_cast<TH2*
>(
object.get());
347 listOfObjects.push_back(
object);
350 ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
356 if (listOfObjects.empty()) {
357 ERROR(
"Nothing to draw." << endl);
364 if (option.find(
"COLZ") != string::npos ||
365 option.find(
"colz") != string::npos) {
366 gPad->SetRightMargin(0.20);
369 if (
X != JRange_t()) {
370 xmin =
X.getLowerLimit();
371 xmax =
X.getUpperLimit();
374 if (
Y != JRange_t()) {
375 ymin =
Y.getLowerLimit();
376 ymax =
Y.getUpperLimit();
379 if (
Z != JRange_t()) {
380 zmin =
Z.getLowerLimit();
381 zmax =
Z.getUpperLimit();
388 if (
X != JRange_t() &&
391 master =
new TH2D(MASTER.c_str(), NULL,
392 100,
X.getLowerLimit(),
X.getUpperLimit(),
393 100,
Y.getLowerLimit(),
Y.getUpperLimit());
397 }
else if (xmin < xmax && ymin < ymax) {
399 master =
new TH2D(MASTER.c_str(), NULL,
407 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
417 if (logx) { gPad->SetLogx(); }
418 if (logy) { gPad->SetLogy(); }
419 if (logz) { gPad->SetLogz(); }
421 master->GetXaxis()->SetRangeUser(xmin, xmax);
422 master->GetYaxis()->SetRangeUser(ymin, ymax);
427 master->SetTitle(title.c_str());
432 if (xLabel !=
"") {
master->GetXaxis()->SetTitle(xLabel.c_str());
master->GetXaxis()->CenterTitle(
true); }
433 if (yLabel !=
"") {
master->GetYaxis()->SetTitle(yLabel.c_str());
master->GetYaxis()->CenterTitle(
true); }
434 if (zLabel !=
"") {
master->GetZaxis()->SetTitle(zLabel.c_str());
master->GetZaxis()->CenterTitle(
true); }
436 master->GetXaxis()->SetMoreLogLabels((logx == 1 &&
log10(xmax/xmin) < 2) ||
437 (logx > 1 && xmax-xmin < 2));
438 master->GetYaxis()->SetMoreLogLabels((logy == 1 &&
log10(ymax/ymin) < 2) ||
439 (logy > 1 && ymax-ymin < 2));
442 master->SetNdivisions(i->second, i->first.c_str());
445 DEBUG(
"Draw " <<
master->GetName() <<
' ' << option << endl);
450 if (logx > 1 || logy > 1) {
452 if (dynamic_cast<TH2*>(i->get()) !=
master) {
454 if (setLogX<TH2> (i->get())) {}
455 else if (setLogX<TF2> (i->get())) {}
456 else if (setLogX<TGraph2DErrors>(i->get())) {}
457 else if (setLogX<TGraph2D> (i->get())) {}
458 else if (setLogX<TGraphErrors> (i->get())) {}
459 else if (setLogX<TGraph> (i->get())) {}
460 else if (setLogX<TLine> (i->get())) {}
461 else if (setLogX<TEllipse> (i->get())) {}
464 if (setLogY<TH2> (i->get())) {}
465 else if (setLogY<TF2> (i->get())) {}
466 else if (setLogY<TGraph2DErrors>(i->get())) {}
467 else if (setLogY<TGraph2D> (i->get())) {}
468 else if (setLogY<TGraphErrors> (i->get())) {}
469 else if (setLogY<TGraph> (i->get())) {}
470 else if (setLogY<TLine> (i->get())) {}
471 else if (setLogY<TEllipse> (i->get())) {}
477 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
478 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
481 gStyle->SetOptStat(stats);
483 gStyle->SetOptFit(kFALSE);
487 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
489 string buffer(option);
495 TH2& h2 =
dynamic_cast<TH2&
>(*(*i));
504 TGraph&
g1 =
dynamic_cast<TGraph&
>(*(*i));
512 TGraph2D& g2 =
dynamic_cast<TGraph2D&
>(*(*i));
521 TF2& f2 =
dynamic_cast<TF2&
>(*(*i));
532 (*i)->Draw(buffer.c_str());
547 return (
master != NULL ? 0 : 1);
Utility class to parse command line options.
then echo Test string reversed by master(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho" -rC fi if (( 1 ))
int main(int argc, char *argv[])
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
#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
void setLogarithmicX(TList *list)
Make x-axis of objects in list logarithmic (e.g. after using log10()).
T & getInstance(const T &object)
Get static instance from temporary object.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
set_variable E_E log10(E_{fit}/E_{#mu})"
do set_variable OUTPUT_DIRECTORY $WORKDIR T
then break fi done getCenter read X Y Z let X
General purpose messaging.
void setLogarithmicY(TList *list)
Make y-axis of objects in list logarithmic (e.g. after using log10()).
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Auxiliary class to handle multiple boolean-like I/O.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
Double_t g1(const Double_t x)
Function.