# Applying a cut when filling a TTree

**URL:** <https://root-forum.cern.ch/t/applying-a-cut-when-filling-a-ttree/15865>\
**Category:** ROOT\
**Created:** [March 30, 2013, 6:07pm UTC](https://root-forum.cern.ch/t/applying-a-cut-when-filling-a-ttree/15865 "2013-03-30T18:07:41Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![arekfu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/arekfu/32/27537_2.png) [@arekfu](https://root-forum.cern.ch/u/arekfu)\
**Post date:** [March 30, 2013, 6:07pm UTC](https://root-forum.cern.ch/t/applying-a-cut-when-filling-a-ttree/15865/1 "2013-03-30T18:07:41Z")

</div>

Hello ROOTers,

I wrote a program that fills a ROOT TTree with the events from a Monte Carlo simulation. Assume the tree contains the following variables:`Short_t n
Float_t x[n]
Float_t y[n]
`I’m not interested in the whole tree, but only in a small subset of events. The events are identified by some condition on the tree variables, e.g.`sqrt(x)<=1./y`which however is user-defined, i.e. known only at run time. I’d like to be able to fill the tree only with the events, or parts of events, that fulfil the user-defined condition.

Ideally I’d like to do something like`
// assign tree branches to variables n, x, y
n = 3;
x[0] = 1.0; x[1] = 1.0; x[2] = 1.0;
y[0] = 10.0; y[1] = 0.1; y[2] = 0.01;
TString condition;
std::cin >> condition;
tree->Fill(condition);`and that would fill the tree with the following event:`n=2
x[0]=1.0 y[0]=0.1
x[1]=1.0 y[1]=0.01`Or, if this is impossible, I could fill the tree only if any of the array items satisfies the relevant condition.

Is there any way to realize that? Perhaps I could fill a temporary tree and copy over only the relevant bits, but I’m not sure how to do that.

Cheers,  
Davide

---

_[View the full topic](https://root-forum.cern.ch/t/applying-a-cut-when-filling-a-ttree/15865)._
