コード例 #1
0
 def __init__(self, **kwargs):
     self.fout = None
     super(HFAnalysisInvMass, self).__init__(**kwargs)
     self.tw = treewriter.RTreeWriter(tree_name='d0',
                                      file_name=self.name + '.root')
     self.twjc = treewriter.RTreeWriter(name='d0jc',
                                        file_name=self.name + '_c.root')
コード例 #2
0
 def __init__(self, **kwargs):
     self.fout = None
     super(HFAnalysisInvMass, self).__init__(**kwargs)
     self.fout = ROOT.TFile(self.name + '.root', 'recreate')
     self.fout.cd()
     self.tw = treewriter.RTreeWriter(tree_name='d0', fout=self.fout)
     self.tw_gen = treewriter.RTreeWriter(tree_name='d0_gen',
                                          fout=self.fout)
コード例 #3
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly',
                                     prog=os.path.basename(__file__))
    parser.add_argument('input', type=str, default='')
    parser.add_argument('--nev', type=int, default=-1)
    args = parser.parse_args()
    finame = args.input
    f = open(finame)
    csv_f = csv.reader(f)

    rfout = ROOT.TFile(finame.replace('.csv', '.root'), 'recreate')
    rfout.cd()
    tw = treewriter.RTreeWriter(tree_name='emissions', fout=rfout)

    pinfo('working on a file', finame)
    irow = 0
    scols = []
    nmax = args.nev
    for row in tqdm.tqdm(csv_f):
        if irow < 1:
            scols = copy.deepcopy(row)
            irow = irow + 1
            continue
        else:
            tw.fill_branch('e', make_dict(scols, row))
            tw.fill_tree()
            if nmax > 0 and irow >= nmax:
                break
            irow = irow + 1
    rfout.Write()
    pinfo('file written:', rfout.GetName())
    pinfo('done.')
コード例 #4
0
def test_cxx_gzip_python_stream(args):

    pinfo(args)

    tw = treewriter.RTreeWriter(name='aleph', file_name=args.output)

    nev = aleph_utils.get_n_events_gzip(args.input)
    with gzip.open(args.input) as f:
        _data = f.readlines()
        data = aleph.StringVector()
        __ = [
            data.push_back("{}".format(s.decode("utf-8").strip('\n')))
            for s in _data
        ]
        pinfo(type(data))
        pinfo('number of lines read', len(data))
        reader = aleph.ReaderLines(data)
        for i in tqdm(range(nev)):
            if reader.read_next_event():
                e = reader.get_event()
                __ = [stream_particle(e, p, tw) for p in e.get_particles()]
            else:
                pinfo('no more events to read')
                break
    tw.write_and_close()
コード例 #5
0
    def get_event_id(self, df):
        self.ev_id = df['ev_id'].values[0]
        self.run_number = df['run_number'].values[0]
        #pindent('processing', 'run_number=', self.run_number, 'ev_id=', self.ev_id, 'internal iev=', self.iev, 'cyclical iev=', self.iev_count)
        if self.iev_count >= self.max_events or self.iev == 0:
            #open a new file
            if self.fout:
                self.fout.Write()
                self.fout.Close()
                self.td = None
                self.fout = None
            outfname = self.file_output.replace('.root',
                                                '_{}.root'.format(self.nfile))
            pinfo('opening new file at', self.iev, 'file number', self.nfile,
                  'file name', outfname)
            self.fout = ROOT.TFile(outfname, 'recreate')
            self.nfile = self.nfile + 1
            self.iev_count = 0
            self.trees = {}

            # these are branches
            # for sdf in df:

            for sdf in self.df:
                foldername = os.path.dirname(sdf.split(';')[0])
                tname = os.path.basename(sdf.split(';')[0])
                self.fout.cd()
                if self.td is None:
                    self.td = ROOT.TDirectoryFile(foldername, foldername)
                self.td.cd()
                # tw = ROOT.TNtuple(tname, tname, ':'.join(self.df[sdf].columns))
                self.trees[tname] = treewriter.RTreeWriter(tree_name=tname,
                                                           fout=self.td)

        # fill for loc of iev and run number for each tree

        # for sdf in self.df:
        # 	pinfo(self.df[sdf])

        for sdf in self.df:
            tname = os.path.basename(sdf.split(';')[0])
            _df_sel = self.df[sdf].loc[
                (self.df[sdf]['run_number'] == self.run_number)
                & (self.df[sdf]['ev_id'] == self.ev_id)]
            #if len(_df_sel) < 1:
            #	pwarning('no entries for', sdf, len(_df_sel), self.run_number, self.ev_id)
            #else:
            #	pinfo('rows for', sdf, len(_df_sel))
            for index, row in _df_sel.iterrows():
                #print(row)
                for c in _df_sel.columns:
                    # pindent(self.trees[tname])
                    # pindent(tname, index, c, '=', row[c])
                    val = row[c]
                    self.trees[tname].fill_branch(c, row[c])
                # pindent(self.trees[tname].tree.GetName(), 'fill')
                self.trees[tname].fill_tree()

        self.iev = self.iev + 1
        self.iev_count = self.iev_count + 1
コード例 #6
0
 def __init__(self, **kwargs):
     self.fout = None
     super(HFAnalysisInvMass, self).__init__(**kwargs)
     self.fout = ROOT.TFile(self.name + '.root', 'recreate')
     self.fout.cd()
     # self.hinvmass = ROOT.TH1F('hinvmass', 'hinvmass', 400, 1.5, 2.5)
     # self.hinvmass.Sumw2()
     # self.hinvmasspt = ROOT.TH2F('hinvmasspt', 'hinvmasspt', 400, 1.5, 2.5, 50, 2, 12)
     # self.hinvmasspt.Sumw2()
     self.tw = treewriter.RTreeWriter(tree_name='event', fout=self.fout)
