Filling a tree with complex number

Hi,
Is there a way to feel a tree with complex numbers?
If so, is there a specific syntax?

I am trying to use complex numbers as input variables for a neural network and figured out that having one single complex variable would be better than two variables with real and imaginary part.

Thank you

Hi,

you can fill a branch of a tree with complex numbers. Here you can find two examples which show how to accomplish this task, one interacting directly with the tree and one using TDataFrame:

{

TFile f1("f1.root", "RECREATE");
TTree t1("t1","Complex numbers");
std::complex<double> c;
auto cptr = &c;

t1.Branch("myComplex", cptr);

TRandom3 r1(1);
for (auto i : ROOT::TSeqI(128)) {
   c.real(r1.Uniform(-1,1));
   c.imag(r1.Uniform(-1,1));
   t1.Fill();
}
t1.Write();
f1.Close();

// Or with TDataFrame
TRandom3 r2(1);
ROOT::Experimental::TDataFrame d(128);
d.Define("myComplex", [&r2](){return std::complex<double>(r2.Uniform(-1,1), r2.Uniform(-1,1));})
  .Snapshot("t2","f2.root");
}

Cheers,
D

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