# Get the number of entries in a branch that are within certain restrictions

**URL:** <https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183>\
**Category:** Newbie\
**Created:** [July 1, 2020, 2:42pm UTC](https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183 "2020-07-01T14:42:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asanch25](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/asanch25/32/20206_2.png) [@asanch25](https://root-forum.cern.ch/u/asanch25)\
**Post date:** [July 1, 2020, 2:42pm UTC](https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183/1 "2020-07-01T14:42:07Z")

</div>

I was wondering if there was an easier way to get the number of entries within a tree that fit a certain restriction. For example, the name of my tree is “store” and I know that using the command

```auto
store->Draw(“x_det”,”x_det>-100”)  

```

Will return the number of entries in the x\_det branch with the restriction that x\_det must be more than -100. But I need to do this many times in a loop, so drawing a graph every time is very inefficient.

\_ROOT Version:6.14.06  
\_Platform: Linux  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [July 1, 2020, 2:57pm UTC](https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183/2 "2020-07-01T14:57:25Z")

</div>

Hi,

try

```auto
printf("%lli entries satisfy the requirement\n", store->Scan("x_det", "x_det > -100"));

```

---

<div class="post-metadata">

**Author:** ![asanch25](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/asanch25/32/20206_2.png) [@asanch25](https://root-forum.cern.ch/u/asanch25)\
**Post date:** [July 1, 2020, 3:12pm UTC](https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183/3 "2020-07-01T15:12:05Z")

</div>

When I run this command it prints out a table telling me the value of each entry, and requires me to type CR to show more entries. My tree has 3\*10^6 entries so this isn’t feasible.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [July 1, 2020, 4:05pm UTC](https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183/4 "2020-07-01T16:05:48Z")

</div>

Right, sorry. I was testing on a very tight selection, and only a handful of events survived the cut, so I didn’t see this effect. Please try this instead:

```auto
printf("%lli entries satisfy the requirement\n", store->GetEntries("x_det > -100"));

```

---

<div class="post-metadata">

**Author:** ![asanch25](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/asanch25/32/20206_2.png) [@asanch25](https://root-forum.cern.ch/u/asanch25)\
**Post date:** [July 1, 2020, 4:27pm UTC](https://root-forum.cern.ch/t/get-the-number-of-entries-in-a-branch-that-are-within-certain-restrictions/40183/5 "2020-07-01T16:27:00Z")

</div>

That seemed to work, thank you!
