def replacepowheg(oldfilename, newfilename, powhegprocess, jhugen):
  oldfilename = os.path.abspath(oldfilename)
  newfilename = os.path.abspath(newfilename)

  with cdtemp() as tmpfolder:
    subprocess.check_call(["scram", "p", "CMSSW", os.environ["CMSSW_VERSION"]])
    with cd(os.path.join(os.environ["CMSSW_VERSION"], "src")):
      for filename in glob.iglob(os.path.join(genproductions, "bin", "Powheg", "*")):
        if filename.endswith(".py") or filename.endswith(".sh") or filename.endswith("/patches") or filename.endswith("/examples"):
          os.symlink(filename, os.path.basename(filename))

      card = "examples/gg_H_quark-mass-effects_withJHUGen_NNPDF30_13TeV/gg_H_quark-mass-effects_NNPDF30_13TeV.input"
      JHUGencard = "examples/gg_H_quark-mass-effects_withJHUGen_NNPDF30_13TeV/JHUGen.input"
      command = ["./run_pwg_condor.py", "-i", card, "-m", powhegprocess, '-f', "tmp", "-p", "0", "-d", "1"]
      if jhugen: command += ["-g", JHUGencard]
      subprocess.check_call(command)

      with cd("tmp"):
        newcompiledfolder = os.getcwd()

    with cdtemp():
      subprocess.check_call(["tar", "xvaf", oldfilename])

      if not os.path.exists("original_pwhg_main"):
        shutil.move("pwhg_main", "original_pwhg_main")
      shutil.move(os.path.join(newcompiledfolder, "pwhg_main"), "pwhg_main")
      if jhugen:
        if not os.path.exists("original_JHUGen"):
          shutil.move("JHUGen", "original_JHUGen")
        shutil.move(os.path.join(newcompiledfolder, "JHUGen"), "pwhg_main")


      subprocess.check_call(["tar", "cvaf", newfilename] + glob.glob("*"))
Пример #2
0
  def findmatchefficiency(self):
    #figure out the filter efficiency
    if not self.hasfilter:
      self.matchefficiency = 1
      return "filter efficiency is set to 1 +/- 0"
    else:
      if not self.implementsfilter: raise ValueError("Can't find match efficiency for {.__name__} which doesn't implement filtering!".format(type(self)))
      mkdir_p(self.workdir)
      jobsrunning = False
      eventsprocessed = eventsaccepted = 0
      with cd(self.workdir):
        for i in range(100):
          mkdir_p(str(i))
          with cd(str(i)), KeepWhileOpenFile("runningfilterjob.tmp", message=LSB_JOBID(), deleteifjobdied=True) as kwof:
            if not kwof:
              jobsrunning = True
              continue
            if not os.path.exists(self.filterresultsfile):
              if not LSB_JOBID():
                submitLSF(self.filterefficiencyqueue)
                jobsrunning = True
                continue
              if not queuematches(self.filterefficiencyqueue):
                jobsrunning = True
                continue
              self.dofilterjob(i)
            processed, accepted = self.getfilterresults(i)
            eventsprocessed += processed
            eventsaccepted += accepted

        if jobsrunning: return "some filter efficiency jobs are still running"
        self.matchefficiency = uncertainties.ufloat(1.0*eventsaccepted / eventsprocessed, (1.0*eventsaccepted * (eventsprocessed-eventsaccepted) / eventsprocessed**3) ** .5)
        #shutil.rmtree(self.workdir)
        return "match efficiency is measured to be {}".format(self.matchefficiency)
Пример #3
0
 def needsupdateiffailed(self, value):
   if value:
     with cd(here), self.writingdict():
       self.value["needsupdateiffailed"] = True
   else:
     if self.needsupdateiffailed:
       del self.needsupdateiffailed
     self.needsupdate = False
Пример #4
0
 def xsecerror(self):
     with cd(here):
         try:
             return self.value["xsecerror"]
         except KeyError:
             try:
                 self.self.getxsec()
             except NoXsecError:
                 return None
             return self.xsecerror
Пример #5
0
 def xsecnominal(self):
     with cd(here):
         try:
             return self.value["xsec"]
         except KeyError:
             try:
                 self.xsec = self.getxsec()
             except NoXsecError:
                 return None
             return self.xsecnominal
Пример #6
0
 def delete(self):
   response = ""
   while response not in ("yes", "no"):
     response = raw_input("are you sure you want to delete {}? [yes/no]".format(self))
   if response == "no": return
   if self.prepid:
     restful().approve("requests", self.prepid, 0)
     restful().deleteA("requests", self.prepid)
   with cd(here), self.writingdict():
     del self.value
