Make a Lorentz vector and extract mass using arrays in the root file

Dear Experts,

I am trying to make two separate TLorentz Vectors for -kaon(pdgcode=-321) and pion(pdgcode=211) so that I can add them and extract the mass to D0. But I am not able to do so because the arrays are involved.

However, I have managed to get the histograms for the momenta and energy for the kaon and the pion. I am using this file: reconstruct_D0.C (3.4 KB). and here’s a the root file: FileName.root

Please help me.


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi,
This sounds like you’d be better off getting some input / help from your supervisor rather than at the ROOT forum, to understand how to write the analysis. Let us know if there’s something ROOT specific that we can help with!
Cheers, Axel.

Dear @Axel,

I’m sorry if I was not clear enough.

I have worked with Lorentz vectors of two final state particles to reconstruct a third particle. For example:

> Double_t proton_mass = 0.938272081;
> TLorentzVector proton_V, antiproton_V;
>  Double_t  lambda_M, anti_lambda_M;
> 	    
>  TLorentzVector pi1_V(KS_pi1_px,KS_pi1_py,KS_pi1_pz,KS_pi1_E);
TLorentzVector pi2_V(KS_pi2_px,KS_pi2_py,KS_pi2_pz,KS_pi2_E);
> 	    
>  //(the proton corresponds to the pi+ for lambda)
>   proton_V.SetXYZM(KS_pi1_px,KS_pi1_py,KS_pi1_pz, proton_mass);
>  TLorentzVector lambda_V = proton_V + pi2_V  ;
>   lambda_M = lambda_V.Mag();

Here also, I want to do a similar thing. The only difference is that in the above code I am not dealing with TTreeReaderArrays. I wanted some help in dealing with the looping for the TTreereader arrays. So that I can make two separate TLorentx vectors like:

TLorentzVector pi_V(pi_px,pi_py,pi_pz,pi_E);
TLorentzVector K_V(K_px,K_py, K_pz,K_E);

so that I can add them to reconstruct and get the mass of another particle.

Regards,
Sanjeeda

Hi @sanjeeda ,
I don’t quite understand the question but trying to guess I think the problem might be that you have 4 TTreeReaderArrays containing a list of px, py, pz and E values and you want to build a TLorentzVector for each of them?

You can do it with a loop:

std::vector<TLorentzVector> lorentzvectors;
for (int i = 0; i < px.GetSize(); ++i)
  lorentzvectors.emplace_back(px[i], py[i], pz[i], E[i]);

Also note that, as per its docs, TLorentzVector is deprecated in favor of alternatives in ROOT::Math: ROOT: TLorentzVector Class Reference

Cheers,
Enrico

Hi @eguiraud

Thank you for the message.
What I am trying to do is similar. I want to make a lorentz vectors for two separate particles, which I later want to add.

Please see the macro: reconstruct_D0.C (4.0 KB)
It shows an error message like:

Regards,
Sanjeeda

Hi @sanjeeda ,
this is a normal C++ compilation error. You are trying to call the method Mag on lorentzvectors, which is of type std::vector<TLorentzVector>, and the compiler complains that std::vector does not have that method.

If you want to call Mag on an element of the vector you have to access that element first, e.g. lorentzvectors[i].Mag() where i is the index of the element you want.

Cheers,
Enrico

Processing: test.tar.xz…
Hi
Let me explain the problem in detail what sanjeeda and me are facing more clearly
We are reading the px, py, pz and Energy values from Treereader from input root file (attached)
we want to make a Lorentzvector from these values.
So far, we are able to read the values from input file, but here we face issues while making Lorentz vector inorder to get the mass of particle.
We tried your method as you suggested, but it gives the mass values: nan, inf or zero (see below)
====================== Run time output (cout statement)=========

kaon_mass = -nan
kaon_mass = 0
kaon_mass = 0
kaon_mass = 0
kaon_mass = 1.72174e-161
kaon_mass = 0
kaon_mass = 0
kaon_mass = 0
kaon_mass = -nan
kaon_mass = 0
kaon_mass = 0
kaon_mass = 0
kaon_mass = -nan
kaon_mass = 0
kaon_mass = 0
kaon_mass = 0
kaon_mass = 1.72174e-161

I am not sure if we are setting up the lorentz vector correctly here.
Can you please have a look on code script and input root file attached in this link
(inputfile – Google Drive)and suggest us for correct solution.