CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FastSimulation/ShowerDevelopment/src/RadialInterval.cc

Go to the documentation of this file.
00001 //FAMOS header
00002 #include "FastSimulation/ShowerDevelopment/interface/RadialInterval.h"
00003 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00004 
00005 #include <cmath>
00006 
00007 RadialInterval::RadialInterval(double RC,unsigned nSpots,double energy,
00008                                const RandomEngine* engine)
00009   :
00010   theR(RC),theNumberOfSpots(nSpots),theSpotEnergy(energy),random(engine)
00011 {
00012 
00013   currentRad=0.;
00014   currentEnergyFraction=0.;
00015   currentUlim=0.;
00016   nInter=0;
00017 }
00018 
00019 void RadialInterval::addInterval(double radius, double spotf)
00020 {
00021   double radiussq=radius*radius;
00022   double enFrac=energyFractionInRadius(radius);
00023   if(radius>10) enFrac=1.;
00024   double energyFrac=enFrac-currentEnergyFraction;
00025   currentEnergyFraction=enFrac;
00026   //  std::cout << " Rad " << nInter << " Energy frac " << energyFrac << std::endl;
00027   
00028   // Calculates the number of spots. Add binomial fluctuations
00029   double dspot = random->gaussShoot(theNumberOfSpots*energyFrac,
00030                             sqrt(energyFrac*(1.-energyFrac)*theNumberOfSpots));
00031   //  std::cout << " Normal : " << theNumberOfSpots*energyFrac << " "<< dspot << std::endl;
00032   unsigned nspot=(unsigned)(dspot*spotf+0.5);
00033 //  if(nspot<100) 
00034 //    {
00035 //      spotf=1.;
00036 //      nspot=(unsigned)(theNumberOfSpots*energyFrac+0.5);
00037 //    }
00038   
00039   dspotsunscaled.push_back(dspot);
00040   spotfraction.push_back(spotf);
00041 
00042   double spotEnergy=theSpotEnergy/spotf;
00043   //  std::cout << " The number of spots " << theNumberOfSpots << " " << nspot << std::endl;
00044 
00045   // This is not correct for the last interval, but will be overriden later
00046   nspots.push_back(nspot);
00047   spotE.push_back(spotEnergy);
00048   // computes the limits
00049   double umax = radiussq/(radiussq+theR*theR);
00050   if(radius>10)
00051     {
00052       umax=1.;
00053     }
00054 
00055   // Stores the limits
00056   uMax.push_back(umax);          
00057   uMin.push_back(currentUlim);           
00058   currentUlim=umax;
00059 
00060   // Stores the energy
00061   //  std::cout << " SpotE " << theSpotEnergy<< " " << spotf << " " << theSpotEnergy/spotf<< std::endl;
00062 
00063   ++nInter;
00064 }
00065 
00066 double RadialInterval::energyFractionInRadius( double rm)
00067 {
00068   double rm2=rm*rm;
00069   return (rm2/(rm2+theR*theR));
00070 }
00071 
00072 void RadialInterval::compute()
00073 {
00074   //  std::cout << " The number of Spots " << theNumberOfSpots << std::endl;
00075   //  std::cout << " Size : " << nInter << " " << nspots.size() << " " << dspotsunscaled.size() << std::endl;
00076   double ntotspots=0.;
00077   for(unsigned irad=0;irad<nInter-1;++irad)
00078     {
00079       ntotspots+=dspotsunscaled[irad];
00080       //    std::cout << " In the loop " << ntotspots << std::endl;
00081     }
00082 
00083   // This can happen (fluctuations)
00084   if(ntotspots>theNumberOfSpots) ntotspots=(double)theNumberOfSpots;
00085   //  std::cout << " Sous-total " << ntotspots << std::endl;
00086   dspotsunscaled[nInter-1]=(double)theNumberOfSpots-ntotspots;
00087   
00088   nspots[nInter-1]=(unsigned)(dspotsunscaled[nInter-1]*spotfraction[nInter-1]+0.5);
00089   //    std::cout << " Nlast " << nspots[nInter-1] << std::endl;
00090 }