Code crashing while accessing TLorentz vector

Hello Expert,

While running my code I found that it is crashing with an error:

Error: Symbol #include is not defined in current scope (tmpfile):1:
Error: Symbol exception is not defined in current scope (tmpfile):1:
Syntax Error: #include (tmpfile):1:
Error: Symbol G__exception is not defined in current scope (tmpfile):1:
Error: type G__exception not defined FILE:(tmpfile) LINE:1
(void)0

I inspected my code line by line and found that while accessing the TLorentz vector on line number 155 and 157 when I do
TLorentzVector J1=JetVec.at(0); and TLorentzVector J2=JetVec.at(1);

the code crashes. If I remove these two lines I dont get any error. Am I doing some thing wrong or stupid? Please help. The code is attached.
trial.C (3.7 KB)

How about:

if (JetVec.size() >= 2) { TLorentzVector J1 = JetVec.at(0); TLorentzVector J2 = JetVec.at(1); }

Thanks it worked like magic. But why was it not running before? Another problem is I am getting this warning:

Warning in TVector3::PseudoRapidity: transvers momentum = 0! return +/- 10e10

Is this a serious warning or I can ignore

See what “pseudo-rapidity” (returned by the “PseudoRapidity()” and also by the “Eta()” methods) is: http://root.cern.ch/root/html/TVector3.html
Apparently “CosTheta()” = +/- 1 (“Pt()” = “Px()” = “Py()” = 0) sometimes in your data.
It’s up to you to understand why this happens and what to do in this case.

[quote]Thanks it worked like magic. But why was it not running before?[/quote]Without the test for the length of the vector, you could try to access and copy objects pass the end of the vector (i.e. essential reading random memory … resulting in random behavior).

Philippe.