如何正确地将分支添加到已存在的树中

How to Properly Add a Branch to An Already Existing Tree

本文关键字:存在 添加 正确地 分支      更新时间:2023-10-16

我正在计算dimuon通道的不变质量。

我正在使用RDataFrame进行此计算。我的代码片段如下:

// Enable multi-threading
ROOT::EnableImplicitMT();
// Create dataframe from NanoAOD files
ROOT::RDataFrame df("Delphes;6",
"tag_1_delphes_events.root");
//auto mu_mass = df.Define("muon_mass", "0.1");
// For simplicity, select only events with exactly two muons and require opposite charge
//auto df_2mu = df.Filter("nMuon == 2", "Events with exactly two muons");
auto df_os = df.Filter("Muon.Charge[0] != Muon.Charge[1]", "Muons with opposite charge");
// Compute invariant mass of the dimuon system
auto df_mu_mass = df_os.Define("muon_mass", "0.1");
auto df_mass = df_mu_mass.Define("Dimuon_mass", InvariantMass<float>, {"Muon.PT", "Muon.Eta", "Muon.Phi", "muon_mass"});
// Make histogram of dimuon mass spectrum
auto h = df_mass.Histo1D({"Dimuon_mass", "Dimuon_mass", 30000, 0.25, 300}, "Dimuon_mass");
// Request cut-flow report
auto report = df_mass.Report();
// Produce plot

我的PT、eta、Phi值是浮点值。我得到的错误是:

terminate called after throwing an instance of 'std::runtime_error'
what():  RColumnValue: type specified for column "muon_mass" is ROOT::VecOps::RVec<float> but temporary column has type double

我试图在我的Define中在0.1前面插入RVec,但没有成功。我该如何解决这个问题以使其正常工作?

我发现解决这个问题的最简单方法是在Tree 中手动添加分支值