如何正确地添加一个分支到一个已经存在的树

How to Properly Add a Branch to An Already Existing Tree

我正在计算来自 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

我试图在我的定义中将 RVec 插入到 0.1 前面,但是那没有用。 我该如何解决这个问题才能让它发挥作用?

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