Hello,
I created an 1D array of TH2D, and I want to fill the histograms and get the RMS for the two axis. In order to do that I wrote:
TH2D *pxx[1001];
char *histname = new char[30];
char *histtype = new char[30];
char *histcuts = new char[100];
for(int i=0;i<=1000;i=i+100){
sprintf(histname, "h_x_%d",i);
pxx[i]=new TH2D(histname,"",100,-(xx+i*dx),xx+i*dx,100,-(pxpx+i*dpx),pxpx+i*dpx);
sprintf(histtype, "px:x>>pxx[%i]",i);
sprintf(histcuts, "n_cycle<=%i", i);
mu.Draw(histtype,histcuts,"goff");
sigmax[i]=pxx[i]->GetRMS(1);
sigmapx[i]=pxx[i]->GetRMS(2);
emittx[i]=sigmax[i]*sigmapx[i]*sqrt(1-pow(pxx[i]->GetCorrelationFactor(1,2),2));
cout<<i<<" "<<sigmax[i]<<" "<<sigmapx[i]<<" "<<emittx[i]<<endl;
}
sadly in the cout I get the correct values of i but for the rest I get all zeroes. If instead I fill a “regular” histogram (non-array) with the same data and then proceed to get the RMS I get the correct values, as in:
TH2D *pxx0 = new TH2D("pxx0","",100,-2e-4,2e-4,100,-1e-3,1e-3);
int i=0;
mu.Draw("px:x>>pxx0","n_cycle==0","col");
sigmax[i]=pxx0->GetRMS(1);
sigmapx[i]=pxx0->GetRMS(2);
emittx[i]=sigmax[i]*sigmapx[i]*sqrt(1-pow(pxx0->GetCorrelationFactor(1,2),2));
cout<<i<<" "<<sigmax[i]<<" "<<sigmapx[i]<<" "<<emittx[i]<<endl;
Also, the histograms in the array are correctly filled because if drawn they show the correct distributions.