How to Pass a TTreeReaderArray<float> to a function

I want to pass a TTreeReaderArray<float> to a function, and I haven’t been able to find the relevant documentation.

Here’s my function:

TVector3 findJetMatchReconToGen(TTreeReaderArray<float> genMomArrayX, TTreeReaderArray<float> genMomArrayY, TTreeReaderArray<float> genMomArrayZ,  TTreeReaderArray<int> typeArray, TVector3 reconMom) {
  for(unsigned int q=0; q<genMomArrayX.GetSize(); q++){
	    if(typeArray[q] == 0){ //not a particle
	      TVector3 genMom(genMomArrayX[q],genMomArrayY[q],genMomArrayZ[q]);
	      double minDR = 999.;
	      double jetGenMatchIndex = 0;
	      for(unsigned int r=0; r<genMomArrayX.GetSize(); r++) {
		double deltaEta = TMath::Abs(reconMom.PseudoRapidity()-genMom.PseudoRapidity());
		double deltaPhi = TMath::Abs(reconMom.Phi()-genMom.Phi());
		double deltaR = TMath::Sqrt(deltaEta*deltaEta + deltaPhi*deltaPhi);
		if (deltaR < minDR) {
		  minDR = deltaR;
		  jetGenMatchIndex = r;
		}
	      }
         TVector3 matchingGenJet(genMomArrayX[jetGenMatchIndex], genMomArrayY[jetGenMatchIndex], genMomArrayZ[jetGenMatchIndex]); 
	      return matchingGenJet;
	    }
  }       
}

I originally got this compiler error:

 error: could not convert ‘& jetGenMomX’ from ‘TTreeReaderArray<float>*’ to ‘TTreeReaderArray<float>’

but when I define the function to have pointer arguments and change the functions to pointer syntax, I get a very long series of error messages that are mostly some form of

error: no match for ‘operator==’ (operand types are ‘TTreeReaderArray<int>’ and ‘int’)
  562 |             if(typeArray[q] == 0){ //not a particle
      |                ~~~~~~~~~~~~ ^~ ~
      |                           |    |
      |                           |    int
      |                           TTreeReaderArray<int>

which is confusing, because I use the same syntax in my main() function without issue.
I also tried to pass the arrays by reference, but the class already does that automatically so it didn’t change anything.
Here’s the parts relevant to the TChain and TTreeReader declaration of the arrays I want to pass to the function.

TChain *mychain = new TChain("events");
mychain->Add(infile);
TFile *ofile = TFile::Open(output,"recreate");
TTreeReader tree_reader(mychain);
TTreeReaderArray<float> jetGenMomX = {tree_reader, "GeneratedJets.momentum.x"};
TTreeReaderArray<float> jetGenMomY = {tree_reader, "GeneratedJets.momentum.y"};
TTreeReaderArray<float> jetGenMomZ = {tree_reader, "GeneratedJets.momentum.z"};

ROOT Version: Not Provided
Platform: Emacs
Compiler: ePIC-analysis


Hi,

I think a very good practice would be to pass these objects by reference also to avoid copies:

TVector3 findJetMatchReconToGen(TTreeReaderArray<float>& genMomArrayX, TTreeReaderArray<float>& genMomArrayY, TTreeReaderArray<float>& genMomArrayZ,  TTreeReaderArray<int>& typeArray, TVector3& reconMom)

Best,
Danilo