16import modularAnalysis
as ma
20 """Test case of ParticleLoader"""
23 """Compare the number of mdst objects and particles."""
24 from ROOT
import TFile
26 testFile = tempfile.NamedTemporaryFile()
28 main = basf2.create_path()
32 ma.fillParticleList(
'pi+:all',
'', path=main)
33 ma.fillParticleList(
'gamma:all',
'', path=main)
34 ma.fillParticleList(
'K_L0:all',
'', path=main)
35 ma.fillParticleList(
'K_S0:V0 -> pi+ pi-',
'', path=main)
36 ma.fillParticleList(
'Lambda0:V0 -> p+ pi-',
'', path=main)
37 ma.fillConvertedPhotonsList(
'gamma:V0 -> e+ e-',
'', path=main)
39 ma.cutAndCopyList(
'K_L0:ecl',
'K_L0:all',
'isFromECL', path=main)
40 ma.cutAndCopyList(
'K_L0:klm',
'K_L0:all',
'isFromKLM', path=main)
42 ma.variablesToNtuple(
'',
43 [
'nTrackFitResults(pi+)',
44 'nParticlesInList(pi+:all)',
45 'nNeutralECLClusters(1)',
46 'nParticlesInList(gamma:all)',
47 'nNeutralECLClusters(2)',
48 'nParticlesInList(K_L0:ecl)',
50 'nParticlesInList(K_L0:klm)',
52 'nParticlesInList(K_S0:V0)',
53 'nParticlesInList(Lambda0:V0)',
54 'nParticlesInList(gamma:V0)'],
55 filename=testFile.name,
61 ntuplefile = TFile(testFile.name)
62 ntuple = ntuplefile.Get(
'tree')
63 totalEvents = ntuple.GetEntries()
64 self.assertFalse(totalEvents == 0,
"Ntuple is empty.")
66 missedTracks = ntuple.GetEntries(
"nTrackFitResults__bopi__pl__bc > nParticlesInList__bopi__pl__clall__bc")
67 missedECLClustersNPhotons = ntuple.GetEntries(
"nNeutralECLClusters__bo1__bc > nParticlesInList__bogamma__clall__bc")
68 missedECLClustersNeutralHad = ntuple.GetEntries(
"nNeutralECLClusters__bo2__bc > nParticlesInList__boK_L0__clecl__bc")
69 missedKLMClusters = ntuple.GetEntries(
"nKLMClusters > nParticlesInList__boK_L0__clklm__bc")
70 missedV0s = ntuple.GetEntries(
"nValidV0s > nParticlesInList__boK_S0__clV0__bc + nParticlesInList__boLambda0__clV0__bc + " +
71 "nParticlesInList__bogamma__clV0__bc")
73 self.assertTrue(missedTracks == 0,
"Tracks are missed to be loaded as charged particles")
74 self.assertTrue(missedECLClustersNPhotons == 0,
"ECLClusters (nPhotons) are missed to be loaded as gammas")
75 self.assertTrue(missedECLClustersNeutralHad == 0,
"ECLClusters (neutralHadron) are missed to be loaded as K_L0s")
76 self.assertTrue(missedKLMClusters == 0,
"KLMClusters are missed to be loaded as K_L0s")
77 self.assertTrue(missedV0s == 0,
"V0s are missed to be loaded as K_S0, Lambda0, and converted-gamma")
79 duplicatedTracks = ntuple.GetEntries(
"nTrackFitResults__bopi__pl__bc < nParticlesInList__bopi__pl__clall__bc")
80 duplicatedECLClustersNPhotons = ntuple.GetEntries(
"nNeutralECLClusters__bo1__bc < nParticlesInList__bogamma__clall__bc")
81 duplicatedECLClustersNeutralHad = ntuple.GetEntries(
"nNeutralECLClusters__bo2__bc < nParticlesInList__boK_L0__clecl__bc")
82 duplicatedKLMClusters = ntuple.GetEntries(
"nKLMClusters < nParticlesInList__boK_L0__clklm__bc")
83 duplicatedV0s = ntuple.GetEntries(
84 "nValidV0s < nParticlesInList__boK_S0__clV0__bc + nParticlesInList__boLambda0__clV0__bc + " +
85 "nParticlesInList__bogamma__clV0__bc")
87 self.assertTrue(duplicatedTracks == 0,
"Tracks are loaded as charged particles more than once")
88 self.assertTrue(duplicatedECLClustersNPhotons == 0,
"ECLClusters (nPhotons) are loaded as gammas more than once")
89 self.assertTrue(duplicatedECLClustersNeutralHad == 0,
"ECLClusters (neutralHadron) are loaded as K_L0s more than once")
90 self.assertTrue(duplicatedKLMClusters == 0,
"KLMClusters are loaded as K_L0s more than once")
91 self.assertTrue(duplicatedV0s == 0,
"V0s are loaded as K_S0, Lambda0, and converted-gamma more than once")
93 print(
"Test passed, cleaning up.")
96if __name__ ==
'__main__':
def testNumberOfParticles(self)
def require_file(filename, data_type="", py_case=None)