sampling code to deal with hierarchical chemical reaction