def METHOD_NAME(hierarchy, map_data, mon_lib_srv, rotamer_manager, unit_cell):
  allhis = all_his.load()
  def compute_target(rg):
     sites_cart  = rg.atoms().extract_xyz()
     t = maptbx.real_space_target_simple(
        unit_cell   = unit_cell,
        density_map = map_data,
        sites_cart  = sites_cart)
     return t/sites_cart.size()
  def per_atom(rg):
    #hs = ["CG", "ND1", "CE1", "NE2", "CD2", "HD1", "HE1", "HE2", "HD2"]
    hs = ["HD1", "HE1", "HE2", "HD2",   "DD1", "DE1", "DE2", "DD2"]
    vals = []
    for a in rg.atoms():
      if a.name.strip().upper() in hs:
        t = maptbx.real_space_target_simple(
          unit_cell   = unit_cell,
          density_map = map_data,
          sites_cart  = flex.vec3_double([a.xyz,]))
        vals.append("%s %5.2f"%(a.name.strip().upper(),t))
    return " ".join(vals)
  for c in hierarchy.chains():
    for i, rg in enumerate(c.residue_groups()):
      o = manageable_HIS(rg=rg)
      if(o is None): continue
      print("chain %s resid %s"%(c.id, rg.resid()),"-"*20)
      rg_dc = rg.detached_copy()
      rg_w  = rg
      print("  t orig:", compute_target(rg), per_atom(rg))
      for i, rg_to_insert in enumerate(allhis.main_three()):
        print("  protonation", i)
        rg_to_insert = allhis.r["d1"]
        rg_to_insert.resseq = rg_w.resseq
        match_residue_groups(rg_working=rg_w, rg_to_insert=rg_to_insert)
        print("    t start:", compute_target(rg_to_insert), per_atom(rg_to_insert))
        o = fit_residue.tune_up(
          target_map           = map_data,
          residue              = rg_to_insert,
          mon_lib_srv          = mon_lib_srv,
          rotamer_manager      = None,
          unit_cell            = unit_cell,
          exclude_hd           = False,
          torsion_search_start = -5,
          torsion_search_stop  = 5,
          torsion_search_step  = 0.1)
        print("    t final:", compute_target(o.residue), per_atom(o.residue))
        rg_to_insert = o.residue.detached_copy()
        c.remove_residue_group(rg_w)
        rg_to_insert.link_to_previous=True
        c.insert_residue_group(i=i, residue_group=rg_to_insert)
        rg_w  = rg_to_insert
        break
        if 0:
          c.remove_residue_group(rg_w)
          rg_to_insert.link_to_previous=True
          c.insert_residue_group(i=i, residue_group=rg_to_insert)
          rg_w  = rg_to_insert
  #
  hierarchy.write_pdb_file(file_name = "inserted.pdb")