Beispiel #1
0
  def analyzeEvents(self):
    
    # Fill det track histograms
    for fj_particles_det in self.df_fjparticles['fj_particles_det']:
      self.fillTrackHistograms(fj_particles_det)
    
    fj.ClusterSequence.print_banner()
    print()
    
    for jetR in self.jetR_list:

      # Set jet definition and a jet selector
      jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
      jet_selector_det = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(self.eta_max - jetR)
      jet_selector_truth_matched = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(self.eta_max - jetR)
      print('jet definition is:', jet_def)
      print('jet selector for det-level is:', jet_selector_det)
      print('jet selector for truth-level matches is:', jet_selector_truth_matched,'\n')

      # Iterate over the groupby and do jet-finding simultaneously for 
      # fj_1 and fj_2 per event, so that I can match jets -- and fill histograms
      for fj_particles_det, fj_particles_truth in \
          zip(self.df_fjparticles['fj_particles_det'],
              self.df_fjparticles['fj_particles_truth']):

        self.analyze_jets(fj_particles_det, fj_particles_truth, jet_def,
                          jet_selector_det, jet_selector_truth_matched)
Beispiel #2
0
    def analyzeEvents(self):

        # Fill det track histograms
        [
            self.fillTrackHistograms(fj_particles_det)
            for fj_particles_det in self.df_fjparticles['fj_particles_det']
        ]

        fj.ClusterSequence.print_banner()
        print()

        for jetR in self.jetR_list:
            for beta in self.beta_list:

                # Set jet definition and a jet selector
                jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
                jet_selector_det = fj.SelectorPtMin(
                    5.0) & fj.SelectorAbsRapMax(0.9 - jetR)
                jet_selector_truth_matched = fj.SelectorPtMin(5.0)
                print('jet definition is:', jet_def)
                print('jet selector for det-level is:', jet_selector_det, '\n')
                print('jet selector for truth-level matches is:',
                      jet_selector_truth_matched, '\n')

                # Then can use list comprehension to iterate over the groupby and do jet-finding
                # simultaneously for fj_1 and fj_2 per event, so that I can match jets -- and fill histograms
                result = [
                    self.analyzeJets(fj_particles_det, fj_particles_truth,
                                     jet_def, jet_selector_det,
                                     jet_selector_truth_matched, beta)
                    for fj_particles_det, fj_particles_truth in zip(
                        self.df_fjparticles['fj_particles_det'],
                        self.df_fjparticles['fj_particles_truth'])
                ]
Beispiel #3
0
 def __init__(self, **kwargs):
     self.configure_constants(
         particle_eta_max=0.9,
         particle_pt_max=
         100,  # reject jets with constituent with pT > max_particle_pt
         jet_R=0.4,
         jet_algorithm=fj.antikt_algorithm,
         jet_pt_min=-200,
         bge_rho_grid_size=-1,  # no background subtraction for -1
         sd_z_cuts=[0.1],
         sd_betas=[0, 2],
         show_progress=False,
         name="MPJetAnalysis",
         output_prefix='./')
     self.jet_eta_max = self.particle_eta_max - self.jet_R * 1.05
     self.jet_def = fj.JetDefinition(self.jet_algorithm, self.jet_R)
     self.jet_selector = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(
         self.jet_eta_max)
     self.particle_selector = fj.SelectorPtMin(0.15) & fj.SelectorAbsRapMax(
         self.particle_eta_max)
     self.jet_area_def = fj.AreaDefinition(
         fj.active_area_explicit_ghosts,
         fj.GhostedAreaSpec(self.particle_eta_max))
     self.bg_estimator = None
     self.constit_subtractor = None
     self.jet_output = None
     self.event_output = None
     self.fout = None
     super(MPJetAnalysis, self).__init__(**kwargs)
     self.filename_output = '{}{}.root'.format(self.output_prefix,
                                               self.name)
     if self.fout is None:
         self.fout = ROOT.TFile(self.filename_output, 'recreate')
     if self.jet_output is None:
         self.jet_output = treewriter.RTreeWriter(tree_name='tjet',
                                                  fout=self.fout)
     if self.event_output is None:
         self.event_output = treewriter.RTreeWriter(tree_name='tev',
                                                    fout=self.fout)
     fj.ClusterSequence.print_banner()
     print()
     print(self)
     print(' . particle selector', self.particle_selector)
     print(' . jet selector', self.jet_selector)
     print(' . jet definition:', self.jet_def)
     # define softdrops
     self.sds = []
     for beta in self.sd_betas:
         for zcut in self.sd_z_cuts:
             _sd = fjcontrib.SoftDrop(beta, zcut, self.jet_R)
             self.sds.append(_sd)
     for _sd in self.sds:
         print(' . sd:', _sd.description())
