nodes: 0, module; 1, function_definition; 2, function_name:get_hits_in_events; 3, parameters; 4, block; 5, identifier:hits_array; 6, identifier:events; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, try_statement; 13, return_statement; 14, identifier:assume_sorted; 15, True; 16, identifier:condition; 17, None; 18, string; 19, call; 20, identifier:assume_sorted; 21, block; 22, block; 23, except_clause; 24, identifier:hits_in_events; 25, string_content:Selects the hits that occurred in events and optional selection criterion.
          If a event range can be defined use the get_data_in_event_range function. It is much faster.
  
      Parameters
      ----------
      hits_array : numpy.array
      events : array
      assume_sorted : bool
          Is true if the events to select are sorted from low to high value. Increases speed by 35%.
      condition : string
          A condition that is applied to the hits in numexpr. Only if the expression evaluates to True the hit is taken.
  
      Returns
      -------
      numpy.array
          hit array with the hits in events.; 26, attribute; 27, argument_list; 28, expression_statement; 29, comment:# reduce the event number range to the max min event number of the given hits to save time; 30, if_statement; 31, if_statement; 32, if_statement; 33, identifier:MemoryError; 34, block; 35, identifier:logging; 36, identifier:debug; 37, binary_operator:"Calculate hits that exists in the given %d events." % len(events); 38, assignment; 39, comparison_operator:events.shape[0] == 0; 40, comment:# if there is not a single selected hit; 41, block; 42, identifier:assume_sorted; 43, block; 44, else_clause; 45, comparison_operator:condition is None; 46, block; 47, else_clause; 48, expression_statement; 49, raise_statement; 50, string:"Calculate hits that exists in the given %d events."; 51, call; 52, pattern_list; 53, call; 54, subscript; 55, integer:0; 56, return_statement; 57, expression_statement; 58, block; 59, identifier:condition; 60, None; 61, expression_statement; 62, comment:# bad hack to be able to use numexpr; 63, block; 64, call; 65, identifier:MemoryError; 66, identifier:len; 67, argument_list; 68, identifier:events; 69, identifier:_; 70, identifier:reduce_sorted_to_intersect; 71, argument_list; 72, attribute; 73, integer:0; 74, subscript; 75, assignment; 76, expression_statement; 77, expression_statement; 78, assignment; 79, for_statement; 80, expression_statement; 81, attribute; 82, argument_list; 83, identifier:events; 84, identifier:events; 85, subscript; 86, identifier:events; 87, identifier:shape; 88, identifier:hits_array; 89, slice; 90, identifier:selection; 91, call; 92, call; 93, assignment; 94, identifier:hits_in_events; 95, subscript; 96, identifier:variable; 97, call; 98, block; 99, assignment; 100, identifier:logging; 101, identifier:error; 102, string; 103, identifier:hits_array; 104, string; 105, integer:0; 106, integer:0; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, identifier:selection; 112, call; 113, identifier:hits_array; 114, identifier:selection; 115, identifier:set; 116, argument_list; 117, expression_statement; 118, identifier:hits_in_events; 119, subscript; 120, string_content:There are too many hits to do in RAM operations. Consider decreasing chunk size and use the write_hits_in_events function instead.; 121, string_content:event_number; 122, identifier:analysis_utils; 123, identifier:in1d_events; 124, subscript; 125, identifier:events; 126, identifier:logging; 127, identifier:warning; 128, string; 129, attribute; 130, argument_list; 131, call; 132, call; 133, identifier:hits_array; 134, call; 135, identifier:hits_array; 136, string; 137, string_content:Events are usually sorted. Are you sure you want this?; 138, identifier:np; 139, identifier:in1d; 140, subscript; 141, identifier:events; 142, attribute; 143, argument_list; 144, identifier:exec; 145, argument_list; 146, attribute; 147, argument_list; 148, string_content:event_number; 149, identifier:hits_array; 150, string; 151, identifier:re; 152, identifier:findall; 153, string; 154, identifier:condition; 155, binary_operator:variable + ' = hits_array[\'' + variable + '\']'; 156, identifier:ne; 157, identifier:evaluate; 158, binary_operator:condition + ' & selection'; 159, string_content:event_number; 160, string_content:[a-zA-Z_]+; 161, binary_operator:variable + ' = hits_array[\'' + variable; 162, string; 163, identifier:condition; 164, string; 165, binary_operator:variable + ' = hits_array[\''; 166, identifier:variable; 167, string_content; 168, string_content:& selection; 169, identifier:variable; 170, string; 171, escape_sequence:\'; 172, string_content; 173, escape_sequence:\'
code: def get_hits_in_events(hits_array, events, assume_sorted=True, condition=None):
      '''Selects the hits that occurred in events and optional selection criterion.
          If a event range can be defined use the get_data_in_event_range function. It is much faster.
  
      Parameters
      ----------
      hits_array : numpy.array
      events : array
      assume_sorted : bool
          Is true if the events to select are sorted from low to high value. Increases speed by 35%.
      condition : string
          A condition that is applied to the hits in numexpr. Only if the expression evaluates to True the hit is taken.
  
      Returns
      -------
      numpy.array
          hit array with the hits in events.
      '''
  
      logging.debug("Calculate hits that exists in the given %d events." % len(events))
      if assume_sorted:
          events, _ = reduce_sorted_to_intersect(events, hits_array['event_number'])  # reduce the event number range to the max min event number of the given hits to save time
          if events.shape[0] == 0:  # if there is not a single selected hit
              return hits_array[0:0]
      try:
          if assume_sorted:
              selection = analysis_utils.in1d_events(hits_array['event_number'], events)
          else:
              logging.warning('Events are usually sorted. Are you sure you want this?')
              selection = np.in1d(hits_array['event_number'], events)
          if condition is None:
              hits_in_events = hits_array[selection]
          else:
              # bad hack to be able to use numexpr
              for variable in set(re.findall(r'[a-zA-Z_]+', condition)):
                  exec(variable + ' = hits_array[\'' + variable + '\']')
  
              hits_in_events = hits_array[ne.evaluate(condition + ' & selection')]
      except MemoryError:
          logging.error('There are too many hits to do in RAM operations. Consider decreasing chunk size and use the write_hits_in_events function instead.')
          raise MemoryError
      return hits_in_events