gpt4 book ai didi

c++ - ROOT(cern) FILE reading+TGraph 工作正常,但 TGraphErrors 不想要

转载 作者:行者123 更新时间:2023-11-28 06:07:28 24 4
gpt4 key购买 nike

接下来的问题是:我已将数据从文件读取到数组。图表绘制没有任何问题。但是 TGraphErrors 不想做任何事情。根说

Error: Can't call TGraphErrors::SetPoint(i,Data[0][i],Data[1][i],Data[2][i],Data[2][i]) in current scope plot2.C:85: Possible candidates are... (in TGraphErrors) (in TGraph) /usr/local/Cellar/root/5.34.26/lib/root/libHist.so -1:-1 0 public: virtual void TGraph::SetPoint(Int_t i,Double_t x,Double_t y); * Interpreter error recovered *"

代码如下:

    void plot2(char* fin1){
const int VAR_N=20,NPOINTS=10000;
Double_t Data[VAR_N][NPOINTS];
int counts,N1;
float E,E1,dE;
FILE* fin12;
printf("%s \n",fin1);
fin12 = fopen(fin1,"r");
if (fin12 == NULL){
printf("Can't open input file: %s !\n",fin1);
}
else{
counts=0;
while (!feof(fin12)) {
fscanf(fin12, "%f %f %f \n",&E,&E1,&dE);
printf("%f %f %f \n",E,E1,dE);
Data[0][counts] = E;
Data[1][counts] = E1;
Data[2][counts] = dE; }
N1=counts;
printf("NP1=%d ",N1);
fclose(fin12);
}
TGraph* V_Graph = new TGraph(N1);
TGraphErrors* V_GraphErrors = new TGraphErrors(N1);
for(int i=0;i<N1;i++){
V_Graph->SetPoint(i,Data[0][i],Data[1][i]);
}
for(int i=0;i<N1;i++){
V_GraphErrors->SetPoint(i,Data[0][i],Data[1][i],Data[2][i],Data[2][i]);
}

TCanvas *c1 = new TCanvas("c1", "c1", 1200, 1000);
c1->cd(1);
TString VName="+Errors";
V_Graph->SetTitle(VName);
V_Graph->SetMarkerStyle(21);
V_Graph->SetMarkerSize(1);
V_Graph->SetMarkerColor(kBlue);
V_Graph->GetXaxis()->SetTitle("x");
V_Graph->GetYaxis()->SetTitle("y");
V_Graph->GetXaxis()->SetLimits(4.,25.);
V_Graph->GetYaxis()->SetRangeUser(10.,80.);
V_Graph->Draw("APL");

V_GraphErrors->SetMarkerStyle(21);
V_GraphErrors->SetMarkerSize(1);
V_GraphErrors->SetMarkerColor(kGreen);
//V_Graph->GetXaxis()->SetLimits(4.,11.);
//V_Graph->GetYaxis()->SetRangeUser(45.,80.);
V_GraphErrors->Draw("C*");
}

我是 root 用户的新手。可能我做的很蠢,但没有注意到。那我做错了什么?提前谢谢你
奥尔卡

最佳答案

问题是没有 SetPointError 方法带有您尝试使用的签名 (int, Double_t, Double_t, Double_t, Double_t)。要设置错误,您应该使用 SetPointError(Double_t ex, Double_t ey) 方法。例如,在您上面的代码中,您将执行如下操作:

V_GraphErrors->SetPoint(i,Data[0][i],Data[1][i]]);
V_GraphErrors->SetPointError(i,Data[2][i],Data[2][i]);

尽管直接在构造函数中传递 arrys 可能会更容易:

V_GraphErrors(N1, Data[0], Data[1], Data[2], Data[2]);

顺便说一句,这会将 x 和 y 错误设置为相同。我不确定这是否是您想要的。

参见 https://root.cern.ch/root/html/TGraphErrors.html有关 TGraphErrors 中可用方法的详细信息

关于c++ - ROOT(cern) FILE reading+TGraph 工作正常,但 TGraphErrors 不想要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32110243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com