def cut_flow(): ''' Defines all cuts that will be applied to input data ''' # dictionary of selection criteria # the 'All' key denotes that an event has to pass all the listed cuts # other options are Any (or) and Not (inverse) # event (`ev`) refers to a single entry in the input tree # names and indices after that are the branch names event_selection = dict(All = ( 'ev : ev.cutflowId[0] == 1', 'ev : ev.nIsoTracksVeto[0] <= 0', 'ev : ev.nJet40[0] >= 2', 'ev : ev.ht40[0] >= 200', 'ev : ev.nJet100[0] >= 1', 'ev : ev.nJet40failedId[0] == 0', 'ev : ev.nJet40Fwd[0] == 0', 'ev : -2.5 < ev.jet_eta[0] < 2.5', 'ev : 0.1 <= ev.jet_chHEF[0] < 0.95', 'ev : 130 <= ev.mht40_pt[0]', )) # These would be nice, but they require scribblers; we add these in step3 # 'ev : ev.MhtOverMet[0] < 1.25', # create a reader + collector pair for the cutflow # the collector will reject events and store the cut flow into a text file return cut_flow_with_counter(event_selection, "cut_flow_table.txt")
def cut_flow(output_directory=None, cut_flow_filename="cut_flow_table.txt"): ''' Defines all cuts that will be applied to input data TODO: Read this directly from a yaml file, allow the file to define cut aliases TODO: Have a way to inspect what variables this cut flow needs... ''' # dictionary of selection criteria # the 'All' key denotes that an event has to pass all the listed cuts # other options are Any (or) and Not (inverse) # event (`ev`) refers to a single entry in the input tree # names and indices after that are the branch names event_selection = dict(All = ( baseline_selection, )) # create a reader + collector pair for the cutflow # the collector will reject events and store the cut flow into a text file if output_directory: cut_flow_filename = os.path.join(output_directory, cut_flow_filename) return cut_flow_with_counter(event_selection, cut_flow_filename)
def Selection(steps={}, cutflow_file=None, weight_attr=None): ''' This class ties together several modules from alphatwirl to bring a simplified Selection experience. :param dict steps: A dictionary of selection steps :param str cutflow_file: path to the cutflow output file. example: preselection = Selection( dict( All=( 'NMuon[0] == 2', 'muon_pt[0] > 20', 'muon_pt[1] > 20', 'Muon_Iso[0] < 0.1', 'Muon_Iso[1] < 0.1', 'Muon_Charge[0] == -1 * Muon_Charge[1]', )), 'output/cutflow_preselection.txt' ) # define in alphatwirl modules to pass to tree.scan modules = [ preselection, ... ] ''' rc_pair = None if cutflow_file: if weight_attr: rc_pair = cut_flow_with_weighted_counter(steps, cutflow_file, weight_attr) else: rc_pair = cut_flow_with_counter(steps, cutflow_file) else: rc_pair = cut_flow(steps) return rc_pair[0]