Halt the process in the middle of a C++ macro


ROOT Version: 6.16.00
Platform: CentOS Linux release 7.6.1810 (Core)
Compiler: gcc49


Dear experts,

In pyroot I found it’s quite useful to put a a = raw_input() after drawing a histogram to check the histogram before going further. I wonder if it’s possible in C++ macro?

I tried to use cin >> var in C++ macro like this:

{
  auto h1 = new TH1F();
  h1->Draw();
  gPad->Draw();

  string xx;
  cin >> xx;
}

But the histogram was not drawn before the cin >> xx line…

Thanks,
Dongliang

Hi,

I propose this strategy:

  auto h1 = new TH1F("h","h",64, -4,4);
  h1->FillRandom("gaus");
  h1->Draw();

  gPad->Update();
  gPad->WaitPrimitive();

}

Thanks a lot for the quick reply. This recipe does make the histogram show up. However, sometimes I want to do a bit more interactively, for example, zooming, set the axis to log scale, or even maybe do a fit, save the pad to a figure… These are doable in pyroot. Is it possible in C++ macro?

Hi,

did you try by chance before asking?

Cheers,
D

Yes. I tried this:

{
//   auto h1 = new TH1F();
//   h1->Draw();
//   gPad->Draw();
// 
//   string xx;
//   cin >> xx;

  auto h1 = new TH1F("h","h",64, -4,4);
  h1->FillRandom("gaus");
  h1->Draw();

  gPad->Update();
  gPad->WaitPrimitive();

  h1->FillRandom("gaus",5000);
  h1->Draw();
}

The histogram updated after I click the Pad…

Hi,

great, thanks!

Cheers,
D

I understand your suggestion better now. I can do a lot of things interactively before left-clicking the axises, which will trigger the next step in the macro. Thanks a lot!

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