How to make a TProfile with number of events and variable bin size

Dear root experts,

I want to make a TProfile with variable bin size. In the X axis I want the Energy of a random distribution and in the Y axis I want dN/dE (Flux). Here is my problem because I don’t know how to get this Flux. Here I copy an extract of my code:

[code]TProfile ToyMC(const double gamma, const int nrEvents ) {

const unsigned int nrBins = 9;
const double bins[nrBins+1] = {1.e+17.1,1.e+17.2,1.e+17.3,1.e+17.4,1.e+17.5,1.e+17.8,1.e+18.,1.e+18.2,1.e+18.5,1.e+20.};

TProfile *flux = new TProfile(“flux”,"",nrBins,bins);
TF1 * energyDistr = new TF1(“energyDistr”,“pow(x, [0])”,1.e+16.5,2.e+20);
energyDistr->SetParameter(0,gamma);
energyDistr->SetNpx(1000000);
for (Int_t i=0; i<nrEvents; i++){
const double energy = energyDistr->GetRandom();
if (measEn < 0)
continue;
Flux->Fill(energy,¿¿¿…???);

}
return *flux;
}
[/code]

Anyone could explain me how to make it?

Many thanks, Nahual