Exemplo n.º 1
0
    def initialize(self, modified_couplings=None):
        ''' Update the restriction card
        '''
        logger.info("#################### Model Setup ######################")

        self.__pre_initialize()

        # couplings
        modified_couplings = modified_couplings if modified_couplings is not None else {}

        # Check whether couplings are in the model
        for coup in modified_couplings.keys():
            if coup not in self.all_model_couplings:
                logger.error(
                    "Coupling %s not found in model %s. All available couplings: %s",
                    coup, self.model_name, ",".join(self.all_model_couplings))
                raise RuntimeError

        logger.debug('Creating restriction file based on template %s',
                     self.restrictCardTemplate)
        # make block strings to be inserted into template file
        block_strings = {}
        for block in self.model.keys():

            # copy defaults
            couplings = copy.deepcopy(self.model[block])

            # make modifications & build string for the template file
            block_strings[block + '_template_string'] = ""
            for i_coupling, coupling in enumerate(
                    couplings):  # coupling is a pair (name, value)
                if modified_couplings.has_key(coupling[0]):
                    coupling[1] = modified_couplings[coupling[0]]
                block_strings[block +
                              '_template_string'] += "%6i %8.6f # %s\n" % (
                                  i_coupling + 1, coupling[1], coupling[0])

        # read template file
        with open(self.restrictCardTemplate, 'r') as f:
            template_string = f.read()

        out = open(self.restrictCard, 'w')
        out.write(template_string.format(**block_strings))
        out.close()

        logger.info('Written restriction file %s', self.restrictCard)
        logger.info("################# Done: Model Setup ###################")
Exemplo n.º 2
0
def getDataDictList(filepath):
    ''' Read postprocessing sh file and format it to dictionary
    '''
    with open(filepath, 'r') as f:
        ppLines = f.readlines()

    ppLines = [line for line in ppLines if line.startswith('python')]

    dictList = []
    for line in ppLines:
        skim = filterEmpty(line.split("--skim ")[1].split(" "))[0]
        year = filterEmpty(line.split("--year ")[1].split(" "))[0]
        dir = filterEmpty(line.split("--processingEra ")[1].split(" "))[0]
        sample = filterEmpty(line.split("--sample ")[1].split(" "))[0]
        command = line
        # find sample arguments
        try:
            sample_args = line.split("--sample")[1].split('--')[0].split(
                '#')[0].rstrip().lstrip().split()
        except IndexError as e:
            logger.error("No sample argument in line? Reading: %s" % line)
            raise e
        if len(sample_args) > 1:
            sample += "_comb"
        if "#SPLIT" not in line:
            nFiles = 1
        else:
            nFiles = filterEmpty(
                line.split("#SPLIT")[1].split(" "))[0].split("\n")[0]
        dictList.append({
            "skim": skim,
            "year": int(year),
            "dir": dir,
            "sample": sample,
            "nFiles": int(nFiles),
            "command": command
        })

    return dictList