Пример #7
0
    def cardsurl(self):

        icard = "VBF_"
        if self.signalbkgbsi == "SIG" or self.signalbkgbsi == "BSI":
            icard += "H125"
        if self.signalbkgbsi == "BKG" or self.signalbkgbsi == "BSI":
            icard += "ZZcont"
        icard += "_NNPDF31_13TeV_"
        icard += {
            "4e": "ee_ee_",
            "4mu": "mumu_mumu_",
            "2e2mu": "ee_mumu_",
            "2e2nue": "ee_veve_",
            "2e2num": "ee_vmvm_",
            "2e2nut": "ee_vtvt_",
            "2mu2nue": "mumu_veve_",
            "2mu2num": "mumu_vmvm_",
            "2mu2nut": "mumu_vtvt_",
        }[self.finalstate]
        icard += ".py"

        card = os.path.join(
            "https://raw.githubusercontent.com/cms-sw/genproductions/",
            self.genproductionscommit,
            "bin/Phantom/cards/production/13TeV/HZZ_VBFoffshell_Phantom",
            icard)

        with cdtemp():
            wget(card)
            with open(os.path.basename(card)) as f:
                gitcardcontents = f.read()
        with cdtemp():
            subprocess.check_output(["tar", "xvaf", self.cvmfstarball])
            if glob.glob("core.*"):
                raise ValueError(
                    "There is a core dump in the tarball\n{}".format(self))
            cardnameintarball = icard
            try:
                with open(cardnameintarball) as f:
                    cardcontents = f.read()
            except IOError:
                raise ValueError("no " + cardnameintarball +
                                 " in the tarball\n{}".format(self))

        if cardcontents != gitcardcontents:
            with cd(here):
                with open("cardcontents", "w") as f:
                    f.write(cardcontents)
                with open("powheggitcard", "w") as f:
                    f.write(gitcardcontents)
            raise ValueError(
                "cardcontents != gitcardcontents\n{}\nSee ./cardcontents and ./gitcardcontents"
                .format(self))

        return card
Пример #8
0
def ExtractPopResults():
    '''Assumes  the simulation results are in a directory called response, and that
	the simulation results are in subdirectories of that directory. Each subdirectory is
	called: 'response_[sigma]_[mu]_0.root'. '''

    res = []
    with ut.cd('response'):
        dirs = sp.check_output(['ls']).split()
        for f in dirs:
            if os.path.isdir(f):
                with ut.cd(f):
                    files = glob.glob("*.root")
                    f, m, s = AnalyseROOTFile(
                        files[0]
                    )  # glob returns  a list, even if it has only one member
                    res.append([f, m, s])

    with open(POPULATION_DATAFILE, 'w') as fpop:
        for r in res:
            fpop.write(str(r[0]) + '\t' + str(r[1]) + '\t' + str(r[2]) + '\n')
 def gridpackjobsrunning(self):
     if not os.path.exists(self.workdirforgridpack):
         return False
     with cd(self.workdirforgridpack):
         logs = glob.glob("condor.*.log")
         if len(logs) > 1:
             raise RuntimeError("Multiple logs in " +
                                self.workdirforgridpack)
         if not logs: return False
         exitstatus = jobexitstatusfromlog(logs[0], okiffailed=True)
         if exitstatus is None: return True
         return False
Пример #10
0
  def badprepid(self):
    with cd(here):
      result = self.value.get("badprepid", [])
      #backwards compatibility
      if isinstance(result, basestring): result = [result]

      originalresult = result[:]
      for _ in result[:]:
        if not LSB_JOBID() and not restful().get("requests", _):
          result.remove(_)

      if result != originalresult:
        self.badprepid = result

      return result
