How to check if the current entry in TTree satisfies a cut

Hi ROOTers.
I need to know if there is a way to check if the current TTree entry satisfies a cut which is of the form of string.

I have a function that draws scintillation waveform. And I need invoke it with cut string as an argument.

void Drawer::Next( const std::string& cut )//or maybe const char* or smth string like
    if ( tree == 0 ) return;

    NEXT :
        if( currentEntry >= nEntries )
            std::cout << "End of the tree reached. No more entries available. Return to the beginning.\n"; 
            currentEntry = -1;
            tree->GetEntry( currentEntry );

            if( /*entry doesn't fulfill cut*/ ) goto NEXT;
                Draw( (*pathToBinFile) );

cut could be "intgeral <= 60000 && intgegral >= 30000".

Well it is definitly possible by assigning a branch address with TTree::SetBranchAddress and then Getting the entry with TTree::GetEntry. The you can ckeck whether your cuts are fulfilled with the assigned variables.
There might be a better way, but to choose it we need more information on what you are trying to do, how your branches look and how this Cut-String looks. Please tell us what data you have and what exactly you want to do with them.

I have edited my question.
How do you check if cut is fulfilled if there are several subcuts in cut string?

There is an easy way using the TTree::Query method:

if(tree->Query("", cut.c_str(), "", 1, currentEntry)->GetRowCount() == 0) goto NEXT;

The Query Function returns a TSQLResult Object whichs number of Rows correspond to the amount of entries for which the cut string evaluates true. Since only one entry (The current entry) is being processed, the result can only be 0 or 1. I assumed now that your cut string is of the class std::string. The query function expects a const char* which is why I added the c_str() function.
The format of the cut string has to be a boolean evaluation like in an if condition where the current valies of the branches can be accessed by their names. You can find further information on this in the documentation of the TTree::Draw method:

Works perfectly so far. Thank you.

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