コード例 #7
0
	def __init__(self, **kwargs):
		self.configure_from_args(d0_tree_name='PWGHF_TreeCreator/tree_D0', 
								 track_tree_name='PWGHF_TreeCreator/tree_Particle',
								 event_tree_name='PWGHF_TreeCreator/tree_event_char',
								 enable_jet=True,
								 enable_d0=True,
								 offset_parts=0,
								 output_prefix='./HFAIO',
								 input_file = None)
		super(HFAIO, self).__init__(**kwargs)
		self.analyses = []
		self.df_grouped = None
		self.df_events = None

		# temp output
		out_file_1 = unique_fname(self.output_prefix + '_djet_tout.root')
		self.tw = treewriter.RTreeWriter(name = 'd0j', file_name = out_file_1)
		out_file_2 = unique_fname(self.output_prefix + '_djet_correl_tout.root')
		self.twjc = treewriter.RTreeWriter(name = 'd0jc', file_name = out_file_2)

		if self.input_file:
			self.process_file(self.input_file)
コード例 #8
0
def main(args):
    if args.output == 'default.root':
        args.output = args.input + '.root'

    pinfo('args', args)

    tw = treewriter.RTreeWriter(name='taleph', file_name=args.output)

    with gzip.open(args.input) as f:
        data = f.readlines()
        pinfo('number of lines read', len(data))
        for l in tqdm(data):
            lstr = l.decode("utf-8")
            if 'ALEPH_DATA RUN' in lstr:
                run_number, event_number, ecm = get_event_info(lstr)
                continue
            if 'Primary vertex info' in lstr:
                vflag, vx, vy, ex, ey = get_pvertex_info(lstr)
                continue
            if 'END_EVENT' in lstr:
                continue
            if 'px=' in lstr:
                px, py, pz, m, q, pwflag, d0, z0, ntpc, nitc, nvdet = get_part(
                    lstr)
                tw.fill_branches(run=run_number,
                                 event=event_number,
                                 ecm=ecm,
                                 vflag=vflag,
                                 vx=vx,
                                 vy=vy,
                                 ex=ex,
                                 ey=ey,
                                 px=px,
                                 py=py,
                                 pz=pz,
                                 m=m,
                                 q=q,
                                 pwflag=pwflag,
                                 d0=d0,
                                 z0=z0,
                                 ntpc=ntpc,
                                 nitc=nitc,
                                 nvdet=nvdet)
                tw.fill_tree()
    tw.write_and_close()
コード例 #9
0
	def __init__(self, **kwargs):
		self.fout = None
		super(HFAnalysisInvMass, self).__init__(**kwargs)
		self.fout = ROOT.TFile(self.name+'.root', 'recreate')
		self.fout.cd()
		# self.hinvmass = ROOT.TH1F('hinvmass', 'hinvmass', 400, 1.5, 2.5)
		# self.hinvmass.Sumw2()
		# self.hinvmasspt = ROOT.TH2F('hinvmasspt', 'hinvmasspt', 400, 1.5, 2.5, 50, 2, 12)
		# self.hinvmasspt.Sumw2()
		self.tw = treewriter.RTreeWriter(tree_name='d0', fout=self.fout)
		# jet stuff

		max_eta = 0.9
		self.parts_selector = fj.SelectorPtMin(0.15) & fj.SelectorPtMax(100.0) & fj.SelectorAbsEtaMax(max_eta)

		jet_R0 = 0.4
		self.jet_selector = fj.SelectorPtMin(5.0) & fj.SelectorPtMax(100.0) & fj.SelectorAbsEtaMax(max_eta - 1.05 * jet_R0)
		self.jarho = JetAnalysisWithRho(jet_R=jet_R0, jet_algorithm=fj.antikt_algorithm, particle_eta_max=max_eta)
