Belle II Software development
MonitoringBranchingFractions Class Reference

Public Member Functions

 __init__ (self)
 
 getExclusive (self, particle)
 
 getInclusive (self, particle)
 
 getBranchingFraction (self, particle, branching_fractions)
 
 loadExclusiveBranchingFractions (self, filename)
 
 loadInclusiveBranchingFractions (self, exclusive_branching_fractions)
 

Public Attributes

 exclusive_branching_fractions = self.loadExclusiveBranchingFractions(decay_file)
 exclusive branching fractions
 
 inclusive_branching_fractions = self.loadInclusiveBranchingFractions(self.exclusive_branching_fractions)
 inclusive branching fractions
 

Static Protected Attributes

 _shared = None
 is the monitoring shared
 

Detailed Description

 Class extracts the branching fractions of a decay channel from the DECAY.DEC file. 

Definition at line 484 of file monitoring.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self)
Create a new MonitoringBranchingFraction object.
The extracted branching fractions are cached, hence creating more than one object does not do anything.

Definition at line 489 of file monitoring.py.

489 def __init__(self):
490 """
491 Create a new MonitoringBranchingFraction object.
492 The extracted branching fractions are cached, hence creating more than one object does not do anything.
493 """
494 if MonitoringBranchingFractions._shared is None:
495 decay_file = get_default_decayfile()
496
497 self.exclusive_branching_fractions = self.loadExclusiveBranchingFractions(decay_file)
498
499 self.inclusive_branching_fractions = self.loadInclusiveBranchingFractions(self.exclusive_branching_fractions)
500 MonitoringBranchingFractions._shared = (self.exclusive_branching_fractions, self.inclusive_branching_fractions)
501 else:
502 self.exclusive_branching_fractions, self.inclusive_branching_fractions = MonitoringBranchingFractions._shared
503

Member Function Documentation

◆ getBranchingFraction()

getBranchingFraction ( self,
particle,
branching_fractions )
 Returns the branching fraction of a particle given a branching_fraction table. 

Definition at line 512 of file monitoring.py.

512 def getBranchingFraction(self, particle, branching_fractions):
513 """ Returns the branching fraction of a particle given a branching_fraction table. """
514 result = {c.label: 0.0 for c in particle.channels}
515 name = particle.name
516 channels = [tuple(sorted(d.split(':')[0] for d in channel.daughters)) for channel in particle.channels]
517 if name not in branching_fractions:
518 name = pdg.conjugate(name)
519 channels = [tuple(pdg.conjugate(d) for d in channel) for channel in channels]
520 if name not in branching_fractions:
521 return result
522 for c, key in zip(particle.channels, channels):
523 if key in branching_fractions[name]:
524 result[c.label] = branching_fractions[name][key]
525 return result
526
conjugate(name)
Definition pdg.py:111

◆ getExclusive()

getExclusive ( self,
particle )
 Returns the exclusive (i.e. without the branching fractions of the daughters) branching fraction of a particle. 

Definition at line 504 of file monitoring.py.

504 def getExclusive(self, particle):
505 """ Returns the exclusive (i.e. without the branching fractions of the daughters) branching fraction of a particle. """
506 return self.getBranchingFraction(particle, self.exclusive_branching_fractions)
507

◆ getInclusive()

getInclusive ( self,
particle )
 Returns the inclusive (i.e. including all branching fractions of the daughters) branching fraction of a particle. 

Definition at line 508 of file monitoring.py.

508 def getInclusive(self, particle):
509 """ Returns the inclusive (i.e. including all branching fractions of the daughters) branching fraction of a particle. """
510 return self.getBranchingFraction(particle, self.inclusive_branching_fractions)
511

◆ loadExclusiveBranchingFractions()

loadExclusiveBranchingFractions ( self,
filename )
Load branching fraction from MC decay-file.

Definition at line 527 of file monitoring.py.

