26 """ Test of fillParticleListFromChargedCluster """
27 testFile = tempfile.NamedTemporaryFile()
32 ma.inputMdst(inputfile, path=main)
34 ma.fillParticleList(
'pi+:ecl',
'clusterE>0', path=main)
35 ma.fillParticleList(
'pi+:klm',
'klmClusterEnergy>0', path=main)
37 ma.fillParticleListFromChargedCluster(
'gamma:bestecl',
'pi+:ecl',
'',
38 useOnlyMostEnergeticECLCluster=
True, path=main)
39 ma.fillParticleListFromChargedCluster(
'gamma:allecl',
'pi+:ecl',
'',
40 useOnlyMostEnergeticECLCluster=
False, path=main)
42 ma.fillParticleListFromChargedCluster(
'gamma:klmT',
'pi+:klm',
'',
43 useOnlyMostEnergeticECLCluster=
True, path=main)
44 ma.fillParticleListFromChargedCluster(
'gamma:klmF',
'pi+:klm',
'',
45 useOnlyMostEnergeticECLCluster=
False, path=main)
47 ma.fillParticleListFromChargedCluster(
'K_L0:ecl',
'pi+:ecl',
'', path=main)
48 ma.fillParticleListFromChargedCluster(
'K_L0:klm',
'pi+:klm',
'', path=main)
50 ma.applyCuts(
'gamma:bestecl',
'isFromECL', path=main)
51 ma.applyCuts(
'gamma:allecl',
'isFromECL', path=main)
52 ma.applyCuts(
'gamma:klmT',
'isFromKLM', path=main)
53 ma.applyCuts(
'gamma:klmF',
'isFromKLM', path=main)
54 ma.applyCuts(
'K_L0:ecl',
'isFromECL', path=main)
55 ma.applyCuts(
'K_L0:klm',
'isFromKLM', path=main)
57 vm.addAlias(
'n_pi_ecl',
'nParticlesInList(pi+:ecl)')
58 vm.addAlias(
'n_pi_klm',
'nParticlesInList(pi+:klm)')
59 vm.addAlias(
'n_gamma_bestecl',
'nParticlesInList(gamma:bestecl)')
60 vm.addAlias(
'n_gamma_allecl',
'nParticlesInList(gamma:allecl)')
61 vm.addAlias(
'n_gamma_klmT',
'nParticlesInList(gamma:klmT)')
62 vm.addAlias(
'n_gamma_klmF',
'nParticlesInList(gamma:klmF)')
63 vm.addAlias(
'n_KL_ecl',
'nParticlesInList(K_L0:ecl)')
64 vm.addAlias(
'n_KL_klm',
'nParticlesInList(K_L0:klm)')
66 ntupler = register_module(
'VariablesToNtuple')
67 ntupler.param(
'fileName', testFile.name)
68 ntupler.param(
'variables',
69 [
'n_pi_ecl',
'n_pi_klm',
70 'n_gamma_bestecl',
'n_gamma_allecl',
'n_gamma_klmT',
'n_gamma_klmF',
71 'n_KL_ecl',
'n_KL_klm'])
72 main.add_module(ntupler)
76 ntuplefile = TFile(testFile.name)
77 ntuple = ntuplefile.Get(
'ntuple')
79 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
81 nEntries = ntuple.GetEntries()
84 sameNumberForPiAndGamma_ECL = ntuple.GetEntries(
"n_pi_ecl == n_gamma_bestecl")
86 sameNumberForPiAndHadron_ECL = ntuple.GetEntries(
"n_pi_ecl >= n_KL_ecl")
88 sameNumberForPiAndBothGammaHadron_KLM = ntuple.GetEntries(
"(n_pi_klm == n_gamma_klmT) && (n_pi_klm == n_KL_klm)")
90 self.assertTrue(nEntries == sameNumberForPiAndGamma_ECL,
91 "Charged ECL-cluster is not correctly loaded for gamma.")
92 self.assertTrue(nEntries == sameNumberForPiAndHadron_ECL,
93 "Charged ECL-cluster is not correctly loaded for neutral hadron.")
94 self.assertTrue(nEntries == sameNumberForPiAndBothGammaHadron_KLM,
95 "Charged KLM-cluster is not correctly loaded for both gamma and neutral hadron.")
97 allIsGreaterThanBest = ntuple.GetEntries(
"n_gamma_allecl >= n_gamma_bestecl")
98 self.assertTrue(nEntries == allIsGreaterThanBest,
"Charged ECL-cluster is missed with useOnlyMostEnergeticECLCluster=False")
100 optionDoesNotChangeKLM = ntuple.GetEntries(
"n_gamma_klmT == n_gamma_klmF")
101 self.assertTrue(nEntries == optionDoesNotChangeKLM,
"Charged KLM-cluster is affected by useOnlyMostEnergeticECLCluster")
103 print(
"Test passed, cleaning up.")
def require_file(filename, data_type="", py_case=None)
def safe_process(*args, **kwargs)