Example #1
0
    def __init__(self, opts, directory, massPoints, datacardPatterns,
                 rootfilePatterns, clsType):
        self.opts = opts
        self.datacardDirectory = directory
        self.massPoints = massPoints
        self.datacardPatterns = datacardPatterns
        self.rootfilePatterns = rootfilePatterns
        self.clsType = clsType.clone()
        self.jobsCreated = False
        self.datacards = {}
        self.rootfiles = {}
        self.scripts = []
        self.configuration = {}

        if not os.path.isdir(directory):
            raise Exception("Datacard directory '%s' does not exist" %
                            directory)

        # this is a dictionary dumped to configuration.json
        self.configuration = {
            "masspoints": massPoints,
            "datacards": datacardPatterns,
            "rootfiles": rootfilePatterns,
            "codeVersion": git.getCommitId(),
            "clsType": self.clsType.name(),
        }
        clsConfig = self.clsType.getConfiguration(self.configuration)
        if clsConfig != None:
            self.configuration["clsConfig"] = clsConfig

        for mass in self.massPoints:
            for dc in datacardPatterns:
                fname = None
                if "%s" in dc:
                    fname = os.path.join(self.datacardDirectory, dc % mass)
                else:
                    fname = os.path.join(self.datacardDirectory, dc)
                if not os.path.isfile(fname):
                    raise Exception("Datacard file '%s' does not exist!" %
                                    fname)

                aux.addToDictList(self.datacards, mass, fname)

            for rf in rootfilePatterns:
                if rf != None:
                    rfname = None
                    if "%s" in rf:
                        rfname = os.path.join(self.datacardDirectory,
                                              rf % mass)
                    else:
                        rfname = os.path.join(self.datacardDirectory, rf)
                    if not os.path.isfile(rfname):
                        raise Exception(
                            "ROOT file (for shapes) '%s' does not exist!" %
                            rfname)

                    aux.addToDictList(self.rootfiles, mass, rfname)
Example #2
0
def parseDiffNuisancesOutput(outputFileName, configFileName, mass):
    # first read nuisance types from datacards
    f = open(configFileName)
    config = json.load(f)
    f.close()
    datacardFiles = [dc % mass for dc in config["datacards"]]

    nuisanceTypes = {}
    type_re = re.compile("\s*(?P<name>\S+)\s+(?P<type>\S+)\s+[\d-]")
    for dc in datacardFiles:
        f = open(dc)
        # rewind until rate
        for line in f:
            if line[0:4] == "rate":
                break
        for line in f:
            m = type_re.search(line)
            if m:
                aux.addToDictList(nuisanceTypes, m.group("name"), m.group("type"))

    # then read the fit values
    f = open(outputFileName)

    ret_bkg = {}
    ret_sbkg = {}
    ret_rho = {}

    nuisanceNames = []

    num1 = "[+-]\d+.\d+"
    num2 = "\d+.\d+"
    nuis_re = re.compile("(?P<name>\S+)\s+(!|\*)?\s+(?P<bshift>%s),\s+(?P<bunc>%s)\s*(!|\*)?\s+(!|\*)?\s+(?P<sbshift>%s),\s+(?P<sbunc>%s)\s*(!|\*)?\s+(?P<rho>%s)" % (num1, num2, num1, num2, num1))
    for line in f:
        m = nuis_re.search(line)
        if m:
            nuisanceNames.append(m.group("name"))
            nuisanceType = nuisanceTypes.get(m.group("name"), None)
            if nuisanceType is not None and len(nuisanceType) == 1:
                nuisanceType = nuisanceType[0]
            if "statBin" in m.group("name"):
                nuisanceType = "shapeStat"
            if nuisanceType is None:
                nuisanceType = "unknown"
            ret_bkg[m.group("name")] = {"fitted_value": m.group("bshift"),
                                        "fitted_uncertainty": m.group("bunc"),
                                        "type": nuisanceType}
            ret_sbkg[m.group("name")] = {"fitted_value": m.group("sbshift"),
                                         "fitted_uncertainty": m.group("sbunc"),
                                         "type": nuisanceType}
            ret_rho[m.group("name")] = {"value": m.group("rho")}

    f.close()

    ret_bkg["nuisanceParameters"] = nuisanceNames
    ret_sbkg["nuisanceParameters"] = nuisanceNames

    return (ret_bkg, ret_sbkg, ret_rho)
