Tuning and monitoring the electronic structure of carbon nanotubes