Пример #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)
Пример #2
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())
Пример #3
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))

        # 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)
Пример #4
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'])
                ]
Пример #5
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)
Пример #6
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
                ]
Пример #7
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())))
    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)
Пример #9
0
def analyze_file_list(file_inputs=[],
                      output_prefix='rg',
                      tree_name='tree_Particle'):

    anl = []

    bg_rho_range = fj.SelectorAbsRapMax(0.9)
    bg_jet_def = fj.JetDefinition(fj.kt_algorithm, 0.4)
    bg_area_def = fj.AreaDefinition(fj.active_area_explicit_ghosts,
                                    fj.GhostedAreaSpec(0.9))
    bg_estimator = fj.JetMedianBackgroundEstimator(bg_rho_range, bg_jet_def,
                                                   bg_area_def)
    print('[i]', bg_estimator.description())
    an_std = MPJetAnalysis(output_prefix=output_prefix,
                           name='std',
                           bg_estimator=bg_estimator)
    anl.append(an_std)

    g_bg_estimator = fj.GridMedianBackgroundEstimator(0.9, 0.4)
    print('[i]', g_bg_estimator.description())
    an_gbg = MPJetAnalysis(output_prefix=output_prefix,
                           name='bgb',
                           bg_estimator=g_bg_estimator)
    anl.append(an_gbg)

    cs004 = csubtractor.CEventSubtractor(alpha=0,
                                         max_distance=0.4,
                                         max_eta=0.9,
                                         bge_rho_grid_size=0.25,
                                         max_pt_correct=100)
    an_cs_004 = MPJetAnalysis(output_prefix=output_prefix,
                              name='cs004',
                              bg_estimator=cs004.bge_rho,
                              constit_subtractor=cs004)
    anl.append(an_cs_004)

    cs404 = csubtractor.CEventSubtractor(alpha=4,
                                         max_distance=0.4,
                                         max_eta=0.9,
                                         bge_rho_grid_size=0.25,
                                         max_pt_correct=100)
    an_cs_404 = MPJetAnalysis(output_prefix=output_prefix,
                              name='cs404',
                              bg_estimator=cs404.bge_rho,
                              constit_subtractor=cs404)
    anl.append(an_cs_404)

    ad = MPAnalysisDriver(file_list=file_inputs,
                          analyses_list=anl,
                          tree_name=tree_name)
    ad.run()

    print()
    print('    ---')
    print()
    print(ad)
    print('[i] done.')
    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)
Пример #12
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)
Пример #13
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))
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
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
Пример #19
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(5.0) & fj.SelectorAbsRapMax(4.5)
    print("jet definition is:", jet_def)
    print("jet selector is:", selector, "\n")

    #filename = '../data/single-event.dat'
    filename = '../data/Pythia-PtMin1000-LHC-10ev.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
        jets = selector(jet_def(event))
        print("Event {0} has {1} particles".format(iev, len(event)))

        # cluster it
        for ijet in range(len(jets)):
            print("jet {0} pt and rap: {1} {2}".format(ijet, jets[ijet].pt(),
                                                       jets[ijet].rap()))

        # make sure jet-related information is correctly held
        if (len(jets) > 0):
            print("Number of constituents of jets[0] is {0}".format(
                len(jets[0].constituents())))
