CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/FastSimulation/Utilities/src/GaussianTail.cc

Go to the documentation of this file.
00001 #include "FastSimulation/Utilities/interface/GaussianTail.h"
00002 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00003 
00004 #include <cmath>
00005 GaussianTail::GaussianTail(const RandomEngine* engine,
00006                            double sigma,double threshold) : 
00007   random(engine),
00008   sigma_(sigma),
00009   threshold_(threshold)
00010 {
00011   s_=threshold_/sigma_;
00012   ssquare_ = s_ * s_;
00013 }
00014 
00015 GaussianTail::~GaussianTail()
00016 {
00017   ;
00018 }
00019 
00020 double GaussianTail::shoot() const
00021 {
00022   // in the zero suppresion case, s is usually >2 
00023   if(s_>1.)
00024     {
00025       /* Use the "supertail" deviates from the last two steps
00026        * of Marsaglia's rectangle-wedge-tail method, as described
00027        * in Knuth, v2, 3rd ed, pp 123-128.  (See also exercise 11, p139,
00028        * and the solution, p586.)
00029        */
00030       
00031       double u, v, x;
00032       
00033       do
00034         {
00035           u = random->flatShoot();
00036           do
00037             {
00038               v = random->flatShoot();
00039             }
00040           while (v == 0.0);
00041           x = std::sqrt (ssquare_ - 2 * std::log (v));
00042         }
00043       while (x * u > s_);
00044       return x * sigma_;
00045     }
00046   else
00047     {
00048        /* For small s, use a direct rejection method. The limit s < 1
00049          can be adjusted to optimise the overall efficiency 
00050        */
00051       
00052       double x;
00053 
00054       do
00055         {
00056           x = random->gaussShoot();
00057         }
00058       while (x < s_);
00059       return x * sigma_; 
00060     }
00061 }