TTree and TChain differences

Hi rooters!

I need some information about TTree and TChain.
In particular, what object type are them and in what are they different?

More precisely, when I start an interactive session of ROOT
I create one TTree and one TChain and then the command

[ ] .ls

return only the TTree:

OBJ: TTree tree tree2 : 0 at: 0x13409e0

and nothing more: there is no output concerning the TChian object.


Thanks a lot in advance to everybody!

ROOT Version: 6.08.06
Platform, compiler: Debian 3.16.43-2+deb8u5 (2017-09-19) x86_64 GNU/Linux, gcc 4.9.2

ROOT Primer -> File I/O and Parallel Analysis -> N-tuples in ROOT -> Processing N-tuples Spanning over Several Files
ROOT User’s Guide -> Trees -> Chains

I am sorry to bother but I am not sure I understood your point.
I know what a TTree and a TChain are and why are they useful in analysis…
…but I don’t understand: why the TChain OBJ is not appearing with the .ls command?


I have already read the TChain documentation…
…but it is not helping me: can anybody actually do it?

And what do the very fist sentence of the TChain Class Reference and the second sentence of the TChain::TChain method description say?
Use e.g. the Google Translate to get them in your native language.

This was very kind and so useful: thank you so much!!

Considering your extremely clarity and patience in explaining things,
could you please tell me how can I get a list of the chains declared in a session?

Thanks a lot in advance!

Maybe using: gROOT->GetListOfDataSets()->ls(); (which possibly returns the list of data sets, TDSet or TChain) and/or using: gROOT->GetListOfSpecials()->ls(); (which returns the list of “special objects”).

Hi mmoo,
to answer your original question, a TChain is just a useful wrapper around files and TTrees, which lets you read multiple TTrees in multiple files as if you were manipulating just one TTree (the chain takes care of switching between files and extracting the trees from it for you).

As a consequence, TChains are not something that is stored in TFile, and therefore do not appear in .ls.
Usually this is not a problem: you should know what variables you have created; .ls is commonly used to check what’s inside the latest file you opened, and should be equivalent to gDirectory->ls().


Thank you so much for the explanation, Enrico!
But, if I create a TTree and a TChain in the interactive session, is there a way to access them by object type?
More generally, is it possible to access all the object created in an interactive session without pretending to actually know their names?

see @Wile_E_Coyote’s latest reply for methods that return certain subsets of objects registered in ROOT.

I don’t know whether there are methods to retrieve “anything with a name”, but what’s your use-case exactly (i.e. why do you need such a thing)? There might be an easier way to reach whatever your goal is.

Hi Enrico,
methods suggested by Wile_E_Coyote are fine to list TChain, but “just” that.

To answer to your question, I would like to crate a sort of SaveSession function which saves certain type of objects (like TChain) that I created in the interactive ROOT session.
More precisely, in my analysis I use lots of chains and I have to perform several selections both with TCut and TCutG and I would like to save each one of them in order to be able to resume/reload the session with all the cuts I have already created.

Do you have any suggestion?

Uhm I wouldn’t know how to save the state of an interactive session, sorry (I don’t do that much work in the root interpreter).

Of course you could keep your TCuts and TCutGs in a collection and write those to file before exiting the session.
You could also write smll helper functions StoreAndApply(TCut &, TChain &) and WriteCuts() that append to the collection of applied cuts and write the current state of the collection to a file, so you don’t have to do it manually.


Thanks Enrico for the suggestion: I was thinking to something similar too!
About that, do you have any idea of how can I add each TCut and TCutG to a TList for example?
Because I wanted to write something general and almost automatic…

Thanks a lot in advance!

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