C++ 读取根cern图形的数据文件

C++ 读取根cern图形的数据文件,c++,text-files,graphing,root-framework,C++,Text Files,Graphing,Root Framework,我创建了一个脚本,从文本文件中获取数据并在根目录(CERN)中对其进行图形化,但大约一年没有使用根目录,已更新为当前版本的根目录,现在出现错误“错误:函数readprn()未在当前作用域中定义:0: *解释器错误已恢复*“当我尝试将其与Root一起使用时 它运行一个excel数据文件,我将其保存为txt文件。第一列是对应于后续768列中每个y值的x值。最后,它在两个图上绘制、拟合和循环 我最想知道的是,新版本中是否有任何内容会导致root无法读取此内容 #include <TGraph.h

我创建了一个脚本,从文本文件中获取数据并在根目录(CERN)中对其进行图形化,但大约一年没有使用根目录,已更新为当前版本的根目录,现在出现错误“错误:函数readprn()未在当前作用域中定义:0: *解释器错误已恢复*“当我尝试将其与Root一起使用时

它运行一个excel数据文件,我将其保存为txt文件。第一列是对应于后续768列中每个y值的x值。最后,它在两个图上绘制、拟合和循环

我最想知道的是,新版本中是否有任何内容会导致root无法读取此内容

#include <TGraph.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TMath.h>
#include <TStyle.h>

#include <iostream>
#include <fstream>
#include <string>

using std::cout;    using std::endl;

int threshold1(Int_t channel=0)
{
    const char* ifname = "thresholdScanRun110FPGA4.txt";

    cout<< "processing file " << ifname <<endl;
    std::ifstream ifile(ifname);
    if (!ifile) {
        cout<< "Could not find file " << ifname <<endl;
        return 0;
    }

    //std::string line;
    // discard the first two lines
    //std::getline(ifile, line);
    //cout<< line <<endl;
    //std::getline(ifile, line);
    //cout<< line <<endl;

    std::string str;
    double number;

    // read the first row (in sense of Exel's row)
    ifile >> str;
    //cout<< str <<endl;
    for (int i=0; i<768; ++i) {
        ifile >> number;
        //cout<< number << " ";
    }
    //cout<<endl;
    // read the second "row"
    ifile >> str;
    //cout<< str <<endl;
    for (int i=0; i<768; ++i) {
        ifile >> number;
        //cout<< number << " ";
    }
    //cout<<endl;

    double thres[60];
    double prob[60][768];
    int nthres_max = 60;

    for (int ithres=0; ithres<nthres_max; ++ithres) {
        ifile >> thres[ithres];
        for (int iprob=0; iprob<768; ++iprob) ifile >> prob[ithres][iprob];
    }

    cout<< "The channel " << channel <<endl;
    for (int ithres=0; ithres<60; ++ithres) {
        cout<< thres[ithres] << " " << prob[ithres][channel] <<endl;
    }

    Double_t probability[60];
    for (int ithres=0; ithres<60; ++ithres) probability[ithres] = prob[ithres][channel];
    TGraph* gr = new TGraph(60, thres, probability);
    gr->SetMarkerStyle(29);
    gr->SetMarkerColor(4);
    gr->SetTitle("Threshold Scan ChipX, ChanY");

    TF1* ferfc = new TF1("ferfc", "0.5*TMath::Erfc((x-[0])/[1])", 0, 767);
    ferfc->SetParameters(100,10);

    new TCanvas;
    gStyle->SetOptFit(1);
    gr->Draw("apl");
    gr->Fit("ferfc");

    return 0;
}

int threshold_all()
{
    for (Int_t channel=0; channel<2; ++channel) {
        threshold1(channel);
    }
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用std::cout;使用std::endl;
整数阈值1(整数通道=0)
{
const char*ifname=“thresholdScanRun110FPGA4.txt”;

cout在root 6.07/04中加载宏时,使用
.L macro.C
我收到以下警告:

/tmp/tmp.rQTNVdlydv/macro.C:88:1: error: control reaches end of non-void function [-Werror,-Wreturn-type]
这是因为在
intthreshold\u all()
中没有return语句。修复这个宏对我来说似乎很好。(运行、打开画布、一些fit输出。由于我没有您的输入值,我只是创建了一个包含一些虚构数字的文本文件,并将阈值和值的数量减少到5x6。这就是为什么我不担心收到的异常fit终止。)


也加载了编译<代码> >宏.C+< /Cord>一旦添加返回语句就很好。

我想你需要C++标签。“解释错误收到”这可能意味着您只是在运行此脚本而没有编译它。您编译过它吗?如果没有,请在ROOT之外编译它。ROOT最近从v5升级到v6,并且CINT解释器已被GRANG(不,不是clang)取代,这对它将允许的内容限制更多。也就是说,使用gcc或clang编译它并在ROOT之外运行。它应该告诉您发生了什么。