-5
(我想通過使用根包繪製直方圖此算法應用於所述連接的數據,我有此錯誤。通過起訴根
error Warning: Automatic variable a1 is allocated cuts3.C:31:
Error: Array index out of range v -> [2] valid upto v cuts3.C:31:
Error: Array index out of range v -> [3] valid upto v cuts3.C:31:
Error: Array index out of range v -> [4] valid upto v cuts3.C:31:
Error: Array index out of range v -> [5] valid upto v cuts3.C:31:
Error: Array index out of range v -> [6] valid upto v cuts3.C:31:
{
#include <string.h>
gROOT->Reset();
ifstream in;
in.open("calibrated.txt");
Int_t crysmax=8;
double e[crysmax];
Int_t nlines = 0;
Int_t nbins2d=500;
double coinmin=1, coinmax=1500, minE2d=1, maxE2d=1500, addcoin;
TFile *f = new TFile("cuts.root","RECREATE");
TH2F *hgate2d = new
TH2F("Gate2D","",nbins2d,minE2d,maxE2d,nbins2d,minE2d,maxE2d);
int i=0;
while (!in.eof())
{
in >>e[0]>>e[1]>>e[2]>>e[3]>>e[4]>>e[5]>>e[6]>>e[7];
addcoin=0.;
// Background elimination.
for (int k=0; k<crysmax; k++)
{
double v[k] = log(log(sqrt(e[k]+1)+1)+1);
for (int p=1; p<=6; p++)
{
for (k=p; k<crysmax-p; k++)(
a1=v[k];
a2=(v[k-p]+v[k+p])/2;
double w[k]=min(a1,a2);
}
for (k=p; k<crysmax-p;k++)
{
v[k]= w[k];
}
for (k=0; k<crysmax; k++)
{
double b[k]=exp(exp(v[k]-1)-1)* exp(exp(v[k]-1)-1)-1;
}
for (int k=0;k<crysmax;k++)
{
addcoin=0.;
if (e[k]>=coinmin&&e[k]<=coinmax)
{
for (int kk=0;kk<crysmax;kk++)
{
if (kk!=k) addcoin+=e[kk];
}
hgate2d->Fill(e[k],addcoin);
}
}
nlines+=1;
cout << nlines << endl;
}
in.close();
gStyle->SetPalette(1);
gStyle->SetOptStat(0);
hgate2d->Draw(); // Draw("COL");
b = new TBrowser();
f->Write();
}
這是所有的代碼是什麼?第31行是'for(k = p; k
doctorlove
@doctorlove call到'new'繼續在下一行 – user463035818
而'v'is ...?'double v [k] = ...'對我來說看起來是錯誤的。不應該在循環之前聲明/分配足夠的「時隙「?但是,也許代碼被格式化(對於我的眼睛),請諮詢。 – Dilettant