TLorentz vector and interger

Hello, today I spent a lot of time to find this bug in my program: I have a function

void function(const TLorentzVector v);

but for some reson I was calling it with


it was very difficult because the compiler didn’t tell me anything. In fact I found that an integer can be converted to a TLorentzVector

TLorentzVector a;
a = 1.2;

is this a feature? Do we need it? I think it is dangerous


you should file a bug report on this here:

That you can do this comes from the fact that TLorentzVector defines a constructor taking 4 doubles where you can omit as many arguments as you like. The missing arguments are taken as 0 then.

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

In your case you gave x and everything else was set to 0.

I think this constructor is totally silly since it makes little sense to only give one component. Either give all components or none (which would set everything to zero). I.e. replace above function with

TLorentzVector(Double_t x, Double_t y, Double_t z, Double_t t);
TLorentzVector() : fP(0, 0, 0), fE(0) { };

The offending code is in math/physics/inc/TLorentzVector.h. Please file a bug report so this gets fixed.