15 import modularAnalysis
as ma
16 from ROOT
import TFile
20 """The unit test case for TreeFitter"""
23 """Run the test fit"""
25 testFile = tempfile.NamedTemporaryFile()
27 main = basf2.create_path()
30 'analysis/1000_B_DstD0Kpipi0_skimmed.root',
'validation', py_case=self)
31 ma.inputMdst(
'default', inputfile, path=main)
33 ma.fillParticleList(
'pi+:a',
'pionID > 0.5', path=main)
34 ma.fillParticleList(
'K+:a',
'kaonID > 0.5', path=main)
36 ma.fillParticleList(
'gamma:a',
'E > 0.08', path=main)
37 ma.reconstructDecay(
'pi0:a -> gamma:a gamma:a',
'0.125 < InvM < 0.145', 0, path=main)
39 ma.reconstructDecay(
'D0:rec -> K-:a pi+:a pi0:a',
'', 0, path=main)
40 ma.reconstructDecay(
'D*+:rec -> D0:rec pi+:a',
'', 0, path=main)
41 ma.reconstructDecay(
'B0:rec -> D*+:rec pi-:a',
' InvM > 5', 0, path=main)
42 ma.matchMCTruth(
'B0:rec', path=main)
45 main.add_module(
'TreeFitter',
46 particleList=
'B0:rec',
48 massConstraintList=[],
49 massConstraintListParticlename=[],
50 expertUseReferencing=
True,
52 updateAllDaughters=
False,
53 customOriginConstraint=
True,
55 customOriginVertex=[0, 0, 0],
56 customOriginCovariance=[1, 0, 0, 0, 1, 0, 0, 0, 1]
59 ntupler = basf2.register_module(
'VariablesToNtuple')
60 ntupler.param(
'fileName', testFile.name)
61 ntupler.param(
'variables', [
'chiProb',
'M',
'isSignal'])
62 ntupler.param(
'particleList',
'B0:rec')
63 main.add_module(ntupler)
67 ntuplefile = TFile(testFile.name)
68 ntuple = ntuplefile.Get(
'ntuple')
70 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
72 allBkg = ntuple.GetEntries(
"isSignal == 0")
73 allSig = ntuple.GetEntries(
"isSignal > 0")
75 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal > 0)")
76 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
78 mustBeZero = ntuple.GetEntries(f
"(chiProb < {conf})")
80 print(f
"True fit survivors: {truePositives} out of {allSig} true candidates")
81 print(f
"False fit survivors: {falsePositives} out of {allBkg} false candidates")
83 self.assertFalse(truePositives == 0,
"No signal survived the fit.")
85 self.assertTrue(falsePositives < 3032, f
"Too many false positives: {falsePositives} out of {allBkg} total bkg events.")
87 self.assertTrue(truePositives > 64,
"Signal rejection too high")
88 self.assertFalse(mustBeZero, f
"We should have dropped all candidates with confidence level less than {conf}.")
90 print(
"Test passed, cleaning up.")
93 if __name__ ==
'__main__':
def require_file(filename, data_type="", py_case=None)