15from basf2
import create_path, process
16import modularAnalysis
as ma
22 """Test case for standard V0 lists"""
26 std_function=stdV0s.stdKshorts,
29 "ParticleListManipulator",
36 "ParticleListManipulator"],
37 expected_lists=['V0_ToFit', 'V0_ToFit', 'all', 'RD', 'merged']):
38 """check that a given function works"""
39 testpath = create_path()
40 std_function(path=testpath)
44 for module
in testpath.modules():
45 loaded_modules.append(module.type())
46 for param
in module.available_params():
47 if module.type() ==
'ParticleLoader' and param.name ==
'decayStrings':
48 name = param.values[0].split(
':')[1].split(
' -> ')[0]
49 built_lists.append(name)
50 if module.type() ==
'ParticleListManipulator' and param.name ==
'outputListName':
51 name = str(param.values).split(
':')[1].split(
' -> ')[0]
52 built_lists.append(name)
53 if module.type() ==
'ParticleCombiner' and param.name ==
'decayString':
54 name = param.values.split(
':')[1].split(
' -> ')[0]
55 built_lists.append(name)
59 loaded_modules, expected_modules,
60 f
"Loaded modules do not match the expected ones (function {std_function.__name__})")
64 built_lists, expected_lists,
65 f
"Built particles lists do not match the expected ones (function {std_function.__name__})")
68 """check that the builder function works with the stdKshorts list"""
72 """check that the builder function works with the legacy Belle Kshorts list"""
73 expected_modules = [
"ParticleLoader",
74 "ParticleListManipulator",
76 "ParticleVertexFitter",
78 self.
_check_list(std_function=stdV0s.goodBelleKshort, expected_modules=expected_modules,
79 expected_lists=[
"legacyGoodKS",
"legacyGoodKS"])
82 """check that the builder function works with the stdLambdas list"""
83 expected_modules = [
"ParticleLoader",
84 "ParticleListManipulator",
87 "DuplicateVertexMarker",
94 "DuplicateVertexMarker",
96 "ParticleListManipulator"]
97 expected_lists = [
'V0_ToFit',
'V0_ToFit',
'all',
'all',
'RD',
'merged']
98 self.
_check_list(std_function=stdV0s.stdLambdas, expected_modules=expected_modules, expected_lists=expected_lists)
101 """check the number of signals in K_S0:merged and K_S0:scaled lists"""
106 ma.inputMdst(inputfile, path=main)
111 ma.matchMCTruth(
'K_S0:merged', path=main)
112 ma.matchMCTruth(
'K_S0:scaled', path=main)
114 testFile = tempfile.NamedTemporaryFile()
115 ma.variablesToNtuple(
'K_S0:merged', [
'isSignal',
'M'], filename=testFile.name, treename=
'merged', path=main)
116 ma.variablesToNtuple(
'K_S0:scaled', [
'isSignal',
'M'], filename=testFile.name, treename=
'scaled', path=main)
120 ntuplefile = TFile(testFile.name)
121 ntuple_merged = ntuplefile.Get(
'merged')
122 ntuple_scaled = ntuplefile.Get(
'scaled')
124 allSig_merged = ntuple_merged.GetEntries(
"isSignal == 1")
125 allSig_scaled = ntuple_scaled.GetEntries(
"isSignal == 1")
127 print(f
"Number of signal K_S0:merged: {allSig_merged}")
128 print(f
"Number of signal K_S0:scaled: {allSig_scaled}")
130 self.assertTrue(allSig_merged > 999,
"Number of signal K_S0:merged is too small.")
131 self.assertTrue(allSig_scaled > 1000,
"Number of signal K_S0:scaled is too small.")
133 tightMSig_merged = ntuple_merged.GetEntries(
"isSignal == 1 && M > 0.48 && M < 0.52")
134 tightMSig_scaled = ntuple_scaled.GetEntries(
"isSignal == 1 && M > 0.48 && M < 0.52")
136 print(f
"Number of signal K_S0:merged with 0.48<M<0.52: {tightMSig_merged}")
137 print(f
"Number of signal K_S0:scaled with 0.48<M<0.52: {tightMSig_scaled}")
139 self.assertTrue(tightMSig_merged > 962,
"Number of signal K_S0:merged with 0.48<M<0.52 is too small.")
140 self.assertTrue(tightMSig_scaled > 962,
"Number of signal K_S0:scaled with 0.48<M<0.52 is too small.")
142 print(
"Test passed, cleaning up.")
145if __name__ ==
'__main__':
def _check_list(self, std_function=stdV0s.stdKshorts, expected_modules=["ParticleLoader", "ParticleListManipulator", "TreeFitter", "ParticleSelector", "ParticleLoader", "ParticleCombiner", "TreeFitter", "ParticleSelector", "ParticleListManipulator"], expected_lists=['V0_ToFit', 'V0_ToFit', 'all', 'RD', 'merged'])
def test_stdlambdas_list(self)
def test_stdkshorts_list(self)
def test_kshort_signals(self)
def test_belle_list(self)
def require_file(filename, data_type="", py_case=None)
def stdKshorts(prioritiseV0=True, fitter='TreeFit', path=None, updateAllDaughters=False, writeOut=False)
def scaleErrorKshorts(prioritiseV0=True, fitter='TreeFit', scaleFactors_V0=[1.125927, 1.058803, 1.205928, 1.066734, 1.047513], scaleFactorsNoPXD_V0=[1.125927, 1.058803, 1.205928, 1.066734, 1.047513], d0Resolution_V0=[0.001174, 0.000779], z0Resolution_V0=[0.001350, 0.000583], d0MomThr_V0=0.500000, z0MomThr_V0=0.00000, scaleFactors_RD=[1.149631, 1.085547, 1.151704, 1.096434, 1.086659], scaleFactorsNoPXD_RD=[1.149631, 1.085547, 1.151704, 1.096434, 1.086659], d0Resolution_RD=[0.00115328, 0.00134704], z0Resolution_RD=[0.00124327, 0.0013272], d0MomThr_RD=0.500000, z0MomThr_RD=0.500000, path=None)