What is the most efficient way to compare the content of two entries in a TTree?

Hi,
I have a TTree containing several arrays of size 1600. I would like to compare all the values of the branches between two different entries of the TTree and print out the differences.
I have a class (ReadTree), created by TTree::MakeClass(), that loads a TTree from a given TFile and provides me with all the variables to read the values of the TBranches.
What would be the most efficient way to do the comparison within that context ?

My bet is something like :

// Write a function within ReadTree.
ReadTree::Compare( entry1, entry2 ){

// get another instance of ReadTree, loading the same TTree in the same TFile
ReadTree t2();

// Read entry1 in this TTree
fChain->GetEntry( entry1 );

// Read entry2 in t2
t2.fChain->GetEntry( entry2 );

// Perform comparison between members
// Loop on all arrays to check for differences
for( int i=0; i<1600; i++){
  if( array1[i] != t2.array1[i] ){
      // print out
  }
  ... so on for all arrays
  
}

Does it sound like a good strategy ? Thanks for your opinion.

probably.

note that this has been already implemented in at least 2 experiments:

just for fun (and because it’s Friday and we are allowed to procrastinate!), I threw together this little tool:

$> root-dump -h
Usage: root-dump [options] f0.root [f1.root [...]]

ex:
 $> root-dump ./testdata/small-flat-tree.root
 $> root-dump -deep=0 ./testdata/small-flat-tree.root

options:
  -deep
    	enable deep dumping of values (including Trees' entries) (default true)

i.e.:

$> root-dump ../testdata/simple.root ../testdata/small-flat-tree.root
>>> file[../testdata/simple.root]
key[000]: tree;1 "fake data" (TTree)
[000][one]: 1
[000][two]: 1.1
[000][three]: uno
[001][one]: 2
[001][two]: 2.2
[001][three]: dos
[002][one]: 3
[002][two]: 3.3
[002][three]: tres
[003][one]: 4
[003][two]: 4.4
[003][three]: quatro
>>> file[../testdata/small-flat-tree.root]
key[000]: tree;1 "my tree title" (TTree)
[000][Int32]: 0
[000][Int64]: 0
[000][UInt32]: 0
[000][UInt64]: 0
[000][Float32]: 0
[000][Float64]: 0
[000][Str]: evt-000
[000][ArrayInt32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt64]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt64]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayFloat32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayFloat64]: [0 0 0 0 0 0 0 0 0 0]
[000][N]: 0
[000][SliceInt32]: []
[000][SliceInt64]: []
[000][SliceInt32]: []
[000][SliceInt64]: []
[000][SliceFloat32]: []
[000][SliceFloat64]: []
[001][Int32]: 1
[001][Int64]: 1
[001][UInt32]: 1
[001][UInt64]: 1
[001][Float32]: 1
[001][Float64]: 1
[001][Str]: evt-001
[001][ArrayInt32]: [1 1 1 1 1 1 1 1 1 1]
[001][ArrayInt64]: [1 1 1 1 1 1 1 1 1 1]
[001][ArrayInt32]: [1 1 1 1 1 1 1 1 1 1]
[001][ArrayInt64]: [1 1 1 1 1 1 1 1 1 1]
[001][ArrayFloat32]: [1 1 1 1 1 1 1 1 1 1]
[001][ArrayFloat64]: [1 1 1 1 1 1 1 1 1 1]
[001][N]: 1
[001][SliceInt32]: [1]
[001][SliceInt64]: [1]
[...]

it’s (of course!) based on my Go-based ROOT reader: rootio.
you can install it like so:

$> go get go-hep.org/x/hep/rootio/cmd/root-dump

it doesn’t dump (yet) Trees with user-defined classes.
but it’s just a matter of coding and wiring the tools from go-hep.org/x/hep/rootio:slight_smile: (famous last words)

hth,
-s

Comparing of data in two different files is a little project we would love to have a little help on! The idea is to

  • compare all data members of a TKey's value, recursively, with a given precision (for flowing point values)
  • if the object is a TTree, compare all leaves of the TTree, with a given precision (for flowing point values)

That should be wrapped into a command line tool, rootcmp --rel-precision=1E5 file1.root file2.root file3.root that returns 1 in case there are differences and 0 for equality, and that dumps the differences onto stdout.

So far the idea! :slight_smile: If nobody picks this up by next spring it will likely become a summer student project.

Axel.

Thanks for your comments.
I am only interested into comparing the TTree leaves between 2 specific entries, not from different TTrees.
Well, I went on with the above mentioned proposition - a Compare function in my ReadTree class - as it is very specific to the tree. Precision and print out must be adapted for every leaf.

Neal

See:

it’s only working (atm) for flat trees (w/o user defined classes), and only compares 2 files.

if you want to try it out (w/o installing Go):

(you’ll have to trust me I am not doing anything bizarre with my binaries, and mark them executable :P)

but, of course, once Go is installed, it’s as easy as:

$> go get go-hep.org/x/hep/rootio/cmd/root-diff
$> export PATH=$GOPATH/bin:$PATH

$> root-diff -h
Usage: root-diff [options] a.root b.root

ex:
 $> root-diff ./testdata/small-flat-tree.root ./testdata/small-flat-tree.root

options:
  -k string
    	comma-separated list of keys to inspect and compare (default=all common keys)

happy to get UI-related suggestions and/or bug reports (at: https://github.com/go-hep/hep/issues/new)
(PRs are, of course, fine as well)

hth,
-s

1 Like

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