fix array overflow issues found by David A.

Issues reported at
https://hypernews.cern.ch/HyperNews/CMS/get/swReleases/4108/1/1/1/1/1/1/1/1.html
and follow ups are mostly fixed here. 
"th" is not a TProfile but rather a TH2F, which has 7. Maybe it was supposed to be the TProfile that was used in this function call?