Skip to content

ATTPC Noise Addition

AT-TPC Noise Addition

Only for use with simulated data

This method is used only when training with simulated data.

It is very difficult to exactly replicate the AT-TPC noise, but we can closely mimic it by creating noise that is uniformly random in z with np.random.randint(0,1000) and Gaussian in r with r_noise = np.random.normal(0, 50, (data_size,1)).

Can be used to add AT-TPC like noise by using np.random.randint() between [-50,50] for x and y, and [0,1000] for z.

Bases: BaseEstimator, TransformerMixin

Adding noise in cylindrical coordinates to simulate AT-TPC noise

Parameters

ratio_noise : (float) Fraction of noise to length of point cloud to be produced

Returns

new_data: (array) Data with AT-TPC noise added event_lengths: (array) New event lengths accounting for added noise points

Source code in scripts/ml_preprocessing_steps.py
class AttpcNoiseAddition(BaseEstimator,TransformerMixin):
    """Adding noise in cylindrical coordinates to simulate AT-TPC noise

    Parameters
    ----------
    ratio_noise : (float)
        Fraction of noise to length of point cloud to be produced

    Returns
    ----------
    new_data: (array)
        Data with AT-TPC noise added
    event_lengths: (array)
        New event lengths accounting for added noise points 
    """
    def __init__(self, ratio_noise: float):
        self.ratio_noise = ratio_noise


    def fit(self,X,y=None):
        return self  

    def transform(self,X,y=None):
        """Adding AT-TPC like noise with cylindrical dataset

        Args:
            X (tuple):Packed data and event lengths np.array
            y (None): Defaults to None.

        Returns:
            (tuple): Data with noise and new event lengths
        """
        data,event_lengths = X
        skipped = 0
        for i in tqdm.tqdm(range(len(data)), desc="Adding Noise"): 
            data_size = int((self.ratio_noise)*event_lengths[i])

            noise_z = np.random.randint(0,1000,(data_size,1))
            r_noise = np.random.normal(0, 50, (data_size,1))

            theta_noise = np.random.uniform(0, 2*np.pi, (data_size,1))

            noise_x = r_noise * np.cos(theta_noise)
            noise_y = r_noise * np.sin(theta_noise)

            array_charge = np.zeros((data_size,1))
            noise_data = np.concatenate((noise_x,noise_y,noise_z,array_charge),axis=1)
            combined_data = np.concatenate((data[i,:event_lengths[i],:],noise_data,data[i,-2:,:]),axis=0)

            if combined_data.shape[0] > data.shape[1]:
                skipped+=1
                continue

            data[i, :combined_data.shape[0], :] = combined_data

            event_lengths[i]+=data_size


        print(f"Number of events skipped: {skipped}")
        return (data,event_lengths)

transform(X, y=None)

Adding AT-TPC like noise with cylindrical dataset

Parameters:

Name Type Description Default
X tuple

Packed data and event lengths np.array

required
y None

Defaults to None.

None

Returns:

Type Description
tuple

Data with noise and new event lengths

Source code in scripts/ml_preprocessing_steps.py
def transform(self,X,y=None):
    """Adding AT-TPC like noise with cylindrical dataset

    Args:
        X (tuple):Packed data and event lengths np.array
        y (None): Defaults to None.

    Returns:
        (tuple): Data with noise and new event lengths
    """
    data,event_lengths = X
    skipped = 0
    for i in tqdm.tqdm(range(len(data)), desc="Adding Noise"): 
        data_size = int((self.ratio_noise)*event_lengths[i])

        noise_z = np.random.randint(0,1000,(data_size,1))
        r_noise = np.random.normal(0, 50, (data_size,1))

        theta_noise = np.random.uniform(0, 2*np.pi, (data_size,1))

        noise_x = r_noise * np.cos(theta_noise)
        noise_y = r_noise * np.sin(theta_noise)

        array_charge = np.zeros((data_size,1))
        noise_data = np.concatenate((noise_x,noise_y,noise_z,array_charge),axis=1)
        combined_data = np.concatenate((data[i,:event_lengths[i],:],noise_data,data[i,-2:,:]),axis=0)

        if combined_data.shape[0] > data.shape[1]:
            skipped+=1
            continue

        data[i, :combined_data.shape[0], :] = combined_data

        event_lengths[i]+=data_size


    print(f"Number of events skipped: {skipped}")
    return (data,event_lengths)