Пример #20
0
    def analyze_event(self, fj_particles, gridsize=None, diagnostic=False):

        self.event_bck_df = None
        self.event_bck_df = self.bck_df[self.bck_df['ev_id'] == self.ev_idx[
            self.event_number]]
        #print(self.event_number)

        self.event_number += 1
        if self.event_number > self.nEvents:
            return

        if len(fj_particles) > 1:
            if np.abs(fj_particles[0].eta() - fj_particles[1].eta()) < 1e-10:
                if fj_particles[0].pt() < 1e-5:
                    print(
                        'WARNING: Duplicate DUMMY particles may be present in event',
                        self.event_number)
                else:
                    print(
                        'WARNING: Duplicate JET particles may be present in event',
                        self.event_number)
                    #[print(p.eta(),p.pt()) for p in fj_particles]

        # If constituent subtraction is enabled, perform subtraction on the event
        if self.constituent_subtractor:

            # Convert df of pt/eta/phi of thermal particles to list of fastjet particles, for convenience
            thermal_particles = []
            if len(self.event_bck_df) != 0:
                thermal_particles = self.get_fjparticles(self.event_bck_df)

            # Drop specified fraction of thermal particles -- loop manually since the wrapped functions are a bit funky
            thermal_particles_selected = []
            for i, p in enumerate(thermal_particles):
                if np.random.uniform() >= self.thermal_rejection_fraction:
                    thermal_particles_selected.append(p)
            #print(f'n_thermals before: {len(thermal_particles)}')
            #print(f'n_thermals after: {len(thermal_particles_selected)}')

            # Determine rho from thermal particles
            self.constituent_subtractor.bge_rho.set_particles(
                thermal_particles_selected)

            # Perform subtraction over full event (jet+recoil)
            fj_particles = self.constituent_subtractor.subtractor.subtract_event(
                fj_particles)

            #rho = self.constituent_subtractor.bge_rho.rho()
            #print(f'rho: {rho}')
            #print()

        # 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(5.0) & fj.SelectorAbsRapMax(0.9 -
                                                                        jetR)

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

            # If no jets were selected, move on to next event
            if len(jets_selected) == 0:
                continue

            #----------------------------------------------
            fj_subtracted_constituents = None
            subtracted_jets = []

            if not self.thermal_subtraction_method:
                subtracted_jets = jets_selected
            elif '4momsub' in self.thermal_subtraction_method.lower():
                '''
                ------------------------------------------------
                Thermal subtraction using 4MomSub method
                ------------------------------------------------
                1. Cluster the initial jet collection from the final state particles (including dummies).
                2. Compile a list of the thermal momenta (particles in the HepMC event record with status code 3).
                For each jet, get the list of thermal momenta that have DeltaR < 1x10-5 with one of the jet constituents, i.e a dummy particle.
                4. Sum up the four-momenta of the matched thermal momenta. This constitutes the background.
                5. For each jet subtract the background four-momentum from the jet's four momentum, this provides the corrected jet collection.
                6. Calculate jet observables from corrected jet four-momenta.
                '''
                for jet in jets_selected:
                    fj_subtracted_constituents = None
                    fj_subtracted_constituents = self.subtract_thermal_4momsub(
                        jet, jetR)
                    jet_def_largerR = fj.JetDefinition(fj.antikt_algorithm,
                                                       2. * jetR)
                    cs_largerR = fj.ClusterSequence(fj_subtracted_constituents,
                                                    jet_def_largerR)
                    subtracted_jets = fj.sorted_by_pt(
                        cs_largerR.inclusive_jets())
                    if len(subtracted_jets) > 1:
                        print(
                            'WARNING: Got more than one subtracted jet out of one input jet'
                        )

            elif 'gridsub' in self.thermal_subtraction_method.lower():
                '''
                ------------------------------------------------
                Thermal subtraction using GridSub1 method
                ------------------------------------------------
                1. Cluster the initial jet collection from the final state particles.
                2. Compile a list of the thermal momenta (particles in the HepMC event record with status code 3).
                3. Define the grid resolution and place grid over jets.
                4. Inside each cell sum the jet constituents' four-momenta and subtract the thermal
                four-momenta that fall into the cell (note: no matching is required, thermal four momenta
                with distance DeltaR < R from the jet axis are considered), providing a single four momentum for each cell.
                5. In case a cell contains more thermal momentum than jet constituents, the cells is set
                to have zero four-momentum. This is deemed to be the case when the (scalar) pT of
                the thermal component is larger than the pT of the particle component.
                6. Re-cluster the jets with the cell four-momenta as input to get the final, subtracted jets.
                7. Calculate jet observables from re-clustered jets.
                '''
                fj_subtracted_constituents = self.subtract_thermal_gridsub1(
                    jets_selected, jetR, gridsize, diagnostic)
                if not fj_subtracted_constituents:
                    continue
                cs = fj.ClusterSequence(fj_subtracted_constituents, jet_def)
                subtracted_jets = fj.sorted_by_pt(cs.inclusive_jets())

            #----------------------------------------------

            result = [
                self.analyze_accepted_jet(jet, jetR, gridsize, diagnostic)
                for jet in subtracted_jets
            ]
