Esempio n. 1
0
    def read(self, detector, nscale=1):

        try:
            usr = Usrbin(self.filename)
            data = usr.readData(0)
            fdata = unpackArray(data)
        except IOError:
            usr = UsrTrack(self.filename)
            data = usr.readData(0)
            fdata = unpackArray(data)[:usr.detector[0].ne]
        usr.say()  # file,title,time,weight,ncase,nbatch
        for i, _ in enumerate(usr.detector):
            logger.debug("-" * 20 + (" Detector number %i " % i) + "-" * 20)
            usr.say(i)  # details for each detector

        # TODO read detector type
        detector.det = "FLUKA"

        # TODO read particle type
        detector.particle = 0

        # TODO read geo type
        detector.geotyp = SHGeoType.unknown

        # TODO cross-check statistics
        detector.nstat = usr.ncase

        # TODO figure out when more detectors are used
        nx = usr.detector[0].nx
        ny = usr.detector[0].ny
        nz = usr.detector[0].nz

        xmin = usr.detector[0].xlow
        ymin = usr.detector[0].ylow
        zmin = usr.detector[0].zlow

        xmax = usr.detector[0].xhigh
        ymax = usr.detector[0].yhigh
        zmax = usr.detector[0].zhigh

        detector.x = MeshAxis(n=nx, min_val=xmin, max_val=xmax,
                              name="X", unit="", binning=MeshAxis.BinningType.linear)
        detector.y = MeshAxis(n=ny, min_val=ymin, max_val=ymax,
                              name="Y", unit="", binning=MeshAxis.BinningType.linear)
        detector.z = MeshAxis(n=nz, min_val=zmin, max_val=zmax,
                              name="Z", unit="", binning=MeshAxis.BinningType.linear)

        detector.unit, detector.name = "", ""

        # TODO read detector type
        detector.dettyp = SHDetType.unknown

        detector.data_raw = np.array(fdata)
        if nscale != 1:
            detector.data *= nscale
            # 1 gigaelectron volt / gram = 1.60217662 x 10-7 Gy
            detector.data *= 1.60217662e-7

        detector.title = usr.detector[0].name.decode('ascii')
Esempio n. 2
0
    def parse_usrbin(self, estimator):
        """
        USRBIN scores distribution of one of several quantities in a regular spatial
        structure (binning detector) independent from the geometry.
        :param estimator: an Estimator object, will be modified here and filled with data
        """
        try:
            usr_object = Usrbin(self.filename)

            # loop over all detectors (pages) in USRBIN object
            for det_no, detector in enumerate(usr_object.detector):
                page = Page(estimator=estimator)
                page.title = detector.name

                # USRBIN doesn't support differential binning type, only spatial binning is allowed
                estimator.x = MeshAxis(n=detector.nx,
                                       min_val=detector.xlow,
                                       max_val=detector.xhigh,
                                       name="X",
                                       unit="cm",
                                       binning=MeshAxis.BinningType.linear)
                estimator.y = MeshAxis(n=detector.ny,
                                       min_val=detector.ylow,
                                       max_val=detector.yhigh,
                                       name="Y",
                                       unit="cm",
                                       binning=MeshAxis.BinningType.linear)
                estimator.z = MeshAxis(n=detector.nz,
                                       min_val=detector.zlow,
                                       max_val=detector.zhigh,
                                       name="Z",
                                       unit="cm",
                                       binning=MeshAxis.BinningType.linear)

                page.name = "scorer {}".format(detector.score)
                page.unit = ""

                # unpack detector data
                # TODO cross-check if reshaping is needed
                page.data_raw = np.array(
                    unpackArray(usr_object.readData(det_no)))
                page.error_raw = np.empty_like(page.data_raw)

                estimator.add_page(page)

            return usr_object
        except IOError:
            return None
