+Double_t AliQuenchingWeights::GetELossRandomKFast(Int_t ipart, Double_t I0, Double_t I1, Double_t e)
+{
+ // return DeltaE for new dynamic version
+ // for given parton type, I0 and I1 value and energy
+ // Dependant on ECM (energy constraint method)
+ // e is used to determine where to set bins to zero.
+ // method is optimized and should only be used if
+ // all parameters are well within the bounds.
+ // read-in data tables before first call
+
+ Double_t r=CalcRk(I0,I1);
+ if(r<=0.){
+ return 0.;
+ }
+
+ Double_t wc=CalcWCk(I1);
+ if(wc<=0.){
+ return 0.;
+ }
+
+ return GetELossRandomKFastR(ipart,r,wc,e);
+}
+
+Double_t AliQuenchingWeights::GetELossRandomKFastR(Int_t ipart, Double_t r, Double_t wc, Double_t e)
+{
+ // return DeltaE for new dynamic version
+ // for given parton type, R and wc value and energy
+ // Dependant on ECM (energy constraint method)
+ // e is used to determine where to set bins to zero.
+ // method is optimized and should only be used if
+ // all parameters are well within the bounds.
+ // read-in data tables before first call
+
+ if(r>=fgkRMax) {
+ r=fgkRMax-1;
+ }
+
+ Double_t discrete=0.;
+ Double_t continuous=0.;
+ Int_t bin=1;
+ Double_t xxxx = fHisto->GetBinCenter(bin);
+ if(fMultSoft)
+ CalcMult(ipart,r,xxxx,continuous,discrete);
+ else
+ CalcSingleHard(ipart,r,xxxx,continuous,discrete);
+
+ if(discrete>=1.0) {
+ return 0.; //no energy loss
+ }
+
+ fHisto->SetBinContent(bin,continuous);
+ Int_t kbinmax=fHisto->FindBin(e/wc);
+ if(kbinmax>=fgkBins) kbinmax=fgkBins-1;
+ if(kbinmax==1) return e; //maximum energy loss
+
+ if(fMultSoft) {
+ for(Int_t bin=2; bin<=kbinmax; bin++) {
+ xxxx = fHisto->GetBinCenter(bin);
+ CalcMult(ipart,r,xxxx,continuous,discrete);
+ fHisto->SetBinContent(bin,continuous);
+ }
+ } else {
+ for(Int_t bin=2; bin<=kbinmax; bin++) {
+ xxxx = fHisto->GetBinCenter(bin);
+ CalcSingleHard(ipart,r,xxxx,continuous,discrete);
+ fHisto->SetBinContent(bin,continuous);
+ }
+ }
+
+ if(fECMethod==kReweight){
+ fHisto->SetBinContent(kbinmax+1,0);
+ fHisto->Fill(0.,discrete*fgkBins/fgkMaxBin);
+ } else if (fECMethod==kReweightCont) {
+ fHisto->SetBinContent(kbinmax+1,0);
+ const Double_t kdelta=fHisto->Integral(1,kbinmax);
+ fHisto->Scale(1./kdelta*(1-discrete));
+ fHisto->Fill(0.,discrete);
+ } else {
+ const Double_t kdelta=fHisto->Integral(1,kbinmax);
+ Double_t val=discrete*fgkBins/fgkMaxBin;
+ fHisto->Fill(0.,val);
+ fHisto->SetBinContent(kbinmax+1,(1-discrete)*fgkBins/fgkMaxBin-kdelta);
+ }
+ for(Int_t bin=kbinmax+2; bin<=fgkBins; bin++) {
+ fHisto->SetBinContent(bin,0);
+ }
+ //cout << kbinmax << " " << discrete << " " << fHisto->Integral() << endl;
+ Double_t ret=fHisto->GetRandom()*wc;
+ if(ret>e) return e;
+ return ret;
+}
+
+Double_t AliQuenchingWeights::CalcQuenchedEnergyKFast(Int_t ipart, Double_t I0, Double_t I1, Double_t e)
+{
+ //return quenched parton energy (fast method)
+ //for given parton type, I0 and I1 value and energy
+
+ Double_t loss=GetELossRandomKFast(ipart,I0,I1,e);
+ return e-loss;
+}
+
+Double_t AliQuenchingWeights::GetDiscreteWeight(Int_t ipart, Double_t I0, Double_t I1)
+{
+ // return discrete weight
+
+ Double_t r=CalcRk(I0,I1);
+ if(r<=0.){
+ return 1.;
+ }
+ return GetDiscreteWeightR(ipart,r);
+}
+
+Double_t AliQuenchingWeights::GetDiscreteWeightR(Int_t ipart, Double_t r)
+{
+ // return discrete weight
+
+ if(r>=fgkRMax) {
+ r=fgkRMax-1;
+ }
+
+ Double_t discrete=0.;
+ Double_t continuous=0.;
+ Int_t bin=1;
+ Double_t xxxx = fHisto->GetBinCenter(bin);
+ if(fMultSoft)
+ CalcMult(ipart,r,xxxx,continuous,discrete);
+ else
+ CalcSingleHard(ipart,r,xxxx,continuous,discrete);
+ return discrete;
+}
+
+void AliQuenchingWeights::GetZeroLossProb(Double_t &p,Double_t &prw,Double_t &prwcont,
+ Int_t ipart,Double_t I0,Double_t I1,Double_t e)
+{
+ //calculate the probabilty that there is no energy
+ //loss for different ways of energy constraint
+ p=1.;prw=1.;prwcont=1.;
+ Double_t r=CalcRk(I0,I1);
+ if(r<=0.){
+ return;
+ }
+ Double_t wc=CalcWCk(I1);
+ if(wc<=0.){
+ return;
+ }
+ GetZeroLossProbR(p,prw,prwcont,ipart,r,wc,e);
+}
+
+void AliQuenchingWeights::GetZeroLossProbR(Double_t &p,Double_t &prw,Double_t &prwcont,
+ Int_t ipart, Double_t r,Double_t wc,Double_t e)
+{
+ //calculate the probabilty that there is no energy
+ //loss for different ways of energy constraint
+ if(r>=fgkRMax) {
+ r=fgkRMax-1;
+ }
+
+ Double_t discrete=0.;
+ Double_t continuous=0.;
+
+ Int_t kbinmax=fHisto->FindBin(e/wc);
+ if(kbinmax>=fgkBins) kbinmax=fgkBins-1;
+ if(fMultSoft) {
+ for(Int_t bin=1; bin<=kbinmax; bin++) {
+ Double_t xxxx = fHisto->GetBinCenter(bin);
+ CalcMult(ipart,r,xxxx,continuous,discrete);
+ fHisto->SetBinContent(bin,continuous);
+ }
+ } else {
+ for(Int_t bin=1; bin<=kbinmax; bin++) {
+ Double_t xxxx = fHisto->GetBinCenter(bin);
+ CalcSingleHard(ipart,r,xxxx,continuous,discrete);
+ fHisto->SetBinContent(bin,continuous);
+ }
+ }
+
+ //non-reweighted P(Delta E = 0)
+ const Double_t kdelta=fHisto->Integral(1,kbinmax);
+ Double_t val=discrete*fgkBins/fgkMaxBin;
+ fHisto->Fill(0.,val);
+ fHisto->SetBinContent(kbinmax+1,(1-discrete)*fgkBins/fgkMaxBin-kdelta);
+ Double_t hint=fHisto->Integral(1,kbinmax+1);
+ p=fHisto->GetBinContent(1)/hint;
+
+ // reweighted
+ hint=fHisto->Integral(1,kbinmax);
+ prw=fHisto->GetBinContent(1)/hint;
+
+ Double_t xxxx = fHisto->GetBinCenter(1);
+ CalcMult(ipart,r,xxxx,continuous,discrete);
+ fHisto->SetBinContent(1,continuous);
+ hint=fHisto->Integral(1,kbinmax);
+ fHisto->Scale(1./hint*(1-discrete));
+ fHisto->Fill(0.,discrete);
+ prwcont=fHisto->GetBinContent(1);
+}
+