# Scan function only shows unique data values?

**URL:** <https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [July 29, 2021, 5:06am UTC](https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071 "2021-07-29T05:06:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nklaus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/db5fbb/32.png) [@nklaus](https://root-forum.cern.ch/u/nklaus)\
**Post date:** [July 29, 2021, 5:06am UTC](https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071/1 "2021-07-29T05:06:02Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/3X/5/c/5c4fbcb305efbbfffeaf8341fa62f30682dedb54.png)

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.](https://root-forum.cern.ch/uploads/default/original/3X/f/1/f1304b94b23668c30e2dc602e32c5310e0a009ec.png)

Thank you for any input!

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 29, 2021, 6:22am UTC](https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071/2 "2021-07-29T06:22:49Z")

</div>

“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

```auto
tree->Print();

```

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

```auto
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:

```auto
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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![nklaus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/db5fbb/32.png) [@nklaus](https://root-forum.cern.ch/u/nklaus)\
**Post date:** [July 30, 2021, 2:05am UTC](https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071/3 "2021-07-30T02:05:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [July 31, 2021, 10:08pm UTC](https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071/4 "2021-07-31T22:08:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [August 24, 2021, 7:28am UTC](https://root-forum.cern.ch/t/scan-function-only-shows-unique-data-values/46071/6 "2021-08-24T07:28:00Z")

</div>

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
