From d71fd6f6b487d1edb42ae83ad8b25077d26189e9 Mon Sep 17 00:00:00 2001 From: "xiangyu.xie" Date: Tue, 21 Apr 2026 10:40:56 +0200 Subject: [PATCH] Add St Corner for datasets; fix 3x3 cluster finding algorithm --- DataAnalysis.py | 2 +- UsefulFuncs.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/DataAnalysis.py b/DataAnalysis.py index e37aa42..4afdda5 100644 --- a/DataAnalysis.py +++ b/DataAnalysis.py @@ -3,7 +3,7 @@ import numpy as np from Configs import Configs from argparse import ArgumentParser argParser = ArgumentParser() -argParser.add_argument('--runName', type=str, default='SiemenStarLowerLeft') +argParser.add_argument('-r', '--runName', type=str, default='SiemenStarLowerLeft') args = argParser.parse_args() measurementConfig = Configs[args.runName] diff --git a/UsefulFuncs.py b/UsefulFuncs.py index 65a4aed..929f3d6 100644 --- a/UsefulFuncs.py +++ b/UsefulFuncs.py @@ -20,7 +20,9 @@ def init(cfg): global _cfg global _aduToKev3DMap _cfg = cfg - _aduToKev3DMap = np.load(cfg['caliFileName']) + NX, NY = cfg['NX'], cfg['NY'] + St_x, St_y = cfg.get('StCorner', [0, 0]) ### with default corner at (0, 0) + _aduToKev3DMap = np.load(cfg['caliFileName'])[:, St_y:St_y+NY, St_x:St_x+NX] Roi = cfg['Roi'] global nChunks nChunks = _cfg.get('NChunks', 16) @@ -265,6 +267,7 @@ def _processFrames(idxChunk): ### for both single and double photon events, usin sumFrame += signalEneFrame signalEneFrame = signalEneFrame[Roi[2]:Roi[3], Roi[0]:Roi[1]] + _signalEneFrame = np.copy(signalEneFrame) ### make a copy of the original energy frame for cluster energy correction later, since the cluster finder will modify the input energy frame CF.find_clusters_X(signalEneFrame) clusters = CF.hits() for idxCluster in range(len(clusters)): @@ -277,8 +280,8 @@ def _processFrames(idxChunk): ### for both single and double photon events, usin ### single photon events if Energy - selectionRange < energy < Energy + selectionRange: - ref_x = clusters['col'][idxCluster] - 1 ### refered to the lower-left corner of the cluster - ref_y = clusters['row'][idxCluster] - 1 + ref_x = clusters['col'][idxCluster] - clusterSize1Photon//2 ### refered to the lower-left corner of the cluster + ref_y = clusters['row'][idxCluster] - clusterSize1Photon//2 if int(ref_x) < 0 or int(ref_x)+clusterSize1Photon > signalEneFrame.shape[1] or int(ref_y) < 0 or int(ref_y)+clusterSize1Photon > signalEneFrame.shape[0]: continue ### skip clusters too close to the border for i in range(len(xs)): @@ -290,16 +293,19 @@ def _processFrames(idxChunk): ### for both single and double photon events, usin _hists['h1_1PhotonClusterDiameterY'].Fill(diameterY) cluster_1Photon = np.zeros((clusterSize1Photon, clusterSize1Photon), dtype=np.float32) - # for i in range(len(xs)): + ### var cluster is less accurate than the 3x3 fixed cluster, since the zero pixels are incontinuous, not friendly for ML. + # for i in range(len(xs)): # x_rel = xs[i] - int(ref_x) # y_rel = ys[i] - int(ref_y) - # _hists['h1_1PhotonClusterPixelEnergy'].Fill(enes[i]) + # # _hists['h1_1PhotonClusterPixelEnergy'].Fill(enes[i]) # if 0 <= x_rel < clusterSize1Photon and 0 <= y_rel < clusterSize1Photon: # cluster_1Photon[y_rel, x_rel] = enes[i] - cluster_1Photon = signalEneFrame[int(ref_y):int(ref_y)+clusterSize1Photon, int(ref_x):int(ref_x)+clusterSize1Photon] - _hists['h1_1PhotonClusterEnergy'].Fill(np.sum(cluster_1Photon)) # use the sum of 3x3 cluster as the cluster energy for single photon events, which is more accurate than the original cluster energy given by the cluster finder, since the cluster finder may miss some pixels with low energy far from the center pixel - for i in range(3): - for j in range(3): + + # use the sum of 3x3 cluster as the cluster energy for single photon events, which is more accurate than the original cluster energy given by the cluster finder, since the cluster finder may miss some pixels with low energy far from the center pixel + cluster_1Photon = _signalEneFrame[int(ref_y):int(ref_y)+clusterSize1Photon, int(ref_x):int(ref_x)+clusterSize1Photon] + _hists['h1_1PhotonClusterEnergy'].Fill(np.sum(cluster_1Photon)) + for i in range(clusterSize1Photon): + for j in range(clusterSize1Photon): _hists['h2_1PhotonSumSample'].Fill(i, j, cluster_1Photon[i, j]) if 'writeClusters' in _cfg and _cfg['writeClusters'] == True: cluster_1Photon_list.append(cluster_1Photon)