Exemplo n.º 3
0
    def __init__(self, model_name, MG260=False):

        self.model_name = model_name
        self.__isPreInitialized = False

        # Load model
        model_file = os.path.expandvars(
            "$CMSSW_BASE/python/TTGammaEFT/Generation/parameters.py")
        logger.info("Loading model %s from file %s", model_name, model_file)

        try:
            tmp_module = imp.load_source(model_name,
                                         os.path.expandvars(model_file))
            self.model = getattr(tmp_module, model_name)
        except:
            logger.error("Failed to import model %s from %s", model_name,
                         model_file)
            raise

        # make work directory
        self.uniquePath = makeUniquePath()
        logger.info("Using temporary directory %s", self.uniquePath)

        # MG file locations
        self.data_path = os.path.expandvars(
            '$CMSSW_BASE/src/TTGammaEFT/Generation/data')

        # MG5 directories

        if self.model_name == 'dim6top_LO' or self.model_name == 'dim6top_LO_v2' or MG260:
            logger.warning("Model dim6top_LO: Using MG 2.6.0!")
            self.MG5_tarball = '/afs/hephy.at/data/rschoefbeck02/MG/MG5_aMC_v2.6.0.tar.gz'  # From MG webpage --> WARNING: No matching PDFs for pattern: Ct10nlo.LHgrid
            self.MG5_tmpdir = os.path.join(self.uniquePath, 'MG5_aMC_v2_6_0')
        else:
            self.MG5_tarball = '/afs/hephy.at/data/dspitzbart01/MG5_aMC_v2.3.3.tar.gz'
            self.MG5_tmpdir = os.path.join(self.uniquePath, 'MG5_aMC_v2_3_3')

        logger.info("Will use MG5 from %s", self.MG5_tarball)

        # GridPack directories
        self.GP_tarball = "/cvmfs/cms.cern.ch/phys_generator/gridpacks/slc6_amd64_gcc481/13TeV/madgraph/V5_2.3.3/ttZ01j_5f_MLM/v1/ttZ01j_5f_tarball.tar.xz"
        self.GP_tmpdir = os.path.join(self.uniquePath, 'centralGridpack')
        logger.info("Will use gridpack from %s", self.GP_tarball)

        # restriction file
        self.restrictCardTemplate = os.path.join(
            self.data_path, 'template',
            'template_restrict_no_b_mass_' + model_name + '.dat')
        self.restrictCard = os.path.join(self.MG5_tmpdir, 'models',
                                         self.model_name,
                                         'restrict_no_b_mass.dat')

        # Consistency check of the model: Check that couplings are unique
        self.all_model_couplings = [c[0] for c in sum(self.model.values(), [])]
        seen = set()
        uniq = [
            x for x in self.all_model_couplings
            if x not in seen and not seen.add(x)
        ]
        if len(seen) != len(self.all_model_couplings):
            logger.error(
                "Apparently, list of couplings for model %s is not unique: %s. Check model file %s.",
                self.model_name, ",".join(self.all_model_couplings),
                model_file)
            raise RuntimeError

        # Get default values for model
        self.default_model_couplings = {}
        for param_set in self.model.values():
            for param, val in param_set:
                self.default_model_couplings[param] = val
Exemplo n.º 4
0
# MVA configuration
import importlib
configs = importlib.import_module(args.config_module)
config = getattr(configs, args.config)

sample_names = []
found = False
for sample in config.training_samples:
    if args.sample == sample.name:
        found = True
        break  # found it
    else:
        sample_names.append(sample.name)

if not found:
    logger.error("Need sample to be one of %s, got %s", ",".join(sample_names),
                 args.sample)
    sys.exit()

logger.info("Processing sample %s", sample.name)

count = int(sample.getYieldFromDraw(weightString="(1)")["val"])
logger.info("Found %i events for sample %s", count, sample.name)

if args.small:
    sample.reduceFiles(to=1)
    subDir += '_small'

# selection
if hasattr(config, "selectionString"):
    sample.addSelectionString(config.selectionString)
    logger.info("Add selectionstring %s", config.selectionString)
Exemplo n.º 5
0
    # recursively make a for loop over all couplings
    def recurse(c_list):
        var, vals = c_list[-1]
        pairs = [(var, val) for val in vals]
        if len(c_list) > 1:
            rec = recurse(c_list[:-1])
            return [r + p for p in pairs for r in rec]
        else:
            return pairs

    param_points = recurse(coupling_list) if len(coupling_list) > 0 else [[]]

else:
    logger.error(
        "Need an even number of coupling arguments of the format coupling1, value1, value2, ... , coupling2, value3, ... . Got %r",
        args.couplings)
    raise ValueError

# Create configuration class
config = Configuration(model_name=args.model)

# Process all the coupling points
for i_param_point, param_point in enumerate(param_points):

    logger.info("Processing parameter point %i/%i", i_param_point + 1,
                len(param_points))

    # Interpret coupling argument list
    names = param_point[::2]
    values = map(float, param_point[1::2])