weird trouble with vectors

From: Mario Kadastik <mario.kadastik_at_cern.ch>
Date: Mon, 3 Jul 2006 10:29:05 +0300


Hello,

I couldn't quite figure out why my code is randomly crashing with segfaults until I started to test around segments of it and came to a bizarre conclusion, that vectors are behaving oddly:

[oberon] /home/mario/pythia > root -l -b
root [0] TLorentzVector p1 = TLorentzVector(1,2,3,4)
root [1] p1.M()

(const Double_t)1.41421356237309515e+00
root [2] vector<TLorentzVector> tst;
root [3] tst.push_back(p1)
root [4] tst.size()

(const unsigned int)1

root [5] tst.clear()
root [6] tst.size()
(const unsigned int)0

root [7] tst.push_back(p1)
root [8] tst.size()

Or for example:

[oberon] /home/mario/pythia > root -l -b
root [0] TLorentzVector p1 = TLorentzVector(1,2,3,4)
root [1] TLorentzVector p2 = TLorentzVector(3,4,7,10)
root [2] vector<TLorentzVector> tst;
root [3] tst.size()

(const unsigned int)0
root [4] tst.push_back(p1)
root [5] tst.push_back(p2)
root [6] tst.clear()

what am I doing wrong? This seems to be some basic misunderstanding on my part on vectors. Am I not supposed to clear them? And if I'm not, then why is the function there? Am I misusing it? What I'd like to do is to have two vectors of TLorentzVector type. One for positive particles, other for negative and then I could fill them at every event, iterate over them to generate plots and then at the end of the event clear them for the next event. How am I supposed to do that without using the clear function?



Mario Kadastik
CMS experiment
mario.kadastik_at_cern.ch

"Physics is like sex, sure it may give some practical results, but that's not why we do it"

Received on Mon Jul 03 2006 - 09:29:17 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET