LCOV - code coverage report
Current view: top level - TEvtGen/EvtGen/EvtGenModels - EvtVubBLNP.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 451 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 48 0.0 %

          Line data    Source code
       1             : 
       2             : //////////////////////////////////////////////////////////////////////
       3             : //
       4             : // Module: EvtVubBLNP.cc
       5             : //
       6             : // Description: Modeled on Riccardo Faccini's EvtVubNLO module
       7             : //
       8             : // tripleDiff from BLNP's notebook (based on BLNP4, hep-ph/0504071)
       9             : //
      10             : //////////////////////////////////////////////////////////////////
      11             : 
      12             : #include "EvtGenBase/EvtPatches.hh"
      13             : #include <stdlib.h>
      14             : #include "EvtGenBase/EvtParticle.hh"
      15             : #include "EvtGenBase/EvtGenKine.hh"
      16             : #include "EvtGenBase/EvtPDL.hh"
      17             : #include "EvtGenBase/EvtReport.hh"
      18             : #include "EvtGenModels/EvtVubBLNP.hh"
      19             : #include <string>
      20             : #include "EvtGenBase/EvtVector4R.hh"
      21             : #include "EvtGenModels/EvtItgSimpsonIntegrator.hh"
      22             : #include "EvtGenModels/EvtItgPtrFunction.hh"
      23             : #include "EvtGenBase/EvtRandom.hh"
      24             : #include "EvtGenModels/EvtPFermi.hh"
      25             : 
      26             : // For incomplete gamma function
      27             : #include "math.h"
      28             : #include "signal.h"
      29             : #define ITMAX 100
      30             : #define EPS 3.0e-7
      31             : #define FPMIN 1.0e-30
      32             : 
      33             : using std::cout;
      34             : using std::endl;
      35             : 
      36           0 : EvtVubBLNP::~EvtVubBLNP() {
      37           0 : }
      38             : 
      39             : std::string EvtVubBLNP::getName(){
      40           0 :   return "VUB_BLNP";
      41             : }
      42             : 
      43             : EvtDecayBase *EvtVubBLNP::clone() {
      44             : 
      45           0 :   return new EvtVubBLNP;
      46             : 
      47           0 : }
      48             : 
      49             : void EvtVubBLNP::init() {
      50             : 
      51             :   // get parameters (declared in the header file)
      52             :   
      53             :   // Input parameters
      54           0 :   mBB = 5.2792;
      55           0 :   lambda2 = 0.12;
      56             : 
      57             :   // Shape function parameters
      58           0 :   b = getArg(0);
      59           0 :   Lambda = getArg(1);
      60           0 :   Ecut = 1.8;
      61           0 :   wzero = mBB - 2*Ecut;
      62             : 
      63             :   // SF and SSF modes
      64           0 :   itype = (int)getArg(5);
      65           0 :   dtype = getArg(5);
      66           0 :   isubl = (int)getArg(6);
      67             : 
      68             :   // flags
      69           0 :   flag1 = (int)getArg(7);
      70           0 :   flag2 = (int)getArg(8);
      71           0 :   flag3 = (int)getArg(9);
      72             : 
      73             :   // Quark mass
      74           0 :   mb = 4.61;
      75             : 
      76             : 
      77             :   // hidden parameter what and SF stuff   
      78             :   const double xlow = 0;
      79           0 :   const double xhigh = mBB;
      80             :   const int aSize = 10000;
      81           0 :   EvtPFermi pFermi(Lambda,b);
      82             :   // pf is the cumulative distribution normalized to 1.
      83           0 :   _pf.resize(aSize);
      84           0 :   for(int i=0;i<aSize;i++){
      85           0 :     double what = xlow + (double)(i+0.5)/((double)aSize)*(xhigh-xlow);
      86           0 :     if ( i== 0 )
      87           0 :       _pf[i] = pFermi.getSFBLNP(what);
      88             :     else
      89           0 :       _pf[i] = _pf[i-1] + pFermi.getSFBLNP(what);
      90           0 :   }
      91           0 :   for (size_t i=0; i<_pf.size(); i++) {
      92           0 :     _pf[i]/=_pf[_pf.size()-1];
      93             :   } 
      94             : 
      95             : 
      96             : 
      97             :   // Matching scales
      98           0 :   muh = mBB*getArg(2); // 0.5
      99           0 :   mui = getArg(3); // 1.5
     100           0 :   mubar = getArg(4); // 1.5
     101             : 
     102             :   // Perturbative quantities
     103           0 :   CF = 4.0/3.0;
     104           0 :   CA = 3.0;
     105             :   double nf = 4.0;
     106             : 
     107           0 :   beta0 = 11.0/3.0*CA - 2.0/3.0*nf;
     108           0 :   beta1 = 34.0/3.0*CA*CA - 10.0/3.0*CA*nf - 2.0*CF*nf;
     109           0 :   beta2 = 2857.0/54.0*CA*CA*CA + (CF*CF - 205.0/18.0*CF*CA - 1415.0/54.0*CA*CA)*nf + (11.0/9.0*CF + 79.0/54.0*CA)*nf*nf;
     110             : 
     111           0 :   zeta3 = 1.0 + 1/8.0 + 1/27.0 + 1/64.0;
     112             : 
     113           0 :   Gamma0 = 4*CF;
     114           0 :   Gamma1 = CF*( (268.0/9.0 - 4.0*M_PI*M_PI/3.0)*CA - 40.0/9.0*nf);
     115           0 :   Gamma2 = 16*CF*( (245.0/24.0 - 67.0/54.0*M_PI*M_PI + + 11.0/180.0*pow(M_PI,4) + 11.0/6.0*zeta3)*CA*CA* + (-209.0/108.0 + 5.0/27.0*M_PI*M_PI - 7.0/3.0*zeta3)*CA*nf + (-55.0/24.0 + 2*zeta3)*CF*nf - nf*nf/27.0);
     116             : 
     117           0 :   gp0 = -5.0*CF;
     118           0 :   gp1 = -8.0*CF*( (3.0/16.0 - M_PI*M_PI/4.0 + 3*zeta3)*CF + (1549.0/432.0 + 7.0/48.0*M_PI*M_PI - 11.0/4.0*zeta3)*CA - (125.0/216.0 + M_PI*M_PI/24.0)*nf );
     119             : 
     120             :   // Lbar and mupisq
     121             : 
     122           0 :   Lbar = Lambda;  // all models
     123           0 :   mupisq = 3*Lambda*Lambda/b;
     124           0 :   if (itype == 1) mupisq = 3*Lambda*Lambda/b;
     125           0 :   if (itype == 2) mupisq = 3*Lambda*Lambda*(Gamma(1+0.5*b)*Gamma(0.5*b)/pow( Gamma(0.5 + 0.5*b), 2) - 1);
     126             : 
     127             :   // moment2 for SSFs
     128           0 :   moment2 = pow(0.3,3);
     129             : 
     130             :   // inputs for total rate (T for Total); use BLNP notebook defaults
     131           0 :   flagpower = 1;
     132           0 :   flag2loop = 1;
     133             : 
     134             :   // stuff for the integrator
     135           0 :   maxLoop = 20;
     136             :   //precision = 1.0e-3;
     137           0 :   precision = 2.0e-2;
     138             : 
     139             :   // vector of global variables, to pass to static functions (which can't access globals);
     140           0 :   gvars.push_back(0.0); // 0
     141           0 :   gvars.push_back(0.0); // 1
     142           0 :   gvars.push_back(mui); // 2
     143           0 :   gvars.push_back(b); // 3
     144           0 :   gvars.push_back(Lambda); // 4
     145           0 :   gvars.push_back(mBB); // 5
     146           0 :   gvars.push_back(mb); // 6
     147           0 :   gvars.push_back(wzero); // 7
     148           0 :   gvars.push_back(beta0); // 8
     149           0 :   gvars.push_back(beta1); // 9
     150           0 :   gvars.push_back(beta2); // 10
     151           0 :   gvars.push_back(dtype); // 11
     152             : 
     153             :   // check that there are 3 daughters and 10 arguments
     154           0 :   checkNDaug(3);
     155           0 :   checkNArg(10);
     156             : 
     157           0 : }
     158             : 
     159             : void EvtVubBLNP::initProbMax() {
     160           0 :   noProbMax();
     161           0 : }
     162             : 
     163             : void EvtVubBLNP::decay(EvtParticle *Bmeson) {
     164             : 
     165             :   int j;
     166             :   
     167             :   EvtParticle *xuhad, *lepton, *neutrino;
     168           0 :   EvtVector4R p4;
     169             :   double Pp, Pm, Pl, pdf, EX, sh, El, ml, mpi, ratemax;
     170             :   
     171             :   double xhigh, xlow, what;
     172             :   
     173           0 :   Bmeson->initializePhaseSpace(getNDaug(), getDaugs());
     174             :   
     175           0 :   xuhad = Bmeson->getDaug(0);
     176           0 :   lepton = Bmeson->getDaug(1);
     177           0 :   neutrino = Bmeson ->getDaug(2);
     178             : 
     179           0 :   mBB = Bmeson->mass();
     180           0 :   ml = lepton->mass();
     181             : 
     182             :   
     183             :   
     184             :   //  get SF value 
     185             :   xlow = 0;
     186           0 :   xhigh = mBB;    
     187             :   // the case for alphas = 0 is not considered 
     188           0 :   what = 2*xhigh;
     189           0 :   while( what > xhigh || what < xlow ) {
     190           0 :     what = findBLNPWhat(); 
     191           0 :     what = xlow + what*(xhigh-xlow);
     192             :   }
     193             :   
     194             :   
     195             :   
     196             :   bool tryit = true;
     197             :   
     198           0 :   while (tryit) {
     199             :     
     200             :     // generate pp between 0 and 
     201             :     // Flat(min, max) gives R(max - min) + min, where R = random btwn 0 and 1
     202             : 
     203           0 :     Pp = EvtRandom::Flat(0, mBB); // P+ = EX - |PX|
     204           0 :     Pl = EvtRandom::Flat(0, mBB);  // mBB - 2El
     205           0 :     Pm = EvtRandom::Flat(0, mBB); // P- = EX + |PX|
     206             : 
     207           0 :     sh = Pm*Pp;
     208           0 :     EX = 0.5*(Pm + Pp);
     209           0 :     El = 0.5*(mBB - Pl);
     210             : 
     211             :     // Need maximum rate.  Waiting for Mr. Paz to give it to me. 
     212             :     // Meanwhile, use this.
     213             :     ratemax = 3.0;  // From trial and error - most events below 3.0
     214             : 
     215             :     // kinematic bounds (Eq. 2)
     216             :     mpi = 0.14;
     217           0 :     if ((Pp > 0)&&(Pp <= Pl)&&(Pl <= Pm)&&(Pm < mBB)&&(El > ml)&&(sh > 4*mpi*mpi)) {
     218             : 
     219             :      // Probability of pass proportional to PDF
     220           0 :       pdf = rate3(Pp, Pl, Pm);
     221           0 :       double testRan = EvtRandom::Flat(0., ratemax);
     222           0 :       if (pdf >= testRan) tryit = false;
     223           0 :     }
     224             :   }
     225             :   // o.k. we have the three kineamtic variables 
     226             :   // now calculate a flat cos Theta_H [-1,1] distribution of the 
     227             :   // hadron flight direction w.r.t the B flight direction 
     228             :   // because the B is a scalar and should decay isotropic.
     229             :   // Then chose a flat Phi_H [0,2Pi] w.r.t the B flight direction 
     230             :   // and and a flat Phi_L [0,2Pi] in the W restframe w.r.t the 
     231             :   // W flight direction.
     232             :   
     233           0 :   double ctH = EvtRandom::Flat(-1,1);
     234           0 :   double phH = EvtRandom::Flat(0,2*M_PI);
     235           0 :   double phL = EvtRandom::Flat(0,2*M_PI);
     236             : 
     237             :   // now compute the four vectors in the B Meson restframe
     238             :     
     239             :   double ptmp,sttmp;
     240             :   // calculate the hadron 4 vector in the B Meson restframe
     241             :   
     242           0 :   sttmp = sqrt(1-ctH*ctH);
     243           0 :   ptmp = sqrt(EX*EX-sh);
     244           0 :   double pHB[4] = {EX,ptmp*sttmp*cos(phH),ptmp*sttmp*sin(phH),ptmp*ctH};
     245           0 :   p4.set(pHB[0],pHB[1],pHB[2],pHB[3]);
     246           0 :   xuhad->init( getDaug(0), p4);
     247             :   
     248             : 
     249             :   bool _storeWhat(true);
     250             :   
     251           0 :   if (_storeWhat ) {
     252             :     // cludge to store the hidden parameter what with the decay; 
     253             :     // the lifetime of the Xu is abused for this purpose.
     254             :     // tau = 1 ps corresponds to ctau = 0.3 mm -> in order to
     255             :     // stay well below BaBars sensitivity we take what/(10000 GeV).
     256             :     // To extract what back from the StdHepTrk its necessary to get
     257             :     // delta_ctau = Xu->decayVtx()->point().distanceTo(XuDaughter->decayVtx()->point());
     258             :     //
     259             :     // what = delta_ctau * 100000 * Mass_Xu/Momentum_Xu     
     260             :     //
     261           0 :     xuhad->setLifetime(what/10000.);
     262           0 :   }
     263             :   
     264             :   
     265             :   // calculate the W 4 vector in the B Meson restrframe
     266             : 
     267             :   double apWB = ptmp;
     268           0 :   double pWB[4] = {mBB-EX,-pHB[1],-pHB[2],-pHB[3]};
     269             : 
     270             :   // first go in the W restframe and calculate the lepton and
     271             :   // the neutrino in the W frame
     272             : 
     273           0 :   double mW2   = mBB*mBB + sh - 2*mBB*EX;
     274           0 :   double beta  = ptmp/pWB[0];
     275           0 :   double gamma = pWB[0]/sqrt(mW2);
     276             : 
     277           0 :   double pLW[4];
     278             :     
     279           0 :   ptmp = (mW2-ml*ml)/2/sqrt(mW2);
     280           0 :   pLW[0] = sqrt(ml*ml + ptmp*ptmp);
     281             : 
     282           0 :   double ctL = (El - gamma*pLW[0])/beta/gamma/ptmp;
     283           0 :   if ( ctL < -1 ) ctL = -1;
     284           0 :   if ( ctL >  1 ) ctL =  1;
     285           0 :   sttmp = sqrt(1-ctL*ctL);
     286             : 
     287             :   // eX' = eZ x eW
     288           0 :   double xW[3] = {-pWB[2],pWB[1],0};
     289             :   // eZ' = eW
     290           0 :   double zW[3] = {pWB[1]/apWB,pWB[2]/apWB,pWB[3]/apWB};
     291             :   
     292           0 :   double lx = sqrt(xW[0]*xW[0]+xW[1]*xW[1]);
     293           0 :   for (j=0;j<2;j++) 
     294           0 :     xW[j] /= lx;
     295             : 
     296             :   // eY' = eZ' x eX'
     297           0 :   double yW[3] = {-pWB[1]*pWB[3],-pWB[2]*pWB[3],pWB[1]*pWB[1]+pWB[2]*pWB[2]};
     298           0 :   double ly = sqrt(yW[0]*yW[0]+yW[1]*yW[1]+yW[2]*yW[2]);
     299           0 :   for (j=0;j<3;j++) 
     300           0 :     yW[j] /= ly;
     301             : 
     302             :   // p_lep = |p_lep| * (  sin(Theta) * cos(Phi) * eX'
     303             :   //                    + sin(Theta) * sin(Phi) * eY'
     304             :   //                    + cos(Theta) *            eZ')
     305           0 :   for (j=0;j<3;j++)
     306           0 :     pLW[j+1] = sttmp*cos(phL)*ptmp*xW[j] 
     307           0 :       +        sttmp*sin(phL)*ptmp*yW[j]
     308           0 :       +          ctL         *ptmp*zW[j];
     309             : 
     310             :   double apLW = ptmp;
     311             :     
     312             :   // boost them back in the B Meson restframe
     313             :   
     314           0 :   double appLB = beta*gamma*pLW[0] + gamma*ctL*apLW;
     315             :  
     316           0 :   ptmp = sqrt(El*El-ml*ml);
     317           0 :   double ctLL = appLB/ptmp;
     318             : 
     319           0 :   if ( ctLL >  1 ) ctLL =  1;
     320           0 :   if ( ctLL < -1 ) ctLL = -1;
     321             :     
     322           0 :   double pLB[4] = {El,0,0,0};
     323           0 :   double pNB[4] = {pWB[0]-El,0,0,0};
     324             : 
     325           0 :   for (j=1;j<4;j++) {
     326           0 :     pLB[j] = pLW[j] + (ctLL*ptmp - ctL*apLW)/apWB*pWB[j];
     327           0 :     pNB[j] = pWB[j] - pLB[j];
     328             :   }
     329             : 
     330           0 :   p4.set(pLB[0],pLB[1],pLB[2],pLB[3]);
     331           0 :   lepton->init( getDaug(1), p4);
     332             : 
     333           0 :   p4.set(pNB[0],pNB[1],pNB[2],pNB[3]);
     334           0 :   neutrino->init( getDaug(2), p4);
     335             : 
     336             :   return ;
     337             : 
     338           0 : }
     339             : 
     340             : double EvtVubBLNP::rate3(double Pp, double Pl, double Pm) {
     341             : 
     342             :   // rate3 in units of GF^2*Vub^2/pi^3
     343             : 
     344           0 :   double factor = 1.0/16*(mBB-Pp)*U1lo(muh, mui)*pow( (Pm - Pp)/(mBB - Pp), alo(muh, mui));
     345             : 
     346           0 :   double doneJS = DoneJS(Pp, Pm, mui);
     347           0 :   double done1 = Done1(Pp, Pm, mui);
     348           0 :   double done2 = Done2(Pp, Pm, mui);
     349           0 :   double done3 = Done3(Pp, Pm, mui);
     350             : 
     351             :   // The EvtSimpsonIntegrator returns zero for bad integrals.
     352             :   // So if any of the integrals are zero (ie bad), return zero.
     353             :   // This will cause pdf = 0, so the event will not pass.
     354             :   // I hope this will not introduce a bias.
     355           0 :   if (doneJS*done1*done2*done3 == 0.0) {
     356             :     //cout << "Integral failed: (Pp, Pm, Pl) = (" << Pp << ", " << Pm << ", " << Pl << ")" << endl;
     357           0 :     return 0.0;
     358             :   }
     359             :   //  if (doneJS*done1*done2*done3 != 0.0) {
     360             :   //    cout << "Integral OK: (Pp, Pm, Pl) = (" << Pp << ", " << Pm << ", " << Pl << ")" << endl;
     361             :   //}
     362             : 
     363           0 :   double f1 = F1(Pp, Pm, muh, mui, mubar, doneJS, done1);
     364           0 :   double f2 = F2(Pp, Pm, muh, mui, mubar, done3);
     365           0 :   double f3 = F3(Pp, Pm, muh, mui, mubar, done2);
     366           0 :   double answer = factor*( (mBB + Pl - Pp - Pm)*(Pm - Pl)*f1 + 2*(Pl - Pp)*(Pm - Pl)*f2 + (mBB - Pm)*(Pm - Pp)*f3 );
     367             :   return answer;
     368             : 
     369           0 : }
     370             : 
     371             : double EvtVubBLNP::F1(double Pp, double Pm, double muh, double mui, double mubar, double doneJS, double done1) {
     372             : 
     373           0 :   std::vector<double> vars(12);
     374           0 :   vars[0] = Pp;
     375           0 :   vars[1] = Pm;
     376           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     377             : 
     378           0 :   double y = (Pm - Pp)/(mBB - Pp);
     379           0 :   double ah = CF*alphas(muh, vars)/4/M_PI;
     380           0 :   double ai = CF*alphas(mui, vars)/4/M_PI;
     381           0 :   double abar = CF*alphas(mubar, vars)/4/M_PI;
     382           0 :   double lambda1 = -mupisq;
     383             : 
     384           0 :   double t1 = -4*ai/(Pp - Lbar)*(2*log((Pp - Lbar)/mui) + 1);
     385           0 :   double t2 = 1 + dU1nlo(muh, mui) + anlo(muh, mui)*log(y);
     386           0 :   double t3 = -4.0*pow(log(y*mb/muh),2) + 10.0*log(y*mb/muh) - 4.0*log(y) - 2.0*log(y)/(1-y) - 4.0*PolyLog(2, 1-y) - M_PI*M_PI/6.0 - 12.0;
     387           0 :   double t4 = 2*pow( log(y*mb*Pp/(mui*mui)), 2) - 3*log(y*mb*Pp/(mui*mui)) + 7 - M_PI*M_PI;
     388             : 
     389           0 :   double t5 = -wS(Pp) + 2*t(Pp) + (1.0/y - 1.0)*(u(Pp) - v(Pp));
     390           0 :   double t6 = -(lambda1 + 3.0*lambda2)/3.0 + 1.0/pow(y,2)*(4.0/3.0*lambda1 - 2.0*lambda2);
     391             : 
     392           0 :   double shapePp = Shat(Pp, vars);
     393             : 
     394           0 :   double answer = (t2 + ah*t3 + ai*t4)*shapePp + ai*doneJS + 1/(mBB - Pp)*(flag2*abar*done1 + flag1*t5) + 1/pow(mBB - Pp, 2)*flag3*shapePp*t6;
     395           0 :   if (Pp > Lbar + mui/exp(0.5)) answer = answer + t1;
     396             :   return answer;
     397             : 
     398           0 : }
     399             : 
     400             : double EvtVubBLNP::F2(double Pp, double Pm, double muh, double /*mui*/, double mubar, double done3) {
     401             :   
     402           0 :   std::vector<double> vars(12);
     403           0 :   vars[0] = Pp;
     404           0 :   vars[1] = Pm;
     405           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     406             : 
     407           0 :   double y = (Pm - Pp)/(mBB - Pp);
     408           0 :   double lambda1 = -mupisq;
     409           0 :   double ah = CF*alphas(muh, vars)/4/M_PI;
     410           0 :   double abar = CF*alphas(mubar, vars)/4/M_PI;
     411             : 
     412           0 :   double t6 = -wS(Pp) - 2*t(Pp) + 1.0/y*(t(Pp) + v(Pp));
     413           0 :   double t7 = 1/pow(y,2)*(2.0/3.0*lambda1 + 4.0*lambda2) - 1/y*(2.0/3.0*lambda1 + 3.0/2.0*lambda2);
     414             : 
     415           0 :   double shapePp = Shat(Pp, vars);
     416             : 
     417           0 :   double answer = ah*log(y)/(1-y)*shapePp + 1/(mBB - Pp)*(flag2*abar*0.5*done3 + flag1/y*t6) + 1.0/pow(mBB - Pp,2)*flag3*shapePp*t7;
     418             :   return answer;
     419             : 
     420           0 : }
     421             : 
     422             : double EvtVubBLNP::F3(double Pp, double Pm, double /*muh*/, double /*mui*/, double mubar, double done2) {
     423             : 
     424           0 :   std::vector<double> vars(12);
     425           0 :   vars[0] = Pp;
     426           0 :   vars[1] = Pm;
     427           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     428             :   
     429           0 :   double y = (Pm - Pp)/(mBB - Pp);
     430           0 :   double lambda1 = -mupisq;
     431           0 :   double abar = CF*alphas(mubar, vars)/4/M_PI;
     432             : 
     433           0 :   double t7 = 1.0/pow(y,2)*(-2.0/3.0*lambda1 + lambda2);
     434             : 
     435           0 :   double shapePp = Shat(Pp, vars);
     436             : 
     437           0 :   double answer = 1.0/(Pm - Pp)*flag2*0.5*y*abar*done2 + 1.0/pow(mBB-Pp,2)*flag3*shapePp*t7;
     438             :   return answer;
     439             : 
     440           0 : }
     441             : 
     442             : double EvtVubBLNP::DoneJS(double Pp, double Pm, double /*mui*/) {
     443             : 
     444           0 :   std::vector<double> vars(12);
     445           0 :   vars[0] = Pp;
     446           0 :   vars[1] = Pm;
     447           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     448             :   
     449           0 :   double lowerlim = 0.001*Pp;
     450           0 :   double upperlim = (1.0-0.001)*Pp;
     451             : 
     452           0 :   EvtItgPtrFunction *func = new EvtItgPtrFunction(&IntJS, lowerlim, upperlim, vars);
     453           0 :   EvtItgSimpsonIntegrator *integ = new EvtItgSimpsonIntegrator(*func, precision, maxLoop);
     454           0 :   double myintegral = integ->evaluate(lowerlim, upperlim);
     455           0 :   delete integ;
     456           0 :   delete func;
     457             :   return myintegral;
     458             : 
     459           0 : }
     460             : 
     461             : double EvtVubBLNP::Done1(double Pp, double Pm, double /*mui*/) {
     462             : 
     463           0 :   std::vector<double> vars(12);
     464           0 :   vars[0] = Pp;
     465           0 :   vars[1] = Pm;
     466           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     467             : 
     468           0 :   double lowerlim = 0.001*Pp;
     469           0 :   double upperlim = (1.0-0.001)*Pp;
     470             : 
     471           0 :   EvtItgPtrFunction *func = new EvtItgPtrFunction(&Int1, lowerlim, upperlim, vars);
     472           0 :   EvtItgSimpsonIntegrator *integ = new EvtItgSimpsonIntegrator(*func, precision, maxLoop);
     473           0 :   double myintegral = integ->evaluate(lowerlim, upperlim);
     474           0 :   delete integ;
     475           0 :   delete func;
     476             :   return myintegral;
     477             : 
     478           0 : }
     479             : 
     480             : double EvtVubBLNP::Done2(double Pp, double Pm, double /*mui*/) {
     481             : 
     482           0 :   std::vector<double> vars(12);
     483           0 :   vars[0] = Pp;
     484           0 :   vars[1] = Pm;
     485           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     486             : 
     487           0 :   double lowerlim = 0.001*Pp;
     488           0 :   double upperlim = (1.0-0.001)*Pp;
     489             : 
     490           0 :   EvtItgPtrFunction *func = new EvtItgPtrFunction(&Int2, lowerlim, upperlim, vars);
     491           0 :   EvtItgSimpsonIntegrator *integ = new EvtItgSimpsonIntegrator(*func, precision, maxLoop);
     492           0 :   double myintegral = integ->evaluate(lowerlim, upperlim);
     493           0 :   delete integ;
     494           0 :   delete func;
     495             :   return myintegral;
     496             : 
     497           0 : }
     498             : 
     499             : double EvtVubBLNP::Done3(double Pp, double Pm, double /*mui*/) {
     500             : 
     501           0 :   std::vector<double> vars(12);
     502           0 :   vars[0] = Pp;
     503           0 :   vars[1] = Pm;
     504           0 :   for (int j=2;j<12;j++) {vars[j] = gvars[j];}
     505             : 
     506           0 :   double lowerlim = 0.001*Pp;
     507           0 :   double upperlim = (1.0-0.001)*Pp;  
     508             : 
     509           0 :   EvtItgPtrFunction *func = new EvtItgPtrFunction(&Int3, lowerlim, upperlim, vars);
     510           0 :   EvtItgSimpsonIntegrator *integ = new EvtItgSimpsonIntegrator(*func, precision, maxLoop);
     511           0 :   double myintegral = integ->evaluate(lowerlim, upperlim);
     512           0 :   delete integ;
     513           0 :   delete func;
     514             :   return myintegral;
     515             : 
     516           0 : }
     517             : 
     518             : double EvtVubBLNP::Int1(double what, const std::vector<double> &vars) {
     519           0 :   return Shat(what, vars)*g1(what, vars);
     520             : }
     521             : 
     522             : double EvtVubBLNP::Int2(double what, const std::vector<double> &vars) {
     523           0 :   return Shat(what, vars)*g2(what, vars);
     524             : }
     525             : 
     526             : double EvtVubBLNP::Int3(double what, const std::vector<double> &vars) {
     527           0 :   return Shat(what, vars)*g3(what, vars);
     528             : }
     529             : 
     530             : double EvtVubBLNP::IntJS(double what, const std::vector<double> &vars) {
     531             :   
     532           0 :   double Pp = vars[0];
     533           0 :   double Pm = vars[1];
     534           0 :   double mui = vars[2];
     535           0 :   double mBB = vars[5];
     536           0 :   double mb = vars[6];
     537           0 :   double y = (Pm - Pp)/(mBB - Pp);
     538             :   
     539           0 :   return 1/(Pp-what)*(Shat(what, vars) - Shat(Pp, vars))*(4*log(y*mb*(Pp-what)/(mui*mui)) - 3);
     540             : }
     541             : 
     542             : double EvtVubBLNP::g1(double w, const std::vector<double> &vars) {
     543             : 
     544           0 :   double Pp = vars[0];
     545           0 :   double Pm = vars[1];
     546           0 :   double mBB = vars[5];
     547           0 :   double y = (Pm - Pp)/(mBB - Pp);
     548           0 :   double x = (Pp - w)/(mBB - Pp);
     549             : 
     550           0 :   double q1 = (1+x)*(1+x)*y*(x+y);
     551           0 :   double q2 = y*(-9 + 10*y) + x*x*(-12.0 + 13.0*y) + 2*x*(-8.0 + 6*y + 3*y*y);
     552           0 :   double q3 = 4/x*log(y + y/x);
     553           0 :   double q4 = 3.0*pow(x,4)*(-2.0 + y) - 2*pow(y,3) - 4*pow(x,3)*(2.0+y) - 2*x*y*y*(4+y) - x*x*y*(12 + 4*y + y*y);
     554           0 :   double q5 = log(1 + y/x);
     555             : 
     556           0 :   double answer = q2/q1 - q3 - 2*q4*q5/(q1*y*x);
     557           0 :   return answer;
     558             : 
     559             : }
     560             : 
     561             : double EvtVubBLNP::g2(double w, const std::vector<double> &vars) {
     562             : 
     563           0 :   double Pp = vars[0];
     564           0 :   double Pm = vars[1];
     565           0 :   double mBB = vars[5];
     566           0 :   double y = (Pm - Pp)/(mBB - Pp);
     567           0 :   double x = (Pp - w)/(mBB - Pp);
     568             : 
     569           0 :   double q1 = (1+x)*(1+x)*pow(y,3)*(x+y);
     570           0 :   double q2 = 10.0*pow(x,4) + y*y + 3.0*pow(x,2)*y*(10.0+y) + pow(x,3)*(12.0+19.0*y) + x*y*(8.0 + 4.0*y + y*y);
     571           0 :   double q3 = 5*pow(x,4) + 2.0*y*y + 6.0*pow(x,3)*(1.0+2.0*y) + 4.0*x*y*(1+2.0*y) + x*x*y*(18.0+5.0*y);
     572           0 :   double q4 = log(1 + y/x);
     573             : 
     574           0 :   double answer = 2.0/q1*( y*q2 - 2*x*q3*q4);
     575           0 :   return answer;
     576             : 
     577             : }
     578             : 
     579             : double EvtVubBLNP::g3(double w, const std::vector<double> &vars) {
     580             : 
     581           0 :   double Pp = vars[0];
     582           0 :   double Pm = vars[1];
     583           0 :   double mBB = vars[5];
     584           0 :   double y = (Pm - Pp)/(mBB - Pp);
     585           0 :   double x = (Pp - w)/(mBB - Pp);
     586             : 
     587           0 :   double q1 = (1+x)*(1+x)*pow(y,3)*(x+y);
     588           0 :   double q2 =  2.0*pow(y,3)*(-11.0+2.0*y) - 10.0*pow(x,4)*(6 - 6*y + y*y) + x*y*y*(-94.0 + 29.0*y + 2.0*y*y) + 2.0*x*x*y*(-72.0 +18.0*y + 13.0*y*y) - x*x*x*(72.0 + 42.0*y - 70.0*y*y + 3.0*y*y*y);
     589           0 :   double q3 =  -6.0*x*(-5.0+y)*pow(y,3) + 4*pow(y,4) + 5*pow(x,5)*(6-6*y + y*y) - 4*x*x*y*y*(-20.0 + 6*y + y*y) + pow(x,3)*y*(90.0 - 10.0*y - 28.0*y*y + y*y*y) + pow(x,4)*(36.0 + 36.0*y - 50.0*y*y + 4*y*y*y);
     590           0 :   double q4 = log(1 + y/x);
     591             : 
     592           0 :   double answer = q2/q1 + 2/q1/y*q3*q4;
     593           0 :   return answer;
     594             : 
     595             : }
     596             : 
     597             : 
     598             : double EvtVubBLNP::Shat(double w, const std::vector<double> &vars) {
     599             : 
     600           0 :   double mui = vars[2];
     601           0 :   double b = vars[3];
     602           0 :   double Lambda = vars[4];
     603           0 :   double wzero = vars[7];
     604           0 :   int itype = (int)vars[11];
     605             : 
     606             :   double norm = 0.0;
     607             :   double shape = 0.0;
     608             : 
     609           0 :   if (itype == 1) {
     610             : 
     611           0 :     double Lambar = (Lambda/b)*(Gamma(1+b)-Gamma(1+b,b*wzero/Lambda))/(Gamma(b) - Gamma(b, b*wzero/Lambda));
     612           0 :     double muf = wzero - Lambar;
     613           0 :     double mupisq = 3*pow(Lambda,2)/pow(b,2)*(Gamma(2+b) - Gamma(2+b, b*wzero/Lambda))/(Gamma(b) - Gamma(b, b*wzero/Lambda)) - 3*Lambar*Lambar;
     614           0 :     norm = Mzero(muf, mui, mupisq, vars)*Gamma(b)/(Gamma(b) - Gamma(b, b*wzero/Lambda));
     615           0 :     shape = pow(b,b)/Lambda/Gamma(b)*pow(w/Lambda, b-1)*exp(-b*w/Lambda);
     616           0 :   }
     617             : 
     618           0 :   if (itype == 2) {
     619           0 :     double dcoef = pow( Gamma(0.5*(1+b))/Gamma(0.5*b), 2);
     620           0 :     double t1 =  wzero*wzero*dcoef/(Lambda*Lambda);
     621           0 :     double Lambar = Lambda*(Gamma(0.5*(1+b)) - Gamma(0.5*(1+b),t1))/pow(dcoef, 0.5)/(Gamma(0.5*b) - Gamma(0.5*b, t1));
     622           0 :     double muf = wzero - Lambar;
     623           0 :     double mupisq = 3*Lambda*Lambda*( Gamma(1+0.5*b) - Gamma(1+0.5*b, t1))/dcoef/(Gamma(0.5*b) - Gamma(0.5*b, t1)) - 3*Lambar*Lambar;
     624           0 :     norm = Mzero(muf, mui, mupisq, vars)*Gamma(0.5*b)/(Gamma(0.5*b) - Gamma(0.5*b, wzero*wzero*dcoef/(Lambda*Lambda)));
     625           0 :     shape = 2*pow(dcoef, 0.5*b)/Lambda/Gamma(0.5*b)*pow(w/Lambda, b-1)*exp(-dcoef*w*w/(Lambda*Lambda));
     626           0 :   }
     627             : 
     628           0 :   double answer = norm*shape;
     629           0 :   return answer;
     630             : }
     631             : 
     632             : double EvtVubBLNP::Mzero(double muf, double mu, double mupisq, const std::vector<double> &vars) {
     633             : 
     634             :   double CF = 4.0/3.0;
     635           0 :   double amu = CF*alphas(mu, vars)/M_PI;
     636           0 :   double answer = 1 - amu*( pow(log(muf/mu), 2) + log(muf/mu) + M_PI*M_PI/24.0) + amu*(log(muf/mu) - 0.5)*mupisq/(3*muf*muf);
     637           0 :   return answer;
     638             : 
     639             : }
     640             : 
     641             : double EvtVubBLNP::wS(double w) {
     642             : 
     643           0 :   double answer = (Lbar - w)*Shat(w, gvars);
     644           0 :   return answer;
     645             : }
     646             : 
     647             : double EvtVubBLNP::t(double w) {
     648             : 
     649           0 :   double t1 = -3*lambda2/mupisq*(Lbar - w)*Shat(w, gvars);
     650           0 :   double myf = myfunction(w, Lbar, moment2);
     651           0 :   double myBIK = myfunctionBIK(w, Lbar, moment2);
     652             :   double answer = t1;
     653             : 
     654           0 :   if (isubl == 1) answer = t1;
     655           0 :   if (isubl == 3) answer = t1 - myf;
     656           0 :   if (isubl == 4) answer = t1 + myf;
     657           0 :   if (isubl == 5) answer = t1 - myBIK;
     658           0 :   if (isubl == 6) answer = t1 + myBIK;
     659             : 
     660           0 :   return answer;
     661             : }
     662             : 
     663             : double EvtVubBLNP::u(double w) {
     664             : 
     665           0 :   double u1 = -2*(Lbar - w)*Shat(w, gvars);
     666           0 :   double myf = myfunction(w, Lbar, moment2);
     667           0 :   double myBIK = myfunctionBIK(w, Lbar, moment2);
     668             :   double answer = u1;
     669             : 
     670           0 :   if (isubl == 1) answer = u1;
     671           0 :   if (isubl == 3) answer = u1 + myf;
     672           0 :   if (isubl == 4) answer = u1 - myf;
     673           0 :   if (isubl == 5) answer = u1 + myBIK;
     674           0 :   if (isubl == 6) answer = u1 - myBIK;
     675             : 
     676           0 :   return answer;
     677             : }
     678             : 
     679             : double EvtVubBLNP::v(double w) {
     680             : 
     681           0 :   double v1 = 3*lambda2/mupisq*(Lbar - w)*Shat(w, gvars);
     682           0 :   double myf = myfunction(w, Lbar, moment2);
     683           0 :   double myBIK = myfunctionBIK(w, Lbar, moment2);
     684             :   double answer = v1;
     685             : 
     686           0 :   if (isubl == 1) answer = v1;
     687           0 :   if (isubl == 3) answer = v1 - myf;
     688           0 :   if (isubl == 4) answer = v1 + myf;
     689           0 :   if (isubl == 5) answer = v1 - myBIK;
     690           0 :   if (isubl == 6) answer = v1 + myBIK;
     691             : 
     692           0 :   return answer;
     693             : }
     694             : 
     695             : double EvtVubBLNP::myfunction(double w, double Lbar, double mom2) {
     696             : 
     697             :   double bval = 5.0;
     698           0 :   double x = w/Lbar;
     699           0 :   double factor = 0.5*mom2*pow(bval/Lbar, 3);
     700           0 :   double answer = factor*exp(-bval*x)*(1 - 2*bval*x + 0.5*bval*bval*x*x);
     701           0 :   return answer;
     702             : 
     703             : }
     704             : 
     705             : double EvtVubBLNP::myfunctionBIK(double w, double Lbar, double /*mom2*/) {
     706             : 
     707             :   double aval = 10.0;
     708           0 :   double normBIK = (4 - M_PI)*M_PI*M_PI/8/(2-M_PI)/aval + 1;
     709           0 :   double z = 3*M_PI*w/8/Lbar;
     710           0 :   double q = M_PI*M_PI*2*pow(M_PI*aval, 0.5)*exp(-aval*z*z)/(4*M_PI - 8)*(1 - 2*pow(aval/M_PI, 0.5)*z) + 8/pow(1+z*z, 4)*(z*log(z) + 0.5*z*(1+z*z) - M_PI/4*(1-z*z));
     711           0 :   double answer = q/normBIK;
     712           0 :   return answer;
     713             : 
     714             : }
     715             : 
     716             : double EvtVubBLNP::dU1nlo(double muh, double mui) { 
     717             : 
     718           0 :   double ai = alphas(mui, gvars);
     719           0 :   double ah = alphas(muh, gvars);
     720             : 
     721           0 :   double q1 = (ah - ai)/(4*M_PI*beta0);
     722           0 :   double q2 = log(mb/muh)*Gamma1 + gp1;
     723           0 :   double q3 = 4*beta1*(log(mb/muh)*Gamma0 + gp0) + Gamma2*(1-ai/ah);
     724           0 :   double q4 = beta1*beta1*Gamma0*(-1.0 + ai/ah)/(4*pow(beta0,3));
     725           0 :   double q5 = -beta2*Gamma0*(1.0 + ai/ah) + beta1*Gamma1*(3 - ai/ah);
     726           0 :   double q6 = beta1*beta1*Gamma0*(ah - ai)/beta0 - beta2*Gamma0*ah + beta1*Gamma1*ai;
     727             :   
     728           0 :   double answer = q1*(q2 - q3/4/beta0 + q4 + q5/(4*beta0*beta0)) + 1/(8*M_PI*beta0*beta0*beta0)*log(ai/ah)*q6;
     729           0 :   return answer;
     730             : }
     731             : 
     732             : double EvtVubBLNP::U1lo(double muh, double mui) {
     733             :   double epsilon = 0.0;
     734           0 :   double answer = pow(mb/muh, -2*aGamma(muh, mui, epsilon))*exp(2*Sfun(muh, mui, epsilon) - 2*agp(muh, mui, epsilon));
     735           0 :   return answer;
     736             : }
     737             : 
     738             : double EvtVubBLNP::Sfun(double mu1, double mu2, double epsilon) {
     739           0 :   double a1 = alphas(mu1, gvars)/4/M_PI;
     740           0 :   double a2 = alphas(mu2, gvars)/alphas(mu1, gvars);
     741             : 
     742           0 :   double answer = S0(a1,a2) + S1(a1,a2) + epsilon*S2(a1,a2);
     743           0 :   return answer;
     744             : 
     745             : }
     746             : 
     747             : double EvtVubBLNP::S0(double a1, double r) {
     748           0 :   double answer = -Gamma0/(4.0*beta0*beta0*a1)*(-1.0 + 1.0/r + log(r));
     749           0 :   return answer;
     750             : }
     751             : 
     752             : double EvtVubBLNP::S1(double /*a1*/, double r) {
     753           0 :   double answer = Gamma0/(4*beta0*beta0)*(0.5*log(r)*log(r)*beta1/beta0 + (Gamma1/Gamma0 - beta1/beta0)*(1 - r + log(r)));
     754           0 :   return answer;
     755             : }
     756             : 
     757             : double EvtVubBLNP::S2(double a1, double r) {
     758             : 
     759           0 :   double w1 = pow(beta1,2)/pow(beta0,2) - beta2/beta0 - beta1*Gamma1/(beta0*Gamma0) + Gamma2/Gamma0;
     760             :   double w2 = pow(beta1,2)/pow(beta0,2) - beta2/beta0;
     761           0 :   double w3 = beta1*Gamma1/(beta0*Gamma0) - beta2/beta0;
     762           0 :   double w4 = a1*Gamma0/(4*beta0*beta0);
     763             : 
     764           0 :   double answer = w4*(-0.5*pow(1-r,2)*w1 + w2*(1-r)*log(r) + w3*(1-r+r*log(r)));
     765           0 :   return answer;
     766             : }
     767             : 
     768             : double EvtVubBLNP::aGamma(double mu1, double mu2, double epsilon) {
     769           0 :   double a1 = alphas(mu1, gvars);
     770           0 :   double a2 = alphas(mu2, gvars);
     771           0 :   double answer = Gamma0/(2*beta0)*log(a2/a1) + epsilon*(a2-a1)/(8.0*M_PI)*(Gamma1/beta0 - beta1*Gamma0/(beta0*beta0));
     772           0 :   return answer;
     773             : }
     774             : 
     775             : double EvtVubBLNP::agp(double mu1, double mu2, double epsilon) { 
     776           0 :   double a1 = alphas(mu1, gvars);
     777           0 :   double a2 = alphas(mu2, gvars);
     778           0 :   double answer = gp0/(2*beta0)*log(a2/a1) + epsilon*(a2-a1)/(8.0*M_PI)*(gp1/beta0 - beta1*gp0/(beta0*beta0));
     779           0 :   return answer;
     780             : }
     781             : 
     782           0 : double EvtVubBLNP::alo(double muh, double mui) { return -2.0*aGamma(muh, mui, 0);}
     783             : 
     784             : double EvtVubBLNP::anlo(double muh, double mui) {   // d/depsilon of aGamma
     785             : 
     786           0 :   double ah = alphas(muh, gvars);
     787           0 :   double ai = alphas(mui, gvars);
     788           0 :   double answer = (ah-ai)/(8.0*M_PI)*(Gamma1/beta0 - beta1*Gamma0/(beta0*beta0));
     789           0 :   return answer;
     790             : }
     791             : 
     792             : double EvtVubBLNP::alphas(double mu, const std::vector<double> &vars) {
     793             : 
     794             :   // Note: Lambda4 and Lambda5 depend on mbMS = 4.25
     795             :   // So if you change mbMS, then you will have to recalculate them.
     796             : 
     797           0 :   double beta0 = vars[8];
     798           0 :   double beta1 = vars[9];
     799           0 :   double beta2 = vars[10];
     800             :   
     801             :   double Lambda4 = 0.298791;
     802           0 :   double lg = 2*log(mu/Lambda4);
     803           0 :   double answer = 4*M_PI/(beta0*lg)*( 1 - beta1*log(lg)/(beta0*beta0*lg) + beta1*beta1/(beta0*beta0*beta0*beta0*lg*lg)*( (log(lg) - 0.5)*(log(lg) - 0.5) - 5.0/4.0 + beta2*beta0/(beta1*beta1)));
     804           0 :   return answer;
     805             :     
     806             : }
     807             : 
     808             : double EvtVubBLNP::PolyLog(double v, double z) {
     809             : 
     810           0 :   if (z >= 1) cout << "Error in EvtVubBLNP: 2nd argument to PolyLog is >= 1." << endl;
     811             : 
     812             :   double sum = 0.0;
     813           0 :   for (int k=1; k<101; k++) { 
     814           0 :     sum = sum + pow(z,k)/pow(k,v);
     815             :   }
     816           0 :   return sum;
     817             : }
     818             : 
     819             : double EvtVubBLNP::Gamma(double z)
     820             : {
     821           0 :    if (z<=0) return 0;
     822             : 
     823           0 :    double v = lgamma(z);
     824           0 :    return exp(v);
     825           0 : }
     826             : 
     827             : double EvtVubBLNP::Gamma(double a, double x)
     828             : {
     829             :     double LogGamma;
     830             :     /*    if (x<0.0 || a<= 0.0) raise(SIGFPE);*/
     831           0 :     if(x<0.0) x=0.0;
     832           0 :     if(a<=0.0)a=1.e-50;
     833           0 :     LogGamma = lgamma(a);
     834           0 :     if (x < (a+1.0)) 
     835           0 :         return gamser(a,x,LogGamma);
     836             :     else 
     837           0 :         return 1.0-gammcf(a,x,LogGamma);
     838           0 : }
     839             : 
     840             : /* ------------------Incomplete gamma function-----------------*/
     841             : /* ------------------via its series representation-------------*/
     842             :               
     843             : double EvtVubBLNP::gamser(double a, double x, double LogGamma)
     844             : {
     845             :     double n;
     846             :     double ap,del,sum;
     847             : 
     848             :     ap=a;
     849           0 :     del=sum=1.0/a;
     850           0 :     for (n=1;n<ITMAX;n++) {
     851           0 :         ++ap;
     852           0 :         del *= x/ap;
     853           0 :         sum += del;
     854           0 :         if (fabs(del) < fabs(sum)*EPS) return sum*exp(-x + a*log(x) - LogGamma);
     855             :     }
     856           0 :     raise(SIGFPE);
     857             :     
     858           0 :     return 0.0;
     859           0 : }        
     860             : 
     861             : /* ------------------Incomplete gamma function complement------*/
     862             : /* ------------------via its continued fraction representation-*/
     863             : 
     864             : double EvtVubBLNP::gammcf(double a, double x, double LogGamma) {
     865             :   
     866             :     double an,b,c,d,del,h;
     867             :     int i;
     868             : 
     869           0 :     b = x + 1.0 -a;
     870             :     c = 1.0/FPMIN;
     871           0 :     d = 1.0/b;
     872             :     h = d;
     873           0 :     for (i=1;i<ITMAX;i++) {
     874           0 :         an = -i*(i-a);
     875           0 :         b+=2.0;
     876           0 :         d=an*d+b;
     877           0 :         if (fabs(d) < FPMIN) d = FPMIN;
     878           0 :         c = b+an/c;
     879           0 :         if (fabs(c) < FPMIN) c = FPMIN;
     880           0 :         d = 1.0/d;
     881           0 :         del=d*c;
     882           0 :         h *= del;
     883           0 :         if (fabs(del-1.0) < EPS) return exp(-x+a*log(x)-LogGamma)*h;  
     884             :     }
     885           0 :     raise(SIGFPE);
     886             : 
     887           0 :     return 0.0;
     888             : 
     889           0 : }
     890             : 
     891             : 
     892             : double EvtVubBLNP::findBLNPWhat() {
     893             : 
     894           0 :   double ranNum=EvtRandom::Flat();
     895           0 :   double oOverBins= 1.0/(float(_pf.size()));
     896             :   int nBinsBelow = 0;     // largest k such that I[k] is known to be <= rand
     897           0 :   int nBinsAbove = _pf.size();  // largest k such that I[k] is known to be >  rand
     898             :   int middle;
     899             :   
     900           0 :   while (nBinsAbove > nBinsBelow+1) {
     901           0 :     middle = (nBinsAbove + nBinsBelow+1)>>1;
     902           0 :     if (ranNum >= _pf[middle]) {
     903             :       nBinsBelow = middle;
     904           0 :     } else {
     905             :       nBinsAbove = middle;
     906             :     }
     907             :   } 
     908             : 
     909           0 :   double bSize = _pf[nBinsAbove] - _pf[nBinsBelow];
     910             :   // binMeasure is always aProbFunc[nBinsBelow], 
     911             :   
     912           0 :   if ( bSize == 0 ) { 
     913             :     // rand lies right in a bin of measure 0.  Simply return the center
     914             :     // of the range of that bin.  (Any value between k/N and (k+1)/N is 
     915             :     // equally good, in this rare case.)
     916           0 :     return (nBinsBelow + .5) * oOverBins;
     917             :   }
     918             :   
     919           0 :   double bFract = (ranNum - _pf[nBinsBelow]) / bSize;
     920             :   
     921           0 :   return (nBinsBelow + bFract) * oOverBins;
     922             :   
     923           0 : } 

Generated by: LCOV version 1.11