Пример #21
0
    def analyze_event(self,
                      fj_particles_det,
                      fj_particles_truth,
                      fj_particles_det_holes=None,
                      fj_particles_truth_holes=None):

        self.event_number += 1
        if self.event_number > self.event_number_max:
            return
        if self.debug_level > 1:
            print('-------------------------------------------------')
            print('event {}'.format(self.event_number))

        # Check that the entries exist appropriately
        # (need to check how this can happen -- but it is only a tiny fraction of events)
        if type(fj_particles_det) != fj.vectorPJ or type(
                fj_particles_truth) != fj.vectorPJ:
            print('fj_particles type mismatch -- skipping event')
            return
        if self.jetscape:
            if type(fj_particles_det_holes) != fj.vectorPJ or type(
                    fj_particles_truth_holes) != fj.vectorPJ:
                print('fj_particles_holes type mismatch -- skipping event')
                return

        if len(fj_particles_truth) > 1:
            if np.abs(fj_particles_truth[0].pt() -
                      fj_particles_truth[1].pt()) < 1e-10:
                print('WARNING: Duplicate particles may be present')
                print([p.user_index() for p in fj_particles_truth])
                print([p.pt() for p in fj_particles_truth])

        # If Pb-Pb, construct embedded event (do this once, for all jetR)
        if not self.is_pp:

            # If thermal model, generate a thermal event and add it to the det-level particle list
            if self.thermal_model:
                fj_particles_combined_beforeCS = self.thermal_generator.load_event(
                )

                # Form the combined det-level event
                # The pp-det tracks are each stored with a unique user_index >= 0
                #   (same index in fj_particles_combined and fj_particles_det -- which will be used in prong-matching)
                # The thermal tracks are each stored with a unique user_index < 0
                [
                    fj_particles_combined_beforeCS.push_back(p)
                    for p in fj_particles_det
                ]

            # Main case: Get Pb-Pb event and embed it into the det-level particle list
            else:
                fj_particles_combined_beforeCS = self.process_io_emb.load_event(
                )

                # Form the combined det-level event
                # The pp-det tracks are each stored with a unique user_index >= 0
                #   (same index in fj_particles_combined and fj_particles_det -- which will be used in prong-matching)
                # The Pb-Pb tracks are each stored with a unique user_index < 0
                [
                    fj_particles_combined_beforeCS.push_back(p)
                    for p in fj_particles_det
                ]

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

            if self.debug_level > 3:
                print([p.user_index() for p in fj_particles_truth])
                print([p.pt() for p in fj_particles_truth])
                print([p.user_index() for p in fj_particles_det])
                print([p.pt() for p in fj_particles_det])
                print([p.user_index() for p in fj_particles_combined_beforeCS])
                print([p.pt() for p in fj_particles_combined_beforeCS])

        if self.dry_run:
            return

        # 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_det = fj.SelectorPtMin(5.0) & fj.SelectorAbsRapMax(
                0.9 - jetR)
            jet_selector_truth_matched = fj.SelectorPtMin(
                5.0) & fj.SelectorAbsRapMax(0.9)
            if self.debug_level > 2:
                print('')
                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)

            # Analyze
            if self.is_pp:

                # Find pp det and truth jets
                cs_det = fj.ClusterSequence(fj_particles_det, jet_def)
                jets_det_pp = fj.sorted_by_pt(cs_det.inclusive_jets())
                jets_det_pp_selected = jet_selector_det(jets_det_pp)

                cs_truth = fj.ClusterSequence(fj_particles_truth, jet_def)
                jets_truth = fj.sorted_by_pt(cs_truth.inclusive_jets())
                jets_truth_selected = jet_selector_det(jets_truth)
                jets_truth_selected_matched = jet_selector_truth_matched(
                    jets_truth)

                self.analyze_jets(jets_det_pp_selected, jets_truth_selected,
                                  jets_truth_selected_matched, jetR)

            else:

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

                    if self.debug_level > 1:
                        print('')
                        print('R_max: {}'.format(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]])))

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

                    # Perform constituent subtraction on det-level, if applicable
                    self.fill_background_histograms(
                        fj_particles_combined_beforeCS,
                        fj_particles_combined[i], jetR, i)

                    # Do jet finding (re-do each time, to make sure matching info gets reset)
                    cs_det = fj.ClusterSequence(fj_particles_det, jet_def)
                    jets_det_pp = fj.sorted_by_pt(cs_det.inclusive_jets())
                    jets_det_pp_selected = jet_selector_det(jets_det_pp)

                    cs_truth = fj.ClusterSequence(fj_particles_truth, jet_def)
                    jets_truth = fj.sorted_by_pt(cs_truth.inclusive_jets())
                    jets_truth_selected = jet_selector_det(jets_truth)
                    jets_truth_selected_matched = jet_selector_truth_matched(
                        jets_truth)

                    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_det(jets_combined)

                    self.analyze_jets(
                        jets_combined_selected,
                        jets_truth_selected,
                        jets_truth_selected_matched,
                        jetR,
                        jets_det_pp_selected=jets_det_pp_selected,
                        R_max=R_max,
                        fj_particles_det_holes=fj_particles_det_holes,
                        fj_particles_truth_holes=fj_particles_truth_holes)
