T树对象;使用绘图选项来绘制差异直方图

TTree objects; using Draw options to histogram the difference

此宏适用于 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");
}

您给出的命令将为树的每个事件制作 hit_PMTidplain.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);

}