Esempio n. 3
0
    def read(self, detector, nscale=1):
        usr = Usrbin(self.filename)
        usr.say()  # file,title,time,weight,ncase,nbatch
        for i, _ in enumerate(usr.detector):
            logger.debug("-" * 20 + (" Detector number %i " % i) + "-" * 20)
            usr.say(i)  # details for each detector
        data = usr.readData(0)
        fdata = unpackArray(data)

        # TODO read detector type
        detector.det = "FLUKA"

        # TODO read particle type
        detector.particle = 0

        # TODO read geo type
        detector.geotyp = SHGeoType.unknown

        # TODO cross-check statistics
        detector.nstat = usr.ncase

        # TODO figure out when more detectors are used
        detector.nx = usr.detector[0].nx
        detector.ny = usr.detector[0].ny
        detector.nz = usr.detector[0].nz

        detector.xmin = usr.detector[0].xlow
        detector.ymin = usr.detector[0].ylow
        detector.zmin = usr.detector[0].zlow

        detector.xmax = usr.detector[0].xhigh
        detector.ymax = usr.detector[0].yhigh
        detector.zmax = usr.detector[0].zhigh

        # TODO read detector type
        detector.dettyp = SHDetType.unknown

        detector.data = np.array(fdata)
        if nscale != 1:
            detector.data *= nscale
            # 1 gigaelectron volt / gram = 1.60217662 x 10-7 Gy
            detector.data *= 1.60217662e-7

        # set units : detector.units are [x,y,z,v,data,detector_title]
        detector.units = [""] * 9

        detector.title = usr.title.decode('ascii')
Esempio n. 4
0
    def parse_resnuclei(self, estimator):
        """
        TODO add support for resnuclei
        RESNUCLEi Scores residual nuclei produced in inelastic interactions on a region basis
        :param estimator: an Estimator object, will be modified here and filled with data
        """
        try:
            usr_object = Resnuclei(self.filename)
            # loop over all detectors (pages) in USRTRACK object
            for det_no, detector in enumerate(usr_object.detector):
                page = Page(estimator=estimator)

                # unpack detector data
                # TODO cross-check if reshaping is needed
                page.data_raw = np.array(
                    unpackArray(usr_object.readData(det_no)))
                page.error_raw = np.empty_like(page.data_raw)

                estimator.add_page(page)
            return usr_object
        except IOError:
            return None
Esempio n. 5
0
    def parse_usrbdx(self, estimator):
        """
        USRBDX defines a detector for a boundary crossing fluence or current estimator
        :param estimator: an Estimator object, will be modified here and filled with data
        """
        try:
            usr_object = Usrbdx(self.filename)

            # loop over all detectors (pages) in USRBDX object
            for det_no, detector in enumerate(usr_object.detector):
                page = Page(estimator=estimator)
                page.title = detector.name
                page.area = detector.area  # area of the detector in cm**2

                if detector.nb == 1:
                    energy_binning = MeshAxis.BinningType.linear
                    angle_binning = MeshAxis.BinningType.linear
                elif detector.nb == -1:
                    energy_binning = MeshAxis.BinningType.logarithmic
                    angle_binning = MeshAxis.BinningType.linear
                elif detector.nb == 2:
                    energy_binning = MeshAxis.BinningType.linear
                    angle_binning = MeshAxis.BinningType.logarithmic
                elif detector.nb == -2:
                    energy_binning = MeshAxis.BinningType.logarithmic
                    angle_binning = MeshAxis.BinningType.logarithmic
                else:
                    return Exception("Invalid binning type")

                # USRBDX doesn't support spatial (XYZ) binning type
                # USRBDX provides double differential binning, first axis is kinetic energy (in GeV)
                page.diff_axis1 = MeshAxis(
                    n=detector.ne,  # number of energy intervals for scoring
                    min_val=detector.
                    elow,  # minimum kinetic energy for scoring (GeV)
                    max_val=detector.
                    ehigh,  # maximum kinetic energy for scoring (GeV)
                    name="kinetic energy",
                    unit="GeV",
                    binning=energy_binning)

                # second axis is solid angle (in steradians)
                page.diff_axis2 = MeshAxis(
                    n=detector.na,  # number of angular bins
                    min_val=detector.alow,  # minimum solid angle for scoring
                    max_val=detector.ahigh,  # maximum solid angle for scoring
                    name="solid angle",
                    unit="sr",
                    binning=angle_binning)

                # detector.fluence corresponds to i2 in WHAT(1) in first card of USBDX
                if detector.fluence == 1:
                    page.name = "fluence"
                elif detector.fluence == 0:
                    page.name = "current"
                else:
                    page.name = ""
                page.unit = "cm-2 GeV-1 sr-1"

                # TODO If the generalised particle is 208.0 (ENERGY) or 211.0 (EM-ENRGY),
                #             the quantity scored is differential energy fluence (if
                #             cosine-weighted) or differential energy current (energy crossing the
                #             surface). In both cases the quantity will be expressed in GeV per
                #             cm2 per energy unit per steradian per primary

                # unpack detector data
                # TODO cross-check if reshaping is needed
                page.data_raw = np.array(
                    unpackArray(usr_object.readData(det_no)))
                page.error_raw = np.empty_like(page.data_raw)

                estimator.add_page(page)

            return usr_object
        except IOError:
            return None
