Write and read a TLorentzVector from a TTree

Hello,

for my analysis I run my code on some ntuples and I save the relevant elements of the good events in an output tree whose branches are TLorentzVector.
Here’s the declaration of my output tree:

// define the output tree TTree *reduced_ntuple = new TTree("higgs", "higgs ntuple"); Int_t channel(-1); TLorentzVector *Higgs = new TLorentzVector(); TLorentzVector *Z_had = new TLorentzVector(); TLorentzVector *Z_lep = new TLorentzVector(); TLorentzVector *jet_l = new TLorentzVector(); TLorentzVector *jet_nl = new TLorentzVector(); TLorentzVector *lep_l = new TLorentzVector(); TLorentzVector *lep_nl = new TLorentzVector(); TVector2 *met = new TVector2(); reduced_ntuple->Branch("last_cut_passed", &last_cut_passed); reduced_ntuple->Branch("channel", &channel); reduced_ntuple->Branch("Higgs", &Higgs); reduced_ntuple->Branch("Z_had", &Z_had); reduced_ntuple->Branch("Z_lep", &Z_lep); reduced_ntuple->Branch("jet_l", &jet_l); reduced_ntuple->Branch("jet_nl", &jet_nl); reduced_ntuple->Branch("lep_l", &lep_l); reduced_ntuple->Branch("lep_nl", &lep_nl); reduced_ntuple->Branch("met", &met);
In my code I run the analysis, fill the variables and at the end there is the

command.

My output ntuple has indeed the TTree with the above structure. Now I have a lot of problems when I try to work with this output ntuple. I cannot make plots from command line:

root [1] higgs->Draw("jet_l.DeltaR(jet_nl)")
Error: Symbol jet_nl is not defined in current scope  (tmpfile):1:
*** Interpreter error recovered ***
Error: class,struct,union or type (unknown) not defined  (tmpfile):1:
Error: Symbol jet_nl is not defined in current scope  (tmpfile):1:
*** Interpreter error recovered ***
Error: class,struct,union or type (unknown) not defined  (tmpfile):1:
*** Interpreter error recovered ***

 *** Break *** segmentation violation
(...)

So I tried to make a Selector from the TTree, and here’s the result (an example for the Higgs branch):

 //TLorentzVector  *Higgs;
   UInt_t          fUniqueID;
   UInt_t          fBits;
   UInt_t          fP_fUniqueID;
   UInt_t          fP_fBits;
   Double_t        fP_fX;
   Double_t        fP_fY;
   Double_t        fP_fZ;
   Double_t        fE;

and the same result for all the other TLorentzVector branches (these are the only variables listed for the Higgs branch).

What’s the problem? How can I work with the TLorentzVectors that I select in my analysis??

Thanks,
Francesco

Hi Francesco,

The string based version of TTree::Draw can only call function take numerical value as an argument (TLorentzVector::DeltaR takes a reference) and MakeSelector decomposes (intentionally) the object into their components so that they can be partially read and can be read without the original shared library.

In your case you should use MakeProxy (similar to MakeSelector but it give access to the objects) directly or indirectly via this simple TTree::Draw script:// file deltaR.C Double_t deltaR.C() { return jet_l.DeltaR(jet_nl); }and use withhiggs->Draw("deltaR.C");

Cheers,
Philippe.

Dear ROOT experts,
I met a similar problem here. To avoid making another thread, let me post the question here. I filled a tree with a “TLorentzVector” branch. Then I want to analyse the tree with “MakeClass”. But it failed to recognize this “TLorentzVector” branch (other types are fine) and gave exactly what @losterzo showed.

Here is the skeleton of how I fill the branch.

TFile* file = new TFile(...)
file -> SetCompressionLevel(1);
 TTree* tree = new TTree (...);
TLorentzVector* tau_0_p4 = 0;
tree -> Branch("tau_0_p4", "TLorentzVector", & tau_0_p4)

I also tried “gSystem → Load(“libPhysics.so”);” before “MakeClass”, but it did not help.

Do you have any ideas?

Let me add one more point. This does not affect reading the branch. I can still read this branch well using the codes like

TLorentzVector* tau_0_p4;
tree -> SetBranchAddress("tau_0_p4", & tau_0_p4);

The only trouble is that “MakeClass” cannot recognize it well. I would still think “MakeClass” is very helpful to print out all branches and save time to define and SetBranchAddress though I was recommended to use other analysis tool like “TTreeReader”.

Many thanks!
Ligang