Exemplo n.º 1
0
    def create_pdf_map(self, var, mean_id):
        """
        Create a pdf map for given variable and mean id
        var: string of the variable name
        mean_id: index of mean map.
        Only 0 (factor=1.00), 27 (factor=1.06) and 36 (factor=0.94) working.
        """
        self.config.logger.info("DataValidator::create_pdf_map, var = %s, mean_id = %d",
                                var, mean_id)
        self.check_mean_id_(mean_id)
        mean_factor = self.get_mean_factor_(mean_id)

        input_file_name = "%s/%s/ndHistogram_%s_mean%.1f_nEv%d.gzip" \
            % (self.config.dirhist, self.config.suffix, var, mean_factor,
               self.config.train_events)
        with gzip.open(input_file_name, 'rb') as input_file:
            histo = pickle.load(input_file)

        output_file_name = "%s/%s/pdfmap_%s_mean%.1f_nEv%d.root" \
            % (self.config.dirtree, self.config.suffix, var, mean_factor,
               self.config.train_events)
        dim_var = 0
        # slices: (start_bin, stop_bin, step, grouping) for each histogram dimension
        slices = ((0, histo['H'].shape[0], 1, 0),
                  (0, histo['H'].shape[1], 1, 0),
                  (0, histo['H'].shape[2], 1, 0),
                  (0, histo['H'].shape[3], 1, 0),
                  (0, histo['H'].shape[4], 1, 0))
        df_pdf_map = makePdfMaps(histo, slices, dim_var)
        pandas_to_tree(df_pdf_map, output_file_name, histo['name'])
        self.config.logger.info("Pdf map %s written to %s.", histo['name'], output_file_name)
Exemplo n.º 2
0
    def create_pdf_map(self, var, mean_id):
        """
        Create a pdf map for given variable and mean id
        var: string of the variable name
        mean_id: index of mean map. Only 0 (factor=1.0), 9 (factor=1.1) and 18 (factor=0.9) working.
        """
        self.config.logger.info(
            "DataValidator::create_pdf_map, var = %s, mean_id = %d", var,
            mean_id)
        if mean_id not in (0, 9, 18):
            self.config.logger.error(
                "Code implementation only designed for mean ids 0, 9, 18.")
            self.config.logger.fatal("Exiting...")
        mean_factor = 1 + 0.1 * (mean_id != 0) * (1 - 2 * (mean_id == 18))

        input_file_name = "%s/%s/ndHistogram_%s_mean%.1f_nEv%d.gzip" \
            % (self.config.dirhist, self.config.suffix, var, mean_factor,
               self.config.train_events)
        with gzip.open(input_file_name, 'rb') as input_file:
            histo = pickle.load(input_file)

        output_file_name = "%s/%s/pdfmap_%s_mean%.1f_nEv%d.root" \
            % (self.config.dirtree, self.config.suffix, var, mean_factor,
               self.config.train_events)
        dim_var = 0
        # slices: (start_bin, stop_bin, step, grouping) for each histogram dimension
        slices = ((0, histo['H'].shape[0], 1, 0), (0, histo['H'].shape[1], 1,
                                                   0), (0, histo['H'].shape[2],
                                                        1, 0),
                  (0, histo['H'].shape[3], 1, 0), (0, histo['H'].shape[4], 1,
                                                   0))
        df_pdf_map = makePdfMaps(histo, slices, dim_var)
        pandas_to_tree(df_pdf_map, output_file_name, histo['name'])
        self.config.logger.info("Pdf map %s written to %s.", histo['name'],
                                output_file_name)
Exemplo n.º 3
0
    def create_pdf_map(self, var, mean_id):
        """
        Create a pdf map for given variable and mean id
        var: string of the variable name
        mean_id: index of mean map. Only 0 (factor=1.0), 9 (factor=1.1) and 18 (factor=0.9) working.
        """
        self.logger.info(
            "DataValidator::create_pdf_map, var = %s, mean_id = %d", var,
            mean_id)
        if mean_id not in (0, 9, 18):
            self.logger.info(
                "Code implementation only designed for mean ids 0, 9, 18. Exiting..."
            )
            sys.exit()
        mean_factor = 1 + 0.1 * (mean_id != 0) * (1 - 2 * (mean_id == 18))

        input_file_name = "%s/%s/ndHistogram_%s_mean%.1f_nEv%d.gzip" \
            % (self.dirouthistograms, self.suffix, var, mean_factor, self.train_events)
        with gzip.open(input_file_name, 'rb') as input_file:
            histo = pickle.load(input_file)

        output_file_name = "%s/%s/pdfmap_%s_mean%.1f_nEv%d.root" \
            % (self.diroutflattree, self.suffix, var, mean_factor, self.train_events)
        dim_var = 0
        # slices: (start_bin, stop_bin, step, grouping) for each histogram dimension
        slices = ((0, histo['H'].shape[0], 1, 0), (0, histo['H'].shape[1], 1,
                                                   0), (0, histo['H'].shape[2],
                                                        1, 0),
                  (0, histo['H'].shape[3], 1, 0), (0, histo['H'].shape[4], 1,
                                                   0))
        df_pdf_map = makePdfMaps(histo, slices, dim_var)
        # set the index name to retrieve the name of the variable of interest later
        df_pdf_map.index.name = histo['name']
        df_pdf_map.to_root(output_file_name,
                           key=histo['name'],
                           mode='w',
                           store_index=True)
        self.logger.info("Pdf map %s written to %s.", histo['name'],
                         output_file_name)