209 typedef JRange<double> JRange_t;
240 JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
242 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
244 zap[
'w'] =
make_field(canvas,
"size of canvas <nx>x<ny> [pixels]") = JCanvas(500, 500);
246 zap[
'L'] =
make_field(legend,
"position legend e.g. TR [factor]") = JLegend(), JLegend(
"TL"), JLegend(
"TR"), JLegend(
"BR"), JLegend(
"BL");
247 zap[
'x'] =
make_field(
X,
"abscissa range") = JRange_t::DEFAULT_RANGE();
248 zap[
'y'] =
make_field(
Y,
"ordinate range") = JRange_t::DEFAULT_RANGE();
249 zap[
'z'] =
make_field(
Z,
"ordinate range of projection)") = JRange_t::DEFAULT_RANGE();
250 zap[
'X'] =
make_field(logx,
"logarithmic x-axis (-XX log10 axis)");
251 zap[
'Y'] =
make_field(logy,
"logarithmic y-axis");
252 zap[
'Z'] =
make_field(logz,
"logarithmic y-axis; after projection");
254 zap[
'>'] =
make_field(xLabel,
"x-axis label") =
"";
255 zap[
'^'] =
make_field(yLabel,
"y-axis label") =
"";
256 zap[
'C'] =
make_field(drawLine,
"draw line (-C black-and-white -CC colour)");
258 zap[
'l'] =
make_field(lineWidth,
"line width") = 2;
259 zap[
'S'] =
make_field(markerSize,
"marker size") = 1.0;
260 zap[
'O'] =
make_field(option,
"plotting option") =
"";
262 zap[
'B'] =
make_field(batch,
"batch processing");
263 zap[
'T'] =
make_field(title,
"graphics title ("
264 <<
"\"" << JName_t <<
"\" -> ROOT name; "
265 <<
"\"" << JTitle_t <<
"\" -> ROOT title)") =
"KM3NeT preliminary";
267 zap[
'g'] =
make_field(group,
"group colour codes of objects") = 1;
268 zap[
't'] =
make_field(xTimeFormat,
"set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") =
"";
273 catch(
const exception &error) {
274 FATAL(error.what() << endl);
278 gROOT->SetBatch(batch);
280 TApplication* tp =
new TApplication(
"user", NULL, NULL);
281 TCanvas* cv =
new TCanvas(
"c1",
"c1", canvas.x, canvas.y);
283 unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
285 gROOT->SetStyle(
"gplot");
289 cv->SetFillStyle(4000);
290 cv->SetFillColor(kWhite);
299 Double_t
xmin = numeric_limits<double>::max();
300 Double_t
xmax = numeric_limits<double>::lowest();
302 Double_t ymin = numeric_limits<double>::max();
303 Double_t ymax = numeric_limits<double>::lowest();
312 logy = (logy || logz);
327 DEBUG(
"Input: " << *input << endl);
332 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
336 const TRegexp regexp(input->getObjectName());
338 TIter iter(dir->GetListOfKeys());
340 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
342 const TString tag(key->GetName());
344 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
348 if (tag.Contains(regexp) &&
isTObject(key)) {
350 if (title == JName_t) {
351 title = key->GetName();
352 }
else if (title == JTitle_t) {
353 title = key->GetTitle();
356 JRootObject object(key->ReadObj());
368 line.SetLineColor(marker.GetMarkerColor());
374 TProfile& h1 =
dynamic_cast<TProfile&
>(*object);
376 object = h1.ProjectionX();
382 TH2& h2 =
dynamic_cast<TH2&
>(*object);
388 h2.GetYaxis()->FindBin(
Z.getLowerLimit()),
389 h2.GetYaxis()->FindBin(
Z.getUpperLimit()) - 1);
393 h2.GetYaxis()->GetNbins());
399 h2.GetXaxis()->FindBin(
Z.getLowerLimit()),
400 h2.GetXaxis()->FindBin(
Z.getUpperLimit()) - 1);
404 h2.GetXaxis()->GetNbins());
408 ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
417 TH3& h3 =
dynamic_cast<TH3&
>(*object);
433 ERROR(
"For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
443 if (dynamic_cast<TMarker*>(
object.
get()) == NULL) {
444 dynamic_cast<TAttMarker&
>(*object) = marker;
450 if (dynamic_cast<TLine*>(
object.
get()) == NULL) {
451 dynamic_cast<TAttLine&
> (*object) = line;
460 TAttFill& fill =
dynamic_cast<TAttFill&
>(*object);
462 fill.SetFillColor(marker.GetMarkerColor());
473 TH1& h1 =
dynamic_cast<TH1&
>(*object);
475 for (
int i = 1;
i <= h1.GetNbinsX(); ++
i) {
476 h1.SetBinError(
i, 0.0);
483 TGraphErrors&
g1 =
dynamic_cast<TGraphErrors&
>(*object);
485 for (Int_t
i = 0;
i != g1.GetN(); ++
i) {
497 TH1& h1 =
dynamic_cast<TH1&
>(*object);
499 h1.SetStats(stats != -1);
501 xmin = min(
xmin, h1.GetXaxis()->GetXmin());
502 xmax = max(xmax, h1.GetXaxis()->GetXmax());
503 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
504 ymax = max(ymax, h1.GetMaximum());
506 if (!logy && h1.GetListOfFunctions() != NULL) {
507 for (unique_ptr<TIterator>
iterator(h1.GetListOfFunctions()->MakeIterator()); TF1*
f1 = (TF1*)
iterator->Next(); ) {
508 ymin = min(ymin, f1->GetMinimum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
509 ymax = max(ymax, f1->GetMaximum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
517 TGraph& g1 =
dynamic_cast<TGraph&
>(*object);
519 for (Int_t
i = 0;
i != g1.GetN(); ++
i) {
522 xmax = max(xmax, g1.GetX()[
i]);
524 if (!logy || g1.GetY()[
i] > 0.0) {
525 ymin = min(ymin, g1.GetY()[
i]);
526 ymax = max(ymax, g1.GetY()[
i]);
534 TGraphErrors& g1 =
dynamic_cast<TGraphErrors&
>(*object);
536 for (Int_t
i = 0;
i != g1.GetN(); ++
i) {
537 if (!logy || g1.GetY()[
i] - g1.GetEY()[
i] > 0.0) { ymin = min(ymin, g1.GetY()[
i] - g1.GetEY()[
i]); }
538 if (!logy || g1.GetY()[
i] + g1.GetEY()[
i] > 0.0) { ymax = max(ymax, g1.GetY()[
i] + g1.GetEY()[
i]); }
545 TMultiGraph& m1 =
dynamic_cast<TMultiGraph&
>(*object);
547 for (TIter i1(m1.GetListOfGraphs()); TGraph* g1 =
dynamic_cast<TGraph*
>(i1()); ) {
549 for (Int_t
i = 0;
i != g1->GetN(); ++
i) {
552 xmax = max(xmax, g1->GetX()[
i]);
554 if (!logy || g1->GetY()[
i] > 0.0) {
555 ymin = min(ymin, g1->GetY()[
i]);
556 ymax = max(ymax, g1->GetY()[
i]);
565 TF2& f2 =
dynamic_cast<TF2&
>(*object);
568 TString formula = f2.GetExpFormula();
569 TString _z_ = TString::Format(
"%f", 0.5 * (
Z.getLowerLimit() +
Z.getUpperLimit()));
576 f2.GetRange(__xmin, __ymin, __xmax, __ymax);
580 formula.ReplaceAll(
"y", _z_);
584 f1->SetRange(__xmin, __xmax);
588 formula.ReplaceAll(
"x", _z_);
589 formula.ReplaceAll(
"y",
"x");
593 f1->SetRange(__ymin, __ymax);
597 ERROR(
"For 2D functions, use option option -P for projections or use JPlot2D" << endl);
602 DEBUG(
"TF1: " << f1->GetExpFormula() << endl);
604 f1->SetParameters(f2.GetParameters());
612 TF1& f1 =
dynamic_cast<TF1&
>(*object);
617 f1.GetRange(__xmin, __xmax);
620 xmax = max(xmax, __xmax);
621 ymin = min(ymin, f1.GetMinimum());
622 ymax = max(ymax, f1.GetMaximum());
628 THStack& hs =
dynamic_cast<THStack&
>(*object);
630 NOTICE(
"THStack" << endl);
632 unique_ptr<TIterator>
iterator(hs.GetHists()->MakeIterator());
636 TH1& h1 =
dynamic_cast<TH1&
>(*i);
638 NOTICE(
"TH1[" << index <<
"] " << h1.GetName() << endl);
640 xmin = min(xmin, h1.GetXaxis()->GetXmin());
641 xmax = max(xmax, h1.GetXaxis()->GetXmax());
643 ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
644 ymax = max(ymax, h1.GetMaximum());
647 h1.SetLineColor(kBlack);
656 TLine& h1 =
dynamic_cast<TLine&
>(*object);
658 xmin = min(xmin, h1.GetX1());
659 xmax = max(xmax, h1.GetX2());
660 ymin = min(ymin, h1.GetY1());
661 ymax = max(ymax, h1.GetY2());
667 for (TString buffer[] = {
object.getLabel(), input->getFilename().c_str(),
"" }, *i = buffer; *i !=
""; ++
i) {
669 *i = (*i)(TRegexp(
"\\[.*\\]"));
671 if (i->Length() > 2) {
672 object.setLabel((*i)(1, i->Length() - 2));
676 DEBUG(
"Add object: " << tag <<
" with label <" <<
object.
getLabel() <<
">" << endl);
679 master =
dynamic_cast<TH1*
>(
object.get());
682 listOfObjects.push_back(
object);
687 if (listOfObjects.empty()) {
688 ERROR(
"Nothing to draw." << endl);
697 TH1* h1 =
dynamic_cast<TH1*
> (i->get());
698 TGraph* g1 =
dynamic_cast<TGraph*
> (i->get());
699 TMultiGraph* m1 =
dynamic_cast<TMultiGraph*
>(i->get());
700 TAttLine* ls =
dynamic_cast<TAttLine*
> (i->get());
708 iterator.reset(h1->GetListOfFunctions()->MakeIterator());
710 }
else if (g1 != NULL) {
712 iterator.reset(g1->GetListOfFunctions()->MakeIterator());
714 }
else if (m1 != NULL) {
716 for (TIter i1(m1->GetListOfGraphs()); TGraph* gi =
dynamic_cast<TGraph*
>(i1()); ) {
717 for (TIter i2(gi->GetListOfFunctions()); TF1*
fi =
dynamic_cast<TF1*
>(i2()); ) {
722 iterator.reset(list.MakeIterator());
725 if (iterator != NULL) {
727 Double_t x1[] = { numeric_limits<Double_t>::max(), numeric_limits<Double_t>::max() };
728 Double_t x2[] = { numeric_limits<Double_t>::lowest(), numeric_limits<Double_t>::lowest() };
730 for (
int nf = 0,
ns = 0, nc = 1; TF1* f1 = (TF1*) iterator->Next(); ++nf) {
732 f1->GetRange(x1[1], x2[1]);
737 if (listOfObjects.size() == 1) {
739 if (x1[0] == x1[1] &&
752 f1->SetLineColor(ls->GetLineColor());
776 xmin =
X.getLowerLimit();
777 xmax =
X.getUpperLimit();
781 ymin =
Y.getLowerLimit();
782 ymax =
Y.getUpperLimit();
783 }
else if (ymax > ymin) {
789 if (!listOfObjects.empty()) {
797 for (Int_t i = 1; i <=
master->GetXaxis()->GetNbins(); ++
i) {
798 master->SetBinContent(i, ymin);
805 TText* p =
new TText(0.5, 0.5,
MAKE_CSTRING(
"No data"));
813 if (logx) { gPad->SetLogx(); }
814 if (logy) { gPad->SetLogy(); }
816 master->GetXaxis()->SetRangeUser(xmin, xmax);
817 master->SetTitle(title.c_str());
826 if (xLabel !=
"") {
master->GetXaxis()->SetTitle(xLabel.c_str());
master->GetXaxis()->CenterTitle(
true); }
827 if (yLabel !=
"") {
master->GetYaxis()->SetTitle(yLabel.c_str());
master->GetYaxis()->CenterTitle(
true); }
829 master->GetXaxis()->SetMoreLogLabels((logx == 1 &&
log10(xmax/xmin) < 2) ||
830 (logx > 1 && (xmax-xmin) < 2));
832 master->GetYaxis()->SetMoreLogLabels( logy &&
log10(ymax/ymin) < 2);
833 master->GetYaxis()->SetNoExponent ( logy &&
log10(ymax/ymin) < 2);
836 master->SetNdivisions(i->second, i->first.c_str());
839 if (xTimeFormat !=
"") {
841 master->GetXaxis()->SetTimeDisplay(1);
843 if (xTimeFormat ==
"utc") {
844 master->GetXaxis()->SetTimeFormat(
"#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
845 master->GetXaxis()->SetTimeOffset(0.0,
"gmt");
846 }
else if (xTimeFormat ==
"UTC") {
847 master->GetXaxis()->SetTimeFormat(
"%d-%m-%y");
848 master->GetXaxis()->SetTimeOffset(0.0,
"gmt");
850 master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
854 master->Draw(option.c_str());
859 if (dynamic_cast<TH1*>(i->get()) !=
master) {
860 if (setLogX<TH1> (i->get())) {}
861 else if (setLogX<TF1> (i->get())) {}
862 else if (setLogX<TGraphErrors>(i->get())) {}
863 else if (setLogX<TGraph> (i->get())) {}
864 else if (setLogX<TMultiGraph> (i->get())) {}
865 else if (setLogX<TLine> (i->get())) {}
866 else if (setLogX<TEllipse> (i->get())) {}
871 if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
872 if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
875 gStyle->SetOptStat(stats);
877 gStyle->SetOptFit(kFALSE);
882 DEBUG(
"Draw " << (*i)->GetName() <<
' ' << (*i)->GetTitle() << endl);
884 string buffer(option);
892 TF1* f1 =
dynamic_cast<TF1*
> (i->get());
893 TGraph* g1 =
dynamic_cast<TGraph*
> (i->get());
894 TMultiGraph* q1 =
dynamic_cast<TMultiGraph*
>(i->get());
901 if (g1->GetN() > 1 && drawLine)
909 for (TIter i1(q1->GetListOfGraphs()); TGraph* gi =
dynamic_cast<TGraph*
>(i1()); ) {
911 string zbuf = buffer;
913 if (gi->GetN() > 1 && drawLine)
918 gi->Draw(zbuf.c_str());
923 (*i).Draw(buffer.c_str());
929 if (legend.is_valid()) {
932 group = listOfObjects.size();
935 Ssiz_t height = listOfObjects.size()/group;
939 width = max(width, getWidth(i->getLabel()));
942 TLegend* lg =
getLegend(width, height, legend.location, legend.factor);
944 for (
size_t i = 0; i < listOfObjects.size(); i += group) {
946 const JRootObject&
object = listOfObjects[
i];
948 if (dynamic_cast<TMarker*>(
object.
get()) == NULL &&
949 dynamic_cast<TLine*
> (
object.get()) == NULL &&
950 dynamic_cast<TText*> (
object.
get()) == NULL) {
968 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 ))
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
const JPolynome f1(1.0, 2.0, 3.0)
Function.
bool isTAttLine(const TObject *object)
Get drawing option of TH1.
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})"
TLegend * getLegend(const Int_t width, const Int_t height, const std::string option, const Double_t factor=1.0)
Get legend.
static const char LABEL_TERMINATOR
label terminator
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range.
Auxiliary class to handle multiple boolean-like I/O.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
no fit printf nominal n $STRING awk v X
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
#define DEBUG(A)
Message macros.
Double_t g1(const Double_t x)
Function.