Esempio n. 1
0
    def parse_particle_line(self, line, barcode):
        """Parse a line that describes a particle and its mothers from a LHE file.

        Need to supply barcode to make Particle obj unique, since not supplied as
        part of LHE format

        Parameters
        ----------
        line : str
            Line of text describing a particle
        barcode : int
            Unique barcode for this particle

        Returns
        -------
        NodeParticle
            NodeParticle object that contains the Particle, as well as its mother barcodes.
        """
        fields = ["pdgid", "status", "parent1", "parent2", "col1", "col2",
                  "px", "py", "pz", "energy", "mass", "lifetime", "spin"]
        contents_dict = map_columns_to_dict(fields, line)
        p = Particle(barcode=barcode,
                     pdgid=int(contents_dict["pdgid"]),
                     status=int(contents_dict["status"]),
                     px=float(contents_dict["px"]),
                     py=float(contents_dict["py"]),
                     pz=float(contents_dict["pz"]),
                     energy=float(contents_dict["energy"]),
                     mass=float(contents_dict["mass"]))
        log.debug(contents_dict)
        np = NodeParticle(particle=p,
                          parent_barcodes=list(range(int(contents_dict['parent1']),
                                                     int(contents_dict['parent2']) + 1)))
        return np
Esempio n. 2
0
    def parse_particle_line(self, line):
        """Parse a HepMC GenParticle line and return an EdgeParticle object

        Note that the EdgeParticle does not have vtx_out_barcode assigned here,
        since we are parsing a line in isolation. The vtx_out_barcode is added
        in the main pars() method. We just use a dummy value for now.
        """
        fields = [
            "barcode", "pdgid", "px", "py", "pz", "energy", "mass", "status",
            "pol_theta", "pol_phi", "vtx_in_barcode"
        ]
        contents = map_columns_to_dict(fields, line[1:])
        p = Particle(barcode=int(contents["barcode"]),
                     pdgid=int(contents["pdgid"]),
                     status=contents["status"],
                     px=float(contents["px"]),
                     py=float(contents["py"]),
                     pz=float(contents["pz"]),
                     energy=float(contents["energy"]),
                     mass=float(contents["mass"]))
        log.debug(p)
        ep = EdgeParticle(particle=p,
                          vtx_in_barcode=abs(int(contents['vtx_in_barcode'])),
                          vtx_out_barcode=0)
        return ep
Esempio n. 3
0
 def parse_vertex_line(self, line):
     """Parse a HepMC GenVertex line and return a GenVertex object"""
     fields = [
         "barcode", "id", "x", "y", "z", "ctau", "n_orphan_in", "n_out"
     ]
     contents = map_columns_to_dict(fields, line[1:])
     return GenVertex(barcode=abs(int(contents["barcode"])),
                      n_orphan_in=contents["n_orphan_in"])
Esempio n. 4
0
    def parse_particle_line(self, line):
        """Parse line representing a particle, return a NodeParticle."""

        log.debug(line)

        # First split by |. This gives us [idx, ID-name, status,
        # parents/children, nParents/Children, pt/eta/phi, px/py/pz/m]
        # parts1 = line.strip().split('|')
        fields = ['idx', 'pdg', 'status', 'family', 'nFamily', '3mom', '4mom']
        contents_dict = map_columns_to_dict(fields, line.strip(), delim='|')

        # Get PDGID - we don't car about the name
        pdgid = contents_dict['pdg'].strip().split()[0]

        # Get mother/daughter IDXs
        family_fields = ['parent1', 'parent2', 'child1', 'child2']
        family_contents = map_columns_to_dict(family_fields,
                                              contents_dict['family'])

        # Get pt/eta/phi
        three_mom_fields = ['pt', 'eta', 'phi']
        three_mom_contents = map_columns_to_dict(three_mom_fields,
                                                 contents_dict['3mom'])

        # Get px/py/pz/m
        four_mom_fields = ['px', 'py', 'pz', 'm']
        four_mom_contents = map_columns_to_dict(four_mom_fields,
                                                contents_dict['4mom'])

        p = Particle(barcode=int(contents_dict['idx']),
                     pdgid=int(pdgid),
                     status=int(contents_dict['status']),
                     px=float(four_mom_contents['px']),
                     py=float(four_mom_contents['py']),
                     pz=float(four_mom_contents['pz']),
                     mass=float(four_mom_contents['m']))
        np = NodeParticle(particle=p,
                          parent_barcodes=list(
                              range(int(family_contents['parent1']),
                                    int(family_contents['parent2']) + 1)))

        log.debug(np)
        return np
Esempio n. 5
0
def parse_event_block(contents):
    """Parse Event listing block in Pythia output

    Parameters
    ----------
    contents : list[str]
        Contents of event block.

    Returns
    -------
    list[NodeParticle]
        NodeParticles extracted from event, with mother barcodes set.
    """
    # These indicate non-particle lines - matches words
    ignore = (("no", "id"), ("Charge", "sum:"), ("0", "90", "(system)"))

    # Store all the NodeParticles in the event
    node_particles = []

    log.debug("start of raw contents")
    log.debug(contents)
    log.debug("end of raw contents")

    for line in contents:
        log.debug(line)

        # first determine if interesting line or not - checks to see if entries
        # in ignore tuple match entries in parts list
        if sum([all([i == p for i, p in izip(ig, line.split())]) for ig in ignore]):
            continue

        # Now assign each field to a dict to make life easier
        fields = ["barcode", "pdgid", "name", "status", "parent1", "parent2",
                  "child1", "child2", "colours1", "colours2",
                  "px", "py", "pz", "energy", "mass"]
        contents_dict = map_columns_to_dict(fields, line)
        log.debug(contents_dict)
        # Create a Particle obj and add to total
        p = Particle(barcode=int(contents_dict['barcode']),
                     pdgid=int(contents_dict['pdgid']),
                     status=int(contents_dict['status']),
                     px=float(contents_dict['px']),
                     py=float(contents_dict['py']),
                     pz=float(contents_dict['pz']),
                     energy=float(contents_dict['energy']),
                     mass=float(contents_dict['mass']))
        # Sometimes parent2 = 0, so set = parent1 if this is the case
        if int(contents_dict['parent2']) == 0:
            contents_dict['parent2'] = contents_dict['parent1']
        np = NodeParticle(particle=p,
                          parent_barcodes=list(range(int(contents_dict['parent1']),
                                                     int(contents_dict['parent2']) + 1)))
        node_particles.append(np)

    return node_particles