コード例 #10
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly',
                                     prog=os.path.basename(__file__))
    pyconf.add_standard_pythia_args(parser)
    parser.add_argument('--nw',
                        help="no warn",
                        default=True,
                        action='store_true')
    parser.add_argument('--ignore-mycfg',
                        help="ignore some settings hardcoded here",
                        default=False,
                        action='store_true')
    parser.add_argument('--enable-background',
                        help="enable background calc",
                        default=False,
                        action='store_true')
    parser.add_argument('--output',
                        help="output file name",
                        default='leadsj_vs_zloss.root',
                        type=str)
    parser.add_argument('--jetptmin',
                        help="jet pt minimum",
                        default=-1,
                        type=float)
    parser.add_argument('--jetptmax',
                        help="jet pt maximum",
                        default=1e6,
                        type=float)
    parser.add_argument('--eta', help="jet eta max", default=2.4, type=float)
    parser.add_argument(
        '--kt',
        help="use kT algorithm instead of anti-kT for the subjets",
        default=False,
        action='store_true')

    args = parser.parse_args()

    # print the banner first
    fj.ClusterSequence.print_banner()
    print()
    # set up our jet definition and a jet selector
    jet_R0 = 0.4
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
    jet_selector = fj.SelectorPtMin(args.py_pthatmin) & fj.SelectorPtMax(
        1000.0) & fj.SelectorAbsEtaMax(args.eta - jet_R0)
    mycfg = []
    if args.jetptmin > 0:
        mycfg = ['PhaseSpace:pThatMin = {}'.format(args.jetptmin)]
        jet_selector = fj.SelectorPtMin(args.jetptmin) & fj.SelectorPtMax(
            args.jetptmax) & fj.SelectorAbsEtaMax(args.eta - jet_R0)
    print(jet_def)

    if args.ignore_mycfg:
        mycfg = []
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if not pythia:
        perror("pythia initialization failed.")
        return

    nbins = 20
    # sjrs = [0.001 + x * 0.04 for x in range(0, nbins)]
    sjrs = logbins(0.001, jet_R0, nbins)
    print(sjrs)
    print('log(1/r) :', [ROOT.TMath.Log(1 / r) for r in sjrs])
    sjdefs = dict()
    for sjr in sjrs:
        if args.kt:
            _jet_def = fj.JetDefinition(fj.kt_algorithm, sjr)
        else:
            _jet_def = fj.JetDefinition(fj.antikt_algorithm, sjr)
        sjdefs[sjr] = _jet_def

    # tw = treewriter.RTreeWriter(name = 'lsjvsx', file_name = 'leadsj_vs_x.root')
    tw = treewriter.RTreeWriter(name='lsjvszloss', file_name=args.output)
    tw.fout.cd()
    h_zloss_r_q = dict()
    h_zloss_r_g = dict()
    for sjr in sjrs:
        sname = 'h_zloss_glue_{}'.format(sjr)
        _h_zloss_r_g = ROOT.TH1F(sname, sname, len(sjrs), 0., 1.)
        h_zloss_r_g[sjr] = _h_zloss_r_g
        sname = 'h_zloss_quark_{}'.format(sjr)
        _h_zloss_r_q = ROOT.TH1F(sname, sname, len(sjrs), 0., 1.)
        h_zloss_r_q[sjr] = _h_zloss_r_q

    lbins = logbins(ROOT.TMath.Log(1. / jet_R0), ROOT.TMath.Log(1. / sjrs[0]),
                    nbins)
    print('lbins:', lbins)

    sname = 'prof_zloss_vs_r_any'
    prof_a = ROOT.TProfile(sname, sname, nbins, 0, jet_R0)
    prof_a_log = ROOT.TProfile(sname + '_log', sname + '_log', nbins, lbins)

    sname = 'prof_zloss_vs_r_glue'
    prof_g = ROOT.TProfile(sname, sname, nbins, 0, jet_R0)
    prof_g_log = ROOT.TProfile(sname + '_log', sname + '_log', nbins, lbins)

    sname = 'prof_zloss_vs_r_quark'
    prof_q = ROOT.TProfile(sname, sname, nbins, 0, jet_R0)
    prof_q_log = ROOT.TProfile(sname + '_log', sname + '_log', nbins, lbins)
    # prof_q_log = ROOT.TProfile(sname+'_log', sname+'_log', nbins, ROOT.TMath.Log(1./jet_R0), ROOT.TMath.Log(1./sjrs[0]))

    sname = 'h2_zloss_vs_r_glue'
    h2_zloss_r_g = ROOT.TH2F(sname, sname, nbins, 0., jet_R0, len(sjrs), 0.,
                             1.)
    sname = 'h2_zloss_vs_r_quark'
    h2_zloss_r_q = ROOT.TH2F(sname, sname, nbins, 0., jet_R0, len(sjrs), 0.,
                             1.)

    # loop

    if args.nev < 100:
        args.nev = 100
    for i in tqdm.tqdm(range(args.nev)):
        if not pythia.next():
            continue
        # parts = pythiafjext.vectorize(pythia, True, -1, 1, False)
        partons = pythiafjext.vectorize_select(pythia, [pythiafjext.kParton],
                                               0, True)
        parts = pythiafjext.vectorize_select(
            pythia, [pythiafjext.kFinal, pythiafjext.kCharged], 0, False)
        # parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal], 0, False)
        jets = jet_selector(jet_def(parts))

        # for j in tqdm.tqdm(jets):
        for j in jets:
            j_type = match_dR(j, partons, jet_R0 / 2.)
            if j_type[0] is None:
                if args.nw:
                    continue
                pwarning('Jet with no parton label')
                continue

            tw.fill_branch("j", j)
            for sjr in sjrs:
                rc_jets = fj.sorted_by_pt(sjdefs[sjr](j.constituents()))
                tw.fill_branch("sjr{}".format(sjr), rc_jets[0])
                zloss = 1. - rc_jets[0].perp() / j.perp()
                tw.fill_branch("sjr{}_zloss".format(sjr), zloss)
                tw.fill_branch("ppid", j_type[0])
                tw.fill_branch("pquark", j_type[1])
                tw.fill_branch("pglue", j_type[2])

                prof_a.Fill(sjr, zloss)
                prof_a_log.Fill(ROOT.TMath.Log(1. / sjr), zloss)

                if j_type[1]:
                    h_zloss_r_q[sjr].Fill(zloss)
                    h2_zloss_r_q.Fill(sjr, zloss)
                    prof_q.Fill(sjr, zloss)
                    prof_q_log.Fill(ROOT.TMath.Log(1. / sjr), zloss)
                if j_type[2]:
                    h_zloss_r_g[sjr].Fill(zloss)
                    h2_zloss_r_g.Fill(sjr, zloss)
                    prof_g.Fill(sjr, zloss)
                    prof_g_log.Fill(ROOT.TMath.Log(1. / sjr), zloss)

            tw.fill_tree()

    pythia.stat()
    tw.write_and_close()