Esempio n. 6
0
    def parse_usrtrack(self, estimator):
        """
        :param estimator: an Estimator object, will be modified here and filled with data
        USRTRACK defines a detector for a track-length fluence estimator
        """
        try:
            usr_object = UsrTrack(self.filename)

            # loop over all detectors (pages) in USRTRACK object
            for det_no, detector in enumerate(usr_object.detector):
                page = Page(estimator=estimator)
                page.title = detector.name
                page.volume = detector.volume  # volume of the detector in cm**3

                # USRTRACK doesn't support spatial (XYZ) binning type
                if detector.type == 1:
                    energy_binning = MeshAxis.BinningType.linear
                elif detector.type == -1:
                    energy_binning = MeshAxis.BinningType.logarithmic
                else:
                    return Exception("Invalid binning type")

                # USRTRACK provides single differential binning, with diff axis in kinetic energy (in GeV)
                page.diff_axis1 = MeshAxis(
                    n=detector.ne,  # number of energy intervals for scoring
                    min_val=detector.
                    elow,  # minimum kinetic energy for scoring (GeV)
                    max_val=detector.
                    ehigh,  # maximum kinetic energy for scoring (GeV)
                    name="kinetic energy",
                    unit="GeV",
                    binning=energy_binning)

                page.name = "fluence"
                page.unit = "cm-2 GeV-1"

                # TODO IMPORTANT! The results of USRTRACK are always given as DIFFERENTIAL
                #             distributions of fluence (or tracklength, if the detector region
                #             volume is not specified) in energy, in units of cm-2 GeV-1 (or
                #             cm GeV-1) per incident primary unit weight. Thus, for example, when
                #             requesting a fluence energy spectrum, to obtain INTEGRAL BINNED
                #             results (fluence in cm-2 or tracklength in cm PER ENERGY BIN per
                #             primary) one must multiply the value of each energy bin by the width
                #             of the bin (even for logarithmic binning)

                # TODO If the generalised particle is 208 (ENERGY) or 211 (EM-ENRGY), the
                #             quantity scored is differential energy fluence (or tracklength, if
                #             the detector region volume is not specified), expressed in GeV per
                #             cm2 (or cm GeV) per energy unit per primary. That can sometimes lead
                #             to confusion since GeV cm-2 GeV-1 = cm-2, where energy does not appear.
                #             Note that integrating over energy one gets GeV/cm2.

                # unpack detector data
                # TODO cross-check if reshaping is needed
                page.data_raw = np.array(
                    unpackArray(usr_object.readData(det_no)))
                page.error_raw = np.empty_like(page.data_raw)

                estimator.add_page(page)
            return usr_object
        except IOError:
            return None