Beispiel #4
0
    def analyze_event(self, event):

        # Get list of hadrons from the event, and fill some histograms
        hadrons = event.hadrons(min_track_pt=self.min_track_pt)
        self.fill_hadron_histograms(hadrons)

        # Get list of final-state partons from the event, and fill some histograms
        partons = event.final_partons()
        self.fill_parton_histograms(partons)

        # Create list of fastjet::PseudoJets
        fj_hadrons = []
        fj_hadrons = self.fill_fastjet_constituents(hadrons)

        # Loop through specified jet R
        for jetR in self.jetR_list:

            # Set jet definition and a jet selector
            jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
            jet_selector = fj.SelectorPtMin(
                self.min_jet_pt) & fj.SelectorAbsRapMax(5.)
            if self.debug_level > 0:
                print('jet definition is:', jet_def)
                print('jet selector is:', jet_selector, '\n')

            # Do jet finding
            jets = []
            jets_selected = []
            cs = fj.ClusterSequence(fj_hadrons, jet_def)
            jets = fj.sorted_by_pt(cs.inclusive_jets())
            jets_selected = jet_selector(jets)

            # Fill some jet histograms
            self.fill_jet_histograms(jets_selected, jetR)
def main():

    # get the banner out of the way early on
    fj.ClusterSequence.print_banner()
    print()

    # set up our jet definition and a jet selector
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    selector = fj.SelectorPtMin(15.0) & fj.SelectorAbsRapMax(4.5)
    print("jet definition is:", jet_def)
    print("jet selector is:", selector, "\n")

    filename = '../data/Pythia-dijet-ptmin100-lhc-pileup-1ev.dat'
    f = open(filename, 'r')
    #filename = '/Users/gsalam/work/fastjet/data/Pythia-PtMin50-LHC-10kev.dat.gz'
    #f = gzip.GzipFile(filename,'rb')

    # get the event
    iev = 0
    while True:
        event = read_event(f)
        iev += 1
        if (len(event) == 0): break

        # cluster it
        jets = selector(jet_def(event))

        # print some info
        npileup = 0
        for p in event:
            if (p.python_info().subevent_index > 0): npileup += 1
        print("Event {0} has {1} particles (of which {2} from pileup)".format(
            iev, len(event), npileup))
        print_jets(jets)
Beispiel #6
0
    def __init__(self, **kwargs):
        self.configure_from_args(jet_R=0.4,
                                 jet_algorithm=fj.antikt_algorithm,
                                 particle_eta_max=0.9,
                                 jet_pt_min=0.0,
                                 particles=None,
                                 explicit_ghosts=False)
        super(JetAnalysis, self).__init__(**kwargs)

        self.particle_selector = fj.SelectorAbsEtaMax(self.particle_eta_max)

        self.jet_eta_max = self.particle_eta_max - self.jet_R * 1.05
        # self.jet_eta_max = self.particle_eta_max - 0.05
        self.jet_def = fj.JetDefinition(self.jet_algorithm, self.jet_R)
        self.jet_selector = fj.SelectorPtMin(
            self.jet_pt_min) & fj.SelectorAbsEtaMax(self.jet_eta_max)
        if self.explicit_ghosts:
            self.jet_area_def = fj.AreaDefinition(
                fj.active_area_explicit_ghosts,
                fj.GhostedAreaSpec(self.particle_eta_max))
        else:
            self.jet_area_def = fj.AreaDefinition(
                fj.active_area, fj.GhostedAreaSpec(self.particle_eta_max))

        if self.particles:
            self.analyze_event(self.particles)
Beispiel #7
0
    def analyzeEvents(self):

        fj.ClusterSequence.print_banner()
        print()

        for jetR in self.jetR_list:

            # Set jet definition and a jet selector
            jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
            jet_selector = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(0.9 -
                                                                        jetR)
            print('jet definition is:', jet_def)
            print('jet selector is:', jet_selector, '\n')

            # Define SoftDrop settings
            sd = fjcontrib.SoftDrop(self.sd_beta, self.sd_zcut, jetR)
            print('SoftDrop groomer is: {}'.format(sd.description()))

            for beta in self.beta_list:

                # Use list comprehension to do jet-finding and fill histograms
                result = [
                    self.analyzeJets(fj_particles, jet_def, jet_selector, beta,
                                     sd)
                    for fj_particles in self.df_fjparticles
                ]
    def analyze_event(self, event):

        # Create list of fastjet::PseudoJets (separately for jet shower particles and holes)
        fj_hadrons_positive = self.fill_fastjet_constituents(event,
                                                             select_status='+')
        fj_hadrons_negative = self.fill_fastjet_constituents(event,
                                                             select_status='-')

        # Fill hadron histograms for jet shower particles
        self.fill_hadron_histograms(fj_hadrons_positive, status='+')
        self.fill_hadron_histograms(fj_hadrons_negative, status='-')

        # Loop through specified jet R
        for jetR in self.jetR_list:

            # Set jet definition and a jet selector
            jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
            jet_selector = fj.SelectorPtMin(
                self.min_jet_pt) & fj.SelectorAbsRapMax(5.)
            if self.debug_level > 0:
                print('jet definition is:', jet_def)
                print('jet selector is:', jet_selector, '\n')

            # Do jet finding
            cs = fj.ClusterSequence(fj_hadrons_positive, jet_def)
            jets = fj.sorted_by_pt(cs.inclusive_jets())
            jets_selected = jet_selector(jets)

            # Fill some jet histograms
            self.fill_jet_histograms(jets_selected, fj_hadrons_negative, jetR)
