def create_nd_histogram(self, var, mean_id): """ Create nd histograms for given variable and mean id Only 0 (factor=1.00), 9 (factor=1.03), 18 (factor=0.97), 27 (factor=1.06) and 36 (factor=0.94) working. :param str var: variable name :param int mean_id: index of mean map. """ self.config.logger.info( "DataValidator::create_nd_histogram, var = %s, mean_id = %d", var, mean_id) self.__check_mean_id(mean_id) mean_factor = self.__get_mean_factor(mean_id) column_names = ['phi', 'r', 'z', 'deltaSC'] diff_index = var.find("Diff") if diff_index == -1: column_names.append(var) else: column_names = column_names + [ var[:diff_index], var[:diff_index] + "Pred" ] df_val = tree_to_pandas( "%s/%s/validation_mean%.2f_nEv%d_fapply%d.root" % (self.config.dirtree, self.config.suffix, mean_factor, self.config.train_events, self.config.num_fourier_coeffs_apply), 'validation', columns=column_names) if diff_index != -1: df_val[var] = \ df_val[var[:diff_index] + "Pred"] - df_val[var[:diff_index]] # Definition string for nd histogram required by makeHistogram function in RootInteractive # 1) variables from data frame # 2) cut selection # 3) histogram name and binning in each dimension # E.g. "var1:var2:var3:#cut_selection>>histo_name(n1,min1,max1,n2,min2,max2,n3,min3,max3)" histo_string = "%s:phi:r:z:deltaSC" % (var) + \ ":#r>0" + \ ">>%s" % (var) + \ "(%d,%.4f,%.4f," % (200, df_val[var].min(), df_val[var].max()) + \ "180,0.0,6.283," + \ "33,83.5,254.5," + \ "40,0,250," + \ "%d,%.4f,%.4f)" % (10, df_val['deltaSC'].min(), df_val['deltaSC'].max()) output_file_name = "%s/%s/ndHistogram_%s_mean%.2f_nEv%d.gzip" \ % (self.config.dirhist, self.config.suffix, var, mean_factor, self.config.train_events) with gzip.open(output_file_name, 'wb') as output_file: pickle.dump(makeHistogram(df_val, histo_string), output_file) output_file.close() self.config.logger.info("Nd histogram %s written to %s.", histo_string, output_file_name)
def create_nd_histogram(self, var, mean_id): """ Create nd histograms 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_nd_histogram, 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)) column_names = ['phi', 'r', 'z', 'deltaSC'] diff_index = var.find("Diff") if diff_index == -1: column_names.append(var) else: column_names = column_names + [ var[:diff_index], var[:diff_index] + "Pred" ] df_val = read_root( "%s/%s/treeValidation_mean%.1f_nEv%d.root" % (self.diroutflattree, self.suffix, mean_factor, self.train_events), key='validation', columns=column_names) if diff_index != -1: df_val[var] = \ df_val[var[:diff_index] + "Pred"] - df_val[var[:diff_index]] # Definition string for nd histogram required by makeHistogram function in RootInteractive # 1) variables from data frame # 2) cut selection # 3) histogram name and binning in each dimension # E.g. "var1:var2:var3:#cut_selection>>histo_name(n1,min1,max1,n2,min2,max2,n3,min3,max3)" histo_string = "%s:phi:r:z:deltaSC" % (var) + \ ":#r>0" + \ ">>%s" % (var) + \ "(%d,%.4f,%.4f," % (200, df_val[var].min(), df_val[var].max()) + \ "180,0.0,6.283," + \ "33,83.5,254.5," + \ "40,0,250," + \ "%d,%.4f,%.4f)" % (10, df_val['deltaSC'].min(), df_val['deltaSC'].max()) output_file_name = "%s/%s/ndHistogram_%s_mean%.1f_nEv%d.gzip" \ % (self.dirouthistograms, self.suffix, var, mean_factor, self.train_events) with gzip.open(output_file_name, 'wb') as output_file: pickle.dump(makeHistogram(df_val, histo_string), output_file) output_file.close() self.logger.info("Nd histogram %s written to %s.", histo_string, output_file_name)