Esempio n. 6
0
 def parse_event_line(self, line):
     """Parse a HepMC GenEvent line and return an Event object"""
     fields = [
         "event_num", "num_mpi", "scale", "aQCD", "aQED",
         "signal_process_id", "signal_process_vtx_id", "n_vtx",
         "beam1_pdgid", "beam2_pdgid"
     ]
     contents = map_columns_to_dict(fields, line[1:])
     return Event(event_num=contents["event_num"],
                  source=self.filename,
                  signal_process_vtx_id=contents["signal_process_vtx_id"])
    def parse_particle_line(self, line):
        """Parse line representing a particle, return a NodeParticle."""

        log.debug(line)

        # First split by |. This gives us [idx, ID-name, status,
        # parents/children, nParents/Children, pt/eta/phi, px/py/pz/m]
        # parts1 = line.strip().split('|')
        fields = ['idx', 'pdg', 'status', 'family', 'nFamily', '3mom', '4mom']
        contents_dict = map_columns_to_dict(fields, line.strip(), delim='|')

        # Get PDGID - we don't car about the name
        pdgid = contents_dict['pdg'].strip().split()[0]

        # Get mother/daughter IDXs
        family_fields = ['parent1', 'parent2', 'child1', 'child2']
        family_contents = map_columns_to_dict(family_fields, contents_dict['family'])

        # Get pt/eta/phi
        three_mom_fields = ['pt', 'eta', 'phi']
        three_mom_contents = map_columns_to_dict(three_mom_fields, contents_dict['3mom'])

        # Get px/py/pz/m
        four_mom_fields = ['px', 'py', 'pz', 'm']
        four_mom_contents = map_columns_to_dict(four_mom_fields, contents_dict['4mom'])

        p = Particle(barcode=int(contents_dict['idx']),
                     pdgid=int(pdgid),
                     status=int(contents_dict['status']),
                     px=float(four_mom_contents['px']),
                     py=float(four_mom_contents['py']),
                     pz=float(four_mom_contents['pz']),
                     mass=float(four_mom_contents['m']))
        np = NodeParticle(particle=p,
                          parent_barcodes=list(range(int(family_contents['parent1']),
                                                     int(family_contents['parent2']) + 1)))

        log.debug(np)
        return np
Esempio n. 8
0
    def parse_event_line(self, line, event_num):
        """Parse a LHE event info line.

        Parameters
        ----------
        line : str
            Line of text describing the event.
        event_num : int
            Event number, as it is not included in the event line.

        Returns
        -------
        Event
            Event object with information from the line.
        """
        fields = ["num_particles", "proc_id", "weight", "scale", "aQED", "aQCD"]
        contents = map_columns_to_dict(fields, line)
        log.debug(contents)
        return Event(event_num=int(event_num), source=self.filename)
Esempio n. 9
0
    def parse_event_line(self, line, event_num):
        """Parse a LHE event info line.

        Parameters
        ----------
        line : str
            Line of text describing the event.
        event_num : int
            Event number, as it is not included in the event line.

        Returns
        -------
        Event
            Event object with information from the line.
        """
        fields = [
            "num_particles", "proc_id", "weight", "scale", "aQED", "aQCD"
        ]
        contents = map_columns_to_dict(fields, line)
        log.debug(contents)
        return Event(event_num=int(event_num), source=self.filename)
Esempio n. 10
0
    def parse_particle_line(self, line, barcode):
        """Parse a line that describes a particle and its mothers from a LHE file.

        Need to supply barcode to make Particle obj unique, since not supplied as
        part of LHE format

        Parameters
        ----------
        line : str
            Line of text describing a particle
        barcode : int
            Unique barcode for this particle

        Returns
        -------
        NodeParticle
            NodeParticle object that contains the Particle, as well as its mother barcodes.
        """
        fields = [
            "pdgid", "status", "parent1", "parent2", "col1", "col2", "px",
            "py", "pz", "energy", "mass", "lifetime", "spin"
        ]
        contents_dict = map_columns_to_dict(fields, line)
        p = Particle(barcode=barcode,
                     pdgid=int(contents_dict["pdgid"]),
                     status=int(contents_dict["status"]),
                     px=float(contents_dict["px"]),
                     py=float(contents_dict["py"]),
                     pz=float(contents_dict["pz"]),
                     energy=float(contents_dict["energy"]),
                     mass=float(contents_dict["mass"]))
        log.debug(contents_dict)
        np = NodeParticle(particle=p,
                          parent_barcodes=list(
                              range(int(contents_dict['parent1']),
                                    int(contents_dict['parent2']) + 1)))
        return np