Zoom axis in loop

I want to write a code that plots several histograms but before ending asks the user if they’d like to change the histogram parameters and re-plot. Basically,

do{

cin >> choice;
} while(choice == ‘y’);

However, the plot axes cannot be zoomed while in the loop, which is necessary to determine how the parameters should be changed. I’ve tried gSystem->ProcessEvents() at various locations in the loop to no avail.

Can someone please help me to solve this problem?

A small running macro would be needed if you want somebody helps you.

Yes please, some help would be great. Here’s a little sample function of the type that I want to loop until the user decides to quit:

#include <Riostream.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <TRandom.h>
#include <TSystem.h>

TCanvas *SimpleCanvas1;
TH1F *Hist1;

void user_query(){

  Char_t choice = 'y';

  Float_t GausDist;
  Float_t mean=74.0,sigma=4.0;

  Hist1 = new TH1F("Hist1","My Histogram",1000,0.0,100.0);

  TRandom random;

  do{
    SimpleCanvas1 = new TCanvas();
    
    for(int i = 0;i<1000000;i++) {      
      GausDist  = random.Gaus(mean,sigma);
      Hist1->Fill(GausDist);
    }     
    
    Hist1->Draw();      
    SimpleCanvas1->Modified();
    gSystem->ProcessEvents();

    cout << "do again? ";
    cin >> choice;
    if(choice == 'y'){
      cout << "enter new mean, sigma: ";
      cin >> mean;
      cin >> sigma;
    }

  }while(choice == 'y');
}

I ran your macro the following way:

Processing user_query.C...
do again? y
enter new mean, sigma: 50 4
do again? y
enter new mean, sigma: 60 0.5
do again? n

At the end I get 3 nice peaks.

What should I do to see the problem ? looking at the code it looks like it does what is expected…

As far as I understand it … the original problem is that while the macro is executing one of “cin >> choice;”, “cin >> mean;”, “cin >> sigma;”, one cannot interactively zoom the canvas (because processing of events is blocked by the “operator>>” when it is waiting for the user’s input).
So, one needs a routine which in some kind of a loop “waits until user presses enter” in a non-blocking way and inside of this loop one would simply need to call “gSystem->ProcessEvents();” in regular intervals. Once the “input is ready to be extracted”, one calls an appropriate “cin >>”.
I did have something like this a long time ago but I cannot find it now, sorry.
Instead of a simple loop waiting for available input, you could probably create and run a thread which would call “gSystem->ProcessEvents();” in regular intervals.

In tat case a small GUI is needed.
Check the examples.

[quote=“Pepe Le Pew”]So, one needs a routine which in some kind of a loop “waits until user presses enter” in a non-blocking way and inside of this loop one would simply need to call “gSystem->ProcessEvents();” in regular intervals. Once the “input is ready to be extracted”, one calls an appropriate “cin >>”.
I did have something like this a long time ago but I cannot find it now, sorry.
Instead of a simple loop waiting for available input, you could probably create and run a thread which would call “gSystem->ProcessEvents();” in regular intervals.[/quote]

Why do you need to do simple things in a such complex unreliable way? In your macro define a function, which accepts as parameters values you now set using std::cin. Call this function passing different arguments (values). In any case it’s not good idea to mix std::cin and ROOT’s gSystem->ProcessEvent (which is also able to read from standart input and make a blocking call).