Esempio n. 1
0
def main(args):
    nevents = args.nevents
    sconfig_pythia = get_pythia_config(args)
    if args.generate:
        pythia = create_and_init_pythia(sconfig_pythia)
        if not pythia:
            return
        all_jets = []
        for iEvent in tqdm(range(nevents), 'event'):
            if not pythia.next(): continue
        print("[i] done generating")

    if args.write:
        pythia = create_and_init_pythia(sconfig_pythia)
        if not pythia:
            return
        pyhepmcwriter = mp.Pythia8HepMCWrapper(args.write)
        all_jets = []
        for iEvent in tqdm(range(nevents), 'event'):
            if not pythia.next(): continue
            pyhepmcwriter.fillEvent(pythia)
        print("[i] done writing to {}".format(args.write))

    if args.read:
        import pyhepmc_ng
        input = pyhepmc_ng.ReaderAsciiHepMC2(args.read)
        if input.failed():
            print("[error] unable to read from {}".format(args.read))
            return

        # print the banner first
        fj.ClusterSequence.print_banner()
        print()
        jet_R0 = 0.4
        jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
        jet_selector = fj.SelectorPtMin(100.0) & fj.SelectorPtMax(
            200.0) & fj.SelectorAbsEtaMax(1)

        event = pyhepmc_ng.GenEvent()
        pbar = tqdm(range(nevents))
        while not input.failed():
            e = input.read_event(event)
            if input.failed():
                break
            fjparts = []
            for i, p in enumerate(event.particles):
                if p.status == 1:
                    psj = fj.PseudoJet(p.momentum.px, p.momentum.py,
                                       p.momentum.pz, p.momentum.e)
                    psj.set_user_index(i)
                    fjparts.append(psj)
            jets = jet_selector(jet_def(fjparts))
            pbar.update()
Esempio n. 2
0
def main():
    nevents = 1000
    sconfig_pythia = [
        "Beams:eCM = 8000.", "HardQCD:all = on", "PhaseSpace:pTHatMin = 100.",
        "PDF:pset = LHAPDF6:EPPS16nlo_CT14nlo_Pb208/0"
    ]
    #  "LHAPDF6:member = 901300"]
    # "PDF:pSet = EPPS16nlo_CT14nlo_Pb208"]
    if 'gen' in sys.argv:
        pythia = create_and_init_pythia(sconfig_pythia)
        if not pythia:
            return
        all_jets = []
        for iEvent in tqdm(range(nevents), 'event'):
            if not pythia.next(): continue
        print("[i] done generating")

    if 'write' in sys.argv:
        pythia = create_and_init_pythia(sconfig_pythia)
        if not pythia:
            return
        pyhepmcwriter = mp.Pythia8HepMCWrapper("test_pythia8_hepmc.dat")
        all_jets = []
        for iEvent in tqdm(range(nevents), 'event'):
            if not pythia.next(): continue
            pyhepmcwriter.fillEvent(pythia)
        print("[i] done writing to test_pythia8_hepmc.dat")

    if 'read' in sys.argv:
        import pyhepmc_ng
        input = pyhepmc_ng.ReaderAsciiHepMC2("test_pythia8_hepmc.dat")
        if input.failed():
            print("[error] unable to read from test_pythia8_hepmc.dat")
            return
        event = pyhepmc_ng.GenEvent()
        pbar = tqdm(range(nevents))
        while not input.failed():
            p = input.read_event(event)
            if input.failed():
                # print ("[i] reading done.")
                break
            pbar.update()
Esempio n. 3
0
def main(args):
	nevents = args.nevents
	procsel = []
	if args.photon:
		procsel.append("PromptPhoton:all = on")
	if args.charm:
		procsel.append("HardQCD:hardccbar = on")
	if len(procsel) < 1:
		procsel.append("HardQCD:all = on")
	sconfig_pythia = get_pythia_config(args, procsel)

	pythia = None
	if args.write or args.generate:
		pythia = create_and_init_pythia(sconfig_pythia)
	if not pythia:
		print("[error] bad or no pythia create and init. stop here.")
		return

	if args.write:
		pyhepmcwriter = mp.Pythia8HepMCWrapper(args.write)
		for iEvent in tqdm(range(nevents), 'event'):
			if not pythia.next(): continue
			pyhepmcwriter.fillEvent(pythia)
		print("[i] done writing to {}".format(args.write))

	if args.generate:
		outfname = '{}_output.root'.format(args.generate).replace('.dat', '')
		print("output file: {}".format(outfname))
		foutput = r.TFile(outfname, "recreate")
		foutput.cd()
		lbins = logbins(1., 100, 10)
		hjetpt = r.TH1F('hjetpt', 'hjetpt', 10, lbins)
		hevent = r.TH1F('hevent', 'hevent', 10, 0, 10);
		hxsection = r.TNtuple('xsection', 'xsection', 'xsec:xsecErr')
		tnpart = r.TNtuple('tnpart', 'tnpart', 'pt:eta:phi:id5:id6')
		for iEvent in tqdm(range(nevents), 'event'):
			if not pythia.next(): continue
			hevent.Fill(0, pythia.info.weight())
			hxsection.Fill(pythia.info.sigmaGen(), pythia.info.sigmaErr())
			if not args.charm and not args.photon:
				for ip in range(pythia.event.size()):
					if abs(pythia.event[ip].id()) == 111:
						tnpart.Fill(pythia.event[ip].pT(), pythia.event[ip].eta(), pythia.event[ip].phi(),
						            pythia.event[5].id(), pythia.event[6].id())
						if pythia.event[ip].eta() > 3 and pythia.event[ip].eta() < 6:
							hjetpt.Fill(pythia.event[ip].pT())
			if args.charm:
				for ip in range(pythia.event.size()):
					if abs(pythia.event[ip].id()) == 421:
						tnpart.Fill(pythia.event[ip].pT(), pythia.event[ip].eta(), pythia.event[ip].phi(),
						            pythia.event[5].id(), pythia.event[6].id())
						if pythia.event[ip].eta() > 3 and pythia.event[ip].eta() < 6:
							hjetpt.Fill(pythia.event[ip].pT())
			if args.photon:
				for idx in range(5,7):
					if pythia.event[idx].id() == 22:
						finalds = get_final_daughters(pythia.event, idx)
						for fidx in finalds:
							if pythia.event[fidx].id() == 22:
								tnpart.Fill(pythia.event[fidx].pT(), pythia.event[fidx].eta(), pythia.event[fidx].phi(),
								            pythia.event[5].id(), pythia.event[6].id())
								if pythia.event[fidx].eta() > 3 and pythia.event[fidx].eta() < 6:
									hjetpt.Fill(pythia.event[fidx].pT())
		w = pythia.info.weightSum()
		xs = pythia.info.sigmaGen()
		tnpart.SetWeight(xs/w)
		hjetpt.Scale(xs/w)
		foutput.Write()
		foutput.Close()
	if pythia:
		pythia.stat()