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

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:

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

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


#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:

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,

ROOT version: 6.16
OS: Ubuntu 16.04

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



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