CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RadialInterval.cc
Go to the documentation of this file.
1 //FAMOS header
4 
5 #include <cmath>
6 
7 RadialInterval::RadialInterval(double RC, unsigned nSpots, double energy, const RandomEngineAndDistribution* engine)
8  : theR(RC), theNumberOfSpots(nSpots), theSpotEnergy(energy), random(engine) {
9  currentRad = 0.;
11  currentUlim = 0.;
12  nInter = 0;
13 }
14 
15 void RadialInterval::addInterval(double radius, double spotf) {
16  double radiussq = radius * radius;
17  double enFrac = energyFractionInRadius(radius);
18  if (radius > 10)
19  enFrac = 1.;
20  double energyFrac = enFrac - currentEnergyFraction;
21  currentEnergyFraction = enFrac;
22  // std::cout << " Rad " << nInter << " Energy frac " << energyFrac << std::endl;
23 
24  // Calculates the number of spots. Add binomial fluctuations
25  double dspot =
26  random->gaussShoot(theNumberOfSpots * energyFrac, sqrt(energyFrac * (1. - energyFrac) * theNumberOfSpots));
27  // std::cout << " Normal : " << theNumberOfSpots*energyFrac << " "<< dspot << std::endl;
28  unsigned nspot = (unsigned)(dspot * spotf + 0.5);
29  // if(nspot<100)
30  // {
31  // spotf=1.;
32  // nspot=(unsigned)(theNumberOfSpots*energyFrac+0.5);
33  // }
34 
35  dspotsunscaled.push_back(dspot);
36  spotfraction.push_back(spotf);
37 
38  double spotEnergy = theSpotEnergy / spotf;
39  // std::cout << " The number of spots " << theNumberOfSpots << " " << nspot << std::endl;
40 
41  // This is not correct for the last interval, but will be overriden later
42  nspots.push_back(nspot);
43  spotE.push_back(spotEnergy);
44  // computes the limits
45  double umax = radiussq / (radiussq + theR * theR);
46  if (radius > 10) {
47  umax = 1.;
48  }
49 
50  // Stores the limits
51  uMax.push_back(umax);
52  uMin.push_back(currentUlim);
53  currentUlim = umax;
54 
55  // Stores the energy
56  // std::cout << " SpotE " << theSpotEnergy<< " " << spotf << " " << theSpotEnergy/spotf<< std::endl;
57 
58  ++nInter;
59 }
60 
62  double rm2 = rm * rm;
63  return (rm2 / (rm2 + theR * theR));
64 }
65 
67  // std::cout << " The number of Spots " << theNumberOfSpots << std::endl;
68  // std::cout << " Size : " << nInter << " " << nspots.size() << " " << dspotsunscaled.size() << std::endl;
69  double ntotspots = 0.;
70  for (unsigned irad = 0; irad < nInter - 1; ++irad) {
71  ntotspots += dspotsunscaled[irad];
72  // std::cout << " In the loop " << ntotspots << std::endl;
73  }
74 
75  // This can happen (fluctuations)
76  if (ntotspots > theNumberOfSpots)
77  ntotspots = (double)theNumberOfSpots;
78  // std::cout << " Sous-total " << ntotspots << std::endl;
79  dspotsunscaled[nInter - 1] = (double)theNumberOfSpots - ntotspots;
80 
81  nspots[nInter - 1] = (unsigned)(dspotsunscaled[nInter - 1] * spotfraction[nInter - 1] + 0.5);
82  // std::cout << " Nlast " << nspots[nInter-1] << std::endl;
83 }
std::vector< double > spotE
const RandomEngineAndDistribution * random
RadialInterval(double RC, unsigned nSpots, double energy, const RandomEngineAndDistribution *engine)
Standard constructor Rc: mean Radius.
T sqrt(T t)
Definition: SSEVec.h:19
double currentEnergyFraction
std::vector< double > uMin
std::vector< double > spotfraction
std::vector< double > uMax
std::vector< unsigned > nspots
unsigned theNumberOfSpots
double energyFractionInRadius(double rm)
std::vector< double > dspotsunscaled
double gaussShoot(double mean=0.0, double sigma=1.0) const
def rm
Definition: eostools.py:363
double theSpotEnergy
void addInterval(double, double)