0

我创建了一个脚本来从文本文件中获取数据并在 Root (CERN) 中绘制它,但大约一年没有使用 root,更新到当前版本的 Root,现在它收到错误“错误:函数 readprn()未在当前范围内定义 :0: * 解释器错误已恢复 * " 当我尝试将它与 Root 一起使用时。

它运行一个我保存为 txt 文件的 excel 数据文件。第一列是后续 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);
    }
}
4

1 回答 1

0

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

/tmp/tmp.rQTNVdlydv/macro.C:88:1: error: control reaches end of non-void function [-Werror,-Wreturn-type]

这是因为您在int threshold_all(). 修复这个宏对我来说似乎很好。(运行,打开画布,一些合适的输出。由于我没有您的输入值,我只是创建了一个带有一些发明数字的文本文件,并将阈值和值的数量减少到 5x6。这就是为什么我不是担心我收到的异常适合终止。)。

一旦添加了 return 语句,对我来说,用编译加载宏也.L macro.C+很好。

于 2016-04-06T09:21:21.297 回答