# Check if branch exists from terminal

**URL:** <https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297>\
**Category:** Newbie\
**Created:** [November 9, 2022, 10:18pm UTC](https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297 "2022-11-09T22:18:40Z")\
**Posts on this page:** 5\
**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:** [November 9, 2022, 10:18pm UTC](https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297/1 "2022-11-09T22:18:40Z")

</div>

Hi all,

I have a silly question, but I could not find the solution anywhere. I want to check from the terminal if my tree, called “Entries” has branches which start with “Electron” in its name and I want them listed.  
As I remember from past, I was able to check it in a following way:  
`Events->Print("Electron*")` but now it just gives me the full list of the branches as an output. So I guess, I remember wrongly 🙂  
P.S. I know for sure that there are various variables stored in the tree, like Electron\_pt, Electron\_eta, etc.

Thanks in advance!

Newbie

---

<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:** [November 10, 2022, 8:27am UTC](https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297/2 "2022-11-10T08:27:53Z")

</div>

[It should work.](https://root.cern/doc/master/classTTree.html#a3d27bde3ec51f3985ea6e0bbfe15863c)

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [November 10, 2022, 8:28am UTC](https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297/3 "2022-11-10T08:28:10Z")

</div>

Hi @beg1nner,

Using `Print` seems to work in my case, it is a bit verbose but it is giving only the branches that pass respect the wildcard I use:

```auto
root [0] TFile f{"Run2012BC_DoubleMuParked_Muons.root"};
root [1] std::unique_ptr<TTree> t{f.Get<TTree>("Events")};
root [2] t
(std::unique_ptr<TTree> &) std::unique_ptr -> 0x55ec47750410
root [3] t->Print("Muon*")
******************************************************************************
*Tree :Events : Events *
*Entries : 61540413 : Total = 4463735053 bytes File Size = 2243340472 *
* : : Tree compression factor = 1.99 *
******************************************************************************
*Br 0 :Muon_pt : Muon_pt[nMuon]/F *
*Entries : 61540413 : Total Size= 843506272 bytes File Size = 634763632 *
*Baskets : 523 : Basket Size= 25600000 bytes Compression= 1.33 *
*............................................................................*
*Br 1 :Muon_eta : Muon_eta[nMuon]/F *
*Entries : 61540413 : Total Size= 843506799 bytes File Size = 653064868 *
*Baskets : 523 : Basket Size= 25600000 bytes Compression= 1.29 *
*............................................................................*
*Br 2 :Muon_phi : Muon_phi[nMuon]/F *
*Entries : 61540413 : Total Size= 843506799 bytes File Size = 652361580 *
*Baskets : 523 : Basket Size= 25600000 bytes Compression= 1.29 *
*............................................................................*
*Br 3 :Muon_mass : Muon_mass[nMuon]/F *
*Entries : 61540413 : Total Size= 843507326 bytes File Size = 102175256 *
*Baskets : 523 : Basket Size= 25600000 bytes Compression= 8.26 *
*............................................................................*
*Br 4 :Muon_charge : Muon_charge[nMuon]/I *
*Entries : 61540413 : Total Size= 843508481 bytes File Size = 162126603 *
*Baskets : 524 : Basket Size= 25600000 bytes Compression= 5.20 *
*............................................................................*

```

What do you see in your case?  
Cheers,  
Vincenzo

---

<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:** [November 10, 2022, 8:30am UTC](https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297/4 "2022-11-10T08:30:58Z")

</div>

From both posts here … a physics hypothesis can be derived … it only works for “muons” but doesn’t work for “electrons”. :mrgreen:  
How about you try “taus”? 🤔

---

<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:** [November 10, 2022, 12:45pm UTC](https://root-forum.cern.ch/t/check-if-branch-exists-from-terminal/52297/5 "2022-11-10T12:45:03Z")

</div>

Haha, true 😃 😃 After a restart of the machine, it worked. Still a mystery why it was giving the whole list of the branches inside the ntuple… @vpadulan thank you for trying 🙂