コード例 #11
0
def main():
	parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly', prog=os.path.basename(__file__))
	pyconf.add_standard_pythia_args(parser)
	parser.add_argument('--nw', help="no warn", default=False, action='store_true')
	parser.add_argument('--ignore-mycfg', help="ignore some settings hardcoded here", default=False, action='store_true')
	parser.add_argument('--enable-background', help="enable background calc", default=False, action='store_true')
	parser.add_argument('--output', help="output file name", default='leadsj_vs_x_output.root', type=str)

	# for background
	parser.add_argument('--cent-bin', help="centraility bin 0 is the  0-5 percent most central bin", type=int, default=0)
	parser.add_argument('--seed', help="pr gen seed", type=int, default=1111)
	parser.add_argument('--harmonics', help="set harmonics flag (0 : v1 - v5) , (1 : v2 - v5) , (2: v3 - v5) , (3: v1 - v4) , (4: v1 - v3) , (5: uniform dN/dphi no harmonics) , (6 : v1 - v2 , v4 - v5) , (7 : v1 - v3 , v5) , (8 : v1 , v3 - v5) , (9 : v1 only) , (10 : v2 only) , (11 : v3 only) , (12 : v4 only) , (13 : v5 only)", 
						type=int, default=5)
	parser.add_argument('--eta', help="set eta range must be uniform (e.g. abs(eta) < 0.9, which is ALICE TPC fiducial acceptance)",
						type=float, default=0.9)
	parser.add_argument('--qa', help="PrintOutQAHistos", default=False, action='store_true')

	parser.add_argument('--dRmax', default=0.25, type=float)
	parser.add_argument('--alpha', default=0, type=float)


	args = parser.parse_args()

	# print the banner first
	fj.ClusterSequence.print_banner()
	print()
	# set up our jet definition and a jet selector
	jet_R0 = 0.4
	jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
	jet_selector = fj.SelectorPtMin(args.py_pthatmin) & fj.SelectorPtMax(1000.0) & fj.SelectorAbsEtaMax(args.eta - jet_R0)
	# jet_selector = fj.SelectorPtMin(40.0) & fj.SelectorPtMax(200.0) &fj.SelectorAbsEtaMax(1)
	print(jet_def)

	all_jets = []

	# mycfg = ['PhaseSpace:pThatMin = 80']
	# mycfg = ['PhaseSpace:pThatMin = 40']	
	mycfg = ['']	
	if args.ignore_mycfg:
		mycfg = []
	pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
	if not pythia:
		perror("pythia initialization failed.")
		return

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

	# sd = fjcontrib.SoftDrop(0, 0.1, 1.0)
	sd01 = fjcontrib.SoftDrop(0, 0.1, 1.0)
	print (sd01)
	sd02 = fjcontrib.SoftDrop(0, 0.2, 1.0)
	print (sd02)

	# jet_def_rc01 = fj.JetDefinition(fj.cambridge_algorithm, 0.1)
	# jet_def_rc02 = fj.JetDefinition(fj.cambridge_algorithm, 0.2)
	# print (jet_def_rc01)
	# print (jet_def_rc02)
	# rc = fjcontrib.Recluster(jet_def_rc, True)

	jet_def_rc01 = fj.JetDefinition(fj.antikt_algorithm, 0.1)
	jet_def_rc02 = fj.JetDefinition(fj.antikt_algorithm, 0.2)
	print (jet_def_rc01)
	print (jet_def_rc02)
	#rc = fjcontrib.Recluster(jet_def_rc, True)

	# tw = treewriter.RTreeWriter(name = 'lsjvsx', file_name = 'leadsj_vs_x.root')
	tw = treewriter.RTreeWriter(name = 'lsjvsx', file_name = args.output)
	tgbkg = None
	be = None
	if args.enable_background:
		# ROOT.gSystem.Load("libpyjetty_TennGen.dylib")
		# tgbkg = ROOT.TennGen() # //constructor
		# tgbkg.SetCentralityBin(args.cent_bin) # //centraility bin 0 is the  0-5 % most central bin
		# tgbkg.SetRandomSeed(args.seed) # //setting the seed
		# tgbkg.SetHarmonics(args.harmonics) # // set harmonics flag (0 : v1 - v5) , (1 : v2 - v5) , (2: v3 - v5) , (3: v1 - v4) , (4: v1 - v3) , (5: uniform dN/dphi no harmonics) , (6 : v1 - v2 , v4 - v5) , (7 : v1 - v3 , v5) , (8 : v1 , v3 - v5) , (9 : v1 only) , (10 : v2 only) , (11 : v3 only) , (12 : v4 only) , (13 : v5 only)
		# tgbkg.SetEtaRange(args.eta) # //set eta range must be uniform (e.g. |eta| < 0.9, which is ALICE TPC fiducial acceptance)
		# tgbkg.PrintOutQAHistos(args.qa) #
		# tgbkg.InitializeBackground() #

		from pyjetty.mputils import BoltzmannEvent
		be = BoltzmannEvent(mean_pt=0.7, multiplicity=2000 * args.eta * 2, max_eta=max_eta, max_pt=100)
		print(be)

		from pyjetty.mputils import CEventSubtractor, CSubtractorJetByJet
		cs = CEventSubtractor(alpha=args.alpha, max_distance=args.dRmax, max_eta=args.eta, bge_rho_grid_size=0.25, max_pt_correct=100)
		print(cs)


	if args.nev < 100:
		args.nev = 100
	for i in tqdm.tqdm(range(args.nev)):
		if not pythia.next():
			continue
		# parts = pythiafjext.vectorize(pythia, True, -1, 1, False)
		partons = pythiafjext.vectorize_select(pythia, [pythiafjext.kParton], 0, True)
		parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal, pythiafjext.kCharged], 0, False)
		# parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal], 0, False)
		jets = jet_selector(jet_def(parts))

		# for j in tqdm.tqdm(jets):
		for j in jets:
			j_type = match_dR(j, partons, jet_R0 / 2.)
			if j_type[0] is None:
				if args.nw:
					continue
				pwarning('Jet with no parton label')
				continue

			j_sd02 = sd02.result(j)
			sd02_info = fjcontrib.get_SD_jet_info(j_sd02)
			j_sd01 = sd01.result(j)
			sd01_info = fjcontrib.get_SD_jet_info(j_sd01)

			rc_sjets01 = fj.sorted_by_pt(jet_def_rc01(j.constituents()))
			rc_sjets02 = fj.sorted_by_pt(jet_def_rc02(j.constituents()))
			tw.fill_branches(	j 			= j, 
								lund 		= [ls for ls in lund_gen.result(j)], 
								dyg1 		= dy_groomer.result(j, 1), 

								sd01 		= j_sd01, 
								sd01_z 		= sd01_info.z, 
								sd01_mu 	= sd01_info.mu, 
								sd01_Delta 	= sd01_info.dR, 

								sd02 		= j_sd02, 
								sd02_z 		= sd02_info.z, 
								sd02_mu 	= sd02_info.mu, 
								sd02_Delta 	= sd02_info.dR, 

								# breaking compatibility
								# sd 			= j_sd, 
								# sd_z 		= sd_info.z, 
								# sd_mu 		= sd_info.mu, 
								# sd_Delta 	= sd_info.dR, 

								lsjet01 	= rc_sjets01[0],
								nsjet01    	= len(rc_sjets01),
								sjet01     	= rc_sjets01,
								lsjet02 	= rc_sjets02[0],
								nsjet02    	= len(rc_sjets02),
								sjet02     	= rc_sjets02,

								ppid       	= j_type[0],
								pquark     	= j_type[1],
								pglue      	= j_type[2], # this is redundancy

								pycode 		= pythia.info.code(),
								pysigmagen  = pythia.info.sigmaGen(),
								pysigmaerr  = pythia.info.sigmaErr(),
								pyid1       = pythia.info.id1pdf(),
								pyid2       = pythia.info.id1pdf(),
								pyx1 	    = pythia.info.x1pdf(),
								pyx2       	= pythia.info.x2pdf(),
								pypdf1      = pythia.info.pdf1(),
								pyQfac 		= pythia.info.QFac(),
								pyalphaS 	= pythia.info.alphaS(),

								pypthat 	= pythia.info.pTHat(),
								pymhat 		= pythia.info.mHat()

							 )
			if be:
				bg_parts = be.generate(offset=10000)
				full_event = bg_parts
				tmp = [full_event.push_back(psj) for psj in j.constituents()]
				if cs:
					cs_parts = cs.process_event(full_event)
					rho = cs.bge_rho.rho()
					bg_jets = fj.sorted_by_pt(jet_def(cs_parts))
					for bj in bg_jets:
						if fjtools.matched_pt(bj, j) > 0.5:
							pass

			tw.fill_tree()

	pythia.stat()

	tw.write_and_close()