Beispiel #9
0
def fj_example_02_area(event):
    # cluster the event
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    area_def = fj.AreaDefinition(fj.active_area, fj.GhostedAreaSpec(5.0))
    cs = fj.ClusterSequenceArea(event, jet_def, area_def)
    jets = fj.SelectorPtMin(5.0)(fj.sorted_by_pt(cs.inclusive_jets()))
    print("jet def:", jet_def)
    print("area def:", area_def)
    print("#-------------------- initial jets --------------------")
    print_jets(jets)
    #----------------------------------------------------------------------
    # estimate the background
    maxrap = 4.0
    grid_spacing = 0.55
    gmbge = fj.GridMedianBackgroundEstimator(maxrap, grid_spacing)
    gmbge.set_particles(event)
    print("#-------------------- background properties --------------------")
    print("rho   = ", gmbge.rho())
    print("sigma = ", gmbge.sigma())
    print()
    #----------------------------------------------------------------------
    # subtract the jets
    subtractor = fj.Subtractor(gmbge)
    subtracted_jets = subtractor(jets)
    print("#-------------------- subtracted jets --------------------")
    print_jets(subtracted_jets)
Beispiel #10
0
    def __init__(self,
                 jetRadius=0.4,
                 jetpTMin=1,
                 jetpTMax=None,
                 jetRapidityCut=None,
                 jetEtaCut=None,
                 **kwargs):
        super().__init__(**kwargs)
        self.clusterPower = -1
        self.jetRadius = jetRadius
        self.jetpTMin = jetpTMin
        self.jetpTMax = jetpTMax
        self.jetRapidityCut = jetRapidityCut
        self.jetEtaCut = jetEtaCut

        if self.clusterPower == -1:
            self.jetDefinition = fj.JetDefinition(fj.antikt_algorithm,
                                                  self.jetRadius)

        self.jetSelector = fj.SelectorPtMin(self.jetpTMin)
        if self.jetpTMax != None:
            self.jetSelector = self.jetSelector & fj.SelectorPtMax(
                self.jetpTMax)
        if self.jetRapidityCut != None:
            self.jetSelector = self.jetSelector & fj.SelectorRapRange(
                self.jetRapidityCut[0], self.jetRapidityCut[1])
        if self.jetEtaCut != None:
            self.jetSelector = self.jetSelector & fj.SelectorEtaRange(
                self.jetEtaCut[0], self.jetEtaCut[1])
Beispiel #11
0
def main():

    # set up our jet definition and a jet selector
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.6)
    selector = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(4.5)

    filename = '../data/single-event.dat'

    # get the event
    event = read_event(filename)
    # cluster it
    jets = selector(jet_def(event))

    # print out some information about the event and clustering
    print("Event has {0} particles".format(len(event)))
    print("jet definition is:", jet_def)
    print("jet selector is:", selector, "\n")

    # print the jets
    print_jets(jets)

    # get internal information about one of the jets
    if (len(jets) > 0):
        print("Number of constituents of jets[0] is {0}".format(
            len(jets[0].constituents())))
Beispiel #12
0
    def __init__(self, **kwargs):
        self.configure_from_args(jet_R=0.4,
                                 jet_algorithm=fj.antikt_algorithm,
                                 particle_eta_max=0.9,
                                 particles=None)
        super(JetAnalysis, self).__init__(**kwargs)

        self.bg_rho_range = fj.SelectorAbsEtaMax(self.particle_eta_max)
        self.bg_jet_def = fj.JetDefinition(fj.kt_algorithm, self.jet_R)
        self.bg_area_def = fj.AreaDefinition(
            fj.active_area_explicit_ghosts,
            fj.GhostedAreaSpec(self.particle_eta_max))
        self.bg_estimator = fj.JetMedianBackgroundEstimator(
            self.bg_rho_range, self.bg_jet_def, self.bg_area_def)
        self.rho = 0

        self.jet_eta_max = self.particle_eta_max - self.jet_R * 1.05
        self.jet_def = fj.JetDefinition(self.jet_algorithm, self.jet_R)
        self.jet_selector = fj.SelectorPtMin(0.0) & fj.SelectorAbsEtaMax(
            self.jet_eta_max)
        self.jet_area_def = fj.AreaDefinition(
            fj.active_area_explicit_ghosts,
            fj.GhostedAreaSpec(self.particle_eta_max))

        if self.particles:
            self.analyze_event(self.particles)
