14import modularAnalysis
as ma
15from variables
import variables
as vm
20 """The unit test case for TreeFitter"""
23 """Run the test fit"""
25 testFile = tempfile.NamedTemporaryFile()
27 main = basf2.create_path()
30 ma.inputMdst(inputfile, path=main)
32 ma.fillParticleList(
'e+:a',
'electronID > 0.5', path=main)
33 ma.fillParticleList(
'gamma:a',
'0.05 < E < 1.0', path=main)
34 ma.correctBremsBelle(
'e+:corrected',
'e+:a',
'gamma:a', path=main)
36 ma.reconstructDecay(
'J/psi:corrected -> e+:corrected e-:corrected ?addbrems',
'', path=main)
37 ma.matchMCTruth(
'J/psi:corrected', path=main)
39 ma.applyCuts(
'J/psi:corrected',
40 'daughterSumOf(extraInfo(bremsCorrected)) == 2 and isSignal==1',
42 ma.applyEventCuts(
'nParticlesInList(J/psi:corrected)', path=main)
45 main.add_module(
'TreeFitter',
46 particleList=
'J/psi:corrected',
48 updateAllDaughters=
True)
50 ma.reconstructDecay(
'J/psi:no -> e+:a e-:a',
'', path=main)
51 ma.matchMCTruth(
'J/psi:no', path=main)
52 ma.applyCuts(
'J/psi:no',
'isSignal==1', path=main)
53 main.add_module(
'TreeFitter',
54 particleList=
'J/psi:no',
56 updateAllDaughters=
True)
58 ma.variablesToEventExtraInfo(
'J/psi:no', {
'chiProb':
'chiProb_woCorrection',
'dM':
'dM_woCorrection'}, path=main)
59 vm.addAlias(
'chiProb_woCorrection',
'eventExtraInfo(chiProb_woCorrection)')
60 vm.addAlias(
'dM_woCorrection',
'eventExtraInfo(dM_woCorrection)')
64 xyz_error = ['x_uncertainty',
'y_uncertainty',
'z_uncertainty']
66 vm.addAlias(f
'e0_diff_{v}', f
'formula(daughter(0, {v}) - daughter(0, daughter(0, {v})))')
67 vm.addAlias(f
'e1_diff_{v}', f
'formula(daughter(1, {v}) - daughter(1, daughter(0, {v})))')
68 vm.addAlias(f
'e0_pull_{v}', f
'formula(e0_diff_{v} / daughter(0, {v}))')
69 vm.addAlias(f
'e1_pull_{v}', f
'formula(e1_diff_{v} / daughter(1, {v}))')
70 alias_list += [f
'e0_pull_{v}', f
'e1_pull_{v}']
73 ntupler = basf2.register_module('VariablesToNtuple')
74 ntupler.param(
'fileName', testFile.name)
75 ntupler.param(
'variables',
76 [
'chiProb',
'chiProb_woCorrection',
'dM',
'dM_woCorrection'])
77 ntupler.param(
'particleList',
'J/psi:corrected')
78 main.add_module(ntupler)
80 basf2.process(main, 10000)
82 ntuplefile = TFile(testFile.name)
83 ntuple = ntuplefile.Get(
'ntuple')
85 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
87 dMImproved = ntuple.GetEntries(
"abs(dM) < abs(dM_woCorrection)")
89 chiProbImproved = ntuple.GetEntries(
"(chiProb > chiProb_woCorrection) && (abs(dM) < abs(dM_woCorrection))")
90 chiProbWorsened = ntuple.GetEntries(
"(chiProb < chiProb_woCorrection) && (abs(dM) < abs(dM_woCorrection))")
92 self.assertTrue(dMImproved == 229,
"Brems-correction algorithm or setting have been changed.")
94 print(f
"Vertex fit quality improved due to the brems-correction, # of candidates = {chiProbImproved}")
95 print(f
"Vertex fit quality worsened due to the brems-correction, # of candidates = {chiProbWorsened}")
97 self.assertTrue(chiProbImproved == dMImproved,
"Brems-correction causes negative effect on the vertex-fit.")
98 print(
"Test passed, cleaning up.")
101if __name__ ==
'__main__':
def require_file(filename, data_type="", py_case=None)
def clean_working_directory()