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         ma.inputMdst(inputfile, path=main)
 
   32         ma.fillParticleList(
'pi+:a', 
'pionID > 0.5', path=main)
 
   34         ma.fillParticleList(
'gamma:a', 
'', path=main)
 
   35         ma.reconstructDecay(
'pi0:a -> gamma:a gamma:a', 
'0.125 < InvM < 0.145', 0, path=main)
 
   37         ma.reconstructDecay(
'B0:rec -> pi-:a pi+:a pi0:a', 
'', 0, path=main)
 
   38         ma.matchMCTruth(
'B0:rec', path=main)
 
   41         main.add_module(
'TreeFitter',
 
   42                         particleList=
'B0:rec',
 
   44                         massConstraintList=[],
 
   45                         massConstraintListParticlename=[],
 
   46                         expertUseReferencing=
True,
 
   48                         updateAllDaughters=
True)
 
   50         ntupler = basf2.register_module(
'VariablesToNtuple')
 
   51         ntupler.param(
'fileName', testFile.name)
 
   52         ntupler.param(
'variables', [
'chiProb', 
'M', 
'isSignal'])
 
   53         ntupler.param(
'particleList', 
'B0:rec')
 
   54         main.add_module(ntupler)
 
   58         ntuplefile = TFile(testFile.name)
 
   59         ntuple = ntuplefile.Get(
'ntuple')
 
   61         self.assertFalse(ntuple.GetEntries() == 0, 
"Ntuple is empty.")
 
   63         allBkg = ntuple.GetEntries(
"isSignal == 0")
 
   64         allSig = ntuple.GetEntries(
"isSignal > 0")
 
   66         truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal > 0)")
 
   67         falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
 
   69         mustBeZero = ntuple.GetEntries(f
"(chiProb < {conf})")
 
   71         print(f
"True fit survivors: {truePositives} out of {allSig} true candidates")
 
   72         print(f
"False fit survivors: {falsePositives} out of {allBkg} false candidates")
 
   74         self.assertFalse(truePositives == 0, 
"No signal survived the fit.")
 
   76         self.assertTrue(falsePositives < 2107, 
"Background rejection too small.")
 
   78         self.assertTrue(truePositives > 32, 
"Signal rejection too high")
 
   79         self.assertFalse(mustBeZero, f
"We should have dropped all candidates with confidence level less than {conf}.")
 
   81         print(
"Test passed, cleaning up.")
 
   84 if __name__ == 
'__main__':
 
def require_file(filename, data_type="", py_case=None)
def clean_working_directory()