C错误:在“{”标记之前应为非限定id
我输入的是:gcc-o plot_na22.C 我得到的是:plot_na22.C:1:error:在“{”标记之前应该是非限定id 我不知道我在做什么。这是别人的代码,我不知道为什么它不起作用。有什么建议吗C错误:在“{”标记之前应为非限定id,c,C,我输入的是:gcc-o plot_na22.C 我得到的是:plot_na22.C:1:error:在“{”标记之前应该是非限定id 我不知道我在做什么。这是别人的代码,我不知道为什么它不起作用。有什么建议吗 { // ROOT style junk gStyle->SetOptStat(0); gStyle->SetTitleFont(132, "XYZ"); gStyle->SetLabelFont(132, "XYZ"); // some const
{
// ROOT style junk
gStyle->SetOptStat(0);
gStyle->SetTitleFont(132, "XYZ");
gStyle->SetLabelFont(132, "XYZ");
// some constants for binning
double qmin = 0.0;
double qmax = 500.0;
int qbins = 250;
double fmin = 0.0;
double fmax = 1.0;
int fbins = 200;
double rscale = 435.0;
double rmin = 0.0;
double rmax = pow(435.0 / rscale, 3);
int rbins = 200;
// 1D charge, fprompt, and scaled centroid histograms
TH1D* hq = new TH1D("hq", "", qbins, qmin, qmax);
hq->SetLineColor(4);
hq->SetXTitle("Charge (PE)");
TH1D* hf = new TH1D("hf", "", fbins, fmin, fmax);
hf->SetLineColor(4);
hf->SetXTitle("f_{p}");
TH1D* hr = new TH1D("hr", "", rbins,
pow(rmin/rscale, 3), rmax);
hr->SetLineColor(4);
hr->SetXTitle("(r / r_{tpb})^{3}");
// 1D reconstructed coordinate histograms
TH1D* hx = new TH1D("hx", "", rbins, -rscale, rscale);
hx->SetLineColor(4);
hx->SetXTitle("Position (mm)");
TH1D* hy = new TH1D("hy", "", rbins, -rscale, rscale);
hy->SetLineColor(2);
hy->SetXTitle("Position (mm)");
TH1D* hz = new TH1D("hz", "", rbins, -rscale, rscale);
hz->SetLineColor(3);
hz->SetXTitle("Position (mmm)");
// 2D histograms
TH2D* hfq = new TH2D("hfq", "", qbins, qmin, qmax, fbins, fmin, fmax);
hfq->SetMarkerColor(4);
hfq->SetMarkerStyle(20);
hfq->SetMarkerSize(0.3);
hfq->SetXTitle("Charge (PE)");
hfq->SetYTitle("f_{p}");
TH2D* hfr = new TH2D("hfr", "", rbins, rmin, rmax, fbins, fmin, fmax);
hfr->SetMarkerColor(4);
hfr->SetMarkerStyle(20);
hfr->SetMarkerSize(0.3);
hfr->SetXTitle("(r / r_{tpb})^{3}");
hfr->SetYTitle("f_{p}");
TH2D* hqr = new TH2D("hqr", "", qbins, qmin, qmax, rbins, rmin, rmax);
hqr->SetMarkerColor(4);
hqr->SetMarkerStyle(20);
hqr->SetMarkerSize(0.3);
hqr->SetXTitle("Charge (PE)");
hqr->SetYTitle("(r / r_{tpb})^{3}");
TH2D* hang = new TH2D("hang", "",
rbins/2, -TMath::Pi(), TMath::Pi(), rbins/2, -1.0,1.0);
hang->SetMarkerStyle(20);
hang->SetMarkerSize(0.2);
hang->SetMarkerColor(4);
hang->SetXTitle("#phi");
hang->SetYTitle("cos(#theta)");
// create a tchain with the simulated data
TChain* tree = new TChain("T", "T");
tree->Add("/home/benjiang/fuck/realdata_*.root");
RAT::DS::Root* ds = new RAT::DS::Root();
tree->SetBranchAddress("ds", &ds);
// count for the number of triggers
int ntriggers = 0;
// begin reading events
for(int iev=0; iev<tree->GetEntries(); iev++){
if(iev % 10000 == 0)
printf("event %i\t of %i\t%i triggers\n", iev, tree->GetEntries(), ntriggers);
tree->GetEvent(iev);
// ignore this event if there wasn't an event trigger
if(ds->GetEVCount() != 1)
continue;
RAT::DS::EV* ev = ds->GetEV(0);
ntriggers ++;
// ignore this event if a data quality cut failed for some reason
if(!ev->GetPassAllCuts())
continue;
// get values from the data structure
double q = ev->GetQPE();
double f = ev->GetFprompt();
TVector3 v = ev->GetCentroid()->GetPosition();
double r = pow(v.Mag() / rscale, 3.0);
// fill histograms
hq->Fill(q);
hr->Fill(r);
hf->Fill(f);
hx->Fill(v.X());
hy->Fill(v.Y());
hz->Fill(v.Z());
hfq->Fill(q, f);
hfr->Fill(r, f);
hqr->Fill(q, r);
hang->Fill(v.Phi(), TMath::Cos(v.Theta()));
};
// legend for 1D coordinate histograms
TLegend* plegend = new TLegend(0.6, 0.6, 0.8, 0.8);
plegend->SetLineColor(0);
plegend->SetFillColor(0);
plegend->AddEntry(hx, "#font[132]{x}", "l");
plegend->AddEntry(hy, "#font[132]{y}", "l");
plegend->AddEntry(hz, "#font[132]{z}", "l");
// canvases to draw the histograms
TCanvas* c0 = new TCanvas("c0", "", 0, 0, 1400, 1200);
c0->Divide(3, 2);
c0->cd(1);
hq->Draw();
c0->cd(2);
hf->Draw();
c0->cd(3);
hr->Draw();
c0->cd(4);
hfq->Draw("colz");
c0->cd(5);
hfr->Draw("colz");
c0->cd(6);
hqr->Draw("colz");
c0->Update();
TCanvas* c2 = new TCanvas("c2", "", 0, 0, 1400, 600);
c2->Divide(2, 1);
c2->cd(1);
hx->Draw();
hy->Draw("same");
hz->Draw("same");
plegend->Draw();
c2->cd(2);
hang->Draw("colz");
c2->Update();
// write the histograms and canvases to a root file
TFile* outfile = new TFile("plot_na22.root", "recreate");
outfile->cd();
c0->Write();
c2->Write();
hq->Write();
hf->Write();
hr->Write();
hfq->Write();
hfr->Write();
hqr->Write();
hx->Write();
hy->Write();
hz->Write();
hang->Write();
outfile->Close();
}
你不能用{启动一个C源文件并直接编译它。这只是一个语法错误。因此,从根本上说,你需要找出如何/在何处使用它,并以那种方式使用它。他的建议似乎是一种有用的方法: grep "include.*plot_na22.C" * -ir
也许最初的作者在另一个文件的include中使用了它,这不是一个好主意,但确实发生了,但这只是猜测。它很高兴地开始使用它没有定义的gStyle或externd之类的符号,这当然是非常可疑的。看起来你有一个C文件是为ROOT用户准备的。你不能用它自己编译它我不熟悉ROOT,但是试试这个
root plot_na22.C
@FiddlingBits因为错误是第1行,我猜没什么。你的意思是文件的第一行实际上只是一个{?这是其他人的代码,我不知道为什么它不工作。因为如果第1行真的以{只有当included位于另一个C源文件的适当位置时,才能使用该文件。请在相关的源代码库上执行grep include.*plot_na22.C*-ir以查找该文件。希望原始作者没有这样做。那将是肮脏和肮脏的!@FiddlingBits:确实会。正如Joel所建议的,该文件看起来像是为ROO准备的理想的是,一个可以写有效的C++,然后C++会被root用户接受,但是根有一点许可,并且允许未命名的宏至少在ROTT5之前,我不知道根RoT6是多么严格。这意味着文件没什么意义,虽然我会说编写根代码是不好的。作为C++的添加,一个可以,我会说应该编写在根中工作的代码,并且可以编译。{在第一行中,并添加缺省包括。然后,可以用root的根目录,用根目录,root PrpTy22A.C+编译,用root和G++$root RoFig -cFLAGS $root CONFIG-LIBS-O图PrtutN22C。一定要使用C++编译器,而不是C编译器,并从根CONFIG命令提供编译器和链接标志。