0

此宏适用于ROOT (cern) TTree对象。其目的是显示一个直方图并从中减去另一个直方图。树是朋友。我正在尝试使用这些Draw()选项从另一个中减去一个直方图;

tree1->Draw("hit_PMTid - plain.hit_PMTid");

然而,它使错误的轴为负。结果看起来像;

奇怪的对称图

据我所知,这些图表的形状几乎相同,这显然是它们背靠背的显示。我怎样才能让它改变它减去的轴,从x到y?

它可能不需要,但这是完整的宏;

void testReader3(){
  TFile * file1 = TFile::Open("alt4aMaskOutput.root");
  TTree * tree1 = (TTree*)file1->Get("HitsTree");
  tree1->AddFriend("plain = HitsTree", "plainMaskOutput.root");

  tree1->Draw("hit_PMTid - plain.hit_PMTid");
}
4

1 回答 1

2

您给出的命令将为树的每个事件生成hit_PMTid和变量之间差异的直方图。plain.hit_PMTid相反,如果您想查看分布中的 bin 差异,则需要填充两个直方图,然后减去它们(使用TH1::Add)。正如您所说,您必须强制执行相同的分箱。这方面的一个例子是:

void testReader3(){
  TFile * file1 = TFile::Open("alt4aMaskOutput.root");
  TTree * tree1 = (TTree*)file1->Get("HitsTree");
  tree1->AddFriend("plain = HitsTree", "plainMaskOutput.root");

  // Draw the two histograms from the tree, specifying the
  // output histogram name and binning
  tree1->Draw("hit_PMTid>>hist1(100,0,6000)");
  tree1->Draw("plain.hit_PMTid>>hist2(100,0,6000)");

  // Retrieve the two histograms we just created
  TH1* hist1 = gDirectory->Get("hist1");
  TH1* hist2 = gDirectory->Get("hist2");

  // Subtract
  TH1* hist_diff = (TH1*) hist1->Clone("hist_diff");
  hist_diff->Add(hist2, -1);

}
于 2015-07-14T11:14:32.937 回答