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)
def cluster(particle_list, Rjet, jetdef_tree): if jetdef_tree == 'antikt': tree_jet_def = fj.JetDefinition(fj.antikt_algorithm, Rjet) elif jetdef_tree == 'kt': tree_jet_def = fj.JetDefinition(fj.kt_algorithm, Rjet) elif jetdef_tree == 'CA': tree_jet_def = fj.JetDefinition(fj.cambridge_algorithm, Rjet) else: print('Missing jet definition') jets = [] out_jet = fj.sorted_by_pt(tree_jet_def(particle_list)) for i in range(len(out_jet)): if i == 0: trees, contents = cluster_h._traverse(out_jet[i]) tree = np.asarray([trees]) tree = np.asarray([np.asarray(e).reshape(-1, 2) for e in tree]) content = np.asarray([contents]) content = np.asarray( [np.asarray(e).reshape(-1, 4) for e in content]) masses = out_jet[i].m() pts = out_jet[i].pt() etas = out_jet[i].eta() phis = out_jet[i].phi() jets.append((tree, content, masses, pts, etas, phis)) return jets
def recluster(particles, Rjet, jetdef_tree): #---------------------------------------------- # Recluster the jet constituents and access the clustering history #set up our jet definition and a jet selector if jetdef_tree == 'antikt': tree_jet_def = fj.JetDefinition(fj.antikt_algorithm, Rjet) elif jetdef_tree == 'kt': tree_jet_def = fj.JetDefinition(fj.kt_algorithm, Rjet) elif jetdef_tree == 'CA': tree_jet_def = fj.JetDefinition(fj.cambridge_algorithm, Rjet) else: print('Missing jet definition') # selector = fj.SelectorPtMin(20.0) #We add extra constraints # out_jet = selector(fj.sorted_by_pt(tree_jet_def(preprocess_const_list)))[0] #Apply jet pT cut of 20 GeV and sort jets by pT. Recluster the jet constituents, they should give us only 1 jet if using the original jet radius. out_jet = fj.sorted_by_pt( tree_jet_def(particles) ) #Recluster the jet constituents, they should give us only 1 jet if using the original jet radius # print( 'jets=',jets) # print('jets const=',jets[0].constituents()) # print('----'*20) # print('Out_jet=',out_jet.px(),out_jet.py(),out_jet.pz(),out_jet.e(),out_jet.m(),out_jet.perp()) return out_jet
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))
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))
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)
def fill_jet_histograms(self, jet, jet_groomed_lund, jetR, obs_setting, grooming_setting, obs_label, jet_pt_ungroomed, suffix): # Recluster with WTA (with larger jet R) jet_def_wta = fj.JetDefinition(fj.cambridge_algorithm, 2*jetR) jet_def_wta.set_recombination_scheme(fj.WTA_pt_scheme) if self.debug_level > 2: print('WTA jet definition is:', jet_def_wta) reclusterer_wta = fjcontrib.Recluster(jet_def_wta) jet_wta = reclusterer_wta.result(jet) name = 'h_{}_JetPt_R{}_{}{}'.format(self.observable, jetR, obs_label, suffix) if 'Standard_SD' in obs_setting: if grooming_setting in self.obs_grooming_settings[self.observable]: jet_groomed = jet_groomed_lund.pair() deltaR = jet.delta_R(jet_groomed) if jet_groomed_lund.Delta() < 0: # untagged jet (i.e. failed SD) deltaR = -1. #getattr(self, 'h_{}_JetPt_R{}_{}'.format(self.observable, jetR, obs_label)).Fill(jet.pt(), deltaR) getattr(self, name).Fill(jet.pt(), deltaR) if obs_setting == 'Standard_WTA': deltaR = jet.delta_R(jet_wta) #getattr(self, 'h_{}_JetPt_R{}_{}'.format(self.observable, jetR, obs_label)).Fill(jet.pt(), deltaR) getattr(self, name).Fill(jet.pt(), deltaR) if 'WTA_SD' in obs_setting: if grooming_setting in self.obs_grooming_settings[self.observable]: jet_groomed = jet_groomed_lund.pair() deltaR = jet_groomed.delta_R(jet_wta) if jet_groomed_lund.Delta() < 0: # untagged jet (i.e. failed SD) deltaR = -1. #getattr(self, 'h_{}_JetPt_R{}_{}'.format(self.observable, jetR, obs_label)).Fill(jet.pt(), deltaR) getattr(self, name).Fill(jet.pt(), deltaR)
def run(data, n_events=1000): out = [] # Loop over events for ievt in range(n_events): # Build a list of all particles pjs = [] for i in range(data.shape[1]): pj = fj.PseudoJet() pj.reset_PtYPhiM(data[ievt, i, 0], data[ievt, i, 1], data[ievt, i, 2], 0) pjs.append(pj) # run jet clustering with AntiKt, R=1.0 R = 1.0 jet_def = fj.JetDefinition(fj.antikt_algorithm, R) # Save the two leading jets jets = jet_def(pjs) jets = [j for j in jets if j.pt() > 30.] out.append([jets[0], jets[1]]) return out
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 do_cs_event_wide(full_event, ptmin=100.): max_eta = 3. # background estimator bge = fj.GridMedianBackgroundEstimator(max_eta, 0.5) bge.set_particles(full_event) rho = bge.rho() rhom = bge.rho_m() subtractor = cs.ConstituentSubtractor() # enum Distance { # deltaR, # angle # } subtractor.set_distance_type(0) subtractor.set_max_distance(max_distance) subtractor.set_alpha(alpha) subtractor.set_ghost_area(ghost_area) subtractor.set_max_eta(max_eta) subtractor.set_background_estimator(bge) subtractor.set_scalar_background_density(rho, rhom) #sel_max_pt = fj.SelectorPtMax(10) #subtractor.set_particle_selector(sel_max_pt) subtractor.initialize() corrected_event = subtractor.subtract_event(full_event) jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4) clust_seq_corr = fj.ClusterSequence(corrected_event, jet_def) corrected_jets = clust_seq_corr.inclusive_jets(ptmin) return corrected_jets, clust_seq_corr
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])
def recluster(particles, Rjet, jetdef_tree): """Recluster the jet constituents""" # Recluster the jet constituents and access the clustering history #set up our jet definition and a jet selector if jetdef_tree == 'antikt': tree_jet_def = fj.JetDefinition(fj.antikt_algorithm, Rjet) elif jetdef_tree == 'kt': tree_jet_def = fj.JetDefinition(fj.kt_algorithm, Rjet) elif jetdef_tree == 'CA': tree_jet_def = fj.JetDefinition(fj.cambridge_algorithm, Rjet) else: logging.info('Missing jet definition') # Recluster the jet constituents, they should give us only 1 jet if using # the original jet radius out_jet = fj.sorted_by_pt(tree_jet_def(particles)) return out_jet
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)
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 fill_observable_histograms(self, hname, jet, jet_groomed_lund, jetR, obs_setting, grooming_setting, obs_label, jet_pt_ungroomed): # Recluster with WTA (with larger jet R) jet_def_wta = fj.JetDefinition(fj.cambridge_algorithm, 2 * jetR) jet_def_wta.set_recombination_scheme(fj.WTA_pt_scheme) if self.debug_level > 3: print('WTA jet definition is:', jet_def_wta) reclusterer_wta = fjcontrib.Recluster(jet_def_wta) jet_wta = reclusterer_wta.result(jet) # Compute jet axis differences if 'Standard_SD' in obs_setting: jet_groomed = jet_groomed_lund.pair() deltaR = jet.delta_R(jet_groomed) if jet_groomed_lund.Delta() < 0: # untagged jet (i.e. failed SD) deltaR = -1. elif obs_setting == 'Standard_WTA': deltaR = jet.delta_R(jet_wta) elif 'WTA_SD' in obs_setting: jet_groomed = jet_groomed_lund.pair() deltaR = jet_groomed.delta_R(jet_wta) if jet_groomed_lund.Delta() < 0: # untagged jet (i.e. failed SD) deltaR = -1. if grooming_setting: grooming_label = self.utils.grooming_label(grooming_setting) grooming_label = '_' + grooming_label else: grooming_label = '' getattr( self, 'h_{}_JetPt_Truth_R{}_{}{}'.format( self.observable, jetR, obs_setting, grooming_label)).Fill(jet_pt_ungroomed, deltaR)
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)
def initialize_user_config(self): # Define subjet finders (from first observable defined) self.subjet_def = {} for subjetR in self.obs_settings[self.observable_list[0]]: self.subjet_def[subjetR] = fj.JetDefinition( fj.antikt_algorithm, subjetR)
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)
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)
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 fill_matched_jet_histograms(self, jet_det, jet_det_groomed_lund, jet_truth, jet_truth_groomed_lund, jet_pp_det, jetR, obs_setting, grooming_setting, obs_label, jet_pt_det_ungroomed, jet_pt_truth_ungroomed, R_max, suffix): # Recluster with WTA (with larger jet R) jet_def_wta = fj.JetDefinition(fj.cambridge_algorithm, 2*jetR) jet_def_wta.set_recombination_scheme(fj.WTA_pt_scheme) if self.debug_level > 3: print('WTA jet definition is:', jet_def_wta) reclusterer_wta = fjcontrib.Recluster(jet_def_wta) jet_det_wta = reclusterer_wta.result(jet_det) jet_truth_wta = reclusterer_wta.result(jet_truth) # Compute jet axis differences jet_det_groomed = jet_det_groomed_lund.pair() jet_truth_groomed = jet_truth_groomed_lund.pair() if obs_setting == 'Standard_SD': deltaR_det = jet_det.delta_R(jet_det_groomed) deltaR_truth = jet_truth.delta_R(jet_truth_groomed) elif obs_setting == 'Standard_WTA': deltaR_det = jet_det.delta_R(jet_det_wta) deltaR_truth = jet_truth.delta_R(jet_truth_wta) elif obs_setting == 'WTA_SD': deltaR_det = jet_det_groomed.delta_R(jet_det_wta) deltaR_truth = jet_truth_groomed.delta_R(jet_truth_wta) # Fill response self.fill_response(self.observable, jetR, jet_pt_det_ungroomed, jet_pt_truth_ungroomed, deltaR_det, deltaR_truth, obs_label, R_max, prong_match = False)
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']) ]
def do_clustering(self): self.jet_def = fj.JetDefinition(self.algorithm, self.R) self.jet_cs = fj.ClusterSequence(self.particles, self.jet_def) jets = self.jet_cs.inclusive_jets(self.ptmin) self.jets = fj.sorted_by_pt(jets) return self.jets
def __init__(self, outputname, enable_aa_trees=False): self.outf = ROOT.TFile(outputname, 'recreate') self.outf.cd() self.t = ROOT.TTree('t', 't') self.tw = RTreeWriter(tree=self.t) self.taaw = None self.tembw = None self.tembwp = None if enable_aa_trees: self.taa = ROOT.TTree('taa', 'taa') self.taaw = RTreeWriter(tree=self.taa) self.temb = ROOT.TTree('temb', 'temb') self.tembw = RTreeWriter(tree=self.temb) self.tembp = ROOT.TTree('tembp', 'tembp') self.tembwp = RTreeWriter(tree=self.tembp) self.jet_def_lund = fj.JetDefinition(fj.cambridge_algorithm, 1.0) self.dy_groomer_alphas = [0.1, 1.0, 2.0] self.sd_zcuts = [0.1, 0.2, 0.3, 0.4] self.gshop = fjcontrib.GroomerShop(self.jet_def_lund) self.gshop_emb = fjcontrib.GroomerShop(self.jet_def_lund) print(self.gshop.description()) self.sds = [] sd01 = fjcontrib.SoftDrop(0, 0.1, 1.0) sd02 = fjcontrib.SoftDrop(0, 0.2, 1.0) self.sds.append(sd01) self.sds.append(sd02)
def draw_parts_thermal(parts, Rabs=0.4): jet_R0 = Rabs * 1.0 jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0) parts_v = [fj.PseudoJet(p.px(), p.py(), p.pz(), p.e()) for p in parts] jets = jet_def(parts_v) for j in jets: draw_jet(j, jet_R0) break
def get_wta_jet(self, jet, jetR): # Recluster with WTA (with larger jet R) jet_def_wta = fj.JetDefinition(fj.cambridge_algorithm, 2 * jetR) jet_def_wta.set_recombination_scheme(fj.WTA_pt_scheme) if self.debug_level > 3: print('WTA jet definition is:', jet_def_wta) reclusterer_wta = fjcontrib.Recluster(jet_def_wta) return reclusterer_wta.result(jet)
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 main(): ''' program to create a list of events with bjets ''' logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s:%(name)s:%(message)s') parser = optparse.OptionParser(description='') parser.add_option( '-f', '--file-list', dest='filelist', help= 'Pass a filename to a file which contains a list of files to process. One file per line.' ) parser.add_option('-j', '--drjet', dest='drjet', help='The radius of anti-kt jets used.', default=0.4, type='int') parser.add_option('-o', '--output-file', dest='output_file', help='file to save b-tagging information', default='btagged_jets.txt') parser.add_option('-n', '--nprocs', dest='nprocs', help='number of pool processes to run', default=4, type='int') options, args = parser.parse_args() manditory_args = ['filelist', 'drjet', 'output_file', 'nprocs'] for man in manditory_args: if man not in options.__dict__ or options.__dict__[man] is None: logger.error('Must specify option: ' + man) parser.print_help() sys.exit(-1) # set global jet definition global jet_def jet_def = fastjet.JetDefinition(fastjet.antikt_algorithm, options.drjet) global drjet drjet = options.drjet nfiles = get_number_of_files(options.filelist) logger.info('processing %s files', nfiles) pool = mp.Pool(processes=options.nprocs) returned = pool.imap_unordered(process_file, file_generator(options.filelist)) pool.close() pool.join()
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)