コード例 #12
0
ファイル: leadsj_vs_x.py プロジェクト: reynier0611/pyjetty
def main():
    parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly',
                                     prog=os.path.basename(__file__))
    pyconf.add_standard_pythia_args(parser)
    parser.add_argument('--ignore-mycfg',
                        help="ignore some settings hardcoded here",
                        default=False,
                        action='store_true')

    args = parser.parse_args()

    # print the banner first
    fj.ClusterSequence.print_banner()
    print()
    # set up our jet definition and a jet selector
    jet_R0 = 0.4
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
    jet_selector = fj.SelectorPtMin(80.0) & fj.SelectorPtMax(
        100.0) & fj.SelectorAbsEtaMax(1)
    # jet_selector = fj.SelectorPtMin(40.0) & fj.SelectorPtMax(200.0) &fj.SelectorAbsEtaMax(1)
    print(jet_def)

    all_jets = []

    mycfg = ['PhaseSpace:pThatMin = 80']
    # mycfg = ['PhaseSpace:pThatMin = 40']
    if args.ignore_mycfg:
        mycfg = []
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if not pythia:
        perror("pythia initialization failed.")
        return

    jet_def_lund = fj.JetDefinition(fj.cambridge_algorithm, 1.0)
    lund_gen = fjcontrib.LundGenerator(jet_def_lund)
    print(lund_gen.description())
    dy_groomer = fjcontrib.DynamicalGroomer(jet_def_lund)
    print(dy_groomer.description())
    # sd = fjcontrib.SoftDrop(0, 0.1, 1.0)
    sd = fjcontrib.SoftDrop(0, 0.2, 1.0)
    print(sd)

    # jet_def_rc01 = fj.JetDefinition(fj.cambridge_algorithm, 0.1)
    # jet_def_rc02 = fj.JetDefinition(fj.cambridge_algorithm, 0.2)
    # print (jet_def_rc01)
    # print (jet_def_rc02)
    # rc = fjcontrib.Recluster(jet_def_rc, True)

    jet_def_rc01 = fj.JetDefinition(fj.antikt_algorithm, 0.1)
    jet_def_rc02 = fj.JetDefinition(fj.antikt_algorithm, 0.2)
    print(jet_def_rc01)
    print(jet_def_rc02)
    #rc = fjcontrib.Recluster(jet_def_rc, True)

    # tw = treewriter.RTreeWriter(name = 'lsjvsx', file_name = 'leadsj_vs_x.root')
    tw = treewriter.RTreeWriter(name='lsjvsx',
                                file_name='leadsj_vs_x_bias80.root')

    if args.nev < 100:
        args.nev = 100
    for i in tqdm.tqdm(range(args.nev)):
        if not pythia.next():
            continue
        # parts = pythiafjext.vectorize(pythia, True, -1, 1, False)
        partons = pythiafjext.vectorize_select(pythia, [pythiafjext.kParton],
                                               0, True)
        parts = pythiafjext.vectorize_select(
            pythia, [pythiafjext.kFinal, pythiafjext.kCharged], 0, False)
        # parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal], 0, False)
        jets = jet_selector(jet_def(parts))

        # for j in tqdm.tqdm(jets):
        for j in jets:
            j_type = match_dR(j, partons, jet_R0 / 2.)
            j_sd = sd.result(j)
            sd_info = fjcontrib.get_SD_jet_info(j_sd)
            rc_sjets01 = fj.sorted_by_pt(jet_def_rc01(j.constituents()))
            rc_sjets02 = fj.sorted_by_pt(jet_def_rc02(j.constituents()))
            tw.fill_branches(
                j=j,
                lund=[ls for ls in lund_gen.result(j)],
                dyg1=dy_groomer.result(j, 1),
                sd=j_sd,
                sd_z=sd_info.z,
                sd_mu=sd_info.mu,
                sd_Delta=sd_info.dR,
                lsjet01=rc_sjets01[0],
                nsjet01=len(rc_sjets01),
                sjet01=rc_sjets01,
                lsjet02=rc_sjets02[0],
                nsjet02=len(rc_sjets02),
                sjet02=rc_sjets02,
                ppid=j_type[0],
                pquark=j_type[1],
                pglue=j_type[2]  # this is redundancy
            )
            tw.fill_tree()

    pythia.stat()

    tw.write_and_close()
