コード例 #1
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 in python',
                                     prog=os.path.basename(__file__))
    pyconf.add_standard_pythia_args(parser)
    args = parser.parse_args()

    hepmc2output = "pythia_gen_test_hepmc2.dat"
    pyhepmc2writer = pythiaext.Pythia8HepMC2Wrapper(hepmc2output)

    # experimental and not functioning as of now - switching off
    # hepmc3output = "pyhia_gen_test_hepmc3.dat"
    # pyhepmc3writer = pythiahepmc3.Pythia8HepMC3Wrapper(hepmc3output)

    mycfg = ['PhaseSpace:pThatMin = 100']
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if args.nev < 10:
        args.nev = 10
    for i in tqdm.tqdm(range(args.nev)):
        if not pythia.next():
            continue
        pyhepmc2writer.fillEvent(pythia)
        # pyhepmc3writer.fillEvent(pythia)
    pythia.stat()

    print("[i] file written: {}".format(hepmc2output))
コード例 #2
0
def main():
	parser = argparse.ArgumentParser(description='pythia8 in python', prog=os.path.basename(__file__))
	parser.add_argument('-o', '--output', help='output file name', default='pythia_hepmc.dat', type=str)
	pyconf.add_standard_pythia_args(parser)
	args = parser.parse_args()	

	hepmc2output = args.output
	pyhepmc2writer = pythiaext.Pythia8HepMC2Wrapper(hepmc2output)

	mycfg = []
	pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
	if args.nev < 10:
		args.nev = 10
	for i in tqdm.tqdm(range(args.nev)):
		if not pythia.next():
			continue
		pyhepmc2writer.fillEvent(pythia)
	pythia.stat()

	print("[i] file written: {}".format(hepmc2output))
コード例 #3
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 in python',
                                     prog=os.path.basename(__file__))
    parser.add_argument('-o',
                        '--output_dir',
                        help='output file location',
                        default='.',
                        type=str,
                        required=True)
    pyconf.add_standard_pythia_args(parser)
    args = parser.parse_args()

    if not os.path.exists(args.output_dir):
        os.makedirs(args.output_dir)
    output_file = os.path.join(args.output_dir, 'pythia8.hepmc')

    pyhepmc2writer = pythiaext.Pythia8HepMC2Wrapper(output_file)
    # pyhepmc3writer = pythiahepmc3.Pythia8HepMC3Wrapper(output_file)

    mycfg = []
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if args.nev < 10:
        args.nev = 10
    for i in range(args.nev):
        if not pythia.next():
            continue
        if i % 100 == 0:
            print(f'event {i}/{args.nev}')

        pyhepmc2writer.fillEvent(pythia)
        # pyhepmc3writer.fillEvent(pythia)

    pythia.stat()
    pythia.settings.writeFile(
        os.path.join(args.output_dir, 'modified_settings.hepmc'))
    print(f"[i] file written: {output_file}")