Example #3
0
    def __init__(self, opts, directory, massPoints, datacardPatterns, rootfilePatterns, clsType):
        self.opts = opts
        self.datacardDirectory = directory
        self.massPoints = massPoints
        self.datacardPatterns = datacardPatterns
        self.rootfilePatterns = rootfilePatterns
        self.clsType = clsType.clone()
        self.jobsCreated = False
        self.datacards = {}
        self.rootfiles = {}
        self.scripts   = []
        self.configuration = {}

        if not os.path.isdir(directory):
            raise Exception("Datacard directory '%s' does not exist" % directory)

        # this is a dictionary dumped to configuration.json
        self.configuration = {
            "masspoints": massPoints,
            "datacards": datacardPatterns,
            "rootfiles": rootfilePatterns,
            "codeVersion": git.getCommitId(),
            "clsType": self.clsType.name(),
        }
        clsConfig = self.clsType.getConfiguration(self.configuration)
        if clsConfig != None:
            self.configuration["clsConfig"] = clsConfig

        for mass in self.massPoints:
            for dc in datacardPatterns:
                fname = None
                if "%s" in dc:
                    fname = os.path.join(self.datacardDirectory, dc % mass)
                else:
                    fname = os.path.join(self.datacardDirectory, dc)
                if not os.path.isfile(fname):
                    raise Exception("Datacard file '%s' does not exist!" % fname)

                aux.addToDictList(self.datacards, mass, fname)

            for rf in rootfilePatterns:
                if rf != None:
                    rfname = None
                    if "%s" in rf:
                        rfname = os.path.join(self.datacardDirectory, rf % mass)
                    else:
                        rfname = os.path.join(self.datacardDirectory, rf)
                    if not os.path.isfile(rfname):
                        raise Exception("ROOT file (for shapes) '%s' does not exist!" % rfname)

                    aux.addToDictList(self.rootfiles, mass, rfname)
