import re


def generate_root_filename(rawname, add="_mass"):
    """Generate the appropriate root filename based on a file's LJH name.
    Takes /path/to/data_chan33.ljh --> /path/to/data_mass.root
    """
    fparts = re.split(r"_chan\d+", rawname)
    prefix_path = fparts[0]
    return prefix_path + add + ".root"