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
import variables as va
from stdPi0s import stdPi0s
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__ = [
"DtoKPiPi0ValidationMode",
]
[docs]
@fancy_validation_mode_header
class DtoKPiPi0ValidationMode(ValidationModeBaseClass):
name = "DtoKPiPi0"
latex_str = r"$D \rightarrow K\pi\pi^0$"
[docs]
def create_basf2_path(self):
main_path = basf2.Path()
ma.fillParticleList("K+:D0", "thetaInCDCAcceptance and abs(d0) < 1 and abs(z0) < 3", path=main_path)
ma.fillParticleList("pi+:D0", "thetaInCDCAcceptance and abs(d0) < 1 and abs(z0) < 3", path=main_path)
stdPi0s("eff50_May2020", path=main_path)
ma.reconstructDecay("D0:Kpipi0 -> K-:D0 pi+:D0 pi0:eff50_May2020", "1.6 < M < 2.1", path=main_path)
ma.reconstructDecay(
"D*+:Dpi -> D0:Kpipi0 pi+:D0", "massDifference(0)<0.17 and useCMSFrame(p)>1.9", path=main_path
)
ma.matchMCTruth("D*+:Dpi", path=main_path)
ma.variablesToExtraInfo("pi0:eff50_May2020", variables={"M": "M_preFit"}, path=main_path)
va.variables.addAlias("M_preFit", "extraInfo(M_preFit)")
vx.treeFit("D*+:Dpi", 0.001, massConstraint=[111], ipConstraint=True, updateAllDaughters=True, path=main_path)
ma.applyCuts(
"D*+:Dpi", "massDifference(0) < 0.16 and 1.66 < daughter(0,M) < 2.06 and useCMSFrame(p) > 2.0", path=main_path
)
kinematics = ["pt", "p", "E", "cosTheta", "theta", "phi"]
cms_kinematics = vu.create_aliases(kinematics, "useCMSFrame({variable})", "CMS")
va.variables.addAlias("deltaM", "massDifference(0)")
va.variables.addAlias("deltaM_Err", "massDifferenceError(0)")
dst_vars = (
vc.mc_truth
+ vc.inv_mass
+ kinematics
+ cms_kinematics
+ ["charge", "Q", "deltaM", "deltaM_Err", "chiProb", "pErr", "ptErr", "thetaErr"]
)
kpi_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="D*+ -> [D0 -> ^K- ^pi+ pi0] pi+",
)
pi0_vars = vu.create_aliases_for_selected(
list_of_variables=vc.mc_truth
+ kinematics
+ cms_kinematics
+ [
"M_preFit",
"daughterDiffOfPhi(0,1)",
"daughterDiffOfPhiCMS(0,1)",
"daughterHighest(E)",
"daughterLowest(E)",
"daughterAngle(0,1)",
],
decay_string="D*+ -> [D0 -> K- pi+ ^pi0] pi+",
)
gamma_vars = vu.create_aliases_for_selected(
list_of_variables=vc.mc_truth
+ kinematics
+ cms_kinematics
+ [
"clusterE",
"clusterTiming",
"clusterErrorTiming",
"clusterSecondMoment",
"clusterZernikeMVA",
"minC2TDist",
"clusterR",
"clusterLAT",
"clusterE1E9",
"clusterDeltaLTemp",
"clusterAbsZernikeMoment51",
"clusterAbsZernikeMoment40",
],
decay_string="D*+ -> [D0 -> K- pi+ [pi0 -> ^gamma ^gamma]] pi+",
)
d_vars = vu.create_aliases_for_selected(
list_of_variables=vc.mc_truth + vc.inv_mass + kinematics + cms_kinematics + vc.flight_info + vc.vertex,
decay_string="D*+ -> [^D0 -> K- pi+ pi0] pi+",
)
pis_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", "pErr", "ptErr", "thetaErr"],
decay_string="D*+ -> [D0 -> K- pi+ pi0] ^pi+",
)
self.variables_to_validation_ntuple(
decay_str="D*+:Dpi",
variables=dst_vars + d_vars + kpi_vars + pi0_vars + gamma_vars + pis_vars,
path=main_path,
)
return main_path
@property
def analysis_validation_histograms(self) -> List[Histogram]:
return [
Histogram(
name="deltaM",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="deltaM"),
label=r"$\Delta M$",
unit=r"GeV/$c^2$",
bins=50,
scope=(0.14, 0.16),
),
hist_components=[
HistComponent(
label="Signal",
additional_cut_str="isSignal == 1",
color="red",
),
HistComponent(
label="Background",
additional_cut_str="isSignal != 1",
color="blue",
),
],
),
Histogram(
name="D0_pi0_p",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D0_pi0_p"),
label=r"p($\pi^0$)",
unit="GeV/$c$",
bins=50,
scope=(0.0, 5.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="D0_pi0_gamma_0_clusterTiming",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D0_pi0_gamma_0_clusterTiming"),
label=r"clusterTiming($\gamma_0$)",
unit="ns",
bins=50,
scope=(0.0, 100.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="D0_pi0_gamma_1_clusterTiming",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D0_pi0_gamma_1_clusterTiming"),
label=r"clusterTiming($\gamma_1$)",
unit="ns",
bins=50,
scope=(0.0, 100.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="D0_pi0_gamma_0_clusterE1E9",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D0_pi0_gamma_0_clusterE1E9"),
label=r"clusterE1E9($\gamma_0$)",
unit="GeV",
bins=50,
scope=(0.0, 5.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
Histogram(
name="D0_pi0_gamma_1_clusterE1E9",
title="",
hist_variable=HistVariable(
df_label=makeROOTCompatible(variable="D0_pi0_gamma_1_clusterE1E9"),
label=r"clusterE1E9($\gamma_1$)",
unit="GeV",
bins=50,
scope=(0.0, 5.0),
),
hist_components=[
HistComponent(
label="All",
),
],
),
]
[docs]
def get_number_of_signal_for_efficiency(self, df: pd.DataFrame) -> float:
return df["isSignal"].sum()