Пример #1
0
def test_particle():
    # for part in ['u', "ubar", "d", "dbar","c","cbar","s","sbar","b","bbar"]:
    #     this = QuantumUniverseParticle(part)
    #     print (this.transformtime)
    particle = QuantumUniverseParticle('Omega*_c0')
    print(particle.decay_channels)
    print(particle.mass)
    for item in particle.decay_channels[0][1]:
        print(ParticleDataSource.getName(item))
    particle2 = QuantumUniverseParticle('Omega_c0')
    print(particle2.type)
    print(particle2.mass)
    print(particle.name in ParticleDataSource.getExcludedParticles())
    print(TransformationChannels.from_decaylist(particle.decay_channels).all)
Пример #2
0
class TransformationChannels(object):
    '''
    TCS class includes ALL the channels of a particular transformation
    TCS = TransformationChannels.from_decaylist([(0.5,[1,2]),(0.5,[3,4])])
    TCS = TransformationChannels.from_decaylistNames([(0.5,['e-','nu_ebar']),(0.5,['mu-','nu_mubar'])])
    TCS.all = [TC1,TC2]
    TCS.length = 2
    TCS.mostProbable: the TC with higher BR
    TCS.getChannel(1) = TC2
    TCS.getChannel(['mu-','nu_mubar']) = TC2
    TCS.lengthCut(3) -> TCs with number of output particles <= 3
    TCS.lengthSelection(3) -> TCs with number of output particles = 3
    '''
    EXCLUDED = ParticleDataSource.getExcludedParticles()
    additional = ['g', 'Omega*_c0', 'Omega_c0']
    EXCLUDED.extend(additional)
    EXCLUDEDSET = set(EXCLUDED)

    #EXCLUDED = set(['rndmflavgbar','rndmflavg','g'])

    def __init__(self, tclist):
        self._tclist = tclist

    @classmethod
    def from_decaylist(cls, decaylist, energy=0):
        '''
        We only accept 2body and 3body channels
        If we find a 1 body channel we use the decay channels of that particle
        '''
        tclist = []
        for channel in decaylist:
            TC = TransformationChannel(channel[0], channel[1])
            if all([
                    TC.length in [2, 3, 4],
                    TC.BR > 0.0,
                    TC.nameSet.intersection(
                        TransformationChannels.EXCLUDEDSET) == set([]),
                    #TC.totalMass <= energy
            ]):
                tclist.append(TC)
            elif TC.length == 1:
                oldBR = TC.BR

                newDCS = ParticleDataSource.getDecayChannels(TC.names[0])
                for newTC in TransformationChannels.from_decaylist(newDCS).all:
                    thisBR = newTC.BR
                    newTC = newTC._replace(BR=oldBR * thisBR)
                    tclist.append(newTC)
        return cls(tclist)

    @classmethod
    def from_decaylistNames(cls, decaylist):
        tclist = []
        for channel in decaylist:
            TC = TransformationChannel(
                channel[0], list(map(ParticleDataSource.getPDGId, channel[1])))
            if all([
                    TC.length in [2, 3, 4], TC.BR > 0.0,
                    TC.nameSet.intersection(
                        TransformationChannels.EXCLUDED) == set([])
            ]):
                tclist.append(TC)
        return cls(tclist)

    @property
    def all(self):
        return self._tclist

    @property
    def length(self):
        return len(self._tclist)

    @property
    def mostProbable(self):
        return sorted(self._tclist, key=lambda x: x.BR)[-1]

    def getChannel(self, *arg):
        if isinstance(arg[0], (int, long)):
            return self.getChannelfromId(arg[0])
        elif isinstance(arg[0], list):
            return self.getChannelfromParticles(arg[0])

    def getChannelfromId(self, id):
        try:
            return self.all[id]
        except:
            return []

    def getChannelfromParticles(self, particles):
        try:
            return [
                channel for channel in self.all
                if channel.nameSet == set(particles)
                and channel.length == len(particles)
            ]
        except:
            return []

    def lengthCut(self, len):
        return [channel for channel in self._tclist if channel.length <= len]

    def lengthSelection(self, len):
        return [channel for channel in self._tclist if channel.length == len]