I am trying to draw a canvas with a TGraph inside a loop for some kind of simple event display, using cin to pause the program for each event.
Nothing is shown, except for the last event in the loop which displays correctly. I get the same result with the C++ compiler or the interpreter.
Here is the code with an example drawing a random TGraph:
#include "TRandom.h"
#include "TGraph.h"
#include "TCanvas.h"
#include <iostream>
void test(){
TCanvas *eventCanvas = new TCanvas("eventCanvas","eventCanvas",100,100,500,500);
unsigned markerStyle = 20;
double markerSize = 1.0;
unsigned nEvents = 10;
const unsigned int nHits = 10;
double xg1[nHits], yg1[nHits];
// begin loop on events
for(unsigned int iEvt = 0; iEvt != nEvents; ++iEvt) {
// begin loop on points to build random TGraph
for(int iH = 0; iH != nHits; ++iH){
xg1[iH] = 2.*gRandom->Rndm()-1.;
yg1[iH] = 2.*gRandom->Rndm()-1.;
}// end loop on points
TGraph *gr_xy = new TGraph(nHits, xg1, yg1);
// draw the graph on eventCanvas
eventCanvas->cd();
gr_xy->SetMarkerStyle(20);
gr_xy->SetMarkerSize(1.);
if(nHits) gr_xy->Draw("AP");
// pause
cout << endl << "Next Event?" << endl;
string testString;
cin >> testString;
if(testString == "stop") return;
cout << "OK" << endl;
}// end loop on events
cout << "End of job" << endl;
}// end test
Thanks for reading down to here!
I will appreciate any help you can give me.
BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).
For the forum problem, try the following …
Open the “Preferences” of your web browser (I assume here it’s the Firefox), go to “Privacy & Security”, find and click the link called “remove individual cookies” (in the “History” section). In the “Cookies Search” field, type “cern” and then click “Remove All Shown”. Afterwards, you should be able to login to the forum again.
has no effect.
You can maybe try to copy and paste my code into your root to see if it is a specific problem of my installation.
I am running ROOT 6.06/06 on a MacBook Air with Mac OX 10.11.16.
Also, after purging all CERN cookies I get “Unknown Error” when I try to login to the forum.
For the forum problem, try the following …
Start your web browser, close all tabs and windows which display any “cern” related web pages and then exit the browser. Start your web browser again (no “cern” related web page should be displayed), then remove all “cern” related cookies as described in my previous post and exit the browser again. Finally, start your web browser again and try to login to the forum.
Well, you may also try to “clear your recent history” (forms, cookies, cache, offline data, site preferences, …).
@couet@Axel It seems to me that the gSystem->ProcessEvents(); requirement on Mac OS X introduces a serious incompatibility. Maybe it’s a bug in some particular ROOT versions and/or graphics backend? I have no way to test it on Mac OS X.
Is it with the Cocoa version on Mac ?
If it is the case I think @tpochep may have an idea.
I remember he posted some explanation on this forum regarding this question but I cannot find it now …