Drawing multiple TMarkers in a loop

I’m trying to use TMarkers to draw a rolling average on top of a histogram while I scan over the values of the histogram to make sure my rolling average code is working. However, I can’t seem to draw multiple TMarkers in a ROOT macro and I am looking at a compiled program I wrote a year ago where I was able to get it to work (using TMarker::DrawMarker to draw multiple copies). Can someone point out why the following macro doesn’t produce any TMarkers on the canvas? Or how to fix it? Thanks you.

[code]{

TCanvas* c1 = new TCanvas();
TH1F* h1 = new TH1F("h1", "h1", 100, 0, 10);
h1->FillRandom("gaus");
h1->Draw();

TMarker* mark;
for(int i=0; i>10; i++) {
    mark = new TMarker(i, i*10, 23);   // Does this die outside the loop?
    mark->SetMarkerStyle(23);
    mark->SetMarkerColor(kRed);
    mark->Draw();
}

}[/code]

replace

for(int i=0; i>10; i++) { by

for(int i=0; i<10; i++) {

Rene

:blush:

Hi,

[quote]replace

for(int i=0; i>10; i++) { by

for(int i=0; i<10; i++) {
[/quote]

You are by no means not the first to make such a mistake and you certainly won’t be the last. :smiley:

When you are having problems like this, it helps a lot to put print statements to let you know what your code is doing. One trick is to litter your code with

std::cout << __LINE__ << std::endl;

(This works with both compiled code and Cint. If you have multiple files, you can add ‘FILE’ as well).

which will print out the current line in the file.

And don’t forget to print out useful quantities (e.g., the loop variable).

Cheers,
Charles