Re: list of unique values from a TTree

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 25 May 2012 11:04:06 -0500


Hi Rob,

Here is two ways to do in C++:

{

    #include <set>
    TFile *file = TFile::Open("hsimple.root");     TTree *tree; file->GetObject("ntuple",tree);     TTreeFormula form("form","i%100",tree);     std::set<int> s;
    for(long long x = 0; x < tree->GetEntries(); ++x) {

       tree->LoadTree(x);
       s.insert(form.EvalInstance(0));

    }

    float px; TBranch *bpx = 0;
    tree->SetBranchAddress("px",&px,&bpx);     for(long long x = 0; x < tree->GetEntries(); ++x) {

       bpx->GetEntry(x);
       s.insert( (int)px );

    }
}

> 2. Why is this (and the equivalent GetEntry loop called from
> CINT) so much slower that tree.Draw("scandata1")?

Most likely because too much of the TTree is being read (instead of just the strict minimum).

Cheers,
Philippe.

On 5/25/12 8:08 AM, Rob Mahurin wrote:
> 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
>
Received on Fri May 25 2012 - 18:04:15 CEST

This archive was generated by hypermail 2.2.0 : Fri May 25 2012 - 23:50:02 CEST