Beispiel #13
0
def main():
	parser = argparse.ArgumentParser(description='pythia8 fastjet on the fly', prog=os.path.basename(__file__))
	pyconf.add_standard_pythia_args(parser)
	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(5.0) & fj.SelectorAbsEtaMax(2)
	print(jet_def)

	all_jets = []

	# mycfg = ['PhaseSpace:pThatMin = 100']
	mycfg = []
	pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)
	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)
		jets = jet_selector(jet_def(parts))
		all_jets.extend(jets)

	pythia.stat()

	jet_def_lund = fj.JetDefinition(fj.cambridge_algorithm, 1.0)
	lund_gen = fjcontrib.LundGenerator(jet_def_lund)

	print('making lund diagram for all jets...')
	lunds = [lund_gen.result(j) for j in all_jets]

	print('listing lund plane points... Delta, kt - for {} selected jets'.format(len(all_jets)))
	for l in lunds:
		print ('- jet pT={0:5.2f} eta={1:5.2f}'.format(l[0].pair().perp(), l[0].pair().eta()))
		print ('  Deltas={}'.format([s.Delta() for s in l]))
		print ('  kts={}'.format([s.Delta() for s in l]))
		print ( )

	print('[i] reclustering and using soft drop...')
	jet_def_rc = fj.JetDefinition(fj.cambridge_algorithm, 1.0)
	print('Reclustering:', jet_def_rc)

	rc = fjcontrib.Recluster(jet_def_rc, True)
	sd = fjcontrib.SoftDrop(0, 0.1, 1.0)
	for i,j in enumerate(all_jets):
		j_rc = rc.result(j)
		print()
		print('- [{0:3d}] orig pT={1:10.3f} reclustered pT={2:10.3f}'.format(i, j.perp(), j_rc.perp()))
		j_sd = sd.result(j)
		print('  |-> after soft drop pT={0:10.3f} delta={1:10.3f}'.format(j_sd.perp(), j_sd.perp() - j.perp()))
		sd_info = fjcontrib.get_SD_jet_info(j_sd)
		print("  |-> SD jet params z={0:10.3f} dR={1:10.3f} mu={2:10.3f}".format(sd_info.z, sd_info.dR, sd_info.mu))
Beispiel #14
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)
    def analyze_event(self, event):
    
        # Initialize empty list for each output observable
        self.initialize_output_lists()

        # Create list of fastjet::PseudoJets (separately for jet shower particles and holes)
        fj_hadrons_positive = self.fill_fastjet_constituents(event, select_status='+')
        fj_hadrons_negative = self.fill_fastjet_constituents(event, select_status='-')
        
        # Create list of charged particles
        fj_hadrons_positive_charged = self.fill_fastjet_constituents(event, select_status='+',
                                                                     select_charged=True)
        fj_hadrons_negative_charged = self.fill_fastjet_constituents(event, select_status='-',
                                                                     select_charged=True)
        
        # Fill hadron histograms for jet shower particles
        self.fill_hadron_histograms(fj_hadrons_positive, status='+')
        self.fill_hadron_histograms(fj_hadrons_negative, status='-')        

        # Loop through specified jet R
        for jetR in self.jet_R:
        
            # Set jet definition and a jet selector
            jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
            jet_selector = fj.SelectorPtMin(self.min_jet_pt) & fj.SelectorAbsRapMax(self.max_jet_y)

            # Full jets
            # -----------------
            cs = fj.ClusterSequence(fj_hadrons_positive, jet_def)
            jets = fj.sorted_by_pt(cs.inclusive_jets())
            jets_selected = jet_selector(jets)

            # Fill inclusive full jet histograms
            [self.analyze_inclusive_jet(jet, fj_hadrons_positive, fj_hadrons_negative, jetR, full_jet=True) for jet in jets_selected]
            
            # Charged jets
            # -----------------
            cs_charged = fj.ClusterSequence(fj_hadrons_positive_charged, jet_def)
            jets_charged = fj.sorted_by_pt(cs_charged.inclusive_jets())
            jets_selected_charged = jet_selector(jets_charged)

            # Fill inclusive charged jet histograms
            [self.analyze_inclusive_jet(jet, fj_hadrons_positive_charged, fj_hadrons_negative_charged, jetR, full_jet=False) for jet in jets_selected_charged]
            
            # Fill semi-inclusive jet correlations
            if self.semi_inclusive_chjet_observables:
                if self.sqrts == 2760:
                    jetR_list = self.semi_inclusive_chjet_observables['IAA_alice']['jet_R']+self.semi_inclusive_chjet_observables['nsubjettiness_alice']['jet_R']
                elif self.sqrts == 200:
                    jetR_list = self.semi_inclusive_chjet_observables['IAA_star']['jet_R']
                if jetR in jetR_list:
                    self.fill_semi_inclusive_chjet_histograms(jets_selected_charged, fj_hadrons_positive_charged, fj_hadrons_negative_charged, jetR)
            
            # Fill dijet histograms
            if self.dijet_observables:
                self.fill_dijet_histograms(jets_selected, fj_hadrons_negative, jetR)
    def analyze_event(self, event):

        # Create list of fastjet::PseudoJets (separately for jet shower particles and holes)
        fj_hadrons_positive_all = self.fill_fastjet_constituents(event, select_status='+')
        fj_hadrons_negative_all = self.fill_fastjet_constituents(event, select_status='-')
        
        # Create list of charged particles
        fj_hadrons_positive_charged_all = self.fill_fastjet_constituents(event, select_status='+',
                                                                         select_charged=True)
        fj_hadrons_negative_charged_all = self.fill_fastjet_constituents(event, select_status='-',
                                                                         select_charged=True)
        
        # Fill hadron histograms for jet shower particles
        self.fill_hadron_histograms(fj_hadrons_positive_all, status='+')
        self.fill_hadron_histograms(fj_hadrons_negative_all, status='-')

        # Loop through several different constituent thresholds
        for constituent_threshold in self.constituent_threshold:
                    
            # Set constituent threshold
            fj_hadrons_positive = [hadron for hadron in fj_hadrons_positive_all if hadron.pt() > constituent_threshold]
            fj_hadrons_negative = [hadron for hadron in fj_hadrons_negative_all if hadron.pt() > constituent_threshold]
            fj_hadrons_positive_charged = [hadron for hadron in fj_hadrons_positive_charged_all if hadron.pt() > constituent_threshold]
            fj_hadrons_negative_charged = [hadron for hadron in fj_hadrons_negative_charged_all if hadron.pt() > constituent_threshold]
                
            # Loop through specified jet R
            for jetR in self.jet_R:
                
                # Set jet definition and a jet selector
                jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
                jet_selector = fj.SelectorPtMin(self.min_jet_pt) & fj.SelectorAbsRapMax(self.max_jet_y)
                if self.debug_level > 0:
                    print('jet definition is:', jet_def)
                    print('jet selector is:', jet_selector, '\n')

                # Full jets
                # -----------------
                cs = fj.ClusterSequence(fj_hadrons_positive, jet_def)
                jets = fj.sorted_by_pt(cs.inclusive_jets())
                jets_selected = jet_selector(jets)

                # Fill inclusive full jet histograms
                [self.analyze_inclusive_jet(jet, fj_hadrons_positive, fj_hadrons_negative, jetR, constituent_threshold, charged=False) for jet in jets_selected]
                
                # Charged jets
                # -----------------
                cs_charged = fj.ClusterSequence(fj_hadrons_positive_charged, jet_def)
                jets_charged = fj.sorted_by_pt(cs_charged.inclusive_jets())
                jets_selected_charged = jet_selector(jets_charged)

                # Fill inclusive charged jet histograms
                [self.analyze_inclusive_jet(jet, fj_hadrons_positive_charged, fj_hadrons_negative_charged, jetR, constituent_threshold, charged=True) for jet in jets_selected_charged]
                
                # Fill jet correlations
                self.fill_semi_inclusive_chjet_histograms(jets_selected_charged, fj_hadrons_positive_charged, fj_hadrons_negative_charged, jetR, constituent_threshold)