Пример #22
0
  def analyze_event(self, fj_particles):

    self.event_number += 1
    if self.event_number > self.event_number_max:
      return
    if self.debug_level > 1:
      print('-------------------------------------------------')
      print('event {}'.format(self.event_number))

    if len(fj_particles) > 1:
      if np.abs(fj_particles[0].pt() - fj_particles[1].pt()) <  1e-10:
        print('WARNING: Duplicate particles may be present')
        print([p.user_index() for p in fj_particles])
        print([p.pt() for p in fj_particles])

    # Perform constituent subtraction for each R_max (do this once, for all jetR)
    if not self.is_pp:
      fj_particles_subtracted = { R_max : cs.process_event(fj_particles) for \
                                  R_max, cs in self.constituent_subtractor.items() }

    # 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 or self.include_no_subtraction:

        # 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)

      if not self.is_pp:

        max_distance = self.max_distance if isinstance(self.max_distance, list) else \
                       self.max_distance[jetR]

        for R_max in 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 = (R_max == max_distance[0])

          # Perform constituent subtraction
          rho = self.constituent_subtractor[R_max].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[R_max], 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)
Пример #23
0
def run(data, n_events = 1000000):
    
    out = []
    njets = []
    met = []
    rho = []
    jets_corr = []
    area = []

    # run jet clustering with AntiKt, R=1.0
    R = 1.0
    jet_def = fj.JetDefinition(fj.antikt_algorithm, R)

    # Area Definition
    ghost_maxrap = 4.7
    area_def = fj.AreaDefinition(fj.active_area, fj.GhostedAreaSpec(ghost_maxrap))

    # Background estimator
    select_rapidity = fj.SelectorAbsRapMax(ghost_maxrap)
    bge = fj.JetMedianBackgroundEstimator(select_rapidity, jet_def, area_def)

    # Loop over events
    for ievt in range(n_events):

        # Build a list of all particles and MET Information
        pjs = []
        pjmet = fj.PseudoJet()
        pjmets = fj.PseudoJet()

        for i in range(int(data.shape[1]/3)):

            pj = fj.PseudoJet()
            pj.reset_PtYPhiM(data.at[ievt, 3*i+0], data.at[ievt, 3*i+1], data.at[ievt, 3*i+2], 0)
            if pj.pt() > 1.0:
                pjs.append(pj)

            pjmet.reset_momentum(-pj.px(), -pj.py(), 0, pj.E())
            pjmets = pjmets + pjmet

        met.append(pjmets)

        # Cluster sequence
        clust_seq = fj.ClusterSequenceArea(pjs, jet_def, area_def)
        jets = fj.sorted_by_pt(clust_seq.inclusive_jets())
        jets = [j for j in jets if j.pt() > 30. and j.eta() < 4.7]
        area.append([jets[0].area(), jets[1].area()])

        # Save the two leading jets and njets
        jets_sel = (fj.SelectorNHardest(2))(jets)
        out.append(jets_sel)
        njets.append(len(jets))

        # Background estimator
        bge.set_particles(pjs)
        rho.append(bge.rho())

        # Correct Jets
        sub = fj.Subtractor(bge)
        sub_jets = sub(jets_sel)
        jets_corr.append(sub_jets)

    return out, area, met, njets, rho, jets_corr