from typing import List
import pandas as pd
import basf2
import modularAnalysis as ma
import vertex as vx
import variables.utils as vu
from vibe.core.utils.misc import fancy_validation_mode_header
from vibe.core.validation_mode import ValidationModeBaseClass
from vibe.core.helper.histogram_tools import HistVariable, Histogram, HistComponent
from vibe.core.helper.root_helper import makeROOTCompatible
__all__ = [
"BtoDpiDtoKpipiValidationMode",
]
[docs]
@fancy_validation_mode_header
class BtoDpiDtoKpipiValidationMode(ValidationModeBaseClass):
name = "BtoDpiDtoKpipi"
latex_str = r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$"
[docs]
def create_basf2_path(self):
main_path = basf2.Path()
# fsp selection
vu.variables.variables.addAlias('PID_bin_pion', 'ifNANgiveX(pidPairProbabilityExpert(211, 321, ALL), 0.5)')
vu.variables.variables.addAlias('PID_bin_kaon', 'ifNANgiveX(pidPairProbabilityExpert(321, 211, ALL), 0.5)')
pions = ("pi-:rec", "PID_bin_pion > 0.2")
kaons = ("K-:rec", "PID_bin_kaon > 0.2")
ma.fillParticleLists(
decayStringsWithCuts=[pions, kaons],
path=main_path,
)
ma.rankByHighest("pi-:rec", "p", path=main_path)
# D^- reconstruction
ma.reconstructDecay(
decayString="D-:Kpipi -> K+:rec pi-:rec pi-:rec",
cut="InvM > 1.75 and InvM < 1.95",
path=main_path,
)
# B meson reconstruction
ma.reconstructDecay(
decayString="B0:KpipiPi -> D-:Kpipi pi+:rec",
cut="Mbc>5.24 and abs(deltaE) < 0.2",
path=main_path,
)
# merge + MC matching + vertex
ma.matchMCTruth(
"B0:KpipiPi",
path=main_path,
)
vx.treeFit("B0:KpipiPi", 0.001, massConstraint=[421], path=main_path)
vx.TagV(list_name="B0:KpipiPi", confidenceLevel=0.001, constraintType="tube", path=main_path)
# save variables
B_variables = ["isSignal", "Mbc", "deltaE", "beamE"]
Dm_variables = vu.create_aliases_for_selected(list_of_variables=['daughterInvM(0,1)', 'daughterInvM(0,2)', 'daughterInvM(1,2)', 'InvM', 'p'], decay_string='B0 -> ^D- pi+', prefix='Dm')
pi_variables = vu.create_aliases_for_selected(list_of_variables=[ 'p'], decay_string='B0 -> D- ^pi+', prefix='pi')
K_variables = vu.create_aliases_for_selected(list_of_variables=[ 'p'], decay_string='B0 -> [D- -> ^K+ pi- pi-] pi+', prefix='K')
D_pi1_variables = vu.create_aliases_for_selected(list_of_variables=[ 'p', 'pionID', 'kaonID', 'PID_bin_pion'], decay_string='B0 -> [D- -> K+ ^pi- pi-] pi+', prefix='D_pi1')
D_pi2_variables = vu.create_aliases_for_selected(list_of_variables=[ 'p', 'pionID', 'kaonID', 'PID_bin_pion'], decay_string='B0 -> [D- -> K+ pi- ^pi-] pi+', prefix='D_pi2')
self.variables_to_validation_ntuple(
decay_str="B0:KpipiPi",
variables=B_variables + Dm_variables + pi_variables + K_variables + D_pi1_variables + D_pi2_variables,
path=main_path,
)
return main_path
@property
def analysis_validation_histograms(self) -> List[Histogram]:
return [
Histogram(
name="Mbc",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Mbc"),
label=r"$M_{bc}$",
unit=r"GeV/$c^2$",
bins=50,
scope=(5.24, 5.29),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="Mbc_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Mbc"),
label=r"$M_{bc}$",
unit=r"GeV/$c^2$",
bins=50,
scope=(5.24, 5.29),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="deltaE",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="deltaE"),
label=r"$\Delta(E)$",
unit=r"GeV",
bins=100,
scope=(-0.2, 0.2),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="deltaE_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="deltaE"),
label=r"$\Delta(E)$",
unit=r"GeV",
bins=100,
scope=(-0.2, 0.2),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="beamE",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="beamE"),
label=r"$E(beam)$",
unit=r"GeV",
bins=40,
scope=(10.8, 11.2),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="mKpi1",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_daughterInvM_0_1"),
label=r"$m(K^+\pi^-_1)$",
unit=r"GeV/$c^2$",
bins=65,
scope=(0.5, 1.8),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="mKpi1_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_daughterInvM_0_1"),
label=r"$m(K^+\pi^-_1)$",
unit=r"GeV/$c^2$",
bins=65,
scope=(0.5, 1.8),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="mKpi2",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_daughterInvM_0_2"),
label=r"$m(K^+\pi^-_2)$",
unit=r"GeV/$c^2$",
bins=65,
scope=(0.5, 1.8),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="mKpi2_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_daughterInvM_0_2"),
label=r"$m(K^+\pi^-_2)$",
unit=r"GeV/$c^2$",
bins=65,
scope=(0.5, 1.8),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="mpipi",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_daughterInvM_1_2"),
label=r"$m(\pi^-\pi^-)$",
unit=r"GeV/$c^2$",
bins=65,
scope=(0.2, 1.5),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="mD",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_InvM"),
label=r"$m(D)$",
unit=r"GeV/$c^2$",
bins=100,
scope=(1.75, 1.95),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="mD_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_InvM"),
label=r"$m(D)$",
unit=r"GeV/$c^2$",
bins=100,
scope=(1.75, 1.95),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="pD",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="Dm_p"),
label=r"$p(D^-)$",
unit=r"GeV/$c$",
bins=105,
scope=(1.4, 3.5),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="pK",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="K_p"),
label=r"$p(K^+)$",
unit=r"GeV/$c$",
bins=150,
scope=(0, 3.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="pDPi1",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D_pi1_p"),
label=r"$p(\pi_1^+)$",
unit=r"GeV/$c$",
bins=150,
scope=(0, 3.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="pDPi2",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D_pi2_p"),
label=r"$p(\pi_2^+)$",
unit=r"GeV/$c$",
bins=150,
scope=(0, 3.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="pDPi1_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D_pi1_p"),
label=r"$p(\pi_1^+)$",
unit=r"GeV/$c$",
bins=150,
scope=(0, 3.0),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="pDPi2_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D_pi2_p"),
label=r"$p(\pi_2^+)$",
unit=r"GeV/$c$",
bins=150,
scope=(0, 3.0),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="pion1PID",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D_pi1_PID_bin_pion"),
label=r"$binary PID(\pi_1^+)$",
unit=r" ",
bins=80,
scope=(0.2, 1.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="pion1PID_matched",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D_pi1_PID_bin_pion"),
label=r"$binary PID(\pi_1^+)$",
unit=r" ",
bins=80,
scope=(0.2, 1.0),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="purple",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="cyan",
),
],
),
Histogram(
name="pPi",
title=r"$B^0 \rightarrow D^- \pi^+, D^- \rightarrow K^+ \pi^- \pi^-$",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="pi_p"),
label=r"$p(\pi^+)$",
unit=r"GeV/$c$",
bins=100,
scope=(1.5, 3.5),
),
hist_components=[
HistComponent(
label="All",
),
],
),
]
[docs]
def offline_df_manipulation(self, df: pd.DataFrame) -> pd.DataFrame:
df = df.sample(frac=1.0).groupby(by=["__event__"]).head(1) # Applying rand BCS offline
return df
[docs]
def get_number_of_signal_for_efficiency(self, df: pd.DataFrame) -> float:
return df["isSignal"].sum()