root_mcp.extended.root_native.templates module

Pre-built code templates for common ROOT operations.

Templates generate Python/PyROOT code strings that can be passed to RootCodeExecutor.execute(). Each template function returns a complete, runnable Python script as a string.

root_mcp.extended.root_native.templates.rdataframe_histogram(file_path, tree_name, branch, bins, range_min, range_max, selection=None, weight=None, output_path=None)[source]

Generate RDataFrame code to compute a 1D histogram.

Parameters:
  • file_path (str) – Path to the ROOT file.

  • tree_name (str) – Name of the TTree or RNTuple.

  • branch (str) – Branch to histogram.

  • bins (int) – Number of bins.

  • range_min (float) – Histogram range.

  • range_max (float) – Histogram range.

  • selection (str | None) – Optional cut expression (C++ syntax for RDF Filter).

  • weight (str | None) – Optional weight column name.

  • output_path (str | None) – If provided, save histogram as PNG to this path.

Returns:

Complete Python script.

Return type:

str

root_mcp.extended.root_native.templates.rdataframe_snapshot(file_path, tree_name, branches, output_path, output_tree_name=None, selection=None)[source]

Generate RDataFrame code to write a filtered/selected subset to a new ROOT file.

Parameters:
  • file_path (str) – Input ROOT file path.

  • tree_name (str) – Input TTree or RNTuple name.

  • branches (list[str]) – Branches to include in output.

  • output_path (str) – Output ROOT file path.

  • output_tree_name (str | None) – Output tree name (defaults to input tree name).

  • selection (str | None) – Optional cut expression.

Returns:

Complete Python script.

Return type:

str

root_mcp.extended.root_native.templates.roofit_fit(file_path, workspace_name, model_name, data_name, output_path=None)[source]

Generate RooFit code to perform a fit from a workspace.

Parameters:
  • file_path (str) – Path to ROOT file containing the workspace.

  • workspace_name (str) – Name of the RooWorkspace.

  • model_name (str) – Name of the PDF model in the workspace.

  • data_name (str) – Name of the dataset in the workspace.

  • output_path (str | None) – If provided, save fit plot to this path.

Returns:

Complete Python script.

Return type:

str

root_mcp.extended.root_native.templates.root_file_write(data, output_path, tree_name='tree')[source]

Generate code to write columnar data to a new ROOT file.

Parameters:
  • data (dict[str, list[float]]) – Column name -> values mapping.

  • output_path (str) – Output ROOT file path.

  • tree_name (str) – Name of the TTree to create.

Returns:

Complete Python script.

Return type:

str

root_mcp.extended.root_native.templates.root_macro(macro_code, output_path=None)[source]

Generate code to execute a ROOT C++ macro via gROOT.ProcessLine.

Parameters:
  • macro_code (str) – C++ code to execute.

  • output_path (str | None) – If provided, save any canvas output to this path.

Returns:

Complete Python script.

Return type:

str

root_mcp.extended.root_native.templates.tcanvas_plot(file_path, tree_name, draw_expr, output_path, selection=None, title=None, width=800, height=600)[source]

Generate TTree::Draw + TCanvas code to create a plot.

Parameters:
  • file_path (str) – Path to the ROOT file.

  • tree_name (str) – Name of the TTree or RNTuple.

  • draw_expr (str) – TTree::Draw expression (e.g. “px:py”, “mass>>h(100,0,200)”).

  • output_path (str) – Output file path for the plot (png, pdf, svg).

  • selection (str | None) – Optional cut expression.

  • title (str | None) – Plot title.

  • width (int) – Canvas dimensions in pixels.

  • height (int) – Canvas dimensions in pixels.

Returns:

Complete Python script.

Return type:

str