コード例 #13
0
def main():
    parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly',
                                     prog=os.path.basename(__file__))
    pyconf.add_standard_pythia_args(parser)
    parser.add_argument('--ignore-mycfg',
                        help="ignore some settings hardcoded here",
                        default=False,
                        action='store_true')
    parser.add_argument('--output',
                        help="output file name",
                        default="test_hjet_parton.root",
                        type=str)
    parser.add_argument('--no-tt',
                        help="do not require TT to accept the event",
                        default=False,
                        action='store_true')
    parser.add_argument('--charged',
                        help="analyze only the charged particles of the FS",
                        default=False,
                        action='store_true')
    parser.add_argument('--max-jet-pt',
                        help="maximum jet pT to consider",
                        type=float,
                        default=100.)
    args = parser.parse_args()

    # print the banner first
    fj.ClusterSequence.print_banner()
    print()
    # set up our jet definition and a jet selector
    hadron_eta_max = 2.0
    jet_R0 = 0.4
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
    jet_selector = fj.SelectorPtMin(10.0) & fj.SelectorPtMax(
        args.max_jet_pt) & fj.SelectorAbsEtaMax(hadron_eta_max - jet_R0)
    # jet_selector = fj.SelectorPtMin(40.0) & fj.SelectorPtMax(200.0) &fj.SelectorAbsEtaMax(hadron_eta_max - jet_R0)
    hTT6_selector = fj.SelectorPtMin(6) & fj.SelectorPtMax(
        7) & fj.SelectorAbsEtaMax(hadron_eta_max)
    hTT12_selector = fj.SelectorPtMin(12) & fj.SelectorPtMax(
        50) & fj.SelectorAbsEtaMax(hadron_eta_max)
    hTT20_selector = fj.SelectorPtMin(20) & fj.SelectorPtMax(
        50) & fj.SelectorAbsEtaMax(hadron_eta_max)

    pythia_fs_part_selection = [pythiafjext.kFinal]
    if args.charged is True:
        pwarning('running with charged particles in the final state')
        pythia_fs_part_selection.append(pythiafjext.kCharged)
    print(jet_def)

    all_jets = []

    # mycfg = ['PhaseSpace:pThatMin = 80']
    # mycfg = ['PhaseSpace:pThatMin = 6']
    # mycfg = ['PhaseSpace:pThatMin = 12']
    # mycfg = ['PhaseSpace:pThatMin = 40']
    mycfg = []
    if args.ignore_mycfg:
        mycfg = []
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
    if not pythia:
        perror("pythia initialization failed.")
        return

    jet_def_lund = fj.JetDefinition(fj.cambridge_algorithm, 1.0)
    lund_gen = fjcontrib.LundGenerator(jet_def_lund)
    print(lund_gen.description())
    dy_groomer = fjcontrib.DynamicalGroomer(jet_def_lund)
    print(dy_groomer.description())
    # sd = fjcontrib.SoftDrop(0, 0.1, 1.0)
    sd = fjcontrib.SoftDrop(0, 0.2, 1.0)
    print(sd)

    # jet_def_rc01 = fj.JetDefinition(fj.cambridge_algorithm, 0.1)
    # jet_def_rc02 = fj.JetDefinition(fj.cambridge_algorithm, 0.2)
    # print (jet_def_rc01)
    # print (jet_def_rc02)
    # rc = fjcontrib.Recluster(jet_def_rc, True)

    jet_def_rc01 = fj.JetDefinition(fj.antikt_algorithm, 0.1)
    jet_def_rc02 = fj.JetDefinition(fj.antikt_algorithm, 0.2)
    print(jet_def_rc01)
    print(jet_def_rc02)
    #rc = fjcontrib.Recluster(jet_def_rc, True)

    # tw = treewriter.RTreeWriter(name = 'lsjvsx', file_name = 'leadsj_vs_x.root')
    tw = treewriter.RTreeWriter(name='lsjvsx', file_name=args.output)

    zero_psj = fj.PseudoJet(0, 0, 10, 10)

    if args.nev < 100:
        args.nev = 100
    t = tqdm.tqdm(total=args.nev)
    while t.n < args.nev:
        if not pythia.next():
            continue

        # information about the leading process
        # print(pythia.info.code(), pythia.info.nameProc(pythia.info.code()))
        # continue
        # parts = pythiafjext.vectorize(pythia, True, -1, 1, False)
        partons = pythiafjext.vectorize_select(pythia, [pythiafjext.kParton],
                                               0, True)
        # parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal, pythiafjext.kCharged], 0, False)
        # parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal], 0, False)
        parts = pythiafjext.vectorize_select(pythia, pythia_fs_part_selection,
                                             0, False)

        hTT6 = zero_psj
        hTT6s = fj.sorted_by_pt(hTT6_selector(parts))
        if len(hTT6s) > 0:
            hTT6 = hTT6s[0]

        hTT12 = zero_psj
        hTT12s = fj.sorted_by_pt(hTT12_selector(parts))
        if len(hTT12s) > 0:
            hTT12 = hTT12s[0]

        hTT20 = zero_psj
        hTT20s = fj.sorted_by_pt(hTT20_selector(parts))
        if len(hTT20s) > 0:
            hTT20 = hTT20s[0]

        if args.no_tt is False:
            if hTT12.perp() < 1 and hTT6.perp() < 1 and hTT20.perp() < 1:
                continue

        jets = jet_selector(jet_def(parts))

        # for j in tqdm.tqdm(jets):
        for j in jets:
            t.update(1)
            j_type = match_dR(j, partons, jet_R0 / 2.)
            if j_type[0] is None:
                continue
            j_sd = sd.result(j)
            sd_info = fjcontrib.get_SD_jet_info(j_sd)
            rc_sjets01 = fj.sorted_by_pt(jet_def_rc01(j.constituents()))
            rc_sjets02 = fj.sorted_by_pt(jet_def_rc02(j.constituents()))
            tw.fill_branches(
                j=j,
                mult=len(parts),
                lund=[ls for ls in lund_gen.result(j)],
                dyg1=dy_groomer.result(j, 1),
                sd=j_sd,
                sd_z=sd_info.z,
                sd_mu=sd_info.mu,
                sd_Delta=sd_info.dR,
                lsjet01=rc_sjets01[0],
                nsjet01=len(rc_sjets01),
                sjet01=rc_sjets01,
                lsjet02=rc_sjets02[0],
                nsjet02=len(rc_sjets02),
                sjet02=rc_sjets02,
                hTT6=hTT6,
                hTT12=hTT12,
                hTT20=hTT20,
                dphi6=j.delta_phi_to(hTT6),
                dphi12=j.delta_phi_to(hTT12),
                dphi20=j.delta_phi_to(hTT20),
                ppid=j_type[0],
                pquark=j_type[1],
                pglue=j_type[2],  # this is redundancy
                pycode=pythia.info.code(),
                pysigmagen=pythia.info.sigmaGen(),
                pysigmaerr=pythia.info.sigmaErr(),
                pyid1=pythia.info.id1pdf(),
                pyid2=pythia.info.id1pdf(),
                pyx1=pythia.info.x1pdf(),
                pyx2=pythia.info.x2pdf(),
                pypdf1=pythia.info.pdf1(),
                pyQfac=pythia.info.QFac(),
                pyalphaS=pythia.info.alphaS(),
                pypthat=pythia.info.pTHat(),
                pymhat=pythia.info.mHat())
            tw.fill_tree()

    t.close()
    pythia.stat()

    tw.write_and_close()