527 def loadExclusiveBranchingFractions(self, filename):
528 """
529 Load branching fraction from MC decay-file.
530 """
531
532 def isFloat(element):
533 """ Checks if element is a convertible to float"""
534 try:
535 float(element)
536 return True
537 except ValueError:
538 return False
539
540 def isValidParticle(element):
541 """ Checks if element is a valid pdg name for a particle"""
542 try:
543 pdg.from_name(element)
544 return True
545 except LookupError:
546 return False
547
548 branching_fractions = {'UNKOWN': {}}
549
550 mother = 'UNKOWN'
551 with open(filename) as f:
552 for line in f:
553 fields = line.split(' ')
554 fields = [x for x in fields if x != '']
555 if len(fields) < 2 or fields[0][0] == '#':
556 continue
557 if fields[0] == 'Decay':
558 mother = fields[1].strip()
559 if not isValidParticle(mother):
560 mother = 'UNKOWN'
561 continue
562 if fields[0] == 'Enddecay':
563 mother = 'UNKOWN'
564 continue
565 if mother == 'UNKOWN':
566 continue
567 fields = fields[:-1]
568 if len(fields) < 1 or not isFloat(fields[0]):
569 continue
570 while len(fields) > 1:
571 if isValidParticle(fields[-1]):
572 break
573 fields = fields[:-1]
574 if len(fields) < 1 or not all(isValidParticle(p) for p in fields[1:]):
575 continue
576 neutrinoTag_list = ['nu_e', 'nu_mu', 'nu_tau', 'anti-nu_e', 'anti-nu_mu', 'anti-nu_tau']
577 daughters = tuple(sorted(p for p in fields[1:] if p not in neutrinoTag_list))
578 if mother not in branching_fractions:
579 branching_fractions[mother] = {}
580 if daughters not in branching_fractions[mother]:
581 branching_fractions[mother][daughters] = 0.0
582 branching_fractions[mother][daughters] += float(fields[0])
583
584 del branching_fractions['UNKOWN']
585 return branching_fractions
586
from_name(name)
Definition pdg.py:63

◆ loadInclusiveBranchingFractions()

loadInclusiveBranchingFractions ( self,
exclusive_branching_fractions )
Get covered branching fraction of a particle using a recursive algorithm
and the given exclusive branching_fractions (given as Hashable List)
@param particle identifier of the particle
@param branching_fractions

Definition at line 587 of file monitoring.py.

587 def loadInclusiveBranchingFractions(self, exclusive_branching_fractions):
588 """
589 Get covered branching fraction of a particle using a recursive algorithm
590 and the given exclusive branching_fractions (given as Hashable List)
591 @param particle identifier of the particle
592 @param branching_fractions
593 """
594 particles = set(exclusive_branching_fractions.keys())
595 particles.update({pdg.conjugate(p) for p in particles if p != pdg.conjugate(p)})
596 particles = sorted(particles, key=lambda x: pdg.get(x).Mass())
597 inclusive_branching_fractions = copy.deepcopy(exclusive_branching_fractions)
598
599 for p in particles:
600 if p in inclusive_branching_fractions:
601 br = sum(inclusive_branching_fractions[p].values())
602 else:
603 br = sum(inclusive_branching_fractions[pdg.conjugate(p)].values())
604 for p_br in inclusive_branching_fractions.values():
605 for c in p_br:
606 for i in range(c.count(p)):
607 p_br[c] *= br
608 return inclusive_branching_fractions
609
610
get(name)
Definition pdg.py:48

Member Data Documentation

◆ _shared

_shared = None
staticprotected

is the monitoring shared

Definition at line 487 of file monitoring.py.

◆ exclusive_branching_fractions

exclusive_branching_fractions = self.loadExclusiveBranchingFractions(decay_file)

exclusive branching fractions

Definition at line 497 of file monitoring.py.

◆ inclusive_branching_fractions

inclusive_branching_fractions = self.loadInclusiveBranchingFractions(self.exclusive_branching_fractions)

inclusive branching fractions

Definition at line 499 of file monitoring.py.


The documentation for this class was generated from the following file: