Esempio n. 1
0
def iterative_search(particles, history="", br=1, last_hist=False):
    global list_result
    query_permutations = order_particles(particles)
    for d in Decay.objects(__raw__={"childs": query_permutations}):
        if br * d.branching >= br_cutoff:
            list_result.append(
                {"parent": d.parent, "branching": br * d.branching, "scheme": d.nice_decay + "; " + history}
            )
            # if d.nice_decay+"; "+history not in result:
            #    result[d.nice_decay+"; "+history]=br*d.branching
            # else:
            #    result[d.nice_decay+"; "+history]+=br*d.branching
    small_query_subsets = []
    for len_part in range(2, len(particles)):
        for comb in set(combinations(particles, len_part)):
            small_query_subsets.append(comb)
    for i in set(small_query_subsets):
        b = copy(particles)
        for j in i:
            b.remove(j)
        subset_permutations = order_particles(i)
        for d in Decay.objects(childs=subset_permutations):
            c = copy(b)
            c.append(d.parent)
            if br * d.branching >= br_cutoff:
                iterative_search(c, d.nice_decay + "; " + history, br * d.branching)
    return True
Esempio n. 2
0
def knowndecays(query):
    d_list = []
    for d in Decay.objects(parent = query.replace("__","/")):
        d_list.append(d.to_dict())
    for d in d_list:
        d['branching'] = nice_br(d['branching'])
    return render_template('SingleParticle.html', particle = query.replace("__","/"), d_list = d_list)
Esempio n. 3
0
def normal_query(particles):
    query_permutations = [" ".join(x) for x in set(permutations(particles, len(particles)))]
    result = []
    # for d in Decay.objects(fstate__in = query_permutations):
    for d in Decay.objects(fstate__in=query_permutations):
        # d.printdecay()
        result.append(d.scheme)
    return result
Esempio n. 4
0
def lazy_query(particles, history=False, br=1, last_hist=False):
    global lazy_result
    query_permutations = [" ".join(x) for x in set(permutations(particles, len(particles)))]
    for d in Decay.objects(fstate__in=query_permutations):
        if br * d.branching >= br_cutoff:
            # lazy_result.append(d.scheme+"; "+history+"    br: "+str(br*d.branching))
            if history:
                # print d.scheme+"; "+history
                dec = Decay(
                    father=d.father, scheme=d.scheme + "; " + history, branching=br * d.branching, fstate=d.fstate
                ).order_history()
                lazy_result[dec.scheme] = last_hist
            else:
                # print d.scheme
                dec = Decay(
                    father=d.father, scheme=d.scheme, branching=br * d.branching, fstate=d.fstate
                ).order_history()
                lazy_result[dec.scheme] = d.fstate
            # print "added "+d.scheme+"; "+history
    small_query_subsets = []
    for len_part in range(2, len(particles)):
        for comb in set(combinations(particles, len_part)):
            small_query_subsets.append(comb)
    #    small_query_subsets = set(combinations(particles, len_part))
    for i in set(small_query_subsets):
        b = copy(particles)
        for j in i:
            b.remove(j)
        subset_permutations = [" ".join(x) for x in set(permutations(i, len(i)))]
        for d in Decay.objects(fstate__in=subset_permutations):
            c = copy(b)
            c.append(d.father)
            if br * d.branching >= br_cutoff:
                if history:
                    lazy_query(c, d.scheme + "; " + history, br * d.branching, d.scheme + "  " + history)
                else:
                    lazy_query(c, d.scheme, br * d.branching, d.scheme)
    return True
Esempio n. 5
0
def do_search(query):
    # Set conversion is done for duplicate removing
    query_permutations = [" ".join(x) for x in set(permutations(query, len(query)))]

    # Cache check
    # if cache_key(query) in mc:
    #     return mc[cache_key(query)]
    #Decay.objects(fstate_in = query_permutations)
    #for d in Decay.objects(fstate__in = query_permutations):
    #    d.printdecay()
        #json_dump(d.to_json)
    #result = sorted(Decay.objects(fstate__in = query_permutations),  key=lambda x: -x['branching'])
    result = []
    for d in Decay.objects(fstate__in = query_permutations):
        result.append(d.to_dict())

    #result = sorted(list(fstates.find(
    #        {"fstate": {"$in": query_permutations}}, 
    #        {"_id": False})),  key=lambda x: -x['branching'][0])

    # for q in query_permutations:
    #     mc[cache_key(q)] = result

    return result
