# TLorentzVector confusing

Hi,

I wrote a buggy code using TLorentzVector like this:

``````double phi(TLorentzVector lvec)
{
return lvec.Phi();
}

void test()
{
TLorentzVector lvec;
lvec.SetXYZM(0.4, 0.6, 1.2, 0.135);
cout << phi(lvec.Phi()) << endl;
}``````

It compiles fine and run but return 0 value because of (I guess, not sure) TLorentzVector(const Double_t* carray) implementation. Although, the code is wrong. It should be phi(lvec). With no error by compiler, the code will be more buggy. Have you guys seen this type of problem?

your function phi expects a TLorentzVector, not phi !
I also suggest to pass lvec by reference instead of by value.
See the changes below.

Rene

[code]double phi(TLorentzVector &lvec)
{
return lvec.Phi();
}

void test()
{
TLorentzVector lvec;
lvec.SetXYZM(0.4, 0.6, 1.2, 0.135);
cout << phi(lvec) << endl;
}
[/code]

Thanks.

That is exactly my question: the function phi should expect TLorentzVector only but it is accepting double also. However, passing by reference solve the problem.

Thanks.

[quote=“manoj”]Thanks.

That is exactly my question: the function phi should expect TLorentzVector only but it is accepting double also. However, passing by reference solve the problem.

Thanks.[/quote]

TLorentzVector class has a constructor:

TLorentzVector(Double_t x = 0.0, Double_t y = 0.0,
Double_t z = 0.0, Double_t t = 0.0);

So, it has default arguments and TLorentzVector can be created like this: TLorentzVector vec0, vec1(1), vec2(1,2), vec3(1,2,3), vec4(1,2,3,4);

and

TLorentzVector v = 10; //this is very similar to how parameter is initialized in your function call.

And your problem has nothing to do with ctor TLorentzVector(const Double_t * carray);
or TLorentzVector(const Float_t * carray); - double can not be converted into pointer.
If the ctor TLorentzVector(Double_t x = 0.0, Double_t y = 0.0, Double_t z = 0.0, Double_t t = 0.0) was declared as ‘explicit’, this will suppress implicit convertion in your example, but, probably, that was not the intention of class’ designers. And your code, in which you call Phi() and pass the result into phi() to calculate phi is quite interesting.