Scan function only shows unique data values?

Hello!

I am new to ROOT and I learned how to use the Scan function to print the data entries of a leaf. I noticed, however, when I use Scan on an entire TTree then the data is printed along with the number of instances that it occurs, as shown here:
image

Is there a way for me to use Scan on a single variable and also have it print how many times it repeats instead of it only printing entries that are different? This is what it shows when I use scan on a single variable:
Capture.

Thank you for any input!

“Instance” usually means the branch or leaf is an array (fixed size) or a vector (different sizes). The size of each vector (within each event or “Row” shown in Scan) may be stored in another branch or leaf in the same tree. Try printing the tree structure

tree->Print();

(of course, change “tree” to the name you are using).
For example, here:

T->Print()
******************************************************************************
*Tree    :T         : T                                                      *
*Entries :        2 : Total =            1555 bytes  File  Size =        640 *
*        :          : Tree compression factor =   1.26                       *
******************************************************************************
*Br    0 :n         : n/I                                                    *
*Entries :        2 : Total  Size=        546 bytes  File Size  =         73 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :a         : a[n]/D                                                 *
*Entries :        2 : Total  Size=        741 bytes  File Size  =        132 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.40     *
*............................................................................*

we see that “a” has size “n” (see a[n]/D), which is given by the branch “n”. So, if this is the case:

T->Scan("n:a")
***********************************************
*    Row   * Instance *         n *         a *
***********************************************
*        0 *        0 *         5 *         0 *
*        0 *        1 *         5 *         2 *
*        0 *        2 *         5 *         4 *
*        0 *        3 *         5 *         6 *
*        0 *        4 *         5 *         8 *
*        1 *        0 *         8 *         1 *
*        1 *        1 *         8 *         3 *
*        1 *        2 *         8 *         5 *
*        1 *        3 *         8 *         7 *
*        1 *        4 *         8 *         9 *
*        1 *        5 *         8 *        11 *
*        1 *        6 *         8 *        13 *
*        1 *        7 *         8 *        15 *
***********************************************
(long long) 13

And you get the size of each “a” by simply scanning “n” alone.

T->Scan("n")
************************
*    Row   *         n *
************************
*        0 *         5 *
*        1 *         8 *
************************
(long long) 2

Also, note that the values of the instances (the "a"s with the same “Row”) are not necessarily equal; they might be in your tree, but that’s not the general case, so if you really want to remove only the repeated values you will need a different solution, unless you are 100% sure all values in the instances of each row (for all rows) are in fact equal.

1 Like

I don’t want to remove the repeated values- that is what I want to see as well as how many times they repeat! In the response you posted, I see you are scanning two variables (n and a), is it possible to see the instances of n without also scanning a?

The is only ‘1’ n per entry, isn’t it? I.e. there is only one instance and thus @dastudillo is accurate, isn’t it?

Hi @nklaus ,
I am afraid TTree::Scan cannot display the data as you request. You can however manually loop over the data and print it as you prefer.

Cheers,
Enrico