Added function and histograms, to complete the weighted plots but the code is crashing when attempting to fill weighted TH2F histograms