读取数据文件为根CERN绘图

reading data file for root cern graphing

本文关键字:CERN 绘图 数据 文件 读取      更新时间:2023-10-16

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

它运行一个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);
    }
}

在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]

这是因为在int threshold_all()中没有返回语句。修复这个宏观对我来说似乎很好。(运行,打开画布,一些合适的输出。因为我没有您的输入值,所以我只创建了一个文本文件,其中包含一些虚构的数字,并将阈值和值的数量减少到5x6。这就是为什么我不关心我收到的异常匹配终止。

也加载宏与编译.L macro.C+看起来很好,我一旦添加返回语句。