def testReader(self): filename = "./testFiles/lhe/simplyGluino.lhe" reader = lheReader.LheReader(filename) events = [event for event in reader] reader.close() self.assertEqual(len(events), 5)
def decompose(lhefile, inputXsecs=None, nevts=None, doCompress=False, doInvisible=False, minmassgap=-1. * GeV): """ Perform LHE-based decomposition. :param lhefile: LHE file with e.g. pythia events :param inputXsecs: xSectionList object with cross sections for the mothers appearing in the LHE file. If None, use information from file. :param nevts: (maximum) number of events used in the decomposition. If None, all events from file are processed. :param doCompress: mass compression option (True/False) :param doInvisible: invisible compression option (True/False) :param minmassgap: minimum mass gap for mass compression (only used if doCompress=True) :returns: list of topologies (TopologyList object) """ if doCompress and minmassgap < 0. * GeV: logger.error( "Asked for compression without specifying minmassgap. Please set minmassgap." ) raise SModelSError() reader = lheReader.LheReader(lhefile, nevts) smsTopList = topology.TopologyList() # Get cross section from file (= event weight, assuming a common weight for # all events) if not inputXsecs: xSectionList = crossSection.getXsecFromLHEFile(lhefile, addEvents=False) else: xSectionList = inputXsecs # Loop over events and decompose for event in reader: momPDG = tuple(sorted(event.getMom())) # Get mother PDGs eventweight = xSectionList.getXsecsFor(momPDG) # Get event element newElement = elementFromEvent(event, eventweight) if not newElement: continue allElements = [newElement] # Perform compression if doCompress or doInvisible: allElements += newElement.compressElement(doCompress, doInvisible, minmassgap) for el in allElements: el.sortBranches() smsTopList.addElement(el) smsTopList._setElementIds() return smsTopList
def testGraph(self): """ draw ascii graph """ from smodels.tools import asciiGraph from smodels.theory import lheReader, lheDecomposer, crossSection filename = "./testFiles/lhe/simplyGluino.lhe" reader = lheReader.LheReader(filename) event = reader.next() element = lheDecomposer.elementFromEvent(event, crossSection.XSectionList()) d1=self.orig().split("\n") d2=asciiGraph.asciidraw ( element, border=True ).split("\n") #for (idx,line) in enumerate(d1): # print "%d >>%s<< >>%s<<" % (idx,line, d2[idx] ) #print d1==d2 reader.close() self.assertEqual(d1,d2)
def testReader(self): """ test the LheReader """ from smodels.theory import lheReader, lheDecomposer, crossSection from smodels.tools.physicsUnits import GeV filename = "./testFiles/lhe/simplyGluino.lhe" reader = lheReader.LheReader(filename) event = reader.next() element = lheDecomposer.elementFromEvent(event, crossSection.XSectionList()) s=str(element) assert ( s == "[[[q,q]],[[q,q]]]" ) b0=element.branches[0] sb0=str(b0) assert ( sb0 == "[[q,q]]" ) assert ( b0.masses[0]-675*GeV ) < .1*GeV assert ( b0.masses[1]-600*GeV ) < .1*GeV
def evaluateStatus(self): """ run status check """ if not os.path.exists(self.filename): # set status flag to -3, as in slha checks for missing input file return -3, "Inputfile %s not found" % self.filename lhe = lheReader.LheReader(self.filename) nevents = lhe.metainfo["nevents"] totxsec = lhe.metainfo["totalxsec"] sqrts = lhe.metainfo["sqrts"] if (not type(sqrts) == type(1 * GeV)) or (not sqrts.asNumber()): return -1, "Center-of-mass energy not found in the input LHE file %s" % self.filename elif not nevents: return -1, "No events found in the input LHE file %s" % self.filename elif (not type(totxsec) == type(1 * fb)) or (not totxsec.asNumber()): return -1, "Total cross section not found in the input LHE file %s" % self.filename return 1, "Input file ok"
def testEventDictionaries(self): filename = "./testFiles/lhe/simplyGluino.lhe" reader = lheReader.LheReader(filename) events = [event for event in reader] reader.close() massDict, decayDict = lheReader.getDictionariesFromEvent(events[0]) self.assertEqual(massDict, { -1: [0.33], 1000021: [675.0], 1000022: [200.0], 1: [0.33] }) gluinoDec = [ pyslha.Decay(br=1., nda=3, ids=[-1, 1, 1000022], parentid=1000021) ] * 2 self.assertTrue(compareDecays(gluinoDec, decayDict[1000021])) self.assertEqual(decayDict[1000022], [])
sys.path.append(os.path.join(os.getenv("HOME"),"smodels/")) # In[2]: #Import those parts of smodels that are needed for this exercise from smodels.theory import lheReader, lheDecomposer, crossSection from smodels.installation import installDirectory from smodels.tools import asciiGraph # In[3]: #Load an input file containing LHE events and start the LHE reader filename="%s/inputFiles/lhe/gluino_squarks.lhe" % installDirectory() reader = lheReader.LheReader ( filename ) # In[4]: #Read the next event and generate the corresponding element event=reader.next() element=lheDecomposer.elementFromEvent (event) # In[5]: #Print the corresponding ASCII graph print asciiGraph.asciidraw ( element )
def getXsecFromLHEFile(lhefile, addEvents=True): """ Obtain cross sections from input LHE file. :parameter lhefile: LHE input file with unweighted MC events :parameter addEvents: if True, add cross sections with the same mothers, otherwise return the event weight for each pair of mothers :returns: a XSectionList object """ # Store information about all cross sections in the LHE file xSecsInFile = XSectionList() reader = lheReader.LheReader(lhefile) if not type(reader.metainfo["totalxsec"]) == type(pb): logger.error("cross section information not found in LHE file.") raise SModelSError() elif not reader.metainfo["nevents"]: logger.error("Total number of events information not found in LHE " + "file.") raise SModelSError() elif not type(reader.metainfo["sqrts"]) == type(TeV): logger.error("Center-of-mass energy information not found in LHE " + "file.") raise SModelSError() # Common cross section info totxsec = reader.metainfo["totalxsec"] nevts = reader.metainfo["nevents"] sqrtS = reader.metainfo["sqrts"] eventCs = totxsec / float(nevts) # Get all mom pids allpids = [] for event in reader: allpids.append(tuple(sorted(event.getMom()))) pids = set(allpids) # Generate zero cross sections for all independent pids for pid in pids: xsec = XSection() xsec.info.sqrts = sqrtS if 'cs_order' in reader.metainfo: xsec.info.order = reader.metainfo["cs_order"] else: # Assume LO xsecs, if not defined in the reader xsec.info.order = 0 wlabel = str(sqrtS / TeV) + ' TeV' if xsec.info.order == LO: wlabel += ' (LO)' elif xsec.info.order == NLO: wlabel += ' (NLO)' elif xsec.info.order == NLL: wlabel += ' (NLL)' xsec.info.label = wlabel xsec.value = 0. * pb xsec.pid = pid # If addEvents = False, set cross section value to event weight if not addEvents: xsec.value = eventCs xSecsInFile.add(xsec) # If addEvents = True, sum up event weights with same mothers if addEvents: for pid in allpids: for ixsec, xsec in enumerate(xSecsInFile.xSections): if xsec.pid == pid: xSecsInFile.xSections[ixsec].value += eventCs reader.close() #Make sure duplicates are removed. xSecsInFile.removeDuplicates() return xSecsInFile
def testClusterer(self): """ test the mass clusterer """ from smodels.theory import lheReader, lheDecomposer, crossSection from smodels.theory import clusterTools from smodels.experiment.txnameObj import TxName, TxNameData from smodels.experiment.infoObj import Info from smodels.tools.physicsUnits import GeV, pb, fb import copy data = [[[[674.99 * GeV, 199.999 * GeV], [674.99 * GeV, 199.999 * GeV]], .03 * fb], [[[725.0001 * GeV, 200. * GeV], [725.0001 * GeV, 200. * GeV]], .06 * fb], [[[750. * GeV, 250. * GeV], [750. * GeV, 250. * GeV]], .03 * fb]] info = Info( os.path.join("./database/8TeV/ATLAS/ATLAS-SUSY-2013-05/data/", "dataInfo.txt")) globalInfo = Info( os.path.join("./database/8TeV/ATLAS/ATLAS-SUSY-2013-05/", "globalInfo.txt")) txnameData = TxNameData(data, "efficiencyMap", Id=1) txname = TxName( "./database/8TeV/ATLAS/ATLAS-SUSY-2013-05/data/T2bb.txt", globalInfo, info) txname.txnameData = txnameData filename = "./testFiles/lhe/simplyGluino.lhe" reader = lheReader.LheReader(filename) event = reader.next() reader.close() event_xsec = event.metainfo["totalxsec"] self.assertTrue(abs(event_xsec - 0.262 * pb) < .1 * pb) xsecs = crossSection.getXsecFromLHEFile(filename) element = lheDecomposer.elementFromEvent(event, xsecs) element.txname = None e0 = copy.deepcopy(element) ## has a gluino with mass of 675 GeV ## make a second element with a slightly different gluino mass e1 = copy.deepcopy(element) e1.branches[0].masses[0] = 725 * GeV e1.branches[1].masses[0] = 725 * GeV e0.txname = txname e1.txname = txname # lets now cluster the two different gluino masses. newel = clusterTools.groupAll([e0, e1]) newmasses = newel.getAvgMass() self.assertTrue( newmasses == None) ## in the case of efficiency maps the avg mass is none ## since it makes no sense txname.txnameData.dataTag = 'upperLimits' newel = clusterTools.clusterElements([e0, e1], 5.) ## this example gives an avg cluster mass of 700 gev self.assertTrue(newel[0].getAvgMass()[0][0] == 700. * GeV) newel = clusterTools.clusterElements([e0, e1], .5) #in this example the distance is not in maxdist, so we dont cluster self.assertTrue(len(newel) == 2)
def decompose(lhefile, inputXsecs=None, nevts=None, doCompress=False, doInvisible=False, minmassgap=-1. * GeV): """ Perform LHE-based decomposition. :param lhefile: LHE file with e.g. pythia events, may be given as URL (though http and ftp only) :param inputXsecs: xSectionList object with cross sections for the mothers appearing in the LHE file. If None, use information from file. :param nevts: (maximum) number of events used in the decomposition. If None, all events from file are processed. :param doCompress: mass compression option (True/False) :param doInvisible: invisible compression option (True/False) :param minmassgap: minimum mass gap for mass compression (only used if doCompress=True) :returns: list of topologies (TopologyList object) """ if lhefile.startswith("http") or lhefile.startswith("ftp"): logger.info("asked for remote lhefile %s. will fetch it." % lhefile) import requests import os.path r = requests.get(lhefile) if r.status_code != 200: logger.error("could not retrieve remote file %d: %s" % (r.status_code, r.reason)) sys.exit() basename = os.path.basename(lhefile) f = open(basename, "w") f.write(r.text) f.close() lhefile = basename if doCompress and minmassgap < 0. * GeV: logger.error( "Asked for compression without specifying minmassgap. Please set minmassgap." ) raise SModelSError() reader = lheReader.LheReader(lhefile, nevts) smsTopList = topology.TopologyList() # Get cross section from file (= event weight, assuming a common weight for # all events) if not inputXsecs: xSectionList = crossSection.getXsecFromLHEFile(lhefile, addEvents=False) else: xSectionList = inputXsecs # Loop over events and decompose for event in reader: momPDG = tuple(sorted(event.getMom())) # Get mother PDGs eventweight = xSectionList.getXsecsFor(momPDG) # Get event element newElement = elementFromEvent(event, eventweight) if not newElement: continue allElements = [newElement] # Perform compression if doCompress or doInvisible: allElements += newElement.compressElement(doCompress, doInvisible, minmassgap) for el in allElements: el.sortBranches() smsTopList.addElement(el) smsTopList._setElementIds() return smsTopList