TTree char variable comparison

Hi. I’ve got a tree with a Branch of char type. Here’s the TTree::Print() output:

root [5] tree->Print()
******************************************************************************
*Tree    :tree      : main tree                                              *
*Entries :   119423 : Total =         9966428 bytes  File  Size =    1654849 *
*        :          : Tree compression factor =   6.01                       *
******************************************************************************
*Br    0 :E         : E/D                                                    *
*Entries :   119423 : Total  Size=     958310 bytes  File Size  =      35451 *
*Baskets :       30 : Basket Size=      32000 bytes  Compression=  27.01     *
*............................................................................*
<blah blah deleted>
*Br   11 :ProcessName : ProcessName/C                                        *
*Entries :   119423 : Total  Size=    1669093 bytes  File Size  =     328129 *
*Baskets :       68 : Basket Size=      32000 bytes  Compression=   5.08     *
*............................................................................*
*Br   12 :SummaryEntry : SummaryEntry/O                                      *
*Entries :   119423 : Total  Size=     120235 bytes  File Size  =      16172 *
*Baskets :        4 : Basket Size=      32000 bytes  Compression=   7.40     *
*............................................................................*

If I do TTree::Draw on ProcessName, it makes nice histograms. However, I’d like to histogram the energy while applying a cut on a particular ProcessName. Basically, I’d like to do the following:

root [6] tree->Draw("Edep","ProcessName==hadElastic")
Error in <TTreeFormula::Compile>:  Bad numerical expression : "hadElastic"
(Long64_t)(-1)
root [7] tree->Draw("Edep","!strcmp(ProcessName,\"hadElastic\")")
Error in <TTreeFormula::Compile>:  Bad numerical expression : "strcmp(ProcessName,"hadElastic")"
(Long64_t)(-1)

Of course both give me errors. Is there a simple way of doing such a comparison?

HI,

Can you please post your tree, (or a reduced version of it), so we can reproduce the problem

Thanks

Lorenzo

Thanks Lorenzo. Please see the root file here:

https://www.dropbox.com/s/ick57vp4r3kl0q9/test.root?dl=0

The branches of interest are “CreatorProcessName” and “ParticleName”. For example, I would like to put a cut on ParticleName (e.g. “gamma”). How would I do it?

Hi,

tree->Draw("Edep","strstr(ProcessName,\"hadElastic\")")should work.

Cheers,
Philippe.

Merci Philippe!

An aside – are there any plans in the future to add strings (and vectors!) to the basic variable types for a TTree::Branch(), or replace char strings altogether with it? It would have been so much more convenient to type ProcessName==\"hadElastic\"

Hi,

string and vector has been supported in TTrees for quite a while now. You can do:

std::string processName; std::vector<int> triggers; ... tree->Branch("ProcessName",&processName); tree->Branch("Triggers",&triggers);

Cheers,
Philippe.

Oh god, I’ve been sleeping under a rock all this time.

Thank you again!

One suggest I would do is to add this to the documentation. While the current TBranch documentation does mention character strings, it may seem that it is meant actual c character arrays, rather than std::string. Same about vectors.

Hi,

[quote]it may seem that it is meant actual c character arrays, rather than std::string.[/quote]This is still 100% accurate. You can now use the ‘leaflist’ technique if you want to use a std::string and std::vector. As shown in my example, you can store the in their own branch (or you can also store them as part of another object).

Cheers,
Philippe.