Error when trying to add lorentz vectors

My code does two things, it gets the masses of electrons in a jet and the transverse mass.

The way it does that is by getting two lorentz vectors and using the method .M().

The problem is that I want to do a histogram with the sum of both masses, so I want to add both lorentz vectors into a new one and apply .M() to that one, but every time I get this message of compilation:

This is the code, the lorentz vectors are called lorentz_electrondata, lorentz_metdata, and the sum of the two is lorentz_wholedata. The line of the problem is signaled with a capital letters comment near the end:

// All libraries you could wish for
#include <iostream>                 // class for inputoutput streams
#include <stdio.h>                  // printf, scanf, puts, NULL
#include <stdlib.h>                 // srand, rand, atof
#include <time.h>                   // time
#include <fstream>                  // class for inputoutput file streams
#include <dirent.h>
#include <string.h>           // class to manipulate strings
#include <sstream>                    // class for parsing strings
#include <vector>


#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TH1F.h>
#include <TF1.h>
#include <TCanvas.h>
#include <TPaveStats.h>
#include <TPad.h>
#include <TMath.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TLegend.h>
#include <TString.h>
#include <TGraph.h>
#include <TLatex.h>
#include <TLorentzVector.h>


#include <unistd.h>
#define GetCurrentDir getcwd

#include <TTree.h>
#include <TClonesArray.h>
#include "Math/SMatrix.h"

using namespace std;

int main(int argc, char* argv[])
{ 
  //Essentials

  //Upload the file with the data
  TFile* file = TFile::Open("/Users/Fer/Documents/traajo/samples/NeroNtuples_9.root"); // TFile::Open() instead of a constructor since it works over xrootd etc.
  
  //Upload the tree with the event data
  TTree *tree=(TTree*)file->Get("nero/events");

  //Create a variable to store all the lepton event data
  TClonesArray *leptondata = new TClonesArray("leptondata");

  //Create the vector to store all the particle identifiers
  std::vector<Int_t> * lepPdgId= 0;

  //Create a variable to store all the "met" data
  TClonesArray *metdata = new TClonesArray("metdata");

  //Specify where all the lepton event data will be stored
  tree->SetBranchAddress("lepP4", &leptondata);

  //Specify where all the lepton identifiers will be stored
  tree->SetBranchAddress("lepPdgId", &lepPdgId);

  //Specify where all the "met" data will be stored
  tree->SetBranchAddress("metP4", &metdata);


  //Histogram variables

  //Histogram to plot the distribution of electron masses 
  TH1F *emass = new TH1F("emass", "Electron mass", 100, 0, 1);

  //Histogram to plot the distribution of the transverse mass 
  TH1F *tmass = new TH1F("tmass", "Transverse mass", 100, 0, 1);

  //Histogram to plot the estimationdistribution of the W mass 
  TH1F *wmass = new TH1F("wmass", "W mass", 20, 0, 1);
  
  //Variables for the for loop

  //Get how many events we have to loop through
  int nentries = tree->GetEntries();

  Double_t mass;

  //Create the vector to store the mass of every electron
  std::vector<Double_t> * electron_mass = new std::vector<Double_t>;

  //Create the vector to store the transverse mass
  std::vector<Double_t> * transverse_mass = new std::vector<Double_t>;

  //Loop through all the events
  for(int ientry = 0; ientry < nentries; ientry++) 
  {
    //Reset the lepton data 
    leptondata->Clear();

    //Reset the met data 
    metdata->Clear();

    //This line stores the proper data in "leptondata", in "lepPdgId", and "metdata"
    tree->GetEntry(ientry);

    //Store all the met data in this variable
    TLorentzVector * lorentz_metdata = (TLorentzVector *) metdata->At(ientry);
    mass=lorentz_metdata->M();
    transverse_mass->push_back(mass);
    cout << (lorentz_metdata->M()) << endl;

    //Fill the histogram with the current data
    tmass->Fill((lorentz_metdata->M()));
    
    //If "leptondata" is empty it skips and the for loop continues, this is to avoid segmentation errors
    if(leptondata->GetSize() == 0) continue;

    //Loop through all the entries in the current event 
    for(int j=0; j<leptondata->GetEntriesFast()-1; j++) 
    {
        //Only if the identifier of the particle is + or - 11 (electron or antielectron) store the data in electrondata
        if(abs(lepPdgId->at(j))!=11) continue;
        //Store all the data of the electron in this variable
        TLorentzVector * lorentz_electrondata = (TLorentzVector *)leptondata->At(j);
        mass=lorentz_electrondata->M();
        electron_mass->push_back(mass);

        //Fill the histogram with the current data
        emass->Fill(lorentz_electrondata->M()); 

        //HERE IS THE PROBLEM 
        TLorentzVector * lorentz_wholedata = lorentz_electrondata + lorentz_metdata;
        mass=lorentz_wholedata->M();

        //Only if the mass is congruent with the W mass we store it in the histogram
        if (mass>70 && mass<90)
        {
          wmass->Fill(lorentz_wholedata->M()); 
        }
        //If one event has more than 1 electron we only consider the first one
        break;
    }
  }

  cout<< electron_mass->size() << endl <<transverse_mass->size()<<endl;

  // cleanup
  delete electron_mass;
  delete transverse_mass;
  delete file; // automatically deletes "tree", too
  delete lepPdgId;
  delete leptondata;
  return 0; 
}

Thanks a lot

Could it be because you are using pointers ?
it works this way:

root [2] TLorentzVector v1;      // initialized by (0., 0., 0., 0.)
root [3] TLorentzVector v2(1., 1., 1., 1.);
root [4] TLorentzVector v3 = v1+v2;

[quote=“couet”]Could it be because you are using pointers ?..
[/quote]

I tried without pointers, changed everything accordingly, and got this message over and over:

and this other message:

TLorentzVector lorentz_wholedata(*lorentz_electrondata + *lorentz_metdata); mass = lorentz_wholedata.M(); if (mass>70 && mass<90) wmass->Fill(mass);