/// <summary>
 /// Given a cut name, see if there are any references to various FSO's.
 /// </summary>
 /// <param name="cut_nameContext"></param>
 /// <returns></returns>
 private IEnumerable <FinalStateObject> ExtractFSOReferences(FinalStatePatternParser.Cut_nameContext cut_nameContext)
 {
     if (cut_nameContext.object_name() != null)
     {
         yield return(Convert(cut_nameContext.object_name()));
     }
     else if (cut_nameContext.NAME() != null)
     {
         var nm = cut_nameContext.NAME().GetText();
         var f  = FSOs.Where(fs => fs.Name == nm).FirstOrDefault();
         if (f != null)
         {
             yield return(f);
         }
     }
 }
        /// <summary>
        /// Convert a cut_name to a IValueBase
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        private IValueBase Convert(FinalStatePatternParser.Cut_nameContext func)
        {
            // Defaults, depending on context
            // This is what happens when the same code is used for multiple rules. :(
            var fso = _current_fso;

            if (fso == null)
            {
                fso = _current_cut;
            }

            // See if the FSO was explicitly defined.
            if (func.object_name() != null)
            {
                fso = Convert(func.object_name(), AllowedFSODefinitionReference.kAsDefinitionOrReference);
            }

            if (fso == null)
            {
                throw new ArgumentException(string.Format("Unable to figure out what object this value is referring to: {0}", func.NAME().GetText()));
            }

            // It is possible to have a name like ETMiss as a stand-alone name.
            // However, then the FSO must be defined.
            // (see above)... And we really need to double check this.
            // TODO: Alias mechanism so ETMiss => ETMiss.ET or similar?
            // Or we can use MET or something like that - so most physicists will
            // end up doing the "right thing".
            var name = func.NAME() == null ? "" : func.NAME().GetText();

            return(new SinglePhysicalQuantity()
            {
                PhysicalQantity = name,
                RefersToObject = fso
            });
        }