307    JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
 
  309    zap[
'f'] = 
make_field(inputFile,  
"<input file>:<object name>");
 
  311    zap[
'w'] = 
make_field(canvas,     
"size of canvas <nx>x<ny> [pixels]")  = 
JCanvas(500, 500);
 
  314    zap[
'L'] = 
make_field(legend,     
"position legend e.g. TR [factor]")   = JLegend(), JLegend(
"TL"), JLegend(
"TR"), JLegend(
"BR"), JLegend(
"BL");
 
  315    zap[
'x'] = 
make_field(X,          
"abscissa range")                     = JRange_t::DEFAULT_RANGE();
 
  316    zap[
'y'] = 
make_field(Y,          
"ordinate range")                     = JRange_t::DEFAULT_RANGE();
 
  317    zap[
'z'] = 
make_field(Z,          
"ordinate range of projection)")      = JRange_t::DEFAULT_RANGE();
 
  318    zap[
'X'] = 
make_field(logx,       
"logarithmic x-axis (-XX log10 axis)");
 
  319    zap[
'Y'] = 
make_field(logy,       
"logarithmic y-axis (-YY log10 axis)");
 
  320    zap[
'Z'] = 
make_field(logz,       
"logarithmic y-axis; after projection");
 
  321    zap[
'P'] = 
make_field(project,    
"projection")                         = 
'\0', 
'x', 
'X', 
'y', 
'Y';
 
  322    zap[
'>'] = 
make_field(xLabel,     
"x-axis label")                       = 
"";
 
  323    zap[
'^'] = 
make_field(yLabel,     
"y-axis label")                       = 
"";
 
  324    zap[
'C'] = 
make_field(drawLine,   
"draw line (-C black-and-white -CC colour)");
 
  325    zap[
'F'] = 
make_field(fillArea,   
"fill area")                          = 0;
 
  326    zap[
'l'] = 
make_field(lineWidth,  
"line width")                         = 2;
 
  327    zap[
'S'] = 
make_field(markerSize, 
"marker size")                        = 1.0;
 
  328    zap[
'O'] = 
make_field(option,     
"plotting option")                    = 
"";
 
  330    zap[
'B'] = 
make_field(batch,      
"batch processing");
 
  331    zap[
'T'] = 
make_field(title,      
"graphics title ("  
  332                          << 
"\"" << JName_t  << 
"\" -> ROOT name; " 
  333                          << 
"\"" << JTitle_t << 
"\" -> ROOT title)")      = 
"KM3NeT preliminary";
 
  335    zap[
'g'] = 
make_field(group,      
"group colour codes of objects")      = 1;
 
  336    zap[
't'] = 
make_field(xTimeFormat, 
"set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") = 
"";
 
  341  catch(
const exception &error) {
 
  342    FATAL(error.what() << endl);
 
  346  gROOT->SetBatch(batch);
 
  348  TApplication* tp = 
new TApplication(
"user", NULL, NULL);
 
  349  TCanvas*      cv = 
new TCanvas(
"c1", 
"c1", canvas.
x, canvas.
y);
 
  352    ((TRootCanvas *) cv->GetCanvasImp())->Connect(
"CloseWindow()", 
"TApplication", tp, 
"Terminate()");
 
  355  unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
 
  358    gStyle->SetTitleOffset(gStyle->GetTitleOffset() * 1.3, 
"Y");
 
  361  gROOT->SetStyle(
"gplot");
 
  364  cv->SetFillStyle(4000);
 
  365  cv->SetFillColor(kWhite);
 
  370  JMarkerAttributes::getInstance().setMarkerSize(markerSize);
 
  371  JLineAttributes  ::getInstance().setLineWidth (lineWidth);
 
  374  Double_t xmin = numeric_limits<double>::max();
 
  375  Double_t xmax = numeric_limits<double>::lowest();
 
  377  Double_t ymin = numeric_limits<double>::max();
 
  378  Double_t ymax = numeric_limits<double>::lowest();
 
  383  const bool px = (project == 
'x' || project == 
'X');  
 
  384  const bool py = (project == 
'y' || project == 
'Y');  
 
  385  const bool pz = (project == 
'z' || project == 
'Z');  
 
  402  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
 
  404    DEBUG(
"Input: " << *input << endl);
 
  406    TDirectory* dir = getDirectory(*input);
 
  409      ERROR(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
  413    const TRegexp regexp(input->getObjectName());
 
  415    TIter iter(dir->GetListOfKeys());
 
  417    for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
 
  419      const TString tag(key->GetName());
 
  421      DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
  425      if (tag.Contains(regexp) && isTObject(key)) {
 
  427        if        (title == JName_t) {
 
  428          title = key->GetName();
 
  429        } 
else if (title == JTitle_t) {
 
  430          title = key->GetTitle();
 
  435        TAttMarker marker = JMarkerAttributes::getInstance().get(0);
 
  436        TAttLine   line   = JLineAttributes  ::getInstance().get(0);
 
  439          marker.SetMarkerColor(JMarkerAttributes::getInstance().get(getSize(listOfObjects)/group).GetMarkerColor());
 
  441          marker = JMarkerAttributes::getInstance().get(getSize(listOfObjects));
 
  444          line = JLineAttributes::getInstance().get(getSize(listOfObjects));
 
  446          line.SetLineColor(marker.GetMarkerColor());
 
  452          TProfile& h1 = 
dynamic_cast<TProfile&
>(*object);
 
  454          object = h1.ProjectionX();
 
  460          TH2& h2 = 
dynamic_cast<TH2&
>(*object);
 
  465              object = h2.ProjectionX(
MAKE_CSTRING(h2.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  466                                      h2.GetYaxis()->FindBin(Z.getLowerLimit()),
 
  467                                      h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
 
  469              object = h2.ProjectionX(
MAKE_CSTRING(h2.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  471                                      h2.GetYaxis()->GetNbins());
 
  476              object = h2.ProjectionY(
MAKE_CSTRING(h2.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  477                                      h2.GetXaxis()->FindBin(Z.getLowerLimit()),
 
  478                                      h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
 
  480              object = h2.ProjectionY(
MAKE_CSTRING(h2.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  482                                      h2.GetXaxis()->GetNbins());
 
  486            ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
 
  495          TH3& h3 = 
dynamic_cast<TH3&
>(*object);
 
  499            object = h3.ProjectionX(
MAKE_CSTRING(h3.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()));
 
  503            object = h3.ProjectionY(
MAKE_CSTRING(h3.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()));
 
  507            object = h3.ProjectionZ(
MAKE_CSTRING(h3.GetName() << 
"_pz" << LABEL_TERMINATOR << listOfObjects.size()));
 
  511            ERROR(
"For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
 
  521          if (
dynamic_cast<TMarker*
>(
object.get()) == NULL) {
 
  522            dynamic_cast<TAttMarker&
>(*object) = marker; 
 
  528          if (
dynamic_cast<TLine*
>(
object.get())   == NULL) {
 
  529            dynamic_cast<TAttLine&
>  (*object) = line;
 
  538            TAttFill& fill = 
dynamic_cast<TAttFill&
>(*object);
 
  540            if (!isTAttLine(
object) || fillArea < 0) {
 
  541              fill.SetFillColor(marker.GetMarkerColor());
 
  542              fill.SetFillStyle(abs(fillArea));
 
  554            TH1& h1 = 
dynamic_cast<TH1&
>(*object);
 
  556            for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
 
  557              h1.SetBinError(i, 0.0);
 
  564            TGraphErrors& 
g1 = 
dynamic_cast<TGraphErrors&
>(*object);
 
  566            for (Int_t i = 0; i != 
g1.GetN(); ++i) {
 
  578          TH1& h1 = 
dynamic_cast<TH1&
>(*object);
 
  580          h1.SetStats(stats != -1);
 
  582          xmin = min(xmin, h1.GetXaxis()->GetXmin());
 
  583          xmax = max(xmax, h1.GetXaxis()->GetXmax());       
 
  584          ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
 
  585          ymax = max(ymax, h1.GetMaximum());
 
  587          if (!logy && h1.GetListOfFunctions() != NULL) {
 
  588            for (unique_ptr<TIterator> 
iterator(h1.GetListOfFunctions()->MakeIterator()); TF1* f1 = (TF1*) 
iterator->Next(); ) {
 
  589              ymin = min(ymin, f1->GetMinimum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
 
  590              ymax = max(ymax, f1->GetMaximum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
 
  598          TGraph& 
g1 = 
dynamic_cast<TGraph&
>(*object);
 
  600          for (Int_t i = 0; i != 
g1.GetN(); ++i) {
 
  602            xmin = min(xmin, 
g1.GetX()[i]);
 
  603            xmax = max(xmax, 
g1.GetX()[i]);
 
  605            if (!logy || 
g1.GetY()[i] > 0.0) {
 
  606              ymin = min(ymin, 
g1.GetY()[i]);
 
  607              ymax = max(ymax, 
g1.GetY()[i]);
 
  615          TGraphErrors& 
g1 = 
dynamic_cast<TGraphErrors&
>(*object);
 
  617          for (Int_t i = 0; i != 
g1.GetN(); ++i) {
 
  618            if (!logy || 
g1.GetY()[i] - 
g1.GetEY()[i] > 0.0) { ymin = min(ymin, 
g1.GetY()[i] - 
g1.GetEY()[i]); }
 
  619            if (!logy || 
g1.GetY()[i] + 
g1.GetEY()[i] > 0.0) { ymax = max(ymax, 
g1.GetY()[i] + 
g1.GetEY()[i]); }
 
  626          TMultiGraph& m1 = 
dynamic_cast<TMultiGraph&
>(*object);
 
  628          for (TIter i1(m1.GetListOfGraphs()); TGraph* 
g1 = 
dynamic_cast<TGraph*
>(i1()); ) {
 
  630            for (Int_t i = 0; i != 
g1->GetN(); ++i) {
 
  632              xmin = min(xmin, 
g1->GetX()[i]);
 
  633              xmax = max(xmax, 
g1->GetX()[i]);
 
  635              if (!logy || 
g1->GetY()[i] > 0.0) {
 
  636                ymin = min(ymin, 
g1->GetY()[i]);
 
  637                ymax = max(ymax, 
g1->GetY()[i]);
 
  646          TF2& f2 = 
dynamic_cast<TF2&
>(*object);
 
  649          TString formula = f2.GetExpFormula();
 
  650          TString _z_     = TString::Format(
"%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
 
  657          f2.GetRange(__xmin, __ymin, __xmax, __ymax);
 
  661            formula.ReplaceAll(
"y", _z_);
 
  663            f1 = 
new TF1(
MAKE_CSTRING(f2.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()), formula);
 
  665            f1->SetRange(__xmin, __xmax);
 
  669            formula.ReplaceAll(
"x", _z_);
 
  670            formula.ReplaceAll(
"y", 
"x");
 
  672            f1 = 
new TF1(
MAKE_CSTRING(f2.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()), formula);
 
  674            f1->SetRange(__ymin, __ymax);
 
  678            ERROR(
"For 2D functions, use option option -P for projections or use JPlot2D" << endl);
 
  683          DEBUG(
"TF1: " << f1->GetExpFormula() << endl);
 
  685          f1->SetParameters(f2.GetParameters());
 
  693          TF1& f1 = 
dynamic_cast<TF1&
>(*object);
 
  698          f1.GetRange(__xmin, __xmax);
 
  700          xmin = min(xmin, __xmin);
 
  701          xmax = max(xmax, __xmax);
 
  702          ymin = min(ymin, f1.GetMinimum());
 
  703          ymax = max(ymax, f1.GetMaximum());
 
  709          THStack& hs = 
dynamic_cast<THStack&
>(*object);
 
  711          NOTICE(
"THStack" << endl);
 
  713          unique_ptr<TIterator> 
iterator(hs.GetHists()->MakeIterator());
 
  717            TH1& h1 = 
dynamic_cast<TH1&
>(*i);
 
  719            NOTICE(
"TH1[" << index << 
"] " << h1.GetName() << endl);
 
  721            xmin = min(xmin, h1.GetXaxis()->GetXmin());
 
  722            xmax = max(xmax, h1.GetXaxis()->GetXmax());
 
  724            ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
 
  725            ymax = max(ymax, h1.GetMaximum());
 
  728            h1.SetLineColor(kBlack);
 
  730            h1.SetFillColor(JMarkerAttributes::getInstance().get(index).GetMarkerColor());
 
  737          TLine& h1 = 
dynamic_cast<TLine&
>(*object);
 
  739          xmin = min(xmin, h1.GetX1());
 
  740          xmax = max(xmax, h1.GetX2());
 
  741          ymin = min(ymin, h1.GetY1());
 
  742          ymax = max(ymax, h1.GetY2());
 
  748        for (TString buffer[] = { 
object.getLabel(), input->getFilename().c_str(), 
"" }, *i = buffer; *i != 
""; ++i) {
 
  750          *i = (*i)(TRegexp(
"\\[.*\\]"));
 
  752          if (i->Length() > 2) {
 
  753            object.setLabel((*i)(1, i->Length() - 2));
 
  757        DEBUG(
"Add object: " << tag << 
" with label <" << 
object.getLabel() << 
">" << endl);
 
  759        if (master == NULL) {
 
  760          master = 
dynamic_cast<TH1*
>(
object.get());
 
  763        listOfObjects.push_back(
object);
 
  768  if (listOfObjects.empty()) {
 
  769    ERROR(
"Nothing to draw." << endl);
 
  778    TH1*         h1 = 
dynamic_cast<TH1*
>        (i->get());
 
  779    TGraph*      
g1 = 
dynamic_cast<TGraph*
>     (i->get());
 
  780    TMultiGraph* m1 = 
dynamic_cast<TMultiGraph*
>(i->get());
 
  781    TAttLine*    
ls = 
dynamic_cast<TAttLine*
>   (i->get());
 
  789      iterator.reset(h1->GetListOfFunctions()->MakeIterator());
 
  791    } 
else if (
g1 != NULL) {
 
  793      iterator.reset(
g1->GetListOfFunctions()->MakeIterator());
 
  795    } 
else if (m1 != NULL) {
 
  797      for (TIter i1(m1->GetListOfGraphs()); TGraph* gi = 
dynamic_cast<TGraph*
>(i1()); ) {
 
  798        for (TIter i2(gi->GetListOfFunctions()); TF1* fi = 
dynamic_cast<TF1*
>(i2()); ) {
 
  808      Double_t x1[] = { numeric_limits<Double_t>::max(),    numeric_limits<Double_t>::max() };
 
  809      Double_t x2[] = { numeric_limits<Double_t>::lowest(), numeric_limits<Double_t>::lowest() };
 
  811      for (
int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*) 
iterator->Next(); ++nf) {
 
  813        f1->GetRange(x1[1], x2[1]);
 
  816        dynamic_cast<TAttLine&
>(*f1) = JLineAttributes::getInstance().get(0);
 
  818        if (getSize(listOfObjects) == 1) {
 
  820          if      (x1[0] == x1[1] && 
 
  826          f1->SetLineStyle(JLineAttributes  ::getInstance().get(ns).GetLineStyle());
 
  827          f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).GetMarkerColor());
 
  833          f1->SetLineColor(
ls->GetLineColor());
 
  834          f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).GetLineStyle());
 
  857    xmin = X.getLowerLimit();
 
  858    xmax = X.getUpperLimit();
 
  862    ymin = Y.getLowerLimit();
 
  863    ymax = Y.getUpperLimit();
 
  864  } 
else if (ymax > ymin) {
 
  865    setRange(ymin, ymax, logy == 1);
 
  869    ymin = pow(10.0, ymin);
 
  870    ymax = pow(10.0, ymax);
 
  873  DEBUG(
"plot frame " << xmin << 
' ' << xmax << 
' ' << ymin << 
' ' << ymax << endl);
 
  877  if (!listOfObjects.empty()) {
 
  879    if (master == NULL) {
 
  881      master = 
new TH1D(MASTER.c_str(), NULL, 1000, xmin, xmax);
 
  883      master->SetStats(kFALSE);
 
  885      for (Int_t i = 1; i <= master->GetXaxis()->GetNbins(); ++i) {
 
  886        master->SetBinContent(i, ymin);
 
  889      DEBUG(
"Creating master " << MASTER << 
' ' << xmin << 
' ' << xmax << 
' ' << ymin << endl);
 
  893  if (master == NULL) {
 
  895    TText* p = 
new TText(0.5, 0.5, 
MAKE_CSTRING(
"No data"));
 
  903    if (logx) { gPad->SetLogx(); }
 
  904    if (logy) { gPad->SetLogy(); }
 
  906    master->SetTitle(title.c_str());
 
  908    master->GetXaxis()->SetRangeUser(max(xmin,master->GetXaxis()->GetXmin()),
 
  909                                     min(xmax,master->GetXaxis()->GetXmax()));
 
  911    if (logx > 1) { setLogarithmicX(master); }
 
  912    if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
 
  914    if (logy > 1) { setLogarithmicY(master); }
 
  915    if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
 
  917    master->SetMinimum(ymin);
 
  918    master->SetMaximum(ymax);
 
  920    if (xLabel != 
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
 
  921    if (yLabel != 
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
 
  923    master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
 
  924                                         (logx >  1 &&      (xmax-xmin) < 2));
 
  925    master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
 
  926                                         (logy >  1 &&      (ymax-ymin) < 2));
 
  929      master->SetNdivisions(i->second, i->first.c_str());
 
  932    if (xTimeFormat != 
"") {
 
  934      master->GetXaxis()->SetTimeDisplay(1);
 
  936      if        (xTimeFormat == 
"utc") {
 
  937        master->GetXaxis()->SetTimeFormat(
"#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
 
  938        master->GetXaxis()->SetTimeOffset(0.0, 
"gmt");
 
  939      } 
else if (xTimeFormat == 
"UTC") {
 
  940        master->GetXaxis()->SetTimeFormat(
"%d-%m-%y");
 
  941        master->GetXaxis()->SetTimeOffset(0.0, 
"gmt");
 
  943        master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
 
  947    master->Draw(option.c_str());
 
  954      if (
dynamic_cast<TH1*
>(i->get()) != master) {
 
  955        if (logx > 1) { setLog<typelist> X(i->get(), 
'X'); }
 
  956        if (logy > 1) { setLog<typelist> Y(i->get(), 
'Y'); }
 
  961  if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
 
  962  if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
 
  965    gStyle->SetOptStat(stats);
 
  967    gStyle->SetOptFit(kFALSE);
 
  970  for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
 
  972    DEBUG(
"Draw " << (*i)->GetName() << 
' ' << (*i)->GetTitle() << endl);
 
  974    string buffer(option);
 
  982    TF1*         f1 = 
dynamic_cast<TF1*
>        (i->get());
 
  983    TGraph*      
g1 = 
dynamic_cast<TGraph*
>     (i->get());
 
  984    TMultiGraph* q1 = 
dynamic_cast<TMultiGraph*
>(i->get());
 
  991      if (
g1->GetN() > 1 && drawLine)
 
  993      else if (fillArea == 0 ||
 
  994               (
dynamic_cast<TGraphErrors*
>     (
g1) == NULL &&
 
  995                dynamic_cast<TGraphAsymmErrors*
>(
g1) == NULL))
 
 1001      for (TIter i1(q1->GetListOfGraphs()); TGraph* gi = 
dynamic_cast<TGraph*
>(i1()); ) {
 
 1003        string zbuf = buffer;
 
 1005        if (gi->GetN() > 1 && drawLine)
 
 1010        gi->Draw(zbuf.c_str());
 
 1015      (*i).Draw(buffer.c_str());
 
 1021  if (legend.is_valid()) {
 
 1024      group = listOfObjects.size();
 
 1030    for (
size_t i = 0; i < listOfObjects.size(); i += group) {
 
 1034      if (is_legend(
object.get())) {
 
 1036        width   = max(width, getWidth(
object.getLabel()));
 
 1040    TLegend* lg = getLegend(width, height, legend.location, legend.factor);
 
 1042    for (
size_t i = 0; i < listOfObjects.size(); i += group) {
 
 1046      if (is_legend(
object.get())) {
 
 1047        lg->AddEntry(
object, 
" " + 
object.getLabel(), isTAttLine(
object) ? 
"L" : isTAttFill(
object)  && fillArea != 0 ? 
"F" : 
"P"); 
 
 1064  return (master != NULL ? 0 : 1);