我编写了一个加载到 ROOT 文件中的代码,然后从带有分支的文件创建 TChain。我将变量分配给用于填充直方图的不同分支。我正在尝试绘制带有切割的直方图。但是,当我运行代码时,我收到一条错误消息,上面写着“Can't call TH2F::Draw("colz","rnpe<300") in current scope...”。你可以看到下面的代码
void MakePlots(string filename)
{
gROOT->Reset();
gStyle->SetPalette(1);
gStyle->SetCanvasColor(0);
gStyle->SetStatBorderSize(1);
TCanvas* recon_zx_1c = new TCanvas("c1", "recon_zx",10,10,700,500);
TCanvas* recon_zx_2c = new TCanvas("c2", "recon_zx", 10,10,700,500);
TCanvas* recon_zx_3c = new TCanvas("c3", "recon_zx", 10,10,700,500);
TCanvas* recon_zx_4c = new TCanvas("c4", "recon_zx", 10,10,700,500);
TChain Data("clusters");
Data.Add(filename.c_str());
// Variable declaration
Double_t rz, rx, rnpe;
// The SetBranchAddress process sets things up so that when you call GetEntry(i), the value of laben.recon.r is stored in the variable reconr, and likewise for all of the others.
Data.SetBranchAddress("laben.recon.z",&rz);
Data.SetBranchAddress("laben.recon.x",&rx);
Data.SetBranchAddress("laben.cluster.npe",&rnpe);
int NumEvents=Data.GetEntries();
cout << "There are " << NumEvents << " events in this run" << endl;
//Definition of the Histograms
TH2F *recon_zx_1 = new TH2F("Recon_1","Recon_1",40,-9,9,40,-9,9);
TH2F *recon_zx_2 = new TH2F("Recon_2","Recon_2",40,-9,9,40,-9,9);
TH2F *recon_zx_3 = new TH2F("Recon_3","Recon_3",40,-9,9,40,-9,9);
TH2F *recon_zx_4 = new TH2F("Recon_4","Recon_4",40,-9,9,40,-9,9);
/*
Loop on Events
*/
for(int event=0;event<NumEvents;event++){
if(event%1000==0) cout << "Processing Event " << event << endl;
Data.GetEvent(event);
recon_zx_1->Fill(rz,rx);
recon_zx_2->Fill(rz,rx);
recon_zx_3->Fill(rz,rx);
recon_zx_4->Fill(rz,rx);
}
recon_zx_1c->cd();
recon_zx_1->Draw("colz","rnpe<300");