Skip to content
Snippets Groups Projects
Commit 69ef16a4 authored by brusale's avatar brusale
Browse files

add plots and move to el9

parents 2e7da20c 73c4c977
Branches
No related tags found
No related merge requests found
AutoDict*
*.csv
*.png
.vscode/*
*.root
*.a
......
import numpy as np
import matplotlib.colors as colors
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from tools import makeCSVFile
class clusters:
def __init__(self, centers, std, n_samples, pfparticles, csv_path):
def __init__(self, centers, std, n_samples, bins, pfparticles, csv_path):
self.centers = centers
self.std = std
self.n_samples = n_samples
self.x, self.y, self.clusters = self.makeClusters()
self.bins = bins
self.csv_path = csv_path
self.pfparticles = pfparticles
self.dictionary()
self.makePixelTruthPlot()
self.makeDetectorView()
def makeClusters(self):
nClusters = len(self.centers)
......@@ -58,3 +64,72 @@ class clusters:
'simCluster_genParticle': self.pfparticles,
}
makeCSVFile(dictionary, self.csv_path)
def binnedClusters(self):
nclusters = len(self.clusters)
bins = self.bins
binned_clusters_content, binned_clusters_x, binned_clusters_y, binned_clusters_fraction = [], [], [], []
for clusters in range(0, nclusters):
content, xedges, yedges = np.histogram2d(self.clusters[clusters][0], self.clusters[clusters][1], bins=bins)
binned_clusters_content.append(content)
binned_clusters_x.append([0.5*(xedges[i] + xedges[i-1]) for i in range(1, len(xedges))])
binned_clusters_y.append([0.5*(yedges[i] + yedges[i-1]) for i in range(1, len(yedges))])
total_content, max_contribution = [], []
for x_bin in range(0, len(bins)-1):
total_content_x = []
for y_bin in range(0, len(bins)-1):
max_fraction = 0
max_fraction_cl = -1
total_bin_content = 0
for cluster in range(0, nclusters):
total_bin_content += binned_clusters_content[cluster][x_bin][y_bin]
if binned_clusters_content[cluster][x_bin][y_bin] > max_fraction:
max_fraction = binned_clusters_content[cluster][x_bin][y_bin]
max_fraction_cl = cluster
if total_bin_content == 0:
denominator = float("inf")
else:
denominator = total_bin_content
max_contribution.append([max_fraction_cl, max_fraction / denominator, total_bin_content])
total_content_x.append(denominator)
total_content.append(total_content_x)
for cluster in range(0, nclusters):
fractions = []
for x_bin in range(0, len(bins)-1):
x_fraction = []
for y_bin in range(0, len(bins)-1):
fraction = binned_clusters_content[cluster][x_bin][y_bin] / total_content[x_bin][y_bin]
x_fraction.append(fraction)
fractions.append(x_fraction)
binned_clusters_fraction.append(fractions)
return binned_clusters_content, binned_clusters_x, binned_clusters_y, max_contribution, binned_clusters_fraction
def makePixelTruthPlot(self):
color = ['white', 'blue', 'green', 'red']
_, _, _, max_contribution, _ = self.binnedClusters()
size = len(self.bins) - 1
min_x = self.bins[0]
max_x = self.bins[-1]
min_y = min_x
max_y = max_x
cmap = colors.LinearSegmentedColormap.from_list("", color)
board = np.zeros((size, size))
fig, ax = plt.subplots(1,1)
for i in range(size):
for j in range(size):
board[i][j] = max_contribution[i + j * size][0]
ax.imshow(board, cmap=cmap, interpolation='nearest', extent=[min_x, max_x, min_y, max_y])
ax.invert_yaxis()
fig.savefig('pixelTruthPlot.png')
fig.clf()
def makeDetectorView(self):
plt.hist2d(self.x, self.y, bins=self.bins, norm=colors.LogNorm(), cmap='inferno')
plt.colorbar()
plt.xlim(self.bins[0], self.bins[-1])
plt.ylim(self.bins[0], self.bins[-1])
plt.savefig('detectorView.png')
......@@ -13,8 +13,8 @@ clusters:
hits:
bins:
start: -0.03
end: 0.03
start: -0.3
end: 0.3
n_bins: 50
csv_file: "csv/hits.csv"
......
......@@ -17,9 +17,14 @@ if __name__ == '__main__':
nSamples = config['clusters']['n_samples']
centers = config['clusters']['centers']
bins = np.linspace(config['hits']['bins']['start'],
config['hits']['bins']['end'],
config['hits']['bins']['n_bins'])
x, y, clusters = clusters(config['clusters']['centers'],
config['clusters']['std'],
config['clusters']['n_samples'],
bins,
config['clusters']['pfparticles'],
config['clusters']['csv_file']).getHitsAndClusters()
......
......@@ -32,7 +32,7 @@ parse_yml() {
}
print_step "Sourcing the LCG environment"
source /cvmfs/sft.cern.ch/lcg/views/LCG_102/x86_64-centos8-gcc11-opt/setup.sh
source /cvmfs/sft.cern.ch/lcg/views/LCG_105/x86_64-el9-gcc11-opt/setup.sh
CURRENT_DIR=$(pwd)
CSV_PATH=$(parse_yml ['csv_path'] | tr -d \', | awk '{print $2}')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment