Exemplo n.º 1
0
    def make_hepmc(self, parse):

        #HepMC3 output

        global hepmc
        from pyHepMC3 import HepMC3 as hepmc

        nam = parse.get("main", "nam").strip("\"'") + ".hepmc"
        print("HepMC3 output name:", nam)

        self.hepmc_out = hepmc.WriterAscii(nam, hepmc.GenRunInfo())
        self.hepmc_ievt = 0
Exemplo n.º 2
0
def test_IO1():
    inputA = hm.ReaderAsciiHepMC2("inputIO1.hepmc")
    if inputA.failed():
        sys.exit(1)
    outputA = hm.WriterAscii(python_label() + "frominputIO1.hepmc")
    if outputA.failed():
        sys.exit(2)
    while not inputA.failed():
        evt = hm.GenEvent()
        inputA.read_event(evt)
        if inputA.failed():
            print("End of file reached. Exit.\n")
            break
        outputA.write_event(evt)
        evt.clear()
    inputA.close()
    outputA.close()

    inputB = hm.ReaderAscii(python_label() + "frominputIO1.hepmc")
    if inputB.failed():
        sys.exit(3)
    outputB = hm.WriterAsciiHepMC2(python_label() + "fromfrominputIO1.hepmc")
    if outputB.failed():
        sys.exit(4)
    while not inputB.failed():
        evt = hm.GenEvent()
        inputB.read_event(evt)
        if inputB.failed():
            print("End of file reached. Exit.\n")
            break
        outputB.write_event(evt)
        evt.clear()
    inputB.close()
    outputB.close()
    assert 0 == COMPARE_ASCII_FILES(python_label() + "fromfrominputIO1.hepmc",
                                    "inputIO1.hepmc")
    return 0
Exemplo n.º 3
0
def test_Pythia8():
    try:
        pythia = p8.Pythia()
    except ImportError:
        return 0
    pythia.readString("WeakSingleBoson:ffbar2gmZ = on")
    pythia.readString("Beams:idA =  11")
    pythia.readString("Beams:idB = -11")
    pythia.readString("Beams:eCM =  91.2")
    pythia.init()
    p8tohm = Pythia8ToHepMC3()
    p8tohm.m_store_pdf = True
    out = hm.WriterAscii(python_label() + "test_Pythia.hepmc")
    for iEvent in range(0, 100):
        if not pythia.next():
            continue
        nCharged = 0
        evt = hm.GenEvent()
        p8tohm.fill_next_event1(pythia, evt, iEvent)
        out.write_event(evt)
        evt.clear()
    pythia.stat()
    out.close()
    return 0
Exemplo n.º 4
0
def test_Polarization():
    xout1 = hm.WriterAscii(python_label() + "testPolarization1.dat")
    xout2 = hm.WriterAscii(python_label() + "testPolarization2.dat")
    xout4 = hm.WriterAsciiHepMC2(python_label() + "testPolarization4.dat")
    xout5 = hm.WriterAscii(python_label() + "testPolarization5.dat")

    # Build the graph, which will look like
    # Please note this is not physically meaningful event.
    #                       p7                   #
    # p1                   /                     #
    #   \v1__p3      p5---v4                     #
    #         \_v3_/       \                     #
    #         /    \        p8                   #
    #    v2__p4     \                            #
    #   /            p6                          #
    # p3                                         #
    #
    # define a flow pattern as  p1 . p3 . p6
    #                       and p2 . p4 . p5
    #

    # First create the event container, with Signal Process 20, event number 1
    #
    evt = hm.GenEvent(hm.Units.GEV, hm.Units.MM)
    evt.set_event_number(1)
    evt.add_attribute("signal_process_id", hm.IntAttribute(20))

    v1 = hm.GenVertex()
    evt.add_vertex(v1)
    p1 = hm.GenParticle(hm.FourVector(0, 0, 7000, 7000), 2212, 3)
    evt.add_particle(p1)
    p1.add_attribute("flow1", hm.IntAttribute(231))
    p1.add_attribute("flow1", hm.IntAttribute(231))
    p1.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p1.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v1.add_particle_in(p1)

    v2 = hm.GenVertex()
    evt.add_vertex(v2)
    p2 = hm.GenParticle(hm.FourVector(0, 0, -7000, 7000), 2212, 3)
    evt.add_particle(p2)
    p2.add_attribute("flow1", hm.IntAttribute(243))
    p2.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p2.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v2.add_particle_in(p2)

    p3 = hm.GenParticle(hm.FourVector(0.751, -1.569, 32.191, 32.238), 1, 3)
    evt.add_particle(p3)
    p3.add_attribute("flow1", hm.IntAttribute(231))
    p3.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p3.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v1.add_particle_out(p3)
    p4 = hm.GenParticle(hm.FourVector(-3.047, -19.0, -54.629, 57.920), -2, 3)
    evt.add_particle(p4)
    p4.add_attribute("flow1", hm.IntAttribute(243))
    p4.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p4.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v2.add_particle_out(p4)

    v3 = hm.GenVertex()
    evt.add_vertex(v3)
    v3.add_particle_in(p3)
    v3.add_particle_in(p4)
    p6 = hm.GenParticle(hm.FourVector(-3.813, 0.113, -1.833, 4.233), 22, 1)
    evt.add_particle(p6)
    p6.add_attribute("flow1", hm.IntAttribute(231))
    p6.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p6.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v3.add_particle_out(p6)
    p5 = hm.GenParticle(hm.FourVector(1.517, -20.68, -20.605, 85.925), -24, 3)
    evt.add_particle(p5)
    p5.add_attribute("flow1", hm.IntAttribute(243))
    p5.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p5.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v3.add_particle_out(p5)
    # create v4
    v4 = hm.GenVertex(hm.FourVector(0.12, -0.3, 0.05, 0.004))
    evt.add_vertex(v4)
    v4.add_particle_in(p5)
    p7 = hm.GenParticle(hm.FourVector(-2.445, 28.816, 6.082, 29.552), 1, 1)
    evt.add_particle(p7)
    v4.add_particle_out(p7)
    p8 = hm.GenParticle(hm.FourVector(3.962, -49.498, -26.687, 56.373), -2, 1)
    evt.add_particle(p8)
    v4.add_particle_out(p8)

    evt.add_attribute("signal_process_vertex", hm.IntAttribute(v3.id()))
    evt.set_beam_particles(p1,p2)
    # The event is complete, we now print it out
    hm.Print.content(evt)
    hm.Print.listing(evt, 8)
    print(hm.version())
    print(hm.Print.line(v4, True))
    a = 0
    print(evt.particles())
    print(len(evt.particles()))
    print(evt.particles()[0])
    for ip in evt.particles():
        print(hm.Print.line(ip, True))
    xout1.write_event(evt)

    # write event in old format
    xout4.write_event(evt)
    # make a copy and write it
    xout5.write_event(hm.GenEvent(evt))
    # try changing polarization
    p2.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p2.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi))
    xout2.write_event(evt)
    xout1.close()
    xout2.close()
    xout4.close()
    xout5.close()
    # now clean-up by deleteing all objects from memory
    #
    # deleting the event deletes all contained vertices, and all particles
    # contained in those vertices
    evt.clear()

    assert (
        COMPARE_ASCII_FILES(python_label() + "testPolarization1.dat", python_label() + "testPolarization5.dat") == 0
    ) and (COMPARE_ASCII_FILES(python_label() + "testPolarization1.dat", python_label() + "testPolarization2.dat") != 0)

    inputA1 = hm.ReaderAscii(python_label() + "testPolarization1.dat")
    if inputA1.failed():
        return 1
    while not inputA1.failed():
        evt = hm.GenEvent()
        inputA1.read_event(evt)
        if inputA1.failed():
            print("End of file reached. Exit.\n")
            break
        evt.clear()
    inputA1.close()
    inputA2 = hm.ReaderAscii(python_label() + "testPolarization2.dat")
    if inputA2.failed():
        return 2
    while not inputA2.failed():
        evt = hm.GenEvent()
        inputA2.read_event(evt)
        if inputA2.failed():
            print("End of file reached. Exit.\n")
            break
        evt.clear()
    inputA2.close()

    inputA4 = hm.ReaderAsciiHepMC2(python_label() + "testPolarization4.dat")
    if inputA4.failed():
        return 4
    while not inputA4.failed():
        evt = hm.GenEvent()
        inputA4.read_event(evt)
        if inputA4.failed():
            print("End of file reached. Exit.\n")
            break
        evt.clear()
    inputA4.close()

    inputA5 = hm.ReaderAscii(python_label() + "testPolarization5.dat")
    if inputA5.failed():
        return 4
    while not inputA5.failed():
        evt = hm.GenEvent()
        inputA5.read_event(evt)
        if inputA5.failed():
            print("End of file reached. Exit.\n")
            break
        evt.clear()
    inputA5.close()

    return 0
