This code used to work, a few years ago. But I have updated my OS and my ROOT in the meantime, and it doesn’t work now. I am running Mac OS 10.11.6, and my ROOT is 6.10/08.
The routine called mczipsteps should run a simple simulation and update the two histograms in the canvas called “results” after each step of the simulation. But it doesn’t do that anymore; it waits (and the spinning beachball comes up) until the macro is finished and then I only see the final histograms.
I hope someone can help me to understand how to fix this.
Try something like mczipsteps(0.1,10) to see what happens.
void mczipsteps(Float_t eot, Int_t nTries) {
int iseed=221137; // random number seed //
int N; // number of links, = Nbins-1 //
float Prel; // relative probability (Boltzmann factor) //
float R; // random number //
float s; // current state label //
float snext; // possible next state //
// The number of bins is one more than the number of links.//
const int Nbins=11;
TCanvas *results = new TCanvas("results","Frequency Distribution",600,40,800,600);
TH1F *sfreq = new TH1F("sfreq","",Nbins,0.,Nbins);
TH1F *slocation = new TH1F("slocation","",Nbins,0.,Nbins);
results->Divide(2,1);
sfreq->SetMinimum(0.0);
sfreq->SetStats(1);
sfreq->SetFillColor(2);
slocation->SetMinimum(0.0);
slocation->SetMaximum(10.0);
slocation->SetStats(0);
slocation->SetFillColor(1);
N=Nbins-1; // This is the number of links.//
Prel=exp(-eot);
gRandom->SetSeed(iseed);
s=0;
sfreq->Reset(); // clears the histogram //
results->cd(1);
sfreq->Draw("HIST"); // draws the histogram in the canvas //
slocation->Reset();
results->cd(2);
slocation->Draw("HIST");
results->Update();
for (int j=0; j<nTries; j++) {
// increment the histo at present location //
sfreq->Fill(s);
slocation->Reset();
slocation->Fill(s);
results->cd(1);
gPad->Modified();
gPad->Update();
results->cd(2);
gPad->Modified();
gPad->Update();
// results->Update();
// choose a possible next value of s //
R=gRandom->Uniform();
if (R < 0.5) {snext = s+1;}
else {snext = s-1;}
// now decide what to do //
if (snext < s) {s=snext;} // always take a lower value //
else { // for larger values, check the Boltzmann factor //
R=gRandom->Uniform();
if (R < Prel) {s=snext;}
}
// check the boundaries //
if (s < 0) {s=0;}
if (s > N) {s=N;}
}
sfreq->Fill(s);
results->cd(1);
gPad->Modified();
gPad->Update();
results->cd(2);
gPad->Modified();
gPad->Update();
// results->Update();
}