from typing import List
import pandas as pd
import basf2
import modularAnalysis as ma
import vertex as vx
import variables.collections as vc
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__ = [
"LambdactoPKPiValidationMode",
]
[docs]
@fancy_validation_mode_header
class LambdactoPKPiValidationMode(ValidationModeBaseClass):
name = "LambdactoPKPi"
latex_str = r"$\Lambda_c^+ \rightarrow p K \pi$"
[docs]
def create_basf2_path(self):
main_path = basf2.Path()
ma.fillParticleList("p+:Lambda_c", "thetaInCDCAcceptance and abs(d0) < 1 and abs(z0) < 3", path=main_path)
ma.fillParticleList("K+:Lambda_c", "thetaInCDCAcceptance and abs(d0) < 1 and abs(z0) < 3", path=main_path)
ma.fillParticleList("pi+:Lambda_c", "thetaInCDCAcceptance and abs(d0) < 1 and abs(z0) < 3", path=main_path)
ma.reconstructDecay("Lambda_c+:pKpi -> p+:Lambda_c K-:Lambda_c pi+:Lambda_c", "2.1 < M < 2.5", path=main_path)
ma.matchMCTruth("Lambda_c+:pKpi", path=main_path)
vx.treeFit("Lambda_c+:pKpi", 0.001, ipConstraint=True, updateAllDaughters=True, path=main_path)
ma.applyCuts("Lambda_c+:pKpi", "2.2 < M < 2.4 and useCMSFrame(p) > 2.0", path=main_path)
kinematics = ["pt", "p", "E", "cosTheta", "theta", "phi"]
cms_kinematics = vu.create_aliases(kinematics, "useCMSFrame({variable})", "CMS")
lc_vars = (
vc.mc_truth
+ vc.inv_mass
+ kinematics
+ cms_kinematics
+ vc.flight_info
+ vc.vertex
+ ["charge", "chiProb", "pErr", "ptErr", "thetaErr", "significanceOfDistance"]
)
pkpi_vars = vu.create_aliases_for_selected(
list_of_variables=vc.mc_truth
+ kinematics
+ cms_kinematics
+ vc.track
+ vc.track_hits
+ ["M", "charge", "protonID", "electronID", "kaonID", "pionID", "muonID"],
decay_string="Lambda_c+ -> ^p+ ^K- ^pi+",
)
self.variables_to_validation_ntuple(
decay_str="Lambda_c+:pKpi",
variables=lc_vars + pkpi_vars,
path=main_path,
)
return main_path
@property
def analysis_validation_histograms(self) -> List[Histogram]:
return [
Histogram(
name="M",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="M"),
label=r"$M(pK\pi)$",
unit=r"GeV/$c^2$",
bins=50,
scope=(2.2, 2.4),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="red",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="blue",
),
],
),
Histogram(
name="significanceOfDistance",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="significanceOfDistance"),
label=r"significance of distance ($\Lambda_c^+$)",
unit="",
bins=50,
scope=(0.0, 5.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="p_protonID",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="p_protonID"),
label=r"protonID($p$)",
unit="",
bins=50,
scope=(0.0, 1.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
]
[docs]
def get_number_of_signal_for_efficiency(self, df: pd.DataFrame) -> float:
return df["isSignal"].sum()