RE: list of unique values from a TTree

From: Amnon Harel <amnon.harel_at_cern.ch>
Date: Fri, 25 May 2012 13:20:45 +0000


Hi Rob,

That's a near trick in PyROOT!

I wonder how much quicker your PyROOT solution will be if you first:

    tree.SetBranchStatus( '*', 0 ) # disables all branches     tree.SetBranchStatus( 'scandata1', 1 ) # and enables the one we really need

AFAIK this is much harder in C++. I wrote a class that can handle most cases (too often a complicated enough tree/chain will break a ROOT event loop). If you want to try it out:

http://www-d0.fnal.gov/~aharel/value_lister.h http://www-d0.fnal.gov/~aharel/value_lister.c

 cheers,
 Amnon Harel,
 University of Rochester



From: owner-roottalk_at_root.cern.ch [owner-roottalk_at_root.cern.ch] on behalf of Rob Mahurin [rob_at_jlab.org] Sent: 25 May 2012 15:08
To: roottalk (Mailing list discussing all aspects of the ROOT system.) Subject: [ROOT] list of unique values from a TTree

Hi ROOT,

I have some TTrees with a handful of branches and a few million entries each. One of the branches ("scandata1") is a label for different phases of a measurement and takes on only about a dozen unique values. I want to make a list of these unique values that I can iterate over.

If I move over into PyROOT, I can do this in a line:

In [33]: { tree.scandata1 for x in range(0, tree.GetEntries()) if tree.GetEntry(x) } Out[33]: set([40.0, 5.0, 70.0, 95.0])

My questions are:

  1. Is there an easy-to-write pattern for doing this without switching over to Python? I can't see a way without mucking around with branch addresses and repeating myself a lot.
  2. Why is this (and the equivalent GetEntry loop called from CINT) so much slower that tree.Draw("scandata1")?

Thanks,
Rob

--
Rob Mahurin
University of Manitoba, Department of Physics
and Thomas Jefferson National Accelerator Facility
12000 Jefferson Avenue Suite 6, Newport News, VA 23606
office 757-269-6510; elsewhere 865-207-2594; rob_at_jlab.org
Received on Fri May 25 2012 - 15:20:55 CEST

This archive was generated by hypermail 2.2.0 : Fri May 25 2012 - 17:50:01 CEST