跳转至

本地运行最小化的 DaVinci 作业

目标

  • 了解什么是 DaVinci 以及如何在本地运行它!

DaVinci 是 LHCb 的离线分析软件。简而言之,我们用它来处理从精选中得到的DST 文件,并生成可用于进一步分析的 ROOT ntuple文件。当需要处理精选的全部输出时,你会使用分析生成工具将作业提交到网格。然而,为了设置这些大型生成作业,你需要能够交互式地运行 DaVinci,以便为生成作业开发控制选项、开发新工具,或者实施和改进选择条件。

提醒 - 已发布的应用程序和lb-run

LHCb 的应用程序会被发布并安装在 CVMFS 上。因此,在标准的 LHCb Linux环境中可以使用它们。要使用一个应用程序,你必须首先使用 lb-run命令设置其环境,该命令会启动环境,然后执行后续命令。例如,运lb-run DaVinci/v65r0 python会启动一个 python shell,其中 DaVinci的所有模块都已在环境中准备就绪,可供使用。如果你想探索函子(Functor)的定义(下一课会更详细地解释),这会很有用:

import Functors as F
help(F.BPVLTIME)

这会显示获取粒子衰变时间(相对于 "最佳" 顶点 PV)的函子的文档字符串。

使用lbexec运行 DaVinci

对于 Run 3,该软件可以使用 lbexec 命令运行。这是 gaudirun的替代方案(如果需要,gaudirun 仍然可用)。典型的 DaVinci 执行命令如下:

lb-run -c x86_64_v3-el9-gcc13+detdesc-opt+g DaVinci/v65r0 lbexec mytuplemaker:main myoptions.yaml

lb-runDaVinci/v65r0 之间的部分用于启动 DaVinci环境,其中-c标志指定平台。在运行蒙特卡洛(MC)数据时,重要的是我们要使用包含+DetDesc的平台,下一课会更详细地介绍这种区别mytuplemaker指的是一个名为mytuplemaker.py的 python文件,该文件包含一个已定义的main函数(文件及其所执行函数的命名是任意的)。这在LHCb 软件入门课程中也有解释。这个python 文件是初始化 FunTuple以及列出所有分支及其函子的地方。options.yaml是一个包含典型控制选项的标记文件,它包括要运行的数据、事件数量、条件标签等。

这种设置相对于之前的gaudirun.py的优势在于数据控制与元组制作的分离,这使得将元组制作应用于各种不同的数据文件变得更加容易。

最小化的 DaVinci 作业

让我们创建一个最小化的作业来打印 DST 中存储的衰变树。在mymodule.py文件中放入以下内容:

from DaVinci import Options, make_config
from DaVinci.algorithms import create_lines_filter
from PyConf.Algorithms import PrintDecayTree
from PyConf.reading import get_particles

def printDecayTree(options: Options):
    # The name of the line we want to look at
    line = "Hlt2B2OC_BdToDsmPi_DsmToKpKmPim"
    input_data = get_particles(f"/Event/HLT2/{line}/Particles")

    # Add a filter: We are not really filtering over particles
    # If the event hasn't fired a HLT2 line then the corresponding TES location does
    # obviously not exist and therefore if any algorithm tries to look for this location,
    # it will of course fail.
    # Resolve this with a filter, where:
    # - 1st argument is a user defined name.
    # - 2nd argument is the line decision (inspect hlt2_starterkit.tck.json if needed))
    my_filter = create_lines_filter("HDRFilter_SeeNoEvil", lines=[f"{line}"])

    # Defining an algorithm. The algorithm here prints the decaytree
    pdt = PrintDecayTree(name="PrintBsToDsPi", Input=input_data)

    user_algorithms = [my_filter, pdt]

    return make_config(options, user_algorithms)

现在,我们可以在一个单独的文件中配置引导选项,文件命名为 options.yaml

input_files:
- root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp7/Run3SK/exampleDST/00257716_00000011_1.hlt2.dst
input_type: ROOT
evt_max: 100
ntuple_file: davinci_ntuple.root
input_process: Hlt2
print_freq: 1
simulation: true
conddb_tag: sim10-2024.W37.39-v00.00-md100
dddb_tag: dddb-20240427

您可以看到,因为我们在运行模拟数据,所以必须设置相应的conddb_tag(条件数据库标签)和dddb_tag(探测器描述数据库标签)。因此还需要指定生成输入文件的处理流程,对于经过Spruce处理后的数据,这通常设置为Spruce。现在运行这个示例:

lb-run -c x86_64_v3-el9-gcc13+detdesc-opt+g DaVinci/v65r0 lbexec mymodule:printDecayTree options.yaml

此示例的输出结果是打印存储在 TES 位置上的衰变树/Event/HLT2/Hlt2B2OC_BdToDsmPi_DsmToKpKmPim/Particles:

PrintBsToJpsiPhi.PrintDecayTreeTool    INFO <-------------------------------------------- Particle -------------------------------------------->
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO                 Name         E         M         P        Pt       phi        Vz    P(C/K)   PP(C/K)
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO                            MeV       MeV       MeV       MeV      mrad        mm
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO B~0                  77456.12   5350.44  77271.10  11006.56  -2894.20    -13.07      36/0       N/A
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO +-->D_s+             61360.38   1964.95  61328.91   9732.58  -3078.29     -6.67      37/0       N/A
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO |+-->K+              34549.66    493.68  34546.14   6104.16  -3091.80    -13.69     27/41      3/41
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO |+-->K-              16242.15    493.68  16234.65   2472.72  -3074.02    -15.05     27/40      3/40
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO |+-->pi+             10571.58    139.57  10570.65   1159.77  -3015.92    -17.99      5/16      3/16
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO +-->pi-              16100.04    139.57  16099.44   2289.99  -2002.85    -14.64      5/48      3/48
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO Used TES locations :-
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO      37 = '/Event/DoNotUseExplicitly/AnonymousDependencyOnly/SourceID_2/0xffffffe2'
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO       5 = '/Event/DoNotUseExplicitly/AnonymousDependencyOnly/SourceID_2/0xffffffe7'
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO      27 = '/Event/DoNotUseExplicitly/AnonymousDependencyOnly/SourceID_2/0xffffffe8'
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO      36 = '/Event/DoNotUseExplicitly/AnonymousDependencyOnly/SourceID_2/0xfffffffb'
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO       3 = '/Event/HLT2/Rec/ProtoP/Long'
PrintBsToJpsiPhi.PrintDecayTreeTool    INFO