Hello all,
I have a query regarding the disappearance of TMarkers I have plotted. I have created a class for some of my work called Skymap, which contains various plotting and output routines using Root classes. However, I am a bit puzzled as to the behaviour of TMarkers.
My class is defined by the following (I’ve cut it right down so only the basics are here):
[code]class Skymap {
public:
Skymap();
~Skymap();
void PlotSinglePoint(const float&,const float&);
void Print(const std::string&);
void DrawAll();
private:
TCanvas mCanvas;
std::vector mMarkers;
}; [/code]
with the source as follows:
[code]Skymap::Skymap()
: mCanvas(“c1”,"",0,0,800,800)
{
mCanvas.Range(-30,-30,30,30);
}
Skymap::~Skymap()
{
}
void Skymap::Print(const std::string& filepth)
{
mCanvas.Print(filepth.c_str());
}
void Skymap::PlotSinglePoint(const float& x,const float& y)
{
mMarkers.push_back(TMarker(x,y,7));
mMarkers.back().Draw();
}[/code]
Now, if I repeatedly call PlotSinglePoint, only the marker corresponding to the most recent function call is shown - all others are invisible upon printing the canvas to a file. If, however, I remove the Draw() command from PlotSinglePoint and, instead, have a function that draws all the TMarkers contained in mMarkers at once:
void Skymap::DrawAll()
{
for(std::vector<TMarker>::iterator vIt=mMarkers.begin();vIt!=mMarkers.end();++vIt){
vIt->Draw();
}
}
all of the TMarkers in mMarkers are present in the image I save.
Can someone please explain why this happens? I’m guessing it’s something to do with the TMarkers going out of scsope and being deleted from mCanvas, but my C++ is not good enough to tell me where that is occurring.
Thanks in advance for any help.