Modeling and engineering impact ionization in avalanche photodiodes for near and mid infrared applications