docs: def patch_xml(files, root_file=None, float_precision=3):
      """
      Apply patches to HistFactory XML output from PrintXML
      """
      if float_precision < 0:
          raise ValueError("precision must be greater than 0")
  
      def fix_path(match):
          path = match.group(1)
          if path:
              head, tail = os.path.split(path)
              new_path = os.path.join(os.path.basename(head), tail)
          else:
              new_path = ''
          return '<Input>{0}</Input>'.format(new_path)
  
      for xmlfilename in files:
          xmlfilename = os.path.abspath(os.path.normpath(xmlfilename))
          patched_xmlfilename = '{0}.tmp'.format(xmlfilename)
          log.info("patching {0} ...".format(xmlfilename))
          fin = open(xmlfilename, 'r')
          fout = open(patched_xmlfilename, 'w')
          for line in fin:
              if root_file is not None:
                  line = re.sub(
                      'InputFile="[^"]*"',
                      'InputFile="{0}"'.format(root_file), line)
              line = line.replace(
                  '<StatError Activate="True"  InputFile=""  '
                  'HistoName=""  HistoPath=""  />',
                  '<StatError Activate="True" />')
              line = re.sub(
                  '<Combination OutputFilePrefix="(\S*)" >',
                  '<Combination OutputFilePrefix="hist2workspace" >', line)
              line = re.sub('\w+=""', '', line)
              line = re.sub('\s+/>', ' />', line)
              line = re.sub('(\S)\s+</', r'\1</', line)
              # HistFactory bug:
              line = re.sub('InputFileHigh="\S+"', '', line)
              line = re.sub('InputFileLow="\S+"', '', line)
              # HistFactory bug:
              line = line.replace(
                  '<ParamSetting Const="True"></ParamSetting>', '')
              # chop off floats to desired precision
              line = re.sub(
                  r'"(\d*\.\d{{{0:d},}})"'.format(float_precision + 1),
                  lambda x: '"{0}"'.format(
                      str(round(float(x.group(1)), float_precision))),
                  line)
              line = re.sub('"\s\s+(\S)', r'" \1', line)
              line = re.sub('<Input>(.*)</Input>', fix_path, line)
              fout.write(line)
          fin.close()
          fout.close()
          shutil.move(patched_xmlfilename, xmlfilename)
          if not os.path.isfile(os.path.join(
                                os.path.dirname(xmlfilename),
                                'HistFactorySchema.dtd')):
              rootsys = os.getenv('ROOTSYS', None)
              if rootsys is not None:
                  dtdfile = os.path.join(rootsys, 'etc/HistFactorySchema.dtd')
                  target = os.path.dirname(xmlfilename)
                  if os.path.isfile(dtdfile):
                      log.info("copying {0} to {1} ...".format(dtdfile, target))
                      shutil.copy(dtdfile, target)
                  else:
                      log.warning("{0} does not exist".format(dtdfile))
              else:
                  log.warning(
                      "$ROOTSYS is not set so cannot find HistFactorySchema.dtd")