コード例 #4
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 in python',
                                     prog=os.path.basename(__file__))
    parser.add_argument('--hepmc',
                        help='write the hepmc files',
                        default=False,
                        action='store_true')
    parser.add_argument('--ml',
                        help='write the ml format root files',
                        default=False,
                        action='store_true')
    parser.add_argument('-c',
                        '--nperfile',
                        help='nevents per output file',
                        default=1000,
                        type=int)
    pyconf.add_standard_pythia_args(parser)
    args = parser.parse_args()

    if args.hepmc:
        hepmc2_output_base = "pythia_gen_qorg.hepmc"
        hepmc2_output_name = None
        hepmc2_writer = None
        hepmc2_fileno = 0

    if args.ml:
        if root_avail is None:
            print('[error] unable to load ROOT so --ml is defunct')
            args.ml = False
        ml_root_output_base = "pythia_gen_qorg.root"
        ml_root_output_name = None
        ml_root_file = None
        ml_root_ntuple_parts = None
        ml_root_ntuple_ev = None
        ml_root_fileno = 0

    if args.hepmc is False and args.ml is False:
        print('[error] one of the --hepmc or --ml is required')
        print('		   --help for more options')
        return

    mycfg = []
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if args.nev < 10:
        args.nev = 10
    run_number = args.py_seed
    event_number = 0
    pbar = tqdm.tqdm(range(args.nev))
    for i in pbar:
        if not pythia.next():
            pbar.update(-1)
            continue
        event_number = event_number + 1
        if i == 0 or i % args.nperfile == 0:
            if args.hepmc:
                if hepmc2_writer:
                    del hepmc2_writer
                hepmc2_output_name = format_output_file(
                    hepmc2_output_base, hepmc2_fileno, args)
                # print('[i] new file', hepmc2_output_name)
                hepmc2_writer = pythiaext.Pythia8HepMC2Wrapper(
                    hepmc2_output_name)
                hepmc2_fileno = hepmc2_fileno + 1
            if args.ml:
                if ml_root_file:
                    if ml_root_ntuple_parts:
                        ml_root_ntuple_parts.Write()
                        ml_root_ntuple_ev.Write()
                    ml_root_file.Write()
                    ml_root_file.Purge()
                    ml_root_file.Close()
                    ml_root_file = None
                    ml_root_ntuple = None
                ml_root_output_name = format_output_file(
                    ml_root_output_base, ml_root_fileno, args)
                ml_root_file = ROOT.TFile(ml_root_output_name, 'recreate')
                ml_root_ntuple_parts = ROOT.TNtuple(
                    'tree_Particle_gen',
                    'particles from PYTHIA8 - {} jets'.format(
                        parton_type_from_args(args)),
                    'run_number:ev_id:ParticlePt:ParticleEta:ParticlePhi:ParticlePID'
                )
                ml_root_ntuple_ev = ROOT.TNtuple(
                    'tree_Event_gen',
                    'event info from PYTHIA8 - {} jets'.format(
                        parton_type_from_args(args)),
                    'run_number:ev_id:xsec:code')
                ml_root_fileno = ml_root_fileno + 1

        if args.hepmc:
            hepmc2_writer.fillEvent(pythia)

        if args.ml:
            parts_pythia_h = pythiafjext.vectorize_select(
                pythia, [pythiafjext.kFinal], 0, True)
            ml_root_ntuple_ev.Fill(run_number, event_number,
                                   pythia.info.sigmaGen(), pythia.info.code())
            for p in parts_pythia_h:
                ml_root_ntuple_parts.Fill(
                    run_number, event_number, p.pt(), p.eta(), p.phi(),
                    pythiafjext.getPythia8Particle(p).id())

    pythia.stat()
    pythia.settings.writeFile(
        format_output_file('pythia_gen_qorg.cmnd', -1, args))

    if args.ml:
        if ml_root_file:
            if ml_root_ntuple_parts:
                ml_root_ntuple_parts.Write()
                ml_root_ntuple_ev.Write()
            ml_root_file.Write()
            ml_root_file.Purge()
            ml_root_file.Close()