Example #4
0
def parseDiffNuisancesOutput(outputFileName, configFileName, mass):
    # first read nuisance types from datacards
    f = open(configFileName)
    config = json.load(f)
    f.close()
    datacardFiles = [dc % mass for dc in config["datacards"]]

    nuisanceTypes = {}
    type_re = re.compile("\s*(?P<name>\S+)\s+(?P<type>\S+)\s+[\d-]")
    for dc in datacardFiles:
        f = open(dc)
        # rewind until rate
        for line in f:
            if line[0:4] == "rate":
                break
        for line in f:
            m = type_re.search(line)
            if m:
                aux.addToDictList(nuisanceTypes, m.group("name"),
                                  m.group("type"))

    # then read the fit values
    f = open(outputFileName)

    ret_bkg = {}
    ret_sbkg = {}
    ret_rho = {}

    nuisanceNames = []

    num1 = "[+-]\d+.\d+"
    num2 = "\d+.\d+"
    nuis_re = re.compile(
        "(?P<name>\S+)\s+(!|\*)?\s+(?P<bshift>%s),\s+(?P<bunc>%s)\s*(!|\*)?\s+(!|\*)?\s+(?P<sbshift>%s),\s+(?P<sbunc>%s)\s*(!|\*)?\s+(?P<rho>%s)"
        % (num1, num2, num1, num2, num1))
    for line in f:
        m = nuis_re.search(line)
        if m:
            nuisanceNames.append(m.group("name"))
            nuisanceType = nuisanceTypes.get(m.group("name"), None)
            if nuisanceType is not None and len(nuisanceType) == 1:
                nuisanceType = nuisanceType[0]
            if "statBin" in m.group("name"):
                nuisanceType = "shapeStat"
            if nuisanceType is None:
                nuisanceType = "unknown"
            ret_bkg[m.group("name")] = {
                "fitted_value": m.group("bshift"),
                "fitted_uncertainty": m.group("bunc"),
                "type": nuisanceType
            }
            ret_sbkg[m.group("name")] = {
                "fitted_value": m.group("sbshift"),
                "fitted_uncertainty": m.group("sbunc"),
                "type": nuisanceType
            }
            ret_rho[m.group("name")] = {"value": m.group("rho")}

    f.close()

    ret_bkg["nuisanceParameters"] = nuisanceNames
    ret_sbkg["nuisanceParameters"] = nuisanceNames

    return (ret_bkg, ret_sbkg, ret_rho)
    def __init__(self, opts, directory, massPoints, datacardPatterns, rootfilePatterns, clsType):
        self.opts = opts
        self.datacardDirectory = directory
        self.massPoints = massPoints
        self.datacardPatterns = datacardPatterns
        self.rootfilePatterns = rootfilePatterns
        self.clsType = clsType.clone()
        self.jobsCreated = False
        self.datacards = {}
        self.rootfiles = {}
        self.scripts   = []
        self.configuration = {}

        if not os.path.isdir(directory):
            raise Exception("Datacard directory '%s' does not exist" % directory)

        # this is a dictionary dumped to configuration.json
        self.configuration = {
            "masspoints": massPoints,
            "datacards": datacardPatterns,
            "rootfiles": rootfilePatterns,
            "codeVersion": git.getCommitId(),
            "clsType": self.clsType.name(),
        }
        clsConfig = self.clsType.getConfiguration(self.configuration)
        if clsConfig != None:
            self.configuration["clsConfig"] = clsConfig

        for mass in self.massPoints:
            for dc in datacardPatterns:
                fname = None
                if "%s" in dc:
                    fname = os.path.join(self.datacardDirectory, dc % mass)
                else:
                    fname = os.path.join(self.datacardDirectory, dc)
                if not os.path.isfile(fname):
                    raise Exception("Datacard file '%s' does not exist!" % fname)

                aux.addToDictList(self.datacards, mass, fname)

            for rf in rootfilePatterns:
                if rf != None:
                    rfname = None
                    if "%s" in rf:
                        rfname = os.path.join(self.datacardDirectory, rf % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    else:
                        rfname = os.path.join(self.datacardDirectory, rf)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    # if root files are not found, try with 1pr and 3pr extensions in the name
                    if not os.path.isfile(rfname):
                        rf_1pr = rf.replace(".root","_1pr.root")
                        rf_3pr = rf.replace(".root","_3pr.root")
                        rfname_1pr = os.path.join(self.datacardDirectory, rf_1pr % mass)
                        rfname_3pr = os.path.join(self.datacardDirectory, rf_3pr % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname_1pr)
                        aux.addToDictList(self.rootfiles, mass, rfname_3pr)     
                        if not os.path.isfile(rfname_1pr) or not os.path.isfile(rfname_3pr):                   
                        # if still not found, raise exception/warning
#                            raise Exception("ROOT file (for shapes) '%s' does not exist!" % rfname)
                            print("\033[91mWarning:  ROOT file (for shapes) '%s' does not exist!\033[00m" % rfname)
Example #6
0
    def __init__(self, opts, directory, massPoints, datacardPatterns,
                 rootfilePatterns, clsType):
        '''
        Constructor
        
        \param directory          Datacard directory

        \param massPoints         List of mass points to calculate the limit

        \param datacardPatterns   List of datacard patterns to include in the limit calculation

        \param rootfilePatterns   List of shape ROOT file patterns to include in the limit calculation

        \param clsType            Object defining the CLs flavour (either LEPType or LHCType).
        '''
        self.opts = opts
        self.datacardDirectory = directory
        self.massPoints = massPoints
        self.datacardPatterns = datacardPatterns
        self.rootfilePatterns = rootfilePatterns
        self.clsType = clsType.clone()
        self.jobsCreated = False
        self.datacards = {}
        self.rootfiles = {}
        self.scripts = []
        self.configuration = {}

        if not os.path.isdir(directory):
            raise Exception("Datacard directory '%s' does not exist" %
                            directory)

        # this is a dictionary dumped to configuration.json
        self.configuration = {
            "masspoints": massPoints,
            "datacards": datacardPatterns,
            "rootfiles": rootfilePatterns,
            "codeVersion": git.getCommitId(),
            "clsType": self.clsType.name(),
        }
        clsConfig = self.clsType.getConfiguration(self.configuration)
        if clsConfig != None:
            self.configuration["clsConfig"] = clsConfig

        for mass in self.massPoints:
            for dc in datacardPatterns:
                fname = None
                if "%s" in dc:
                    fname = os.path.join(self.datacardDirectory, dc % mass)
                else:
                    fname = os.path.join(self.datacardDirectory, dc)
                if not os.path.isfile(fname):
                    raise Exception("Datacard file '%s' does not exist!" %
                                    fname)

                aux.addToDictList(self.datacards, mass, fname)

            for rf in rootfilePatterns:
                if rf != None:
                    rfname = None
                    if "%s" in rf:
                        rfname = os.path.join(self.datacardDirectory,
                                              rf % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    else:
                        rfname = os.path.join(self.datacardDirectory, rf)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    # if root files are not found, try with 1pr and 3pr extensions in the name
                    if not os.path.isfile(rfname):
                        # 1+2 b-jets
                        #                        rf_1pr = rf.replace(".root","_2bjets.root")
                        #                        rf_3pr = rf.replace(".root","_1bjet.root")
                        # 0+1 b-jets
                        #                        rf_1pr = rf.replace(".root","_1bjets.root")
                        #                        rf_3pr = rf.replace(".root","_0bjets.root")
                        rf_1pr = rf.replace(".root", "_0bjet.root")
                        rf_3pr = rf.replace(".root", "_1bjet.root")
                        rf_extra = rf.replace(".root", "_2bjets.root")

                        rfname_1pr = os.path.join(self.datacardDirectory,
                                                  rf_1pr % mass)
                        rfname_3pr = os.path.join(self.datacardDirectory,
                                                  rf_3pr % mass)
                        rfname_extra = os.path.join(self.datacardDirectory,
                                                    rf_extra % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname_1pr)
                        aux.addToDictList(self.rootfiles, mass, rfname_3pr)
                        aux.addToDictList(self.rootfiles, mass, rfname_extra)

                        if not os.path.isfile(
                                rfname_1pr) or not os.path.isfile(
                                    rfname_3pr) or not os.path.isfile(
                                        rfname_extra):
                            # if still not found, raise exception/warning
                            #                            raise Exception("ROOT file (for shapes) '%s' does not exist!" % rfname)
                            print(
                                "\033[91mWarning:  ROOT file (for shapes) '%s' does not exist!\033[00m"
                                % rfname)
    def __init__(self, opts, directory, massPoints, datacardPatterns, rootfilePatterns, clsType):
        '''
        Constructor
        
        \param directory          Datacard directory

        \param massPoints         List of mass points to calculate the limit

        \param datacardPatterns   List of datacard patterns to include in the limit calculation

        \param rootfilePatterns   List of shape ROOT file patterns to include in the limit calculation

        \param clsType            Object defining the CLs flavour (either LEPType or LHCType).
        '''
        self.opts = opts
        self.datacardDirectory = directory
        self.massPoints = massPoints
        self.datacardPatterns = datacardPatterns
        self.rootfilePatterns = rootfilePatterns
        self.clsType = clsType.clone()
        self.jobsCreated = False
        self.datacards = {}
        self.rootfiles = {}
        self.scripts   = []
        self.configuration = {}

        if not os.path.isdir(directory):
            raise Exception("Datacard directory '%s' does not exist" % directory)

        # this is a dictionary dumped to configuration.json
        self.configuration = {
            "masspoints": massPoints,
            "datacards": datacardPatterns,
            "rootfiles": rootfilePatterns,
            "codeVersion": git.getCommitId(),
            "clsType": self.clsType.name(),
        }
        clsConfig = self.clsType.getConfiguration(self.configuration)
        if clsConfig != None:
            self.configuration["clsConfig"] = clsConfig

        for mass in self.massPoints:
            for dc in datacardPatterns:
                fname = None
                if "%s" in dc:
                    fname = os.path.join(self.datacardDirectory, dc % mass)
                else:
                    fname = os.path.join(self.datacardDirectory, dc)
                if not os.path.isfile(fname):
                    raise Exception("Datacard file '%s' does not exist!" % fname)

                aux.addToDictList(self.datacards, mass, fname)

            for rf in rootfilePatterns:
                if rf != None:
                    rfname = None
                    if "%s" in rf:
                        rfname = os.path.join(self.datacardDirectory, rf % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    else:
                        rfname = os.path.join(self.datacardDirectory, rf)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    # if root files are not found, try with category A/B/C extensions in the name
                    if not os.path.isfile(rfname):
                        rf_a = rf.replace(".root","_a.root")
                        rf_b = rf.replace(".root","_b.root")
                        rf_c = rf.replace(".root","_c.root")
                        rfname_a = os.path.join(self.datacardDirectory, rf_a % mass)
                        rfname_b = os.path.join(self.datacardDirectory, rf_b % mass)
                        rfname_c = os.path.join(self.datacardDirectory, rf_c % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname_a)
                        aux.addToDictList(self.rootfiles, mass, rfname_b)     
                        aux.addToDictList(self.rootfiles, mass, rfname_c)     
                        if not os.path.isfile(rfname_a) or not os.path.isfile(rfname_b) or not os.path.isfile(rfname_c):                   
                        # if still not found, raise exception/warning
#                            raise Exception("ROOT file (for shapes) '%s' does not exist!" % rfname)
                            print("\033[91mWarning:  ROOT file (for shapes) '%s' does not exist!\033[00m" % rfname)
Example #8
0
    def __init__(self, opts, directory, massPoints, datacardPatterns,
                 rootfilePatterns, clsType):
        self.opts = opts
        self.datacardDirectory = directory
        self.massPoints = massPoints
        self.datacardPatterns = datacardPatterns
        self.rootfilePatterns = rootfilePatterns
        self.clsType = clsType.clone()
        self.jobsCreated = False
        self.datacards = {}
        self.rootfiles = {}
        self.scripts = []
        self.configuration = {}

        if not os.path.isdir(directory):
            raise Exception("Datacard directory '%s' does not exist" %
                            directory)

        # this is a dictionary dumped to configuration.json
        self.configuration = {
            "masspoints": massPoints,
            "datacards": datacardPatterns,
            "rootfiles": rootfilePatterns,
            "codeVersion": git.getCommitId(),
            "clsType": self.clsType.name(),
        }
        clsConfig = self.clsType.getConfiguration(self.configuration)
        if clsConfig != None:
            self.configuration["clsConfig"] = clsConfig

        for mass in self.massPoints:
            for dc in datacardPatterns:
                fname = None
                if "%s" in dc:
                    fname = os.path.join(self.datacardDirectory, dc % mass)
                else:
                    fname = os.path.join(self.datacardDirectory, dc)
                if not os.path.isfile(fname):
                    raise Exception("Datacard file '%s' does not exist!" %
                                    fname)

                aux.addToDictList(self.datacards, mass, fname)

            for rf in rootfilePatterns:
                if rf != None:
                    rfname = None
                    if "%s" in rf:
                        rfname = os.path.join(self.datacardDirectory,
                                              rf % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    else:
                        rfname = os.path.join(self.datacardDirectory, rf)
                        aux.addToDictList(self.rootfiles, mass, rfname)
                    # if root files are not found, try with 1pr and 3pr extensions in the name
                    if not os.path.isfile(rfname):
                        rf_1pr = rf.replace(".root", "_1pr.root")
                        rf_3pr = rf.replace(".root", "_3pr.root")
                        rfname_1pr = os.path.join(self.datacardDirectory,
                                                  rf_1pr % mass)
                        rfname_3pr = os.path.join(self.datacardDirectory,
                                                  rf_3pr % mass)
                        aux.addToDictList(self.rootfiles, mass, rfname_1pr)
                        aux.addToDictList(self.rootfiles, mass, rfname_3pr)
                        if not os.path.isfile(
                                rfname_1pr) or not os.path.isfile(rfname_3pr):
                            # if still not found, raise exception/warning
                            #                            raise Exception("ROOT file (for shapes) '%s' does not exist!" % rfname)
                            print(
                                "\033[91mWarning:  ROOT file (for shapes) '%s' does not exist!\033[00m"
                                % rfname)