コード例 #14
0
def main():
	parser = argparse.ArgumentParser(description='test the TennGen', prog=os.path.basename(__file__))
	pyconf.add_standard_pythia_args(parser)
	parser.add_argument('--ignore-mycfg', help="ignore some settings hardcoded here", default=False, action='store_true')
	parser.add_argument('--cent-bin', help="centraility bin 0 is the  0-5 % most central bin", type=int, default=0)
	parser.add_argument('--seed', help="pr gen seed", type=int, default=1111)
	parser.add_argument('--harmonics', help="set harmonics flag (0 : v1 - v5) , (1 : v2 - v5) , (2: v3 - v5) , (3: v1 - v4) , (4: v1 - v3) , (5: uniform dN/dphi no harmonics) , (6 : v1 - v2 , v4 - v5) , (7 : v1 - v3 , v5) , (8 : v1 , v3 - v5) , (9 : v1 only) , (10 : v2 only) , (11 : v3 only) , (12 : v4 only) , (13 : v5 only)", 
						type=int, default=5)
	parser.add_argument('--eta', help="set eta range must be uniform (e.g. |eta| < 0.9, which is ALICE TPC fiducial acceptance)",
						type=float, default=0.9)
	parser.add_argument('--qa', help="PrintOutQAHistos", default=False, action='store_true')

	args = parser.parse_args()

	args.py_pthatmin = 100
	mycfg = ['PhaseSpace:pThatMin = {}'.format(args.py_pthatmin)]
	if args.ignore_mycfg:
		mycfg = []
	pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
	if not pythia:
		perror("pythia initialization failed.")
		return

	tgbkg = ROOT.TennGen() # //constructor
	tgbkg.SetCentralityBin(args.cent_bin) # //centraility bin 0 is the  0-5 % most central bin
	tgbkg.SetRandomSeed(args.seed) # //setting the seed
	tgbkg.SetHarmonics(args.harmonics) # // set harmonics flag (0 : v1 - v5) , (1 : v2 - v5) , (2: v3 - v5) , (3: v1 - v4) , (4: v1 - v3) , (5: uniform dN/dphi no harmonics) , (6 : v1 - v2 , v4 - v5) , (7 : v1 - v3 , v5) , (8 : v1 , v3 - v5) , (9 : v1 only) , (10 : v2 only) , (11 : v3 only) , (12 : v4 only) , (13 : v5 only)
	tgbkg.SetEtaRange(args.eta) # //set eta range must be uniform (e.g. |eta| < 0.9, which is ALICE TPC fiducial acceptance)
	tgbkg.PrintOutQAHistos(args.qa) #
	tgbkg.InitializeBackground() #

	jet_R0 = 0.4
	jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
	jet_selector_pythia = fj.SelectorPtMin(args.py_pthatmin) & fj.SelectorPtMax(1000.0) &fj.SelectorAbsEtaMax(args.eta - jet_R0)
	jet_selector_hybrid = fj.SelectorPtMin(10) & fj.SelectorPtMax(1000.0) &fj.SelectorAbsEtaMax(args.eta - jet_R0)
	# jet_selector = fj.SelectorPtMin(40.0) & fj.SelectorPtMax(200.0) &fj.SelectorAbsEtaMax(1)
	parts_selector = fj.SelectorAbsEtaMax(args.eta)
	print(jet_def)

	tw = treewriter.RTreeWriter(name = 'tparts', file_name = 'test_TennGen.root')

	if args.nev < 100:
		args.nev = 100
	pbar = tqdm.tqdm(total = args.nev)
	while pbar.n < args.nev:
		if not pythia.next():
			continue

		# get pythia particles
		# parts = pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal, pythiafjext.kCharged], 0, False)
		_py_fj_parts = parts_selector(pythiafjext.vectorize_select(pythia, [pythiafjext.kFinal], 0, False))
		# get jets w/o area determination
		# pythia_jets = jet_selector_pythia(jet_def(_py_fj_parts))

		# with area determination
		jet_area_def = fj.AreaDefinition(fj.active_area, fj.GhostedAreaSpec(args.eta))
		cs = fj.ClusterSequenceArea(_py_fj_parts, jet_def, jet_area_def)
		pythia_jets = jet_selector_pythia(cs.inclusive_jets())

		if len(pythia_jets) < 1:
			continue
		pbar.update(1)
		tw.fill_branches(pyj = pythia_jets)

		# now generate bg
		bg_tclones = tgbkg.GetBackground()
		# tgbkg.GetRandomSeed()
		nParticles = bg_tclones.GetEntries();
		# pinfo('event', pbar.n, 'number of parts', nParticles)
		# _parts = { 'pt' : [], 'eta' : [], 'phi' : [], 'kf' : []}
		_parts = [[], [], [], []]
		_ = [[_parts[0].append(p[0].Pt()), _parts[1].append(p[0].Eta()), _parts[2].append(p[0].Phi()), _parts[3].append(p[1])] for p in [[tlv_from_tmcparticle(_p), _p.GetKF()] for _p in bg_tclones if _p.GetEnergy()>0]]
		_bg_fj_parts = fjext.vectorize_pt_eta_phi(_parts[0], _parts[1], _parts[2], 1000) #bg particles with index > 1000

		# add background and pythia 
		_fj_parts = []
		_ = [_fj_parts.append(_p) for _p in _py_fj_parts]
		_ = [_fj_parts.append(_p) for _p in _bg_fj_parts]

		# stream all particles
		_ = [tw.fill_branches(part_pt = _pfj.perp(), part_eta = _pfj.eta(), part_phi = _pfj.phi(), part_idx=_pfj.user_index()) for _pfj in _fj_parts]

		# find jets in the hybrid event
		# w/o area
		# jets = jet_selector_hybrid(jet_def(_fj_parts))
		# w/area
		cs_hybrid = fj.ClusterSequenceArea(_fj_parts, jet_def, jet_area_def)
		jets = jet_selector_hybrid(cs_hybrid.inclusive_jets())
		# stream jets from the hybrid event
		tw.fill_branches(j = jets)

		# estimate the background
		bg_rho_range = fj.SelectorAbsEtaMax(args.eta * 1.1)
		bg_jet_def = fj.JetDefinition(fj.kt_algorithm, jet_R0)
		bg_area_def = fj.AreaDefinition(fj.active_area_explicit_ghosts, fj.GhostedAreaSpec(args.eta))
		# bg_area_def = fj.AreaDefinition(fj.active_area, fj.GhostedAreaSpec(args.eta)) #active area defunct for bg estim
		bg_estimator = fj.JetMedianBackgroundEstimator(bg_rho_range, bg_jet_def, bg_area_def)
		bg_estimator.set_particles(_fj_parts)
		if len(_fj_parts) < 0:
			perror('no particles in the hybrid event?')
			continue
		rho = bg_estimator.rho()
		sigma = bg_estimator.sigma()
		corr_jet_pt = [j.pt() - j.area() * rho for j in jets]
		# matches = [j.perp(), matched_jet(j, pythia_jets) for j in jets]
		delta_pt = [delta_pt_matched(j, pythia_jets, rho) for j in jets]
		tw.fill_branches(j_corr_pt = corr_jet_pt, dpt = delta_pt)
		tw.fill_branches(rho = rho, rho_sigma = sigma)

		tw.fill_tree()
		bg_tclones.Clear()

	pbar.close()

	tgbkg.CloserFunction()
	tw.write_and_close()