def plot_WW_distr(infile, outdir, out_formats=["pdf", "png"]): """ Plot the distribution that is stored in the given file. """ base_name = os.path.basename(infile).replace(".csv", "") log.debug("Reading file: {}.csv".format(base_name)) reader = IOR.Reader(infile) # Get the pandas dataframe for the cut histograms df = reader["Data"] # Get the data angles = ("costh_Wminus_star", "costh_l_star", "phi_l_star") x = np.array([df["BinCenters:{}".format(angle)] for angle in angles]) y = np.array(df["Cross sections"]) xmin = np.array( [np.amin(df["BinLow:{}".format(angle)]) for angle in angles]) xmax = np.array( [np.amax(df["BinUp:{}".format(angle)]) for angle in angles]) # Bin counting assumes that bins are not binned thinner than 1/1000 and that # absolute values are of order 0.1-1 nbins = np.array( [len(np.unique((x[d] * 10000.).astype(int))) for d in range(len(x))]) create_2D_projection_plot(x, y, xmin, xmax, nbins, angles, base_name, outdir, out_formats) for i in range(len(angles)): create_1D_projection_plot(i, x, y, xmin, xmax, nbins, angles, base_name, outdir, out_formats)
def plot_mumu_distr(infile, outdir, out_formats=["pdf", "png"]): """ Plot the distribution that is stored in the given file. """ base_name = os.path.basename(infile).replace(".csv", "") log.debug("Reading file: {}.csv".format(base_name)) reader = IOR.Reader(infile) # Get the pandas dataframe for the cut histograms df = reader["Data"] # Get the data x_name = "costh_f_star" x = np.array(df["BinCenters:{}".format(x_name)]) y = np.array(df["Cross sections"]) xmin = np.array(np.amin(df["BinLow:{}".format(x_name)])) xmax = np.array(np.amax(df["BinUp:{}".format(x_name)])) # Bin counting assumes that bins are not binned thinner than 1/1000 and that # absolute values are of order 0.1-1 nbins = len(np.unique((x * 10000.).astype(int))) # Create the figure and plot fig = plt.figure(figsize=(6.5, 5), tight_layout=True) ax = plt.gca() ax.hist(x=x, weights=y, bins=nbins, range=(xmin, xmax), ls="-", lw=3, histtype=u'step') # Useful limits ax.set_xlim(xmin, xmax) # ax.set_ylim(0, 1.1*ax.get_ylim()[1]) # Useful labels ax.set_xlabel("${}$".format(PN.observable_str(x_name, "mumu"))) ax.set_ylabel("$d\\sigma [$fb$]$") # Mark which process it is chirality = IOFH.find_chirality(base_name) Z_direction = IOFH.find_Z_direction(base_name) mass_label = IOFH.find_2f_mass_label(base_name) process_str = "${}$".format( PN.difermion_process_str("mu", chirality, mass_label, Z_direction)) ax.set_title(process_str) # Save the plot in files for out_format in out_formats: format_dir = "{}/{}".format(outdir, out_format) IOSH.create_dir(format_dir) fig.savefig("{}/{}_{}.{}".format(format_dir, base_name, x_name, out_format), transparent=True, bbox_inches='tight')
log.basicConfig(level=log.INFO) # Set logging level PDF.set_default_mpl_format() MCLumi = 5000 # MC Statistics is 5ab^-1 input_dir = "/home/jakob/DESY/MountPoints/DUST/TGCAnalysis/SampleProduction/NewMCProduction/2f_Z_l/PrEWInput/MuAcc_costheta_0.9925" # input_dir = "/home/jakob/DESY/MountPoints/DUST/TGCAnalysis/SampleProduction/NewMCProduction/2f_Z_l/PrEWInput/MuAcc_costheta_0.9925/TrueAngle" output_dir = input_dir + "/shape_checks" IOSH.create_dir(output_dir) log.info("Looking in dir: {}".format(input_dir)) for file_path in IOSH.find_files(input_dir, ".csv"): # Read the input file base_name = os.path.basename(file_path).replace(".csv","") log.info("Reading file: {}.csv".format(base_name)) reader = IOR.Reader(file_path) # Get the pandas dataframe for the cut histograms angle = "costh_f_star_true" if "TrueAngle" in input_dir else "costh_f_star" df = reader["Data"] bin_vals = np.array(df["Cross sections"]) bin_middles = np.array(df["BinCenters:{}".format(angle)]) edges_min = np.array(df["BinLow:{}".format(angle)]) edges_max = np.array(df["BinUp:{}".format(angle)]) bin_width = edges_max[0] - edges_min[0] # Rescale to MC Lumi bin_vals *= MCLumi # Perform fits to the distributions fit_vals_ha, p_ha, cov_ha = SST.fit_1D(SSF.helicity_amplitudes, bin_vals, edges_min, edges_max, bounds=[[0,0],[np.inf,np.inf]])
output_dir = input_dir_nocor + "/ISR_shape_checks" IOSH.create_dir(output_dir) file_pairs = [ ["2f_mu_81to101_BZ_250_eLpR.csv", "2f_mu_81to101_BZ_true_250_eLpR.csv"], ["2f_mu_81to101_BZ_250_eRpL.csv", "2f_mu_81to101_BZ_true_250_eRpL.csv"], ["2f_mu_81to101_FZ_250_eLpR.csv", "2f_mu_81to101_FZ_true_250_eLpR.csv"], ["2f_mu_81to101_FZ_250_eRpL.csv", "2f_mu_81to101_FZ_true_250_eRpL.csv"], ] for file_pair in file_pairs: # Read the input file base_name = file_pair[0].replace(".csv", "") log.info("Processing: {}".format(base_name)) reader_nocor = IOR.Reader(input_dir_nocor + "/" + file_pair[0]) reader_sicor = IOR.Reader(input_dir_sicor + "/" + file_pair[1]) # Get the pandas dataframe for the cut histograms df_nocor = reader_nocor["Data"] df_sicor = reader_sicor["Data"] bin_vals_nocor = MCLumi * np.array(df_nocor["Cross sections"]) bin_vals_sicor = MCLumi * np.array(df_sicor["Cross sections"]) angle = "costh_f_star" bin_middles = np.array(df_nocor["BinCenters:{}".format(angle)]) edges_min = np.array(df_nocor["BinLow:{}".format(angle)]) edges_max = np.array(df_nocor["BinUp:{}".format(angle)]) bin_width = edges_max[0] - edges_min[0] # Perform fits to the distributions