Drawing histograms on a TCanvas in a Loop

Hi

I’m trying to compare 2 histograms visually.

When drawing single histograms on a single canvas (or different canvases also) I have no problem.
However, if I try to do it in a loop (try to change histograms through the time) - there is a problem:

  • I can’t close the canvas with ‘x’
  • There is no ‘menu bar’
  • I can’t zoom in / zoom out
  • Basically, I can do nothing - there is just picture of histograms

I can change method and try not to use for and while loop, but is there a way to fix this?
Also, what is the reason for it?

Here is the example:

//Test histograms
    TH1D *histMassive[2];

    TH1D *h1 = new TH1D("h1", "Histo from a Gaussian", 100, -3, 3);
    h1->FillRandom("gaus", 10000);

    TH1D *h2 = new TH1D("h2", "Histo from a Gaussian", 100, -3, 3);
    h2->FillRandom("gaus", 10000);

    histMassive[0] = h1;
    histMassive[1] = h2;

    TCanvas *can1 = new TCanvas("canvas1");
    can1->Divide(2, 1);
    //--

    for (int i = 0; i < 2; i++)
    {
        can1->cd(1);
        histMassive[i]->Draw();
        can1->Update();

        TH1D *h = (TH1D *)histMassive[i]->Clone("hclone");
        can1->cd(2);

        int reb = 2;
        while (true)
        {
            int stopInt = 0;
            h->Rebin(reb);
            h->Draw();
            can1->Update();
            cout << "Enter 0 if it's OK:";
            cin >> stopInt;
            if (!stopInt)
                break;
            h = (TH1D *)hADC[i]->Clone("hclone");
            reb++;
        }
    }

_ROOT Version: 6.18/04
Platform: kubuntu 18.04
Compiler: vs code


You cannot use “cin >> stopInt;”. You need to use some “non-blocking I/O” (and “gSystem->ProcessEvents();” calls inside).

I don’t quite understand why I cant use Blocking I/O -
I want the user to choose if (s)he wants to “stay in loop” and make another step or not

P.S. Can you tell some NIO’s I can use here also?

The current GUI is single threaded, if the thread is blocked waiting for user input (cin >> stopInt) nothing will happen since no GUI code will be executed until it returns (and the outstanding events are processed (indirectly) by ProcessEvents). See also TPad::WaitPrimitive

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.