def addElement(self, newelement): """ Add an Element object to the elementList. For all the pre-existing elements, which match the new element, add weight. If no pre-existing elements match the new one, add it to the list. OBS: newelement MUST ALREADY BE SORTED (see element.sort()) :parameter newelement: element to be added (Element object) :returns: True, if the element was added. False, otherwise """ # If the topology info has not been set yet, set it using the element # info if not self.vertparts: self.vertparts = newelement.getEinfo()["vertparts"] if not self.vertnumb: self.vertnumb = newelement.getEinfo()["vertnumb"] #First check if element matches topology structure info = newelement.getEinfo() if info != self._getTinfo(): logger.warning('Element to be added does not match topology') return False index = index_bisect(self.elementList,newelement) if index != len(self.elementList) and self.elementList[index] == newelement: self.elementList[index].weight.combineWith(newelement.weight) self.elementList[index].combinePIDs(newelement) self.elementList[index].combineMotherElements(newelement) else: self.elementList.insert(index,newelement) return True
def index(self,topo): """ Uses bisect to find the index where of topo in the list. If topo does not appear in the list, returns None. :param topo: Topology object :return: position of topo in the list. If topo does not appear in the list, return None. """ i = index_bisect(self, topo) if i != len(self) and self[i] == topo: return i return None
def add(self, newTopology): """ Check if elements in newTopology matches an entry in self.topos. If it does, add weight. If the same topology exists, but not the same element, add element. If neither element nor topology exist, add the new topology and all its elements. :param newTopology: Topology object """ index = index_bisect(self, newTopology) if index != len(self) and self[index] == newTopology: for newelement in newTopology.elementList: self.topos[index].addElement(newelement) else: self.insert(index,newTopology)
def addToGeneralElements(self, el, missingX): """ Adds an element to the list of missing topologies = general elements. If the element contributes to a missing topology that is already in the list, add element and weight to topology. :parameter el: element to be added :parameter missingX: missing cross-section for the element (in fb) """ newGenEl = GeneralElement(el, missingX, self.smFinalStates, self.bsmFinalStates) index = index_bisect(self.generalElements, newGenEl) if index != len(self.generalElements ) and self.generalElements[index] == newGenEl: self.generalElements[index]._contributingElements.append(el) self.generalElements[index].missingX += missingX else: self.generalElements.insert(index, newGenEl)
def addElement(self, newelement): """ Add an Element object to the corresponding topology in the list. If the element topology does not match any of the topologies in the list, create a new topology and insert it in the list. If the element topology already exists, add it to the respective topology. :parameter newelement: element to be added (Element object) :returns: True, if the element was added. False, otherwise """ #First create a dummy topology from the element to check #if this topology already exists in the list: elInfo = newelement.getEinfo() topoDummy = Topology() topoDummy.elementList.append(newelement) topoDummy.vertnumb = elInfo["vertnumb"] topoDummy.vertparts = elInfo["vertparts"] index = index_bisect(self,topoDummy) if index != len(self) and self.topos[index] == topoDummy: self.topos[index].addElement(newelement) else: self.topos.insert(index,topoDummy)