# Transverse mass calculalation from arrays with different lengths

**URL:** <https://root-forum.cern.ch/t/transverse-mass-calculalation-from-arrays-with-different-lengths/55013>\
**Category:** Newbie\
**Tags:** root\
**Created:** [May 24, 2023, 11:10am UTC](https://root-forum.cern.ch/t/transverse-mass-calculalation-from-arrays-with-different-lengths/55013 "2023-05-24T11:10:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![helton](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@helton](https://root-forum.cern.ch/u/helton)\
**Post date:** [May 24, 2023, 11:10am UTC](https://root-forum.cern.ch/t/transverse-mass-calculalation-from-arrays-with-different-lengths/55013/1 "2023-05-24T11:10:10Z")

</div>

Hello,  
I have a very general question regarding the calculation of a transverse mass. I have a MC data .root file from a ttbar-\>WbWb-\>lepton,neutrino,2jets decay. Lets say I wanted to calculate the transverse mass of the one W boson decaying to an electron and a neutrino. I now have the float arrays of the transverse momentum of the electron and the neutrino to calculate transverse mass via a given formula.

Now my question: What if the arrays are of different lengths/have different amount of entries? I get a mass for every pair of momentum of the leptons but what if there are more statistics in one than the other? (say 1000 entries for electron transverse momentum and 3000 for neutrino transverse momentum.) This is kind of the code I have so far, I just started using ROOT a week ago. This is in the .C file in the “Process” section corresponding to the .h file created by TSelector().

```auto
   for (Float_t elphi : el_phi) {       
      for (Float_t elpt : el_pt){         	    

			TLorentzVector P_elec;
   			TLorentzVector P_neut;            
			// Set TLorentzVector values
            P_elec.SetPtEtaPhiM(elpt, 0, elphi, 0);
            P_neut.SetPtEtaPhiM(*met_met, 0, *met_phi, 0);

            // Calculate transverse mass
	      Double_t W_transverse_mass = (P_elec + P_neut).Mt();
            // Output the transverse mass
            hist->Fill(W_transverse_mass);
      }
    }

```

el\_pt and el\_phi are TTreeReaderArray while met\_met and met\_phi are TTreeReaderValue\<Float\_t\>.  
In the code met\_met is kind of the transverse momentum of the neutrino and phi the azimutal angle to calculate transverse mass.  
Ive been having some trouble so hopefully someone can help me out. Thanks alot!

* * *

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 30, 2023, 9:13am UTC](https://root-forum.cern.ch/t/transverse-mass-calculalation-from-arrays-with-different-lengths/55013/2 "2023-05-30T09:13:29Z")

</div>

Dear @helton ,

Sorry for the late reply, this post slipped through.

First off, I see you are using `TLorentzVector`. If you read the [documentation](https://root.cern.ch/doc/master/classTLorentzVector.html), you will see that this class is highly discouraged. You should use the superior alternative [ROOT::Math::LorentzVector](https://root.cern.ch/doc/master/classROOT_1_1Math_1_1LorentzVector.html).

Second, from your code I understand that what you are trying to do is to compute for multiple instances of `elphi` and `elpt` the corresponding transverse mass of the same neutrino observables `met_met` and `met_phi`. I am not sure about this use case. More often, the calculations are done per event, so that only observables related to the same event are involved in the computation. Unless what you mean is that within a certain event you have N leptons but only one neutrino.

In any case, I would highly suggest that you try to frame your analysis with the API of [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html). Maybe take a look at the documentation and then I can try to guide you towards writing the analysis once you have specific questions.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![helton](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@helton](https://root-forum.cern.ch/u/helton)\
**Post date:** [May 31, 2023, 9:25am UTC](https://root-forum.cern.ch/t/transverse-mass-calculalation-from-arrays-with-different-lengths/55013/3 "2023-05-31T09:25:43Z")

</div>

Hi Vincenzo,

yes you are right I indeed wanted to do the calculations per event. Ive learned from there so the question is obsolete now. Thanks!
