Drawing elements of a TMatrixT using TTree::Draw

Could you please let me know if there is a way to draw elements of a TMatrixT using TTree::Draw?

Obvious guesses

root [2] t->Draw("x[0][0]");
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Warning in <TSelectorDraw::ProcessFillObject>: Not implemented for TMatrixT<float>

root [3] t->Draw("x(0,0)");
Error in <TTreeFormula::Compile>:  Bad numerical expression : "x(0,0)"
Info in <TSelectorDraw::AbortProcess>: Variable compilation failed: {x(0,0),}

root [4] t->Draw("x->GetMatrixArray()[0]"); // All elements are drawn as zeros

do not work.

Hi,

if you have the possibility to use a ROOT development release, this might be an opportunity to try the TDataFrame.
You can formulate the “query” like this:

ROOT::Experimental::TDataFrame tdf("myTree","myFile.root");
auto h = tdf.AddColumn("el_00","x(0,0)",{"x"}).Histo1D<float>("el_00") ; // in the master: tdf.Define("el_00", "x(0,0)").Histo1D("el_00");
h->Draw();

Cheers,
D

1 Like

Hello,

Something did not work:

$ root.exe 
   ------------------------------------------------------------
  | Welcome to ROOT 6.09/02                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-09-02, 8 March 2017                            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] ROOT::Experimental::TDataFrame tdf("t", "file.root");
ROOT_prompt_0:1:21: error: no member named 'TDataFrame' in namespace 'ROOT::Experimental'
ROOT::Experimental::TDataFrame tdf("t", "file.root");

Please, let me know if I need to compile ROOT with some special option to enable the experimental code.

Thanks!

Hi,

my bad: that constructor will be part of the forthcoming release.
The right syntax would be for 6.09/02

root [0] TFile f("file.root");
root [1]  ROOT::Experimental::TDataFrame tdf("t", &f);

Cheers,
D

Hello,

Still no joy:

$ root.exe
   ------------------------------------------------------------
  | Welcome to ROOT 6.09/02                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-09-02, 8 March 2017                            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] TFile f("file.root");
root [1] ROOT::Experimental::TDataFrame tdf("t", &f);
ROOT_prompt_1:1:21: error: no member named 'TDataFrame' in namespace 'ROOT::Experimental'
ROOT::Experimental::TDataFrame tdf("t", &f);
~~~~~~~~~~~~~~~~~~~~^

Hi,

this is unexpected. Can you prepend a

#include "ROOT/TDataFrame.hxx"

Cheers,
D

Hello,

Maybe, I need to compile ROOT with some special option to enable it?

$ root.exe
   ------------------------------------------------------------
  | Welcome to ROOT 6.09/02                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-09-02, 8 March 2017                            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] #include "ROOT/TDataFrame.h"
ROOT_prompt_0:1:10: fatal error: 'ROOT/TDataFrame.h' file not found
#include "ROOT/TDataFrame.h"
         ^

I can confirm the issue as well. Doing an ls of the include folder suggested the header ROOT/TDataFrame.hxx then the following worked for me:

   ------------------------------------------------------------
  | Welcome to ROOT 6.09/02                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for macosx64                                         |
  | From tag v6-09-02, 8 March 2017                            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] #include "ROOT/TDataFrame.hxx"
root [1] ROOT::Experimental::TDataFrame tdf("myTree","myFile.root");

Some progress, but no cigar yet:

root [0] #include "ROOT/TDataFrame.hxx"
root [1] ROOT::Experimental::TDataFrame tdf("tree", "file.root");
root [2] auto h = tdf.AddColumn("el_00", "tree(0,0)", {"tree"}).Histo1D<float>("el_00");
In file included from input_line_11:21:
In file included from .../root-6.09.02.build/etc/dictpch/allHeaders.h:1041:
In file included from .../root-6.09.02.build/include/ROOT/TDFOperations.hxx:14:
.../root-6.09.02.build/include/ROOT/TDFTraitsUtils.hxx:31:54: error: type 'const char *' cannot be used prior to '::' because it has no members
   using Args_t = typename TFunctionTraits<decltype(&T::operator())>::Args_t;
                                                     ^
.../root-6.09.02/include/ROOT/TDataFrame.hxx:483:52: note: in instantiation of template class 'ROOT::Internal::TDFTraitsUtils::TFunctionTraits<const char *>' requested here
      auto nArgs = ROOT::Internal::TDFTraitsUtils::TFunctionTraits<F>::Args_t::fgSize;
                                                   ^
ROOT_prompt_2:1:14: note: in instantiation of function template specialization 'ROOT::Experimental::TDataFrameInterface<ROOT::Detail::TDataFrameImpl>::AddColumn<const char *>' requested here
auto h = tdf.AddColumn("el_00", "tree(0,0)", {"tree"}).Histo1D<float>("el_00");
             ^
In file included from input_line_11:21:
In file included from .../root-6.09.02.build/etc/dictpch/allHeaders.h:1041:
In file included from .../root-6.09.02.build/include/ROOT/TDFOperations.hxx:14:
.../root-6.09.02.build/include/ROOT/TDFTraitsUtils.hxx:32:61: error: type 'const char *' cannot be used prior to '::' because it has no members
   using ArgsNoDecay_t = typename TFunctionTraits<decltype(&T::operator())>::ArgsNoDecay_t;
                                                            ^
.../root-6.09.02.build/include/ROOT/TDFTraitsUtils.hxx:33:53: error: type 'const char *' cannot be used prior to '::' because it has no members
   using Ret_t = typename TFunctionTraits<decltype(&T::operator())>::Ret_t;
                                                    ^
 *** Break *** segmentation violation

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.