Beispiel #17
0
    def analyze_event(self, fj_particles):

        # Perform constituent subtraction for each R_max (do this once, for all jetR)
        if not self.is_pp:
            fj_particles_subtracted = [
                self.constituent_subtractor[i].process_event(fj_particles)
                for i, R_max in enumerate(self.max_distance)
            ]

        # Loop through jetR, and process event for each R
        for jetR in self.jetR_list:

            # Keep track of whether to fill R-independent histograms
            self.fill_R_indep_hists = (jetR == self.jetR_list[0])

            # Set jet definition and a jet selector
            jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
            jet_selector = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(0.9 -
                                                                        jetR)
            if self.debug_level > 2:
                print('jet definition is:', jet_def)
                print('jet selector is:', jet_selector, '\n')

            # Analyze
            if self.is_pp:

                # Do jet finding
                cs = fj.ClusterSequence(fj_particles, jet_def)
                jets = fj.sorted_by_pt(cs.inclusive_jets())
                jets_selected = jet_selector(jets)

                self.analyze_jets(jets_selected, jetR)

            else:

                for i, R_max in enumerate(self.max_distance):

                    if self.debug_level > 1:
                        print('R_max: {}'.format(R_max))

                    # Keep track of whether to fill R_max-independent histograms
                    self.fill_Rmax_indep_hists = (i == 0)

                    # Perform constituent subtraction
                    rho = self.constituent_subtractor[i].bge_rho.rho()
                    if self.fill_R_indep_hists and self.fill_Rmax_indep_hists:
                        getattr(self, 'hRho').Fill(rho)

                    # Do jet finding (re-do each time, to make sure matching info gets reset)
                    cs = fj.ClusterSequence(fj_particles_subtracted[i],
                                            jet_def)
                    jets = fj.sorted_by_pt(cs.inclusive_jets())
                    jets_selected = jet_selector(jets)

                    self.analyze_jets(jets_selected, jetR, R_max=R_max)
Beispiel #18
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()
Beispiel #19
0
 def fjPseudoJet(self):
     jet_def = fj.JetDefinition(fj.antikt_algorithm, 1.0)
     jet_selector = fj.SelectorPtMin(0.0)
     self.constituents_psj = []
     for c in self.constituents:
         self.constituents_psj.append(c)
     pyfj_from_psj(constituents)
     jets = jet_selector(jet_def(self.constituents_psj))
     if len(jets) < 1 or len(jets) > 1:
         print('[error] reclustering resulted in more that 1 jets')
     psj = jets[0]
     return psj