Пример #11
0
def addJHUGentomadgraph(oldfilename, newfilename, JHUGenversion, decaycard):
    newfilename = os.path.abspath(newfilename)

    with cdtemp():
        subprocess.check_call(["tar", "xvaf", oldfilename])

        if not os.path.exists("original_runcmsgrid.sh"):
            shutil.move("runcmsgrid.sh", "original_runcmsgrid.sh")

        with open("original_runcmsgrid.sh") as f, open("runcmsgrid.sh",
                                                       "w") as newf:
            sawexit = False
            for line in f:
                if "exit" in line:
                    if sawexit:
                        raise IOError("Multiple exit lines in runcmsgrid.sh")
                    newf.write(JHUGenpart)
                    sawexit = True
                if "JHUGen" in line:
                    raise IOError("runcmsgrid.sh already has JHUGen decay")
                newf.write(line)
            if not sawexit:
                newf.write(JHUGenpart)
        os.chmod("runcmsgrid.sh", os.stat("original_runcmsgrid.sh").st_mode)

        tmpdir = os.getcwd()

        with cdtemp():
            subprocess.check_call([
                "wget", "http://spin.pha.jhu.edu/Generator/JHUGenerator." +
                JHUGenversion + ".tar.gz"
            ])
            subprocess.check_call(
                ["tar", "xvzf", "JHUGenerator." + JHUGenversion + ".tar.gz"])
            with cd("JHUGenerator"):
                with open("makefile") as f:
                    oldmakefile = f.read()
                newmakefile = re.sub("(linkMELA *= *)Yes", r"\1No",
                                     oldmakefile)
                assert re.search("linkMELA *= *No", newmakefile)
                with open("makefile", "w") as f:
                    f.write(newmakefile)
                os.system("make")
                shutil.copy("JHUGen", tmpdir)

        shutil.copy(decaycard, "InputCards/JHUGen.input")

        subprocess.check_call(["tar", "cvaf", newfilename] + glob.glob("*"))
Пример #12
0
    def run_package(self, log_run_to_db=None): 
        
        # Set defaults - if caller doesn't specify whether they want database logging, then use the package global defaults
        if log_run_to_db is None:
            log_run_to_db = Config.LOG_RUN_TO_DB
        
        if log_run_to_db:
            logging.debug("Logging package start to DB.")
            self._log_package_start_to_db()

        # switch to package directory with cd - so that paths are relative to the config file location.
        logging.debug("Executing package command.")
        with cd(self.parameters['directory']):
            self._script_thread = ScriptRunner(self.command, self.parameters['timeout'])
            self._script_thread.run_script()
        
        if log_run_to_db:
            logging.debug("Logging package end to DB.")
            self._log_package_end_to_db()
Пример #13
0
 def makegridpackcommand(self):
     args = {
         "-i": self.powhegcard,
         "-m": self.powhegprocess,
         "-f": self.foldernameforrunpwg,
         "-s": str(self.makegridpackseed % 2147483647),
     }
     if self.powhegsubmissionstrategy == "onestep":
         args.update({
             "-p": "f",
             "-n": "10",
             "-q": self.creategridpackqueue,
         })
     elif self.powhegsubmissionstrategy == "multicore":
         if self.multicore_upto[0] == 0:
             args.update({
                 "-p": "0",
             })
         elif self.multicore_upto[0] in (1, 2, 3):
             args.update({
                 "-p": str(self.multicore_upto[0]),
                 "-x": str(self.multicore_upto[1]),
                 "-j": "10",
                 "-t": "100",
                 "-n": "10",
                 "-q": self.creategridpackqueue,
             })
             with cd(
                     os.path.join(self.workdirforgridpack,
                                  self.foldernameforrunpwg)):
                 for _ in glob.iglob("run_{-p}_{-x}_*.*".format(**args)):
                     os.remove(_)
         elif self.multicore_upto[0] == 9:
             args.update({
                 "-p": "9",
                 "-k": "1",
             })
         else:
             assert False, self.multicore_upto
     else:
         assert False, self.powhegsubmissionstrategy
     return ["./run_pwg_condor.py"] + sum(
         ([k, v] for k, v in args.iteritems()), [])
Пример #14
0
 def needspatch(self, value):
   if value:
     if isinstance(value, int):
       pass
     else:
       try:
         value["oldtarballversion"]
       except TypeError:
         raise ValueError("needspatch has to be a dict or version number")
       except KeyError:
         raise ValueError('needspatch has to have "oldtarballversion" in it')
       for _ in "oldfilename", "newfilename", "sample":
         if _ in value:
           raise ValueError('''needspatch can't have "'''+_+'" in it')
       if "functionname" not in value:
         raise ValueError('needspatch has to have "functionname" in it')
       if value["functionname"] not in patches.functiondict:
         raise ValueError('invalid functionname "{functionname}", choices:\n{}'.format(", ".join(patches.functiondict), **value))
     with cd(here), self.writingdict():
       self.value["needspatch"] = value
   elif self.needspatch:
     del self.needspatch
Пример #15
0
 def xsecnominal(self):
     with cd(here), self.writingdict():
         del self.value["xsec"]