Canvas suddenly closing with ROOT terminal not responding

ROOT Version: v 6.14.00
Platform: Windows
Compiler: C++

July 31st
Hi ROOT Forum:
I have some problems in executing this piece of code, the canvas created always close itself before I can read the plots without notifying (less than a second). But I can create a TH1D histogram directly in ROOT program. Moreover, even by adding a
The ROOT panel is still not responding to any commands. After unpausing, the canvas still shuts in less than a second. MCsimang.c (806 Bytes)

Is there any problems with my program that may have contributed to this phenomenon? Or is it hardware malfunction? Thanks for any help!


void MCsimang()
   const auto PbR = 7;
   const auto PbN = 1.3;
   const auto kboxsize = 5;
   const auto events = 10000;
   double a[events];
   double b[events];
   double c[events];
   double m[events];
   double n[events];
   double o[events];
   double x[events];
   auto c11 = new TCanvas("c11", "c11", 800, 800);
   for (auto i=0; i <events; i++) {
      a[i] = (gRandom->Rndm() - 0.5) * 2 * PbR;
      b[i] = (gRandom->Rndm() - 0.5) * 2 * PbR;
      c[i] = (gRandom->Rndm() - 0.5) * 2 * PbR;
      x[i] = sqrt(a[i]*a[i] + b[i]*b[i] + c[i]*c[i]);
      if (x[i] < PbR) {
         m[i] = a[i];
         n[i] = b[i];
         o[i] = c[i];
   c11->Divide(1, 2);

   auto gr = new TGraph(400, m, n);

   auto grr = new TGraph2D(400, m, n, o);

then do:

$ root MCsimang.c 

and you get the following plot on screen as long as you want.


1 Like

Thank you! This functions normally! But what caused the original code to quit without responds?

There was several mistakes. Do a diff between your original macro and the corrected version I sent you.

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