0

I wrote a code that loads in ROOT file then creates TChain from file with branches. I assign variables to different branches which I use to fill histograms. I am trying to plot a histogram with a cut. However, when I run the code I get an error message that says "Can't call TH2F::Draw("colz","rnpe<300") in current scope...". You can see the code below

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

1 に答える 1

1

あなたの場合、Draw メソッドが 1 つのパラメーターのみを受け取る TH2F タイプのオブジェクトを描画しています。そのパラメーターは、基本的に「グラフィカル」オプションを設定しています。それを使用してカットを適用することはできません。

カットを適用するには、fill ループで if 条件として実装するか、カットをサポートする TChain の Draw メソッドを使用する必要があります。

于 2014-07-30T07:58:54.280 に答える