Beispiel #20
0
def main():

    # get the banner out of the way early on
    fj.ClusterSequence.print_banner()
    print()

    # set up our jet definition and a jet selector
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    selector = fj.SelectorPtMin(15.0) & fj.SelectorAbsRapMax(4.5)
    print("jet definition is:", jet_def)
    print("jet selector is:", selector, "\n")

    filename = './Pythia-dijet-ptmin100-lhc-pileup-1ev.dat'
    f = open(filename, 'r')
    #filename = '/Users/gsalam/work/fastjet/data/Pythia-PtMin50-LHC-10kev.dat.gz'
    #f = gzip.GzipFile(filename,'rb')

    # get the event
    iev = 0
    while True:
        event = read_event(f)
        iev += 1
        if (len(event) == 0): break

        # cluster it
        jets = selector(jet_def(event))

        # print some info
        npileup = 0
        for p in event:
            if (p.python_info().subevent_index > 0): npileup += 1
        print("Event {0} has {1} particles (of which {2} from pileup)".format(
            iev, len(event), npileup))
        print_jets(jets)

        jet_def_rc = fj.JetDefinition(fj.antikt_algorithm, 0.1)
        rc = rt.Recluster(jet_def_rc, True)
        sd = rt.SoftDrop(0, 0.1, 1.0)
        for i, j in enumerate(jets):
            j_rc = rc.result(j)
            print(
                '- [{0:3d}] orig pT={1:10.3f} reclustered pT={2:10.3f}'.format(
                    i, j.perp(), j_rc.perp()))
            j_sd = sd.result(j)
            # j_sd.structure_of<fj.contrib.SoftDrop>().delta_R()
            # print(j_sd.python_info())
            print('  |-> after soft drop pT={0:10.3f} delta={1:10.3f}'.format(
                j_sd.perp(),
                j_sd.perp() - j.perp()))
            sd_info = rt.get_SD_jet_info(j_sd)
            print("  |-> SD jet params z={0:10.3f} dR={1:10.3f} mu={2:10.3f}".
                  format(sd_info.z, sd_info.dR, sd_info.mu))
Beispiel #21
0
    def __init__(self, **kwargs):
        self.configure_from_args(tree_name='tree_Particle',
                                 tree_name_gen='tree_Particle_gen',
                                 args=None)
        super(Embedding, self).__init__(**kwargs)
        self.copy_attributes(self.args)
        self.jet_def = fj.JetDefinition(fj.antikt_algorithm, self.jetR)
        if self.benchmark:
            self.jet_selector = fj.SelectorPtMin(80.0) & fj.SelectorPtMax(
                100.0) & fj.SelectorAbsEtaMax(self.max_eta - 1.05 * self.jetR)
            # jet_selector_cs = fj.SelectorPtMin(50.0) & fj.SelectorAbsEtaMax(max_eta - 1.05 * self.jetR)
        else:
            self.jet_selector = fj.SelectorAbsEtaMax(self.max_eta -
                                                     1.05 * self.jetR)
        self.parts_selector = fj.SelectorAbsEtaMax(self.max_eta)

        self.output = EmbeddingOutput(args=self.args)
        # self.output.copy_attributes(self)

        self.sd = fjcontrib.SoftDrop(0, self.sd_zcut, self.jetR)

        self.ja_part = JetAnalysis(jet_R=self.jetR,
                                   jet_algorithm=fj.antikt_algorithm,
                                   jet_pt_min=5.,
                                   particle_eta_max=self.max_eta)
        self.ja_det = JetAnalysis(jet_R=self.jetR,
                                  jet_algorithm=fj.antikt_algorithm,
                                  jet_pt_min=self.jetptcut,
                                  particle_eta_max=self.max_eta)
        self.ja_hybrid = JetAnalysis(jet_R=self.jetR,
                                     jet_algorithm=fj.antikt_algorithm,
                                     jet_pt_min=5.,
                                     particle_eta_max=self.max_eta)

        self.dataPbPb = DataBackgroundIO(name='Data PbPb',
                                         file_list=self.datalistAA)
        self.det_sim = DataIO(name='Sim Pythia Detector level',
                              file_list=self.simulationpp,
                              random_file_order=False)
        self.part_sim = DataIO(name='Sim Pythia Particle level',
                               file_list=self.simulationpp,
                               random_file_order=False,
                               tree_name='tree_Particle_gen')

        self.cs = None
        if self.dRmax > 0:
            self.cs = CEventSubtractor(alpha=self.alpha,
                                       max_distance=self.dRmax,
                                       max_eta=self.max_eta,
                                       bge_rho_grid_size=0.25,
                                       max_pt_correct=100)
Beispiel #22
0
 def analyzeEvents(self):
   
   fj.ClusterSequence.print_banner()
   print()
   
   for jetR in self.jetR_list:
     
     # Set jet definition and a jet selector
     jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
     jet_selector = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(self.eta_max - jetR)
     print('jet definition is:', jet_def)
     print('jet selector is:', jet_selector,'\n')
     
     for alpha in self.alpha_list:
       for fj_particles in self.df_fjparticles:
         # do jet-finding and fill histograms
         self.analyzeJets(fj_particles, jet_def, jet_selector, alpha)
