|
| 1 | +import os |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import pandas as pd |
| 4 | +import numpy as np |
| 5 | + |
| 6 | + |
| 7 | +def plot_initial_data(input_data): |
| 8 | + save_dir = "D:\Desktop\GSoC-ATLAS\initial_data_plots" |
| 9 | + if not os.path.exists(save_dir): |
| 10 | + os.makedirs(save_dir) |
| 11 | + |
| 12 | + variable_list = ['pt_', 'eta_', 'phi_', 'mass_', |
| 13 | + 'fX', 'fY', 'fZ', 'mJetArea', |
| 14 | + 'mPileupEnergy', 'mChargedHadronEnergy', 'mNeutralHadronEnergy', |
| 15 | + 'mPhotonEnergy', |
| 16 | + 'mElectronEnergy', 'mMuonEnergy', 'mHFHadronEnergy', |
| 17 | + 'mHFEMEnergy', 'mChargedHadronMultiplicity', |
| 18 | + 'mNeutralHadronMultiplicity', |
| 19 | + 'mPhotonMultiplicity', 'mElectronMultiplicity', |
| 20 | + 'mMuonMultiplicity', |
| 21 | + 'mHFHadronMultiplicity', 'mHFEMMultiplicity', 'mChargedEmEnergy', |
| 22 | + 'mChargedMuEnergy', 'mNeutralEmEnergy', 'mChargedMultiplicity', |
| 23 | + 'mNeutralMultiplicity'] |
| 24 | + |
| 25 | + prefix = 'ak5PFJets_' |
| 26 | + n_bins = 100 |
| 27 | + save = True # Option to save figure |
| 28 | + |
| 29 | + branches = [prefix + 'pt_', prefix + 'eta_', prefix + 'phi_', prefix + 'mass_', |
| 30 | + prefix + 'fX', prefix + 'fY', prefix + 'fZ', prefix + 'mJetArea', |
| 31 | + prefix + 'mPileupEnergy', prefix + 'mChargedHadronEnergy', prefix + 'mNeutralHadronEnergy', |
| 32 | + prefix + 'mPhotonEnergy', |
| 33 | + prefix + 'mElectronEnergy', prefix + 'mMuonEnergy', prefix + 'mHFHadronEnergy', |
| 34 | + prefix + 'mHFEMEnergy', prefix + 'mChargedHadronMultiplicity', |
| 35 | + prefix + 'mNeutralHadronMultiplicity', |
| 36 | + prefix + 'mPhotonMultiplicity', prefix + 'mElectronMultiplicity', |
| 37 | + prefix + 'mMuonMultiplicity', |
| 38 | + prefix + 'mHFHadronMultiplicity', prefix + 'mHFEMMultiplicity', prefix + 'mChargedEmEnergy', |
| 39 | + prefix + 'mChargedMuEnergy', prefix + 'mNeutralEmEnergy', prefix + 'mChargedMultiplicity', |
| 40 | + prefix + 'mNeutralMultiplicity'] |
| 41 | + |
| 42 | + for kk in range(0, 28): |
| 43 | + if branches[kk] == prefix + 'pt_' or branches[kk] == prefix + 'mass_': |
| 44 | + n_hist_data, bin_edges, _ = plt.hist(input_data[branches[kk]], color='orange', label='Input', alpha=1, |
| 45 | + bins=n_bins, log=True) |
| 46 | + plt.xlabel(xlabel=variable_list[kk]) |
| 47 | + plt.ylabel('# of jets') |
| 48 | + elif branches[kk] == prefix + 'phi_': |
| 49 | + n_hist_data, bin_edges, _ = plt.hist(input_data[branches[kk]], color='orange', label='Input', alpha=1, |
| 50 | + bins=50) |
| 51 | + plt.xlabel(xlabel=variable_list[kk]) |
| 52 | + plt.ylabel('# of jets') |
| 53 | + else: |
| 54 | + n_hist_data, bin_edges, _ = plt.hist(input_data[branches[kk]], color='orange', label='Input', alpha=1, |
| 55 | + bins=n_bins) |
| 56 | + plt.xlabel(xlabel=variable_list[kk]) |
| 57 | + plt.ylabel('# of jets') |
| 58 | + plt.show() |
| 59 | + if save: |
| 60 | + plt.savefig(os.path.join(save_dir, variable_list[kk] + '.png')) |
| 61 | + |
| 62 | + |
| 63 | +def plot_test_pred_data(test_data, predicted_data): |
| 64 | + save_dir = "D:\Desktop\GSoC-ATLAS\AE_plots" |
| 65 | + if not os.path.exists(save_dir): |
| 66 | + os.makedirs(save_dir) |
| 67 | + |
| 68 | + variable_list = ['pt_', 'eta_', 'phi_', 'mass_', |
| 69 | + 'fX', 'fY', 'fZ', 'mJetArea', |
| 70 | + 'mPileupEnergy', 'mChargedHadronEnergy', 'mNeutralHadronEnergy', |
| 71 | + 'mPhotonEnergy', |
| 72 | + 'mElectronEnergy', 'mMuonEnergy', 'mHFHadronEnergy', |
| 73 | + 'mHFEMEnergy', 'mChargedHadronMultiplicity', |
| 74 | + 'mNeutralHadronMultiplicity', |
| 75 | + 'mPhotonMultiplicity', 'mElectronMultiplicity', |
| 76 | + 'mMuonMultiplicity', |
| 77 | + 'mHFHadronMultiplicity', 'mHFEMMultiplicity', 'mChargedEmEnergy', |
| 78 | + 'mChargedMuEnergy', 'mNeutralEmEnergy', 'mChargedMultiplicity', |
| 79 | + 'mNeutralMultiplicity'] |
| 80 | + |
| 81 | + colors = ['pink', 'green'] |
| 82 | + prefix = 'ak5PFJets_' |
| 83 | + n_bins = 100 |
| 84 | + save = True # Option to save figure |
| 85 | + |
| 86 | + #predicted_data = predicted_data.detach().numpy() |
| 87 | + test_data = test_data.values |
| 88 | + |
| 89 | + # plot the input data along with the reconstructed from the AE |
| 90 | + for kk in np.arange(28): |
| 91 | + plt.figure() |
| 92 | + n_hist_data, bin_edges, _ = plt.hist(test_data[:, kk], color=colors[1], label='Input', alpha=1, bins=n_bins) |
| 93 | + n_hist_pred, _, _ = plt.hist(predicted_data[:, kk], color=colors[0], label='Output', alpha=0.8, bins=bin_edges) |
| 94 | + plt.suptitle(variable_list[kk]) |
| 95 | + plt.xlabel(xlabel=variable_list[kk]) |
| 96 | + plt.ylabel('Number of jets') |
| 97 | + # ms.sciy() |
| 98 | + plt.yscale('log') |
| 99 | + plt.legend() |
| 100 | + if save: |
| 101 | + plt.savefig(os.path.join(save_dir, variable_list[kk] + '.png')) |
| 102 | + |
| 103 | + |
| 104 | +# plot(data_df = pd.read_csv('27D_openCMS_preprocessed_data.csv')) |
0 commit comments