11import modularAnalysis 
as ma
 
   12from ROOT 
import Belle2
 
   18class Generator(basf2.Module):
 
   19    """Generate list of 10 electrons which have random momenta and one 
   20    electron where all momentum components are nan""" 
   23        """We need to register the mc particles""" 
   26        self.mcp.registerInDataStore()
 
   29        """And then we generate particles""" 
   31            p = self.mcp.appendNew()
 
   34            p.setMomentum(random.randrange(0, 5), random.randrange(0, 5), random.randrange(0, 5))
 
   36        p = self.mcp.appendNew()
 
   39        p.setMomentum(math.nan, math.nan, math.nan)
 
   42class MergingChecker(basf2.Module):
 
   43    """Check if merging works correctly""" 
   46        """Create particle list objects""" 
   56        """Check if the particle lists have the expected size""" 
   57        allsize = self.all.getListSize()
 
   58        below2size = self.below2.getListSize()
 
   59        above3size = self.above3.getListSize()
 
   60        onlyallsize = self.onlyall.getListSize()
 
   61        goodmergesize = self.goodmerge.getListSize()
 
   62        bestsize = self.best.getListSize()
 
   64        assert onlyallsize == allsize
 
   65        assert goodmergesize == below2size + above3size
 
   66        assert bestsize == below2size + above3size
 
   71path.add_module(
"EventInfoSetter", evtNumList=10)
 
   72path.add_module(Generator())
 
   74ma.fillParticleListFromMC(
"e-:allMC", 
"", path=path)
 
   75ma.variablesToExtraInfo(
'e-:allMC', {
'formula(0)': 
'identifier', 
'random': 
'quality'}, path=path)
 
   77ma.fillParticleListFromMC(
"e-:below2", 
"px < 2", path=path)
 
   78ma.variablesToExtraInfo(
'e-:below2', {
'formula(2)': 
'identifier', 
'formula(1 + random)': 
'quality'}, option=2, path=path)
 
   80ma.fillParticleListFromMC(
"e-:above3", 
"px > 3", path=path)
 
   81ma.variablesToExtraInfo(
'e-:above3', {
'formula(3)': 
'identifier', 
'formula(2 + random)': 
'quality'}, option=2, path=path)
 
   88ma.copyLists(
'e-:onlyall', [
'e-:allMC', 
'e-:below2', 
'e-:above3'], path=path)
 
   90ma.printVariableValues(
'e-:onlyall', [
'extraInfo(identifier)'], path=path)
 
   94ma.copyLists(
'e-:goodmerge', [
'e-:below2', 
'e-:above3', 
'e-:allMC'], path=path)
 
   99ma.printVariableValues(
'e-:goodmerge', [
'extraInfo(identifier)'], path=path)
 
  100ma.applyCuts(
'e-:goodmerge', 
'extraInfo(identifier) > 0', path=path)
 
  103path.add_module(
'ParticleListManipulator', outputListName=
'e-:best', inputListNames=[
'e-:allMC', 
'e-:below2', 
'e-:above3'],
 
  104                variable=
'extraInfo(quality)', preferLowest=
False)
 
  106ma.printVariableValues(
'e-:best', [
'extraInfo(identifier)'], path=path)
 
  107ma.applyCuts(
'e-:best', 
'extraInfo(identifier) > 0', path=path)
 
  109path.add_module(MergingChecker())
 
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.