Beispiel #23
0
    def analyze_event(self, fj_particles_hard, fj_particles_combined_beforeCS):

        # Check that the entries exist appropriately
        if type(fj_particles_hard) != fj.vectorPJ or type(
                fj_particles_combined_beforeCS) != fj.vectorPJ:
            print('fj_particles type mismatch -- skipping event')
            return

        # Perform constituent subtraction for each R_max
        fj_particles_combined = []
        for i, R_max in enumerate(self.max_distance):
            if R_max == 0:
                fj_particles_combined.append(fj_particles_combined_beforeCS)
            else:
                fj_particles_combined.append(
                    self.constituent_subtractor[i].process_event(
                        fj_particles_combined_beforeCS))

        # Loop through jetR, and process event for each R
        for jetR in self.jetR_list:

            # Set jet definition and a jet selector
            jet_def = fj.JetDefinition(fj.antikt_algorithm, jetR)
            jet_selector = fj.SelectorPtMin(
                self.min_jet_pt) & fj.SelectorAbsRapMax(self.eta_max - jetR)

            for i, R_max in enumerate(self.max_distance):
                #print()
                #print(R_max)
                #print('Total number of combined particles: {}'.format(len([p.pt() for p in fj_particles_combined_beforeCS])))
                #print('After constituent subtraction {}: {}'.format(i, len([p.pt() for p in fj_particles_combined[i]])))

                # Do jet finding (re-do each time, to make sure matching info gets reset)
                cs_combined = fj.ClusterSequence(fj_particles_combined[i],
                                                 jet_def)
                jets_combined = fj.sorted_by_pt(cs_combined.inclusive_jets())
                jets_combined_selected = jet_selector(jets_combined)
                cs_hard = fj.ClusterSequence(fj_particles_hard, jet_def)
                jets_hard = fj.sorted_by_pt(cs_hard.inclusive_jets())
                jets_hard_selected = jet_selector(jets_hard)

                self.analyze_jets(jets_combined_selected,
                                  jets_hard_selected,
                                  jetR,
                                  R_max=R_max)
Beispiel #24
0
def main():
    input_file = "$HOME/data/jetscape/test_out.hepmc"
    if len(sys.argv) > 1:
        input_file = sys.argv[1]

    input_file = os.path.expandvars(input_file)

    print('[i] reading from:', input_file)
    # input = pyhepmc_ng.ReaderAsciiHepMC2(input_file)
    input = pyhepmc_ng.ReaderAscii(input_file)
    if input.failed():
        print("[error] unable to read from {}".format(input_file))
        return
    nevents = 1000

    # 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(0.0) & fj.SelectorPtMax(
        200.0) & fj.SelectorAbsEtaMax(3)

    all_jets = []
    event = pyhepmc_ng.GenEvent()
    pbar = tqdm.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 and not p.end_vertex:
                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))
        all_jets.append([[j.pt(), j.eta()] for j in jets])
        pbar.update()
        for j in jets:
            hjetpt.Fill(j.perp())
        if pbar.n >= nevents:
            break
    pbar.close()
Beispiel #25
0
def main_jets(args):
	outfname = '{}_output.root'.format(args.read).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)

	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(0.0) & fj.SelectorPtMax(200.0) & fj.SelectorAbsEtaMax(3)

	all_jets = []
	event = pyhepmc_ng.GenEvent()
	pbar = tqdm(range(args.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 and not p.end_vertex:
				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))
		all_jets.append([ [j.pt(), j.eta()] for j in jets])
		pbar.update()
		for j in jets:
			hjetpt.Fill(j.perp())
		if pbar.n >= args.nevents:
			break
	foutput.Write()
	foutput.Close()
	joblib.dump(all_jets, outfname.replace(".root", ".joblib"))
Beispiel #26
0
def main():

    # get the banner out of the way early on
    fj.ClusterSequence.print_banner()
    print()

    # set up our jet definition and a jet selector
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    selector = fj.SelectorPtMin(15.0) & fj.SelectorAbsRapMax(4.5)
    print("jet definition is:", jet_def)
    print("jet selector is:", selector, "\n")

    # create a user-defined recombiner which checks for photons and
    # sums user-indices (see below for details)
    recombiner = UserRecombiner()
    jet_def_user_recomb = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    jet_def_user_recomb.set_python_recombiner(recombiner)
    print("jet definition with user recombiner is:", jet_def_user_recomb)

    filename = '../data/Pythia-dijet-ptmin100-lhc-pileup-1ev.dat'
    f = open(filename, 'r')

    # get the event
    iev = 0
    while True:
        event = read_event(f)
        iev += 1
        if (len(event) == 0): break

        # cluster it with the default recombiner and print some info
        jets = selector(jet_def(event))
        print("Event {0} has {1} particles".format(iev, len(event)))
        print_jets(jets)
        print("")

        # now re-cluster with our user-defined recombiner
        jets = selector(jet_def_user_recomb(event))
        print("")
        print("CHECK: below, the user index (built through the recombiner)")
        print("       should correspond to the number of photons")
        print("")
        print_jets(jets)