Esempio n. 6
0
def delete_decays_by_key(key):
    for d in Decay.objects(user_keys__contains = key):
        #print("Deleting decay:")
        #d.printdecay()
        d.delete()
Esempio n. 7
0
def delete_decays_by_key(key):
    for d in Decay.objects(user_keys__contains = key):
        d.delete()
Esempio n. 8
0
def add_decay(father, decay, user_keys="", history = "", uniterated_daughters = [], test_mode=False):
    """
    Father = <Name of a particle from particle DB>
    decay = {
                "branching": 0.0175,
                "daughters": [
                    "e-",
                    "nu_e~",
                    "nu_tau",
                    "gamma"
                ]
            }
    This function adds a decay to the existing DB (No need to full rebuild)
    Please keep in mind, that all particles in the decay should be in particle DB 
    """
    global br_cutoff

    if history == "":
        history = "{} --> {}".format(father, ' '.join(decay['daughters']))
    if user_keys == "":
        user_keys = history
    for d in decay['daughters']:
        if not check_if_particle_exist(d):
            print("Trying to add decay of "+father)
            print(json.dumps(decay,sort_keys=True, indent=4))
            print("with unexisting particle   "+d)
            return False
    if ((decay["branching"]>br_cutoff) and (1<len(decay["daughters"])<max_decay_chain)):
        db_dec = Decay(father = father, scheme = history, branching = decay["branching"], fstate = ' '.join(decay["daughters"]), user_keys = user_keys).order_history()
        if test_mode:
            print("Trying to save decay:")
            db_dec.printdecay()
        try:
            db_dec.save()
            if test_mode:
                print("Decay saved!")
        except:
            print("Failed to save decay!")
            db_dec.printdecay()
            
        try:
            #Now need to update all decays having this particle in final state with this mode of decay
            db_dec.update_ancestors()
            if test_mode:
                print("Ancestors updated!")
        except:
            print("Failed to update ancestors")
            db_dec.printdecay()
        
        if test_mode:
            print("cc-ing decay")
        db_dec_cc = db_dec.do_cc().order_history()
        if db_dec_cc:
            if test_mode:
                print("decay cc-ed")
            try:
                db_dec_cc.save()
                db_dec_cc.update_ancestors()
            except:
                print("Failed to save decay!")
                db_dec_cc.printdecay()
        elif test_mode:
            print("failed to cc decay")

        if uniterated_daughters:
            if test_mode:
                print("Iterating over the daughters")
            for i, daughter in enumerate(uniterated_daughters):
                if test_mode:
                    print("Daughter "+daughter)
                for saved_dec in Decay.objects(father = daughter):
                    if test_mode:
                        print("decay: "+saved_dec.scheme)
                    subst = history.split('; ') + saved_dec.scheme.split('; ')
                    new_history = '; '.join(subst[:1] + sorted(subst[1:]))
                    new_user_keys = saved_dec.user_keys+user_keys
                    daughters = []
                    for d in decay["daughters"]:
                        if d!=daughter:
                            daughters.append(d)
                    for d in saved_dec.fstate.split(' '):
                        daughters.append(d)
                    new_uniterated_daughters = []
                    for d in uniterated_daughters:
                        if d!=daughter:
                            new_uniterated_daughters.append(d)
                    branching = decay["branching"]*saved_dec.branching
                    new_decay = {"branching":branching, "daughters":copy.deepcopy(daughters)}
                    if i == 0:
                        add_decay(father, new_decay, new_user_keys, new_history, new_uniterated_daughters, test_mode)
                    else:
                        add_decay(father, new_decay, new_user_keys, new_history, [], test_mode)
    return True