예제 #1
0
def topas_ntuple_compare(path_test, path_ref, rtol, atol):
    res_t = read_ntuple(path_test)
    res_r = read_ntuple(path_ref)

    if res_t.dtype.names != res_r.dtype.names:
        raise ValueError('Inconsistent column names')
    if res_t.size != res_r.size:
        raise ValueError('Inconsistent ntuple sizes')
    for s in res_t.dtype.names:
        assert_allclose(res_t[s], res_r[s], rtol, atol)

    return True
예제 #2
0
    def __ReadInTopasASCIIdata(self):
        """
        Read in topas ASCII phase space data
        assumption is that this in in cm and MeV
        """

        PhaseSpace = tp.read_ntuple(self.Data)
        ParticleTypes = PhaseSpace['Particle Type (in PDG Format)']
        ParticleDir = PhaseSpace[
            'Flag to tell if Third Direction Cosine is Negative (1 means true)']
        PaarticleDirInd = ParticleDir == 1  # only want forward moving particles
        ParticleTypeInd = ParticleTypes == 11  # only want electrons
        Ind = np.logical_and(PaarticleDirInd, ParticleTypeInd)

        self.x = PhaseSpace['Position X [cm]'][Ind] * 1e1
        self.y = PhaseSpace['Position Y [cm]'][Ind] * 1e1
        self.z = PhaseSpace['Position Z [cm]'][Ind] * 1e1
        DirCosineX = PhaseSpace['Direction Cosine X'][Ind]
        DirCosineY = PhaseSpace['Direction Cosine Y'][Ind]
        self.E = PhaseSpace['Energy [MeV]'][Ind]

        # figure out the momentums:
        self.__CosinesToMom(DirCosineX, DirCosineY, self.E)

        print('hello!')
    def __ReadInTopasData(self):
        """
        Read in topas  data
        assumption is that this in in cm and MeV
        """

        PhaseSpace = tp.read_ntuple(self.Data)
        ParticleTypes = PhaseSpace['Particle Type (in PDG Format)']
        ParticleTypes = ParticleTypes.astype(int)
        ParticleDir = PhaseSpace[
            'Flag to tell if Third Direction Cosine is Negative (1 means true)']
        ParticleDir = ParticleDir.astype(int)
        ParticleDirInd = ParticleDir == 1  # only want forward moving particles
        if self.ParticleType == 'electrons':
            ParticleTypeInd = ParticleTypes == 11  # only want electrons
            Ind = np.logical_and(ParticleDirInd, ParticleTypeInd)
        elif self.ParticleType == 'gamma':
            ParticleTypeInd = ParticleTypes == 22  # only want photons
            Ind = np.logical_and(ParticleDirInd, ParticleTypeInd)
        else:
            Ind = ParticleDirInd

        self.x = PhaseSpace['Position X [cm]'][Ind] * 1e1
        self.y = PhaseSpace['Position Y [cm]'][Ind] * 1e1
        self.z = PhaseSpace['Position Z [cm]'][Ind] * 1e1
        self.DirCosineX = PhaseSpace['Direction Cosine X'][Ind]
        self.DirCosineY = PhaseSpace['Direction Cosine Y'][Ind]
        self.E = PhaseSpace['Energy [MeV]'][Ind]

        # figure out the momentums:
        self.__CosinesToMom()

        # if any values of pz == 0 exist, remove them with warning:
        if np.any(self.pz == 0):
            ind = self.pz == 0
            logging.warning(
                f'\nIn read in of topas data, removing {np.count_nonzero(ind)} of {ind.shape[0]} values where pz ==0. '
                f'\nWhile this is not necesarily an error,it means electrons are going completely sideways.'
                f'\nIt also makes transverse emittance calcs difficult, so im just going to delete those entries.'
                f'\nIf this is happening a lot I need to find a better solution\n'
            )

            self.x = np.delete(self.x, ind)
            self.y = np.delete(self.y, ind)
            self.z = np.delete(self.z, ind)
            self.px = np.delete(self.px, ind)
            self.py = np.delete(self.py, ind)
            self.pz = np.delete(self.pz, ind)
            self.E = np.delete(self.E, ind)
            self.TOT_E = np.delete(self.TOT_E, ind)
예제 #4
0
 def setUp(self):
     self.ascii = read_ntuple(ascii_path)
     self.binary = read_ntuple(binary_path)
     self.limited = read_ntuple(limited_path)
예제 #5
0
 def setUp(self):
     self.result = read_ntuple(limited_path)
     self.column_names = column_names_limited
예제 #6
0
 def setUp(self):
     self.result = read_ntuple(binary_path)
     self.column_names = column_names
예제 #7
0
 def setUp(self):
     self.result = read_ntuple(ascii_path)
     self.column_names = column_names
예제 #8
0
 def setUp(self):
     self.result = read_ntuple(binary_other_path)
예제 #9
0
 def setUp(self):
     self.result = read_ntuple(ascii_other_path)
예제 #10
0
 def setUp(self):
     self.ascii = read_ntuple(ascii_path)
     self.binary = read_ntuple(binary_path)
     self.limited = read_ntuple(limited_path)
예제 #11
0
 def setUp(self):
     self.result = read_ntuple(limited_path)
     self.column_names = column_names_limited
예제 #12
0
 def setUp(self):
     self.result = read_ntuple(binary_path)
     self.column_names = column_names
예제 #13
0
 def setUp(self):
     self.result = read_ntuple(ascii_path)
     self.column_names = column_names
예제 #14
0
 def setUp(self):
     self.result = read_ntuple(binary_other_path)
예제 #15
0
 def setUp(self):
     self.result = read_ntuple(ascii_other_path)