コード例 #5
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly',
                                     prog=os.path.basename(__file__))
    pyconf.add_standard_pythia_args(parser)
    # could use --py-seed
    parser.add_argument('--fj-R', help='jet finder R', default=0.8, type=float)
    parser.add_argument('--user-seed',
                        help='pythia seed',
                        default=-1,
                        type=int)
    parser.add_argument('--output',
                        default='{}.root'.format(os.path.basename(__file__)),
                        type=str)
    parser.add_argument('--min-jet-pt',
                        help='jet pt selection',
                        default=50.,
                        type=float)
    parser.add_argument('--max-jet-pt',
                        help='jet pt selection',
                        default=1000.,
                        type=float)
    parser.add_argument('--npart-min',
                        help='minimum npart in Argantyr',
                        default=2,
                        type=int)
    args = parser.parse_args()

    if args.user_seed < 0:
        args.user_seed = -1
        mycfg = []
    else:
        pinfo('user seed for pythia', args.user_seed)
        # mycfg = ['PhaseSpace:pThatMin = 100']
        mycfg = ['Random:setSeed=on', 'Random:seed={}'.format(args.user_seed)]

    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if args.nev < 100:
        args.nev = 100

    # print the banner first
    fj.ClusterSequence.print_banner()
    print()
    # set up our jet definition and a jet selector
    jet_R0 = args.fj_R
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
    print(jet_def)

    # hadron level - ALICE
    max_eta_hadron = 3.
    pwarning('max eta for particles after hadronization set to',
             max_eta_hadron)
    parts_selector_h = fj.SelectorAbsEtaMax(max_eta_hadron)
    jet_selector = fj.SelectorPtMin(args.min_jet_pt) & fj.SelectorPtMax(
        args.max_jet_pt) & fj.SelectorAbsEtaMax(max_eta_hadron - 1.05 * jet_R0)

    parts_selector_cent = fj.SelectorAbsEtaMax(5.) & fj.SelectorAbsEtaMin(3.)

    hepmc2output = '{}.hepmc2.dat'.format(args.output.replace('.root', ''))
    pyhepmc2writer = pythiaext.Pythia8HepMC2Wrapper(hepmc2output)

    outf = ROOT.TFile(args.output, 'recreate')
    outf.cd()
    t = ROOT.TTree('t', 't')
    tw = RTreeWriter(tree=t)
    tch = ROOT.TTree('tch', 'tch')
    twch = RTreeWriter(tree=tch)

    te = ROOT.TTree('te', 'te')
    twe = RTreeWriter(tree=te)

    jet_def_lund = fj.JetDefinition(fj.cambridge_algorithm, 1.0)
    dy_groomer = fjcontrib.DynamicalGroomer(jet_def_lund)
    print(dy_groomer.description())

    sds = []
    sd01 = fjcontrib.SoftDrop(0, 0.1, 1.0)
    sd02 = fjcontrib.SoftDrop(0, 0.2, 1.0)
    sds.append(sd01)
    sds.append(sd02)

    # event loop
    for iev in tqdm.tqdm(range(args.nev)):
        if not pythia.next():
            continue

        twe.clear()
        tw.clear()
        twch.clear()

        weight = pythia.info.weight()
        if args.py_PbPb:
            # from main113.cc
            # Also fill the number of (absorptively and diffractively)
            # wounded nucleaons.
            nw = pythia.info.hiinfo.nAbsTarg() + pythia.info.hiinfo.nDiffTarg(
            ) + pythia.info.hiinfo.nAbsProj() + pythia.info.hiinfo.nDiffProj()
            fill_ncoll_branches(pythia, twe)
        else:
            nw = 2
        twe.fill_branch('nw', nw)
        twe.fill_branch('w', weight)

        parts_pythia_h = pythiafjext.vectorize_select(pythia,
                                                      [pythiafjext.kFinal], 0,
                                                      False)
        parts_pythia_h_selected = parts_selector_h(parts_pythia_h)

        parts_pythia_ch = pythiafjext.vectorize_select(
            pythia, [pythiafjext.kFinal, pythiafjext.kCharged], 0, False)
        parts_pythia_ch_selected = parts_selector_h(parts_pythia_ch)

        nch_total = len(parts_pythia_ch)
        twe.fill_branch('nch', nch_total)

        ncharged_fwd = len(parts_selector_cent(parts_pythia_ch))
        twe.fill_branch('nchfwd', ncharged_fwd)

        twe.fill_branch('iev', iev)
        if args.py_PbPb and args.npart_min > nw:
            twe.fill_tree()
            continue

        if args.py_PbPb:
            pyhepmc2writer.fillEvent(pythia)

        # do the rest only if centrality right
        tw.fill_branch('iev', iev)
        tw.fill_branch('w', weight)
        twch.fill_branch('iev', iev)
        twch.fill_branch('w', weight)

        jets_h = jet_selector(fj.sorted_by_pt(jet_def(parts_pythia_h)))
        jets_h_ch = jet_selector(fj.sorted_by_pt(jet_def(parts_pythia_ch)))

        [
            fill_branches(tw, j, dy_groomer, alphas=[0.1, 1.0, 2.0], sds=sds)
            for j in jets_h
        ]
        if len(jets_h) > 0:
            tw.fill_tree()
            if args.py_PbPb is False:
                pyhepmc2writer.fillEvent(pythia)

        [
            fill_branches(twch, j, dy_groomer, alphas=[0.1, 1.0, 2.0], sds=sds)
            for j in jets_h_ch
        ]
        if len(jets_h_ch) > 0:
            twch.fill_tree()

        twe.fill_tree()

    pythia.stat()
    outf.Write()
    outf.Close()