# Number of Processed events

**URL:** <https://root-forum.cern.ch/t/number-of-processed-events/46783>\
**Category:** Newbie\
**Created:** [September 10, 2021, 10:59am UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783 "2021-09-10T10:59:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [September 10, 2021, 10:59am UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/1 "2021-09-10T10:59:43Z")

</div>

Hello,

is there an easy way to check the number of processed events from terminal for a branch taken from already existing ntuple (.root file) ? For example, if I have a branch named “Muon\_pt” and I would like to know how many events are there in total.

Cheers!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 10, 2021, 12:20pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/2 "2021-09-10T12:20:33Z")

</div>

There is this way:

```auto
int n = your_tree->Project("h","Muon_pt","some_selection_on_Muon_pt");

```

`n` should be what you are looking for.  
May be some other ways are possible also.

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [September 10, 2021, 4:18pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/3 "2021-09-10T16:18:54Z")

</div>

Thanks for your reply. Like this I get exactly what is written in “Entries” , is number of Events and Entries the same?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 10, 2021, 5:05pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/4 "2021-09-10T17:05:25Z")

</div>

If you add a selection you will get the number of event passing the selection.

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [September 10, 2021, 6:50pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/5 "2021-09-10T18:50:57Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [September 15, 2021, 3:56pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/6 "2021-09-15T15:56:25Z")

</div>

Dear @couet ,  
Do you happen to know why the results I get are different when I count number of events manually (with output in the terminal, with `std::cout << " ... " << std::endl;`) and when I do as suggested with `Events->Project("h", "Muon_pt", "Muon_pt>25")` ? I get much less number of events when checking them with “Project”.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 15, 2021, 4:44pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/7 "2021-09-15T16:44:09Z")

</div>

Try: `Events->Scan("Muon_pt", "Muon_pt>25")`

---

<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:** [September 15, 2021, 7:05pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/8 "2021-09-15T19:05:38Z")

</div>

> [@beg1nner](#):
>
> is number of Events and Entries the same?

Not exactly. An event may have many muons, this depends on the structure of your ntuple. Consider you have just two events: one with 5 muons, another one with 3 muons. This is two events but 5+3=8 entries.

Regarding the

> [@beg1nner](#):
>
> I get much less number of events when checking them with “Project”.

, can you show exactly how you

> [@beg1nner](#):
>
> count number of events manually

please?

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [September 15, 2021, 8:51pm UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/9 "2021-09-15T20:51:36Z")

</div>

Hi @yus!

So, what I am doing is something like this:  
`for(int i = 0 ; i<nMuon; i++){ `  
`if(Muon_pt[i]>25) {`  
`std::cout << " muon pt " << std::endl;`  
`hist->Fill(Muon_pt[i]); }`  
`}`  
Now, I expect that the frequency of “muon pt” as an output (let’s say I will have 10 “muon pt” outputs in the terminal from “cout”) should be the same as number of entries. However when I checked with ` Events->Project("Muon_pt", "Muon_pt>25")` as well as with `Events->Project("h","Muon_pt","Muon_pt>25")` , the number I got was much smaller than 10. And I am trying to understand why.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 16, 2021, 6:47am UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/10 "2021-09-16T06:47:39Z")

</div>

Try: `std::cout << h->GetEntries() << std:;endl;`

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [September 16, 2021, 8:22am UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/11 "2021-09-16T08:22:58Z")

</div>

Hello @Wile_E_Coyote ,  
It works like this, however I am trying to understand what is the difference between what I described for @yus …

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 16, 2021, 9:25am UTC](https://root-forum.cern.ch/t/number-of-processed-events/46783/12 "2021-09-16T09:25:36Z")

</div>

It has explicitly been explained in [his post](https://root-forum.cern.ch/t/number-of-processed-events/46783/8).
