#include "puUtils.h" #include std::vector GetPUWeights(TFile* dataPUFile, TTree* theMCTree){ std::vector thePUWeightsVector; if(dataPUFile){ TH1F* dataPUHisto = (TH1F*)dataPUFile->Get("pileup"); dataPUHisto->Scale(1./dataPUHisto->Integral()); //get MC distribution; copy histo from data TH1F* mcPUHisto = (TH1F*)dataPUHisto->Clone("mcPUHisto"); theMCTree->Project("mcPUHisto", "InTimePU"); mcPUHisto->Scale(1./mcPUHisto->Integral()); TH1F* theWeights = (TH1F*)dataPUHisto->Clone("theWeights"); theWeights->SetName("PUWeights"); theWeights->Divide(mcPUHisto); for(int iBin = 1; iBin < theWeights->GetNbinsX() + 1; iBin++){ thePUWeightsVector.push_back(theWeights->GetBinContent(iBin)); } } dataPUFile->Close(); return thePUWeightsVector; }