Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Ranbo.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of Gismo 2
00004 // Implementation of the phase space generator Ranbo
00005 
00006 #include "Ranbo.h"
00007 
00008 #include "Random.h"  //TODO fix
00009 static inline double sqr(double x) { return x*x;}
00010 
00011 HepRandom* ran;  // file scope to pass to Ran4Vec constructor
00012 
00013 Ranbo::Ranbo(double W, unsigned n, double mu[], HepRandom& _ran)
00014 {
00015 
00016         // create a set of randomized 4-momenta (see constructor)
00017         ran = &_ran;
00018         q =  new Ran4Vec[n] ;
00019 
00020         HepLorentzVector qsum;
00021         unsigned i;
00022         for(  i=0; i<n; i++)
00023           qsum += q[i];
00024 
00025         double x = W/qsum.mag();
00026         Hep3Vector beta = -qsum.boostVector();
00027 
00028         // now boost to CM and rescale to correct total energy
00029         for(i=0; i<n; i++)
00030         {
00031                 q[i].boost(beta);
00032                 q[i] *= x;
00033         }
00034 
00035         // iterate to find factor to multiply all 3-momenta so that
00036         // total energy is OK
00037         double xisq = 1;  // start from here
00038         double* musq = new double[n];
00039         double* psq = new double[n];
00040         double* energy = new double[n];
00041         for( i=0; i<n; i++)
00042         {
00043                 musq[i]= sqr(mu[i]);
00044                 psq[i] = sqr(q[i].t());
00045         }
00046         if( n==2 ) // this case is exact
00047         {
00048                 xisq = (1-sqr((mu[0]+mu[1])/W))
00049                                 *(1-sqr((mu[0]-mu[1])/W));
00050         }
00051         else   // otherwise iterate
00052         {
00053           double f,df;   // E-conservation function & deriviate
00054           do
00055           {
00056                  f = -W; df=0;
00057                  for( i=0; i<n; i++)
00058                  {  double e = energy[i] = sqrt(musq[i]+xisq*psq[i]);
00059                         f += e;
00060                         df += psq[i]/e;
00061                  }
00062                  df *= 0.5;
00063                  xisq -= f/df;
00064           }while( fabs(f)>1e-6*W ); // this should always converge
00065         }
00066         if( xisq != 1 )
00067         {
00068           double xi = sqrt(xisq);
00069           for( i=0; i<n; i++)
00070                  (Hep3Vector&)q[i] *= xi;
00071         }
00072         // finally calculate weight
00073         double numerator=W,denominator=0;
00074         for(i=0; i<n; i++)
00075         {
00076                 double betasq = xisq*psq[i]/sqr(energy[i]);
00077                 numerator *= sqrt(betasq);
00078                 denominator += betasq*energy[i];
00079         }
00080         _weight = numerator/denominator*pow(sqrt(xisq),int(2*n-3));
00081 
00082         delete [] musq;
00083         delete [] psq;
00084         delete [] energy;
00085 }
00086 
00087 Ranbo::~Ranbo()
00088 {
00089         delete []q;
00090 }
00091 
00092 
00093 Ranbo::Ran4Vec::Ran4Vec()
00094 {
00095   double c = -1 + 2*ran->flat();
00096   double phi = 2*M_PI*ran->flat();
00097   double r = -log(ran->flat()*ran->flat());
00098   double s = sqrt(1-c*c);
00099   setX(r*s*cos(phi));
00100   setY(r*s*sin(phi));
00101   setZ(r*c);
00102   setT(r);
00103 }
00104 
00105 Ranbo::Ran4Vec &
00106 Ranbo::Ran4Vec::operator *= (float f)
00107 {
00108           setX(f*x());
00109           setY(f*y());
00110           setZ(f*z());
00111           setT(f*t());
00112           return *this;
00113 }
00114 
00115 

Generated at Mon Nov 26 18:18:34 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000