def getCorrectParent(mcp): pars = mcp.getParents() if len(pars) > 1: #pick the parent which is furthest from the IP if same return the first (flen,furthest) = (-1,0) for par in pars: if um.threeDRadius(par.getVertex()) > flen: (flen,furthest) = (um.threeDRadius(par.getVertex()),par) return furthest else: #An expection here means we made it to the root of the event #ie the ip detection below failed return pars[0]
def getHeavyHadronDecayLength(mcp): #True if flavour change start = mcp.getVertex() same_flavour = [quarkType(d.getPDG()) == quarkType(mcp.getPDG()) for d in mcp.getDaughters()] while any(same_flavour): mcp = mcp.getDaughters()[same_flavour.index(True)] same_flavour = [quarkType(d.getPDG()) == quarkType(mcp.getPDG()) for d in mcp.getDaughters()] end = mcp.getEndpoint() return mu.threeDRadius(mu.sub(start,end))
def mcVertexNumber(event,rp): track = rp.getTracks()[0] mcps = event.getRelatedTo(track,[collectionnames.trackmcpcollection,]) mcp = mcps[0] v = mcp.getVertex() #Go back through the tree counting all none resonant decays v_num = 0 while mc.quarkType(mcp.getPDG()) != -1: #print mcp.getPDG() mcp = getCorrectParent(mcp) if um.threeDRadius(um.sub(mcp.getVertex(),mcp.getEndpoint())) > 0.0000000001 : v_num += 1 #print flavourOfParentVertex(event,rp) , v_num, v return v_num
def mCVertices(mcps): #group mc particles by production point, assume same point if they have a distance less than 0.01micron! vertices = {} for mcp in mcps: #check that there is not a key that is below the threshold nearkeys = (key for key in vertices.iterkeys() if mu.threeDRadius(mu.sub(mcp.getVertex(),key)) < 0.0000001) try: vertices[nearkeys.next()].append(mcp) except StopIteration: try: vertices[mcp.getVertex()].append(mcp) except KeyError: vertices[mcp.getVertex()] = [mcp,] return vertices
def printMCTree(mcps,filename="temp.dot"): #start the graph f=open(filename, 'w') f.write('digraph G {\nranksep="equally";\noverlap="false";\nrankdir="LR";\ncompound=true;\n') #make a node for each mcp colors = {-1:"white",0:"white",1:"grey",2:"yellow",3:"green",4:"red",5:"blue",6:"pink"} for mcp in mcps: name = str(mcp.id()) label = lc.pdgToName(mcp.getPDG()) colour= colors[quarkType(mcp.getPDG())] f.write('"'+name+'" [ label="'+label+' '+str(len(mcp.getParents()))+'",style="filled",color="'+colour+'" ];\n') #idn = 0 #mcp_ids = [mcp.id() for mcp in mcps] #for mcp in mcps: # daughters = [daughter for daughter in mcp.getDaughters() if daughter.id() in mcp_ids] # if daughters: # f.write('subgraph cluster'+str(idn)+'{\n') # for daughter in daughters: # f.write(str(daughter.id())+';\n') # f.write('}\n') # f.write(str(mcp.id())+'->'+str(daughter.id())+' [ lhead=cluster'+str(idn)+',label = #"'+str(mu.threeDRadius(sub(mcp.getVertex(),mcp.getEndpoint())))[:4]+'" ];') # idn += 1 #make a node in each cluster #idn = 0 #for vert in mCVertices(mcps).itervalues(): # #we need to remove the ones that leave this vertex # #vert = [mcp for mcp in vert if mu.threeDRadius(sub(mcp.getVertex(),mcp.getEndpoint())) < 0.00000001] # if len(vert) > 1: # f.write('subgraph cluster'+str(idn)+'{\n') # for mcp in vert: # f.write(str(mcp.id())+';\n') # f.write('}\n') # idn += 1 #make a link for each decay (whose product is in the list!) mcp_ids = [mcp.id() for mcp in mcps ]#if fromIP(mcp)] for mcp in mcps: for parent in mcp.getParents(): # if fromIP(parent): f.write(str(parent.id())+'->'+str(mcp.id())+' [ label = "'+str(mu.threeDRadius(mu.sub(parent.getVertex(),parent.getEndpoint())))[:4]+'" ];') #end graph f.write('}\n') f.close() f=open(filename+".png", 'w') sp.call(['dot', '-Tpng', filename],stdout = f) f.close() sp.call(['eog', filename+".png"])