Exemplo n.º 5
0
def test_Print():
    evt = hm.GenEvent(hm.Units.MomentumUnit.GEV, hm.Units.LengthUnit.CM)
    evt.set_event_number(1)
    evt.add_attribute("signal_process_id", hm.IntAttribute(20))
    #     create vertex 1
    v1 = hm.GenVertex()
    evt.add_vertex(v1)
    p1 = hm.GenParticle(hm.FourVector(1.0, 1.0, 7000, 7000), 2212, 3)
    evt.add_particle(p1)
    p1.add_attribute("flow1", hm.IntAttribute(231))
    p1.add_attribute("flow1", hm.IntAttribute(231))
    p1.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p1.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))

    v2 = hm.GenVertex()
    evt.add_vertex(v2)
    p2 = hm.GenParticle(hm.FourVector(1.0, 1.0, -7000, 7000), 2212, 3)
    evt.add_particle(p2)
    p2.add_attribute("flow1", hm.IntAttribute(243))
    p2.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p2.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v2.add_particle_in(p2)
    #
    #     create the outgoing particles of v1 and v2
    p3 = hm.GenParticle(hm.FourVector(0.750, -1.569, 32.191, 32.238), 1, 3)
    evt.add_particle(p3)
    p3.add_attribute("flow1", hm.IntAttribute(231))
    p3.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p3.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v1.add_particle_out(p3)
    p4 = hm.GenParticle(hm.FourVector(-3.047, -19.0, -54.629, 57.920), -2, 3)
    evt.add_particle(p4)
    p4.add_attribute("flow1", hm.IntAttribute(243))
    p4.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p4.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v2.add_particle_out(p4)
    #
    #     create v3
    v3 = hm.GenVertex()
    evt.add_vertex(v3)
    v3.add_particle_in(p3)
    v3.add_particle_in(p4)
    p6 = hm.GenParticle(hm.FourVector(-3.813, 0.113, -1.833, 4.233), 22, 1)
    evt.add_particle(p6)
    p6.add_attribute("flow1", hm.IntAttribute(231))
    p6.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p6.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v3.add_particle_out(p6)
    p5 = hm.GenParticle(hm.FourVector(1.517, -20.68, -20.605, 85.925), -24, 3)
    evt.add_particle(p5)
    p5.add_attribute("flow1", hm.IntAttribute(243))
    p5.add_attribute("theta", hm.DoubleAttribute(random.random() * math.pi))
    p5.add_attribute("phi", hm.DoubleAttribute(random.random() * math.pi * 2))
    v3.add_particle_out(p5)
    #
    #     create v4
    v4 = hm.GenVertex(hm.FourVector(0.12, -0.3, 0.05, 0.004))
    evt.add_vertex(v4)
    v4.add_particle_in(p5)
    p7 = hm.GenParticle(hm.FourVector(-2.445, 28.816, 6.082, 29.552), 1, 1)
    evt.add_particle(p7)
    v4.add_particle_out(p7)
    p8 = hm.GenParticle(hm.FourVector(3.962, -49.498, -26.687, 56.373), -2, 1)
    evt.add_particle(p8)
    v4.add_particle_out(p8)
    #
    #     tell the event which vertex is the signal process vertex

    evt.add_attribute("signal_process_vertex", hm.IntAttribute(v3.id()))
    print(dir(hm))
    print(hm.Print.content(evt))
    #    we now print it out in old format
    print(hm.Print.listing(evt, 8))
    #     print each particle so we can see the polarization
    for ip in evt.particles():
        print(hm.Print.line(ip, True))

    xout1 = hm.WriterAscii(python_label() + "testBoost1.out")
    xout1.set_precision(6)
    xout1.write_event(evt)
    xout1.close()
    # different outputs
    ff = io.StringIO()
    hm.Print.listing(ff, evt)
    print(ff.getvalue())
    # different outputs
    for ip in evt.particles():
        print(hm.Print.line(ip, True))
    for ip in evt.particles():
        print(hm.Print.line(ip, True))
    xout2 = hm.WriterAscii(python_label() + "testBoost2.out")
    xout2.set_precision(6)
    xout2.write_event(evt)
    xout2.close()
    assert COMPARE_ASCII_FILES(python_label() + "testBoost1.out",
                               python_label() + "testBoost2.out") == 0
    evt.clear()
    return 0