25        """ Test of fillParticleListFromChargedCluster """ 
   26        testFile = tempfile.NamedTemporaryFile()
 
   31        ma.inputMdst(inputfile, path=main)
 
   33        ma.fillParticleList(
'pi+:ecl', 
'clusterE>0', path=main)
 
   34        ma.fillParticleList(
'pi+:klm', 
'klmClusterEnergy>0', path=main)
 
   36        ma.fillParticleListFromChargedCluster(
'gamma:bestecl', 
'pi+:ecl', 
'',
 
   37                                              useOnlyMostEnergeticECLCluster=
True, path=main)
 
   38        ma.fillParticleListFromChargedCluster(
'gamma:allecl', 
'pi+:ecl', 
'',
 
   39                                              useOnlyMostEnergeticECLCluster=
False, path=main)
 
   41        ma.fillParticleListFromChargedCluster(
'gamma:klmT', 
'pi+:klm', 
'',
 
   42                                              useOnlyMostEnergeticECLCluster=
True, path=main)
 
   43        ma.fillParticleListFromChargedCluster(
'gamma:klmF', 
'pi+:klm', 
'',
 
   44                                              useOnlyMostEnergeticECLCluster=
False, path=main)
 
   46        ma.fillParticleListFromChargedCluster(
'K_L0:ecl', 
'pi+:ecl', 
'', path=main)
 
   47        ma.fillParticleListFromChargedCluster(
'K_L0:klm', 
'pi+:klm', 
'', path=main)
 
   49        ma.applyCuts(
'gamma:bestecl', 
'isFromECL', path=main)
 
   50        ma.applyCuts(
'gamma:allecl', 
'isFromECL', path=main)
 
   51        ma.applyCuts(
'gamma:klmT', 
'isFromKLM', path=main)
 
   52        ma.applyCuts(
'gamma:klmF', 
'isFromKLM', path=main)
 
   53        ma.applyCuts(
'K_L0:ecl', 
'isFromECL', path=main)
 
   54        ma.applyCuts(
'K_L0:klm', 
'isFromKLM', path=main)
 
   56        vm.addAlias(
'n_pi_ecl', 
'nParticlesInList(pi+:ecl)')
 
   57        vm.addAlias(
'n_pi_klm', 
'nParticlesInList(pi+:klm)')
 
   58        vm.addAlias(
'n_gamma_bestecl', 
'nParticlesInList(gamma:bestecl)')
 
   59        vm.addAlias(
'n_gamma_allecl', 
'nParticlesInList(gamma:allecl)')
 
   60        vm.addAlias(
'n_gamma_klmT', 
'nParticlesInList(gamma:klmT)')
 
   61        vm.addAlias(
'n_gamma_klmF', 
'nParticlesInList(gamma:klmF)')
 
   62        vm.addAlias(
'n_KL_ecl', 
'nParticlesInList(K_L0:ecl)')
 
   63        vm.addAlias(
'n_KL_klm', 
'nParticlesInList(K_L0:klm)')
 
   65        ntupler = register_module(
'VariablesToNtuple')
 
   66        ntupler.param(
'fileName', testFile.name)
 
   67        ntupler.param(
'variables',
 
   68                      [
'n_pi_ecl', 
'n_pi_klm',
 
   69                       'n_gamma_bestecl', 
'n_gamma_allecl', 
'n_gamma_klmT', 
'n_gamma_klmF',
 
   70                       'n_KL_ecl', 
'n_KL_klm'])
 
   71        main.add_module(ntupler)
 
   75        ntuplefile = TFile(testFile.name)
 
   76        ntuple = ntuplefile.Get(
'ntuple')
 
   78        self.assertFalse(ntuple.GetEntries() == 0, 
"Ntuple is empty.")
 
   80        nEntries = ntuple.GetEntries()
 
   83        sameNumberForPiAndGamma_ECL = ntuple.GetEntries(
"n_pi_ecl == n_gamma_bestecl")
 
   85        sameNumberForPiAndHadron_ECL = ntuple.GetEntries(
"n_pi_ecl >= n_KL_ecl")
 
   87        sameNumberForPiAndBothGammaHadron_KLM = ntuple.GetEntries(
"(n_pi_klm == n_gamma_klmT) && (n_pi_klm == n_KL_klm)")
 
   89        self.assertTrue(nEntries == sameNumberForPiAndGamma_ECL,
 
   90                        "Charged ECL-cluster is not correctly loaded for gamma.")
 
   91        self.assertTrue(nEntries == sameNumberForPiAndHadron_ECL,
 
   92                        "Charged ECL-cluster is not correctly loaded for neutral hadron.")
 
   93        self.assertTrue(nEntries == sameNumberForPiAndBothGammaHadron_KLM,
 
   94                        "Charged KLM-cluster is not correctly loaded for both gamma and neutral hadron.")
 
   96        allIsGreaterThanBest = ntuple.GetEntries(
"n_gamma_allecl >= n_gamma_bestecl")
 
   97        self.assertTrue(nEntries == allIsGreaterThanBest, 
"Charged ECL-cluster is missed with useOnlyMostEnergeticECLCluster=False")
 
   99        optionDoesNotChangeKLM = ntuple.GetEntries(
"n_gamma_klmT == n_gamma_klmF")
 
  100        self.assertTrue(nEntries == optionDoesNotChangeKLM, 
"Charged KLM-cluster is affected by useOnlyMostEnergeticECLCluster")
 
  102        print(
"Test passed, cleaning up.")