18 """Run the test fit"""
20 testFile = tempfile.NamedTemporaryFile()
22 main = basf2.create_path()
25 'analysis/1000_B_DstD0Kpipi0_skimmed.root',
'validation', py_case=self)
26 ma.inputMdst(
'default', inputfile, path=main)
28 ma.fillParticleList(
'pi+:a',
'pidProbabilityExpert(211, ALL) > 0.5', path=main)
29 ma.fillParticleList(
'K+:a',
'pidProbabilityExpert(321, ALL) > 0.5', path=main)
31 ma.fillParticleList(
'gamma:a',
'E > 0.08', path=main)
32 ma.reconstructDecay(
'pi0:a -> gamma:a gamma:a',
'0.125 < InvM < 0.145', 0, path=main)
34 ma.reconstructDecay(
'D0:rec -> K-:a pi+:a pi0:a',
'', 0, path=main)
35 ma.reconstructDecay(
'D*+:rec -> D0:rec pi+:a',
'', 0, path=main)
36 ma.reconstructDecay(
'B0:rec -> D*+:rec pi-:a',
' InvM > 5', 0, path=main)
37 ma.matchMCTruth(
'B0:rec', path=main)
40 main.add_module(
'TreeFitter',
41 particleList=
'B0:rec',
43 massConstraintList=[],
44 massConstraintListParticlename=[],
45 expertUseReferencing=
True,
47 updateAllDaughters=
False,
48 customOriginConstraint=
True,
50 customOriginVertex=[0, 0, 0],
51 customOriginCovariance=[1, 0, 0, 0, 1, 0, 0, 0, 1]
54 ntupler = basf2.register_module(
'VariablesToNtuple')
55 ntupler.param(
'fileName', testFile.name)
56 ntupler.param(
'variables', [
'chiProb',
'M',
'isSignal'])
57 ntupler.param(
'particleList',
'B0:rec')
58 main.add_module(ntupler)
62 ntuplefile = TFile(testFile.name)
63 ntuple = ntuplefile.Get(
'ntuple')
65 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
67 allBkg = ntuple.GetEntries(
"isSignal == 0")
68 allSig = ntuple.GetEntries(
"isSignal > 0")
70 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal > 0)")
71 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
73 mustBeZero = ntuple.GetEntries(
"(chiProb < {})".format(conf))
75 print(
"True fit survivors: {0} out of {1} true candidates".format(truePositives, allSig))
76 print(
"False fit survivors: {0} out of {1} false candidates".format(falsePositives, allBkg))
78 self.assertFalse(truePositives == 0,
"No signal survived the fit.")
80 self.assertTrue(falsePositives < 3032, f
"Too many false positives: {falsePositives} out of {allBkg} total bkg events.")
82 self.assertTrue(truePositives > 64,
"Signal rejection too high")
83 self.assertFalse(mustBeZero,
"We should have dropped all candidates with confidence level less than {}.".format(conf))
85 print(
"Test passed, cleaning up.")