# Custom function for TTree::Draw() with python for padded array size evaluation

**URL:** <https://root-forum.cern.ch/t/custom-function-for-ttree-draw-with-python-for-padded-array-size-evaluation/39301>\
**Category:** ROOT\
**Created:** [May 7, 2020, 2:30pm UTC](https://root-forum.cern.ch/t/custom-function-for-ttree-draw-with-python-for-padded-array-size-evaluation/39301 "2020-05-07T14:30:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apetukho](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/838e76/32.png) [@apetukho](https://root-forum.cern.ch/u/apetukho)\
**Post date:** [May 7, 2020, 2:30pm UTC](https://root-forum.cern.ch/t/custom-function-for-ttree-draw-with-python-for-padded-array-size-evaluation/39301/1 "2020-05-07T14:30:38Z")

</div>

Dear ROOT experts,

I want to plot the size of the one of the branches in my tree which is an `int` array padded with `99999`, i.e plot the number of array entries `< 999999` for every event in the tree.

I’ve tried to do the following based on the previous topics on this forum and `RDataFrame` tutorials:

```auto
sizeFuncCode = '''
    int arraySize(int *ar){
        int n = 0;

        for(unsigned int i = 0; i < (sizeof(ar) / sizeof(ar[0])); i++){
            if (ar[i] < 99999) {
                n++;
            }
        }
        return n;
    }
'''

ROOT.gInterpreter.Declare(sizeFuncCode)

#skipped code of getting the tree (both it and the file do exist)
tree.Draw('arraySize(hit_layer)>>arraySizehit_layerOld(50,0,50)', cut, 'gOff')

```

But I get the following error:

```auto
Error in <TTreeFormula::Compile>: Bad numerical expression : "arraySize(hit_layer)"
Info in <TSelectorDraw::AbortProcess>: Variable compilation failed: {arraySize(hit_layer),weight}

```

What could’ve caused those errors?

Thanks in advance,  
Aleksandr

* * *

ROOT version: 6.16  
OS: Ubuntu 16.04

---

<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:** [May 7, 2020, 3:27pm UTC](https://root-forum.cern.ch/t/custom-function-for-ttree-draw-with-python-for-padded-array-size-evaluation/39301/2 "2020-05-07T15:27:00Z")

</div>

TTree::Draw calls function with the elements of the array instead of the array.  
Try:

```auto
tree.Draw('Sum$(hit_layer<99999)')

```

Cheers  
Philippe.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 21, 2020, 3:27pm UTC](https://root-forum.cern.ch/t/custom-function-for-ttree-draw-with-python-for-padded-array-size-evaluation/39301/3 "2020-05-21T15:27:11Z")

</div>

Closed on May 21, 2020, 3:27pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
