274    JParser<> zap(
"General purpose plot program for 1D ROOT objects.");
 
  276    zap[
'f'] = 
make_field(inputFile,  
"<input file>:<object name>");
 
  278    zap[
'w'] = 
make_field(canvas,     
"size of canvas <nx>x<ny> [pixels]")  = 
JCanvas(500, 500);
 
  281    zap[
'L'] = 
make_field(legend,     
"position legend e.g. TR [factor]")   = JLegend(), JLegend(
"TL"), JLegend(
"TR"), JLegend(
"BR"), JLegend(
"BL");
 
  282    zap[
'x'] = 
make_field(X,          
"abscissa range")                     = JRange_t::DEFAULT_RANGE();
 
  283    zap[
'y'] = 
make_field(Y,          
"ordinate range")                     = JRange_t::DEFAULT_RANGE();
 
  284    zap[
'z'] = 
make_field(Z,          
"ordinate range of projection)")      = JRange_t::DEFAULT_RANGE();
 
  285    zap[
'X'] = 
make_field(logx,       
"logarithmic x-axis (-XX log10 axis)");
 
  286    zap[
'Y'] = 
make_field(logy,       
"logarithmic y-axis (-YY log10 axis)");
 
  287    zap[
'Z'] = 
make_field(logz,       
"logarithmic y-axis; after projection");
 
  288    zap[
'P'] = 
make_field(project,    
"projection")                         = 
'\0', 
'x', 
'X', 
'y', 
'Y';
 
  289    zap[
'>'] = 
make_field(xLabel,     
"x-axis label")                       = 
"";
 
  290    zap[
'^'] = 
make_field(yLabel,     
"y-axis label")                       = 
"";
 
  291    zap[
'C'] = 
make_field(drawLine,   
"draw line (-C black-and-white -CC colour)");
 
  292    zap[
'F'] = 
make_field(fillArea,   
"fill area")                          = 0;
 
  293    zap[
'l'] = 
make_field(lineWidth,  
"line width")                         = 2;
 
  294    zap[
'S'] = 
make_field(markerSize, 
"marker size")                        = 1.0;
 
  295    zap[
'O'] = 
make_field(option,     
"plotting option")                    = 
"";
 
  297    zap[
'B'] = 
make_field(batch,      
"batch processing");
 
  298    zap[
'T'] = 
make_field(title,      
"graphics title ("  
  299                          << 
"\"" << JName_t  << 
"\" -> ROOT name; " 
  300                          << 
"\"" << JTitle_t << 
"\" -> ROOT title)")      = 
"KM3NeT preliminary";
 
  302    zap[
'g'] = 
make_field(group,      
"group colour codes of objects")      = 1;
 
  303    zap[
't'] = 
make_field(xTimeFormat, 
"set time format for x-axis, e.g. \%d\\/\%m\\/\\%y%F1970-01-01 00:00:00") = 
"";
 
  308  catch(
const exception &error) {
 
  309    FATAL(error.what() << endl);
 
  313  gROOT->SetBatch(batch);
 
  315  TApplication* tp = 
new TApplication(
"user", NULL, NULL);
 
  316  TCanvas*      cv = 
new TCanvas(
"c1", 
"c1", canvas.
x, canvas.
y);
 
  319    ((TRootCanvas *) cv->GetCanvasImp())->Connect(
"CloseWindow()", 
"TApplication", tp, 
"Terminate()");
 
  322  unique_ptr<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh(), parameters));
 
  325    gStyle->SetTitleOffset(gStyle->GetTitleOffset() * 1.3, 
"Y");
 
  328  gROOT->SetStyle(
"gplot");
 
  331  cv->SetFillStyle(4000);
 
  332  cv->SetFillColor(kWhite);
 
  337  JMarkerAttributes::getInstance().setMarkerSize(markerSize);
 
  338  JLineAttributes  ::getInstance().setLineWidth (lineWidth);
 
  341  Double_t xmin = numeric_limits<double>::max();
 
  342  Double_t xmax = numeric_limits<double>::lowest();
 
  344  Double_t ymin = numeric_limits<double>::max();
 
  345  Double_t ymax = numeric_limits<double>::lowest();
 
  350  const bool px = (project == 
'x' || project == 
'X');  
 
  351  const bool py = (project == 
'y' || project == 
'Y');  
 
  352  const bool pz = (project == 
'z' || project == 
'Z');  
 
  369  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
 
  371    DEBUG(
"Input: " << *input << endl);
 
  373    TDirectory* dir = getDirectory(*input);
 
  376      ERROR(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
  380    const TRegexp regexp(input->getObjectName());
 
  382    TIter iter(dir->GetListOfKeys());
 
  384    for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
 
  386      const TString tag(key->GetName());
 
  388      DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
  392      if (tag.Contains(regexp) && isTObject(key)) {
 
  394        if        (title == JName_t) {
 
  395          title = key->GetName();
 
  396        } 
else if (title == JTitle_t) {
 
  397          title = key->GetTitle();
 
  402        TAttMarker marker = JMarkerAttributes::getInstance().get(0);
 
  403        TAttLine   line   = JLineAttributes  ::getInstance().get(0);
 
  406          marker.SetMarkerColor(JMarkerAttributes::getInstance().get(listOfObjects.size()/group).GetMarkerColor());
 
  410          line = JLineAttributes::getInstance().get(listOfObjects.size());
 
  412          line.SetLineColor(marker.GetMarkerColor());
 
  418          TProfile& h1 = 
dynamic_cast<TProfile&
>(*object);
 
  420          object = h1.ProjectionX();
 
  426          TH2& h2 = 
dynamic_cast<TH2&
>(*object);
 
  431              object = h2.ProjectionX(
MAKE_CSTRING(h2.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  432                                      h2.GetYaxis()->FindBin(Z.getLowerLimit()),
 
  433                                      h2.GetYaxis()->FindBin(Z.getUpperLimit()) - 1);
 
  435              object = h2.ProjectionX(
MAKE_CSTRING(h2.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  437                                      h2.GetYaxis()->GetNbins());
 
  442              object = h2.ProjectionY(
MAKE_CSTRING(h2.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  443                                      h2.GetXaxis()->FindBin(Z.getLowerLimit()),
 
  444                                      h2.GetXaxis()->FindBin(Z.getUpperLimit()) - 1);
 
  446              object = h2.ProjectionY(
MAKE_CSTRING(h2.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()), 
 
  448                                      h2.GetXaxis()->GetNbins());
 
  452            ERROR(
"For 2D histograms, use option option -P for projections or use JPlot2D" << endl);
 
  461          TH3& h3 = 
dynamic_cast<TH3&
>(*object);
 
  465            object = h3.ProjectionX(
MAKE_CSTRING(h3.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()));
 
  469            object = h3.ProjectionY(
MAKE_CSTRING(h3.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()));
 
  473            object = h3.ProjectionZ(
MAKE_CSTRING(h3.GetName() << 
"_pz" << LABEL_TERMINATOR << listOfObjects.size()));
 
  477            ERROR(
"For 3D histograms, use option option -P for projections or use JPlot2D -P <projection>" << endl);
 
  487          if (
dynamic_cast<TMarker*
>(
object.get()) == NULL) {
 
  488            dynamic_cast<TAttMarker&
>(*object) = marker; 
 
  494          if (
dynamic_cast<TLine*
>(
object.get())   == NULL) {
 
  495            dynamic_cast<TAttLine&
>  (*object) = line;
 
  504            TAttFill& fill = 
dynamic_cast<TAttFill&
>(*object);
 
  506            if (!isTAttLine(
object) || fillArea < 0) {
 
  507              fill.SetFillColor(marker.GetMarkerColor());
 
  508              fill.SetFillStyle(abs(fillArea));
 
  520            TH1& h1 = 
dynamic_cast<TH1&
>(*object);
 
  522            for (
int i = 1; i <= h1.GetNbinsX(); ++i) {
 
  523              h1.SetBinError(i, 0.0);
 
  530            TGraphErrors& 
g1 = 
dynamic_cast<TGraphErrors&
>(*object);
 
  532            for (Int_t i = 0; i != 
g1.GetN(); ++i) {
 
  544          TH1& h1 = 
dynamic_cast<TH1&
>(*object);
 
  546          h1.SetStats(stats != -1);
 
  548          xmin = min(xmin, h1.GetXaxis()->GetXmin());
 
  549          xmax = max(xmax, h1.GetXaxis()->GetXmax());       
 
  550          ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
 
  551          ymax = max(ymax, h1.GetMaximum());
 
  553          if (!logy && h1.GetListOfFunctions() != NULL) {
 
  554            for (unique_ptr<TIterator> 
iterator(h1.GetListOfFunctions()->MakeIterator()); TF1* f1 = (TF1*) 
iterator->Next(); ) {
 
  555              ymin = min(ymin, f1->GetMinimum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
 
  556              ymax = max(ymax, f1->GetMaximum(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax()));
 
  564          TGraph& 
g1 = 
dynamic_cast<TGraph&
>(*object);
 
  566          for (Int_t i = 0; i != 
g1.GetN(); ++i) {
 
  568            xmin = min(xmin, 
g1.GetX()[i]);
 
  569            xmax = max(xmax, 
g1.GetX()[i]);
 
  571            if (!logy || 
g1.GetY()[i] > 0.0) {
 
  572              ymin = min(ymin, 
g1.GetY()[i]);
 
  573              ymax = max(ymax, 
g1.GetY()[i]);
 
  581          TGraphErrors& 
g1 = 
dynamic_cast<TGraphErrors&
>(*object);
 
  583          for (Int_t i = 0; i != 
g1.GetN(); ++i) {
 
  584            if (!logy || 
g1.GetY()[i] - 
g1.GetEY()[i] > 0.0) { ymin = min(ymin, 
g1.GetY()[i] - 
g1.GetEY()[i]); }
 
  585            if (!logy || 
g1.GetY()[i] + 
g1.GetEY()[i] > 0.0) { ymax = max(ymax, 
g1.GetY()[i] + 
g1.GetEY()[i]); }
 
  592          TMultiGraph& m1 = 
dynamic_cast<TMultiGraph&
>(*object);
 
  594          for (TIter i1(m1.GetListOfGraphs()); TGraph* 
g1 = 
dynamic_cast<TGraph*
>(i1()); ) {
 
  596            for (Int_t i = 0; i != 
g1->GetN(); ++i) {
 
  598              xmin = min(xmin, 
g1->GetX()[i]);
 
  599              xmax = max(xmax, 
g1->GetX()[i]);
 
  601              if (!logy || 
g1->GetY()[i] > 0.0) {
 
  602                ymin = min(ymin, 
g1->GetY()[i]);
 
  603                ymax = max(ymax, 
g1->GetY()[i]);
 
  612          TF2& f2 = 
dynamic_cast<TF2&
>(*object);
 
  615          TString formula = f2.GetExpFormula();
 
  616          TString _z_     = TString::Format(
"%f", 0.5 * (Z.getLowerLimit() + Z.getUpperLimit()));
 
  623          f2.GetRange(__xmin, __ymin, __xmax, __ymax);
 
  627            formula.ReplaceAll(
"y", _z_);
 
  629            f1 = 
new TF1(
MAKE_CSTRING(f2.GetName() << 
"_px" << LABEL_TERMINATOR << listOfObjects.size()), formula);
 
  631            f1->SetRange(__xmin, __xmax);
 
  635            formula.ReplaceAll(
"x", _z_);
 
  636            formula.ReplaceAll(
"y", 
"x");
 
  638            f1 = 
new TF1(
MAKE_CSTRING(f2.GetName() << 
"_py" << LABEL_TERMINATOR << listOfObjects.size()), formula);
 
  640            f1->SetRange(__ymin, __ymax);
 
  644            ERROR(
"For 2D functions, use option option -P for projections or use JPlot2D" << endl);
 
  649          DEBUG(
"TF1: " << f1->GetExpFormula() << endl);
 
  651          f1->SetParameters(f2.GetParameters());
 
  659          TF1& f1 = 
dynamic_cast<TF1&
>(*object);
 
  664          f1.GetRange(__xmin, __xmax);
 
  666          xmin = min(xmin, __xmin);
 
  667          xmax = max(xmax, __xmax);
 
  668          ymin = min(ymin, f1.GetMinimum());
 
  669          ymax = max(ymax, f1.GetMaximum());
 
  675          THStack& hs = 
dynamic_cast<THStack&
>(*object);
 
  677          NOTICE(
"THStack" << endl);
 
  679          unique_ptr<TIterator> 
iterator(hs.GetHists()->MakeIterator());
 
  683            TH1& h1 = 
dynamic_cast<TH1&
>(*i);
 
  685            NOTICE(
"TH1[" << index << 
"] " << h1.GetName() << endl);
 
  687            xmin = min(xmin, h1.GetXaxis()->GetXmin());
 
  688            xmax = max(xmax, h1.GetXaxis()->GetXmax());
 
  690            ymin = min(ymin, logy ? h1.GetMinimum(0.0) : h1.GetMinimum());
 
  691            ymax = max(ymax, h1.GetMaximum());
 
  694            h1.SetLineColor(kBlack);
 
  696            h1.SetFillColor(JMarkerAttributes::getInstance().get(index).GetMarkerColor());
 
  703          TLine& h1 = 
dynamic_cast<TLine&
>(*object);
 
  705          xmin = min(xmin, h1.GetX1());
 
  706          xmax = max(xmax, h1.GetX2());
 
  707          ymin = min(ymin, h1.GetY1());
 
  708          ymax = max(ymax, h1.GetY2());
 
  714        for (TString buffer[] = { 
object.getLabel(), input->getFilename().c_str(), 
"" }, *i = buffer; *i != 
""; ++i) {
 
  716          *i = (*i)(TRegexp(
"\\[.*\\]"));
 
  718          if (i->Length() > 2) {
 
  719            object.setLabel((*i)(1, i->Length() - 2));
 
  723        DEBUG(
"Add object: " << tag << 
" with label <" << 
object.getLabel() << 
">" << endl);
 
  725        if (master == NULL) {
 
  726          master = 
dynamic_cast<TH1*
>(
object.get());
 
  729        listOfObjects.push_back(
object);
 
  734  if (listOfObjects.empty()) {
 
  735    ERROR(
"Nothing to draw." << endl);
 
  744    TH1*         h1 = 
dynamic_cast<TH1*
>        (i->get());
 
  745    TGraph*      
g1 = 
dynamic_cast<TGraph*
>     (i->get());
 
  746    TMultiGraph* m1 = 
dynamic_cast<TMultiGraph*
>(i->get());
 
  747    TAttLine*    
ls = 
dynamic_cast<TAttLine*
>   (i->get());
 
  755      iterator.reset(h1->GetListOfFunctions()->MakeIterator());
 
  757    } 
else if (
g1 != NULL) {
 
  759      iterator.reset(
g1->GetListOfFunctions()->MakeIterator());
 
  761    } 
else if (m1 != NULL) {
 
  763      for (TIter i1(m1->GetListOfGraphs()); TGraph* gi = 
dynamic_cast<TGraph*
>(i1()); ) {
 
  764        for (TIter i2(gi->GetListOfFunctions()); TF1* fi = 
dynamic_cast<TF1*
>(i2()); ) {
 
  774      Double_t x1[] = { numeric_limits<Double_t>::max(),    numeric_limits<Double_t>::max() };
 
  775      Double_t x2[] = { numeric_limits<Double_t>::lowest(), numeric_limits<Double_t>::lowest() };
 
  777      for (
int nf = 0, ns = 0, nc = 1; TF1* f1 = (TF1*) 
iterator->Next(); ++nf) {
 
  779        f1->GetRange(x1[1], x2[1]);
 
  782        dynamic_cast<TAttLine&
>(*f1) = JLineAttributes::getInstance().get(0);
 
  784        if (listOfObjects.size() == 1) {
 
  786          if      (x1[0] == x1[1] && 
 
  792          f1->SetLineStyle(JLineAttributes  ::getInstance().get(ns).GetLineStyle());
 
  793          f1->SetLineColor(JMarkerAttributes::getInstance().get(nc).GetMarkerColor());
 
  799          f1->SetLineColor(
ls->GetLineColor());
 
  800          f1->SetLineStyle(JLineAttributes::getInstance().get(ns++).GetLineStyle());
 
  823    xmin = X.getLowerLimit();
 
  824    xmax = X.getUpperLimit();
 
  828    ymin = Y.getLowerLimit();
 
  829    ymax = Y.getUpperLimit();
 
  830  } 
else if (ymax > ymin) {
 
  831    setRange(ymin, ymax, logy == 1);
 
  835    ymin = pow(10.0, ymin);
 
  836    ymax = pow(10.0, ymax);
 
  841  if (!listOfObjects.empty()) {
 
  843    if (master == NULL) {
 
  845      master = 
new TH1D(MASTER.c_str(), NULL, 1000, xmin, xmax);
 
  847      master->SetStats(kFALSE);
 
  849      for (Int_t i = 1; i <= master->GetXaxis()->GetNbins(); ++i) {
 
  850        master->SetBinContent(i, ymin);
 
  855  if (master == NULL) {
 
  857    TText* p = 
new TText(0.5, 0.5, 
MAKE_CSTRING(
"No data"));
 
  865    if (logx) { gPad->SetLogx(); }
 
  866    if (logy) { gPad->SetLogy(); }
 
  868    master->SetTitle(title.c_str());
 
  870    master->GetXaxis()->SetRangeUser(xmin, xmax);
 
  872    if (logx > 1) { setLogarithmicX(master); }
 
  873    if (logx > 2) { master->GetXaxis()->SetNoExponent(); }
 
  875    if (logy > 1) { setLogarithmicY(master); }
 
  876    if (logy > 2) { master->GetYaxis()->SetNoExponent(); }
 
  878    master->SetMinimum(ymin);
 
  879    master->SetMaximum(ymax);
 
  881    if (xLabel != 
"") { master->GetXaxis()->SetTitle(xLabel.c_str()); master->GetXaxis()->CenterTitle(
true); }
 
  882    if (yLabel != 
"") { master->GetYaxis()->SetTitle(yLabel.c_str()); master->GetYaxis()->CenterTitle(
true); }
 
  884    master->GetXaxis()->SetMoreLogLabels((logx == 1 && log10(xmax/xmin) < 2) ||
 
  885                                         (logx >  1 &&      (xmax-xmin) < 2));
 
  886    master->GetYaxis()->SetMoreLogLabels((logy == 1 && log10(ymax/ymin) < 2) ||
 
  887                                         (logy >  1 &&      (ymax-ymin) < 2));
 
  890      master->SetNdivisions(i->second, i->first.c_str());
 
  893    if (xTimeFormat != 
"") {
 
  895      master->GetXaxis()->SetTimeDisplay(1);
 
  897      if        (xTimeFormat == 
"utc") {
 
  898        master->GetXaxis()->SetTimeFormat(
"#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}");
 
  899        master->GetXaxis()->SetTimeOffset(0.0, 
"gmt");
 
  900      } 
else if (xTimeFormat == 
"UTC") {
 
  901        master->GetXaxis()->SetTimeFormat(
"%d-%m-%y");
 
  902        master->GetXaxis()->SetTimeOffset(0.0, 
"gmt");
 
  904        master->GetXaxis()->SetTimeFormat(xTimeFormat.c_str());
 
  908    master->Draw(option.c_str());
 
  915      if (
dynamic_cast<TH1*
>(i->get()) != master) {
 
  916        if (logx > 1) { setLog<typelist> X(i->get(), 
'X'); }
 
  917        if (logy > 1) { setLog<typelist> Y(i->get(), 
'Y'); }
 
  922  if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
 
  923  if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
 
  926    gStyle->SetOptStat(stats);
 
  928    gStyle->SetOptFit(kFALSE);
 
  931  for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
 
  933    DEBUG(
"Draw " << (*i)->GetName() << 
' ' << (*i)->GetTitle() << endl);
 
  935    string buffer(option);
 
  943    TF1*         f1 = 
dynamic_cast<TF1*
>        (i->get());
 
  944    TGraph*      
g1 = 
dynamic_cast<TGraph*
>     (i->get());
 
  945    TMultiGraph* q1 = 
dynamic_cast<TMultiGraph*
>(i->get());
 
  952      if (
g1->GetN() > 1 && drawLine)
 
  954      else if (fillArea == 0 ||
 
  955               (
dynamic_cast<TGraphErrors*
>     (
g1) == NULL &&
 
  956                dynamic_cast<TGraphAsymmErrors*
>(
g1) == NULL))
 
  962      for (TIter i1(q1->GetListOfGraphs()); TGraph* gi = 
dynamic_cast<TGraph*
>(i1()); ) {
 
  964        string zbuf = buffer;
 
  966        if (gi->GetN() > 1 && drawLine)
 
  971        gi->Draw(zbuf.c_str());
 
  976      (*i).Draw(buffer.c_str());
 
  982  if (legend.is_valid()) {
 
  985      group = listOfObjects.size();
 
  988    Ssiz_t height = listOfObjects.size()/group;
 
  991    for (vector<JRootObject>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
 
  992      width = max(width, getWidth(i->getLabel()));
 
  995    TLegend* lg = getLegend(width, height, legend.location, legend.factor);
 
  997    for (
size_t i = 0; i < listOfObjects.size(); i += group) {
 
 1001      if (
dynamic_cast<TMarker*
>(
object.get()) == NULL  &&
 
 1002          dynamic_cast<TLine*
>  (
object.get()) == NULL  &&
 
 1003          dynamic_cast<TText*
>  (
object.get()) == NULL) {
 
 1004        lg->AddEntry(
object, 
" " + 
object.getLabel(), isTAttLine(
object) ? 
"L" : isTAttFill(
object)  && fillArea != 0 ? 
"F" : 
"P"); 
 
 1021  return (master != NULL ? 0 : 1);