hi experts,
I would like to make a simple movie of 1d histograms.
#include <unistd.h>
#include <stdio.h>
#include <TH2F.h>
#include <TH1F.h>
TH1F *readDataFile(char* fname, int nch) {
int ch,counts;
float fc;
TH1F *h = new TH1F("h1","",nch,-0.5,nch-0.5);
FILE* fp=fopen(fname,"r");
if (fp==NULL) {
printf("Could not open file %s\n",fname);
return h;
}
for (int j=0; j<nch; j++) {
fscanf(fp,"%d %f",&ch,&fc);
counts=fc;
h->SetBinContent(j+1,fc);
}
fclose(fp);
h->Sumw2();
return h;
}
TH2F* createScan(char* fn, int mi, int ma, int step, int nch) {
char fname[100];
TH1F *hdum;
Int_t nstep=((ma-mi)/step)+1;
TH2F *h2 = new TH2F("h2","",nch,-0.5,nch-0.5,nstep,mi-step/2., ma+step/2.);
h2->SetStats(kFALSE);
for (float i=mi; i<ma+1; i=i+step) {
sprintf(fname,fn,i);
hdum=readDataFile(fname, nch);
for (int j=0; j<nch; j++)
h2->Fill(j,i,hdum->GetBinContent(j+1));
delete hdum;
}
return h2;
}
float movie_function (TH2F *h2) {
float V;
int minChan;
int maxChan;
TH1F *hdum;
for(int ichan = minChan; ichan<maxChan+1; ichan++) {
hdum = getCh (h2,ichan);
hdum->Draw();
usleep(40000); // do i need to reset something here, apart from making the system sleep? As I loop, I want to get rid of the old image and load a new image.
}
return V;
}
Many thanks
F.