Beispiel #27
0
def main():

    # get the banner out of the way early on
    fj.ClusterSequence.print_banner()
    print()

    # set up our jet definition and a jet selector
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    selector = fj.SelectorPtMin(15.0) & fj.SelectorAbsRapMax(4.5)
    print("jet definition is:", jet_def)
    print("jet selector is:", selector, "\n")

    filename = '../data/Pythia-dijet-ptmin100-lhc-pileup-1ev.dat'
    f = open(filename, 'r')
    #filename = '/Users/gsalam/work/fastjet/data/Pythia-PtMin50-LHC-10kev.dat.gz'
    #f = gzip.GzipFile(filename,'rb')

    # get the event
    iev = 0
    while True:
        event = read_event(f)
        iev += 1
        if (len(event) == 0): break

        # cluster it
        jets = selector(jet_def(event))

        # Create a FastJet selector based on a Python function (which
        # takes a PseudoJet and returns True if the PseudoJet passes the
        # selection condition). The resulting selector can be used in the
        # same way as any normal FastJet selector.
        #
        # See print_jets below for other examples of python-defined
        # Selectors (built either from a class or from a function)
        sel_pileup = fj.SelectorPython(is_pileup)
        n_pileup_particles = sel_pileup.count(event)

        # print some info
        print("Event {0} has {1} particles (of which {2} from pileup)".format(
            iev, len(event), n_pileup_particles))
        print_jets(jets)
Beispiel #28
0
 def get_event(self):
     if not self.pythia:
         return None
     parts_selector = fj.SelectorAbsEtaMax(self.eta_max)
     jet_selector = fj.SelectorPtMin(
         self.jet_pt_min) & fj.SelectorAbsEtaMax(self.eta_max -
                                                 1.05 * self.jet_R0)
     jet_def = fj.JetDefinition(fj.antikt_algorithm, self.jet_R0)
     while True:
         if not self.pythia.next():
             continue
         self.parts_pythia = pythiafjext.vectorize_select(
             self.pythia, [pythiafjext.kFinal])
         parts_gen = parts_selector(self.parts_pythia)
         signal_jets = fj.sorted_by_pt(
             jet_selector(jet_def(self.parts_pythia)))
         if len(signal_jets) < 1:
             continue
         else:
             break
     return self.parts_pythia
Beispiel #29
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()

    mycfg = []
    pythia = pyconf.create_and_init_pythia_from_args(args, mycfg)

    max_eta_hadron = 3
    jet_R0 = 0.4
    jet_selector = fj.SelectorPtMin(100.0) & fj.SelectorPtMax(
        125.0) & fj.SelectorAbsEtaMax(max_eta_hadron - 1.05 * jet_R0)
    parts_selector_h = fj.SelectorAbsEtaMax(max_eta_hadron)

    fj.ClusterSequence.print_banner()
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)

    pbar = tqdm.tqdm(range(args.nev))
    for i in pbar:
        if not pythia.next():
            pbar.update(-1)
            continue

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

        jets_h = fj.sorted_by_pt(jet_selector(
            jet_def(parts_pythia_h_selected)))

        if len(jets_h) < 1:
            continue

        # do your things with jets here...

    pythia.stat()
    pythia.settings.writeFile(args.py_cmnd_out)
Beispiel #30
0
def do_cs_jet_by_jet(full_event, ptmin=100.):
    # clustering with ghosts and get the jets
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    ghost_RapMax = 3.
    ghost_spec = fj.GhostedAreaSpec(ghost_RapMax, 1, ghost_area)
    area_def = fj.AreaDefinition(fj.active_area_explicit_ghosts, ghost_spec)
    clust_seq_full = fj.ClusterSequenceArea(full_event, jet_def, area_def)
    full_jets = clust_seq_full.inclusive_jets(ptmin)

    # background estimation
    jet_def_bge = fj.JetDefinition(fj.kt_algorithm, 0.4)
    area_def_bge = fj.AreaDefinition(fj.active_area_explicit_ghosts,
                                     ghost_spec)

    bge_range = fj.SelectorAbsRapMax(3.0)
    bge = fj.JetMedianBackgroundEstimator(bge_range, jet_def_bge, area_def_bge)
    bge.set_particles(full_event)

    # subtractor
    subtractor = cs.ConstituentSubtractor()
    subtractor.set_distance_type(0)
    subtractor.set_max_distance(max_distance)
    subtractor.set_alpha(alpha)
    subtractor.set_max_eta(3.0)
    subtractor.set_background_estimator(bge)
    subtractor.set_common_bge_for_rho_and_rhom()

    #sel_max_pt = fj.SelectorPtMax(10)
    #subtractor.set_particle_selector(sel_max_pt)

    # do subtraction
    corrected_jets = cs.PseudoJetVec()
    for jet in full_jets:
        subtracted_jet = subtractor.result(jet)
        corrected_jets.push_back(subtracted_jet)

    # pt cut
    selector = fj.SelectorPtMin(ptmin)
    return selector(corrected_jets), clust_seq_full