使用ROOT绘制直方图时的空画布

时间:2014-07-24 00:51:14

标签: git histogram root-framework

我编写了一个在ROOT文件中加载的代码,然后从带有分支的文件创建TChain。我将变量分配给不同的分支,我用它来填充直方图。我试图用切割绘制直方图。但是,当我运行代码时,我收到一条错误消息,上面写着"无法调用TH2F :: Draw(" colz"," rnpe< 300")in目前的范围......"。您可以看到以下代码

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");

1 个答案:

答案 0 :(得分:0)

在你的情况下,你正在绘制一个TH2F类型的对象,Draw方法只接受一个参数。该参数基本上是设置“图形”选项。你无法使用它进行切割。

要应用剪切,您需要在填充循环中将其实现为if if条件,或者您可以使用支持剪切的TChain的Draw方法。