7 #include <CLHEP/GenericFunctions/IncompleteGamma.hh>
8 #include <CLHEP/GenericFunctions/LogGamma.hh>
9 #include <CLHEP/Units/PhysicalConstants.h>
10 #include <CLHEP/Units/SystemOfUnits.h>
11 #include <CLHEP/Random/Randomize.h>
12 #include <CLHEP/Random/RandGaussQ.h>
13 #include <CLHEP/Random/RandPoissonQ.h>
50 double showerDepthR50 = 0.0;
51 bool firstHcalHit =
true;
56 double deltaStep = 0.0;
57 double showerDepth = 0.0;
63 while(stepLengthLeft > 0.0) {
67 deltaStep = stepLengthLeft;
72 stepLengthLeft -= deltaStep;
75 showerDepth += deltaStep;
76 showerDepthR50 += deltaStep;
82 double heightProfile = 0.;
83 double deltaEnergy = 0.;
93 if(heightProfile < 1.00
e-08 )
continue;
100 double hadronicFraction = 1.0;
101 double fluctuatedEnergy = deltaEnergy;
103 int nSpotsInStep =
std::max(1,static_cast<int>(
getNumberOfSpots(whichCalor)*(deltaEnergy/energyScale[whichCalor]) ));
104 double sampleSpotEnergy = hadronicFraction*fluctuatedEnergy/nSpotsInStep;
109 firstHcalHit =
false;
117 double hitEnergy = sampleSpotEnergy*CLHEP::GeV;
122 for (
int ispot = 0 ; ispot < nSpotsInStep ; ispot++) {
127 + (deltaStep/nSpotsInStep)*(ispot+0.5 - 0.5*nSpotsInStep);
138 hitPosition *= CLHEP::cm;
156 double r0 = CLHEP::HepUniformRand();
161 if( r0 < nonzeroProb && leftoverE > 0.0) {
173 while(stepLengthLeft > 0.0) {
177 deltaStep = stepLengthLeft;
178 stepLengthLeft = 0.0;
182 stepLengthLeft -= deltaStep;
185 showerDepth += deltaStep;
191 double heightProfile = 0.;
192 double deltaEnergy = 0.;
205 double hoFraction = 1.00;
206 double poissonProb = CLHEP::RandPoissonQ::shoot(1.0);
208 double fluctuatedEnergy = deltaEnergy*poissonProb;
209 double sampleSpotEnergy = hoFraction*fluctuatedEnergy/nSpotsInStep;
216 double hitEnergy = sampleSpotEnergy*CLHEP::GeV;
219 for (
int ispot = 0 ; ispot < nSpotsInStep ; ispot++) {
222 + (deltaStep/nSpotsInStep)*(ispot+0.5 - 0.5*nSpotsInStep);
229 hitPosition *= CLHEP::cm;
231 if(std::fabs(hitPosition.getZ()/CLHEP::cm) >
Gflash::Zmax[Gflash::kHO] )
continue;
249 edm::LogInfo(
"SimGeneralGFlash") <<
"GflashHadronShowerProfile::loadParameters() "
250 <<
"should be implimented for each particle type";
255 double lateralArm = 0.0;
265 double sigmaSq =
std::log(varinanceR50/(R50*R50)+1.0);
267 double meanR50 =
std::log(R50) - (sigmaSq/2.);
269 lateralArm =
std::exp(meanR50 + sigmaR50* CLHEP::RandGaussQ::shoot());
278 double rnunif = CLHEP::HepUniformRand();
279 double rxPDF =
std::sqrt(rnunif/(1.-rnunif));
280 double rShower = lateralArm*rxPDF;
286 double azimuthalAngle = CLHEP::twopi*CLHEP::HepUniformRand();
305 double heightProfile = 0.0;
320 if(showerType == 0 || showerType == 1 || showerType == 4 || showerType == 5 ) {
327 else heightProfile = 0.;
329 else if (showerType == 2 || showerType == 6 ) {
331 if((showerDepth - transDepth) > 0.0) {
334 else heightProfile = 0.;
336 else if (showerType == 3 || showerType == 7 ) {
341 return heightProfile;
346 double heightProfile = 0;
352 heightProfile =
std::exp(-1.0*refDepth/dint);
354 return heightProfile;
361 double **xr =
new double *[dim];
362 double **xrho =
new double *[dim];
364 for(
int j=0;
j<dim;
j++) {
365 xr[
j] =
new double [dim];
366 xrho[
j] =
new double [dim];
369 for(
int i = 0;
i < dim;
i++) {
370 for(
int j = 0;
j <
i+1 ;
j++) {
371 if(
j==i) xrho[
i][
j] = 1.0;
373 xrho[
i][
j] = lowTriangle[i*(i-1)/2 +
j];
374 xrho[
j][
i] = xrho[
i][
j];
381 for(
int i = 0 ;
i < dim ;
i++) {
382 for (
int j = 0 ;
j <
i+1 ;
j++){
383 correlationVector[i*(i+1)/2 +
j] = xr[i][
j];
387 for(
int j=0;
j<dim;
j++)
delete [] xr[
j];
389 for(
int j=0;
j<dim;
j++)
delete [] xrho[
j];
401 for(
int j=1 ;
j < ndim ;
j++) {
402 cc[
j][0] = vv[
j][0]/cc[0][0];
405 for(
int j=1 ;
j < ndim ;
j++) {
408 for (
int k=0 ;
k <
j ;
k++) sumCjkSquare += cc[j][
k]*cc[j][
k];
410 vjjLess = vv[
j][
j] - sumCjkSquare;
415 for (
int i=j+1 ;
i < ndim ;
i++) {
417 for(
int k=0 ;
k <
j ;
k++) sumCikjk += cc[
i][
k]*cc[j][
k];
418 cc[
i][
j] = (vv[
i][
j] - sumCikjk)/cc[j][j];
431 int numberOfSpots = 0;
435 if(showerType == 0 || showerType == 1 || showerType == 4 || showerType == 5 ) {
437 nmean = 10000 + 5000*
log(einc);
441 nmean = 5000 + 2500*
log(einc);
445 else if (showerType == 2 || showerType == 3 || showerType == 6 || showerType == 7 ) {
447 nmean = 5000 + 2500*
log(einc);
458 numberOfSpots =
std::max(500,static_cast<int> (nmean+nsigma* CLHEP::RandGaussQ::shoot()));
463 numberOfSpots =
static_cast<int>(numberOfSpots/100);
466 numberOfSpots =
static_cast<int>(numberOfSpots/3.0);
469 return numberOfSpots;
474 if(einc>0.0) func = par[0]+par[1]*std::tanh(par[2]*(
std::log(einc)-par[3]));
480 if(einc>0.0) func = par[0]+par[1]*
std::log(einc);
486 if(length>0.0) func =
std::pow((ssp-ssp0)/length,2.0);
493 if(showerDepth>0.0) {
494 Genfun::LogGamma lgam;
495 double x = showerDepth*(beta/lengthUnit);
502 double twoGamma = 0.0;
504 longPar[0] =
std::min(1.0,longPar[0]);
505 if(longPar[3] > 4.0 || longPar[4] > 4.0) {
506 double rfactor = 2.0/
std::max(longPar[3],longPar[4]);
507 longPar[3] = rfactor*(longPar[3]+1.0);
508 longPar[4] *= rfactor;
Gflash3Vector locateHitPosition(GflashTrajectoryPoint &point, double lateralArm)
double fTanh(double einc, const double *par)
double longHcal[Gflash::NPar]
T getParameter(std::string const &) const
static GflashHistogram * instance()
void setEnergy(const double energy)
double longitudinalProfile()
const double divisionStep
double lateralPar[Gflash::kNumberCalorimeter][Gflash::Nrpar]
const double Zmax[kNumberCalorimeter]
Gflash3Vector getCrossUnitVector()
double twoGammaProfile(double *par, double depth, Gflash::CalorimeterNumber kIndex)
Gflash3Vector & getPosition()
GflashTrajectory * getHelix()
GflashShowino * theShowino
double medianLateralArm(double depth, Gflash::CalorimeterNumber kCalor)
Sin< T >::type sin(const T &t)
void setPosition(const Gflash3Vector &pos)
Exp< T >::type exp(const T &t)
const double EtaMax[kNumberCalorimeter]
const double ho_nonzero[4]
virtual ~GflashHadronShowerProfile()
static int position[TOTALCHAMBERS][3]
GflashHadronShowerProfile(edm::ParameterSet parSet)
GflashHistogram * theHisto
void doCholeskyReduction(double **cc, double **vv, const int ndim)
void addEnergyDeposited(double energy)
double getStepLengthToHcal()
void setTime(const double time)
double longEcal[Gflash::NPar]
const T & max(const T &a, const T &b)
double getPathLengthAtShower()
virtual void loadParameters()
double fLnE1(double einc, const double *par)
double getEnergyDeposited()
Cos< T >::type cos(const T &t)
const double MinEnergyCutOffForHO
void setPathLength(double pathLength)
double gammaProfile(double alpha, double beta, double depth, double lengthUnit)
Gflash3Vector & getPositionAtShower()
Gflash3Vector getOrthogonalUnitVector()
const double intLength[kNumberCalorimeter]
void getGflashTrajectoryPoint(GflashTrajectoryPoint &point, double s) const
std::vector< GflashHit > theGflashHitList
void hadronicParameterization()
const double maxShowerDepthforR50
const double radLength[kNumberCalorimeter]
Log< T >::type log(const T &t)
CLHEP::Hep3Vector Gflash3Vector
CalorimeterNumber getCalorimeterNumber(const Gflash3Vector position)
Gflash3Vector & getPosition()
const double maxLateralArmforR50
void getFluctuationVector(double *lowTriangle, double *correlationVector)
double depthScale(double ssp, double ssp0, double length)
const double Rmax[kNumberCalorimeter]
int getNumberOfSpots(Gflash::CalorimeterNumber kCalor)
double hoProfile(double pathLength, double refDepth)
double getStepLengthToOut()
const double Rmin[kNumberCalorimeter]
Power< A, B >::type pow(const A &a, const B &b)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
void initialize(int showerType, double energy, double globalTime, double charge, Gflash3Vector &position, Gflash3Vector &momentum)
const double par[8 *NPar][4]
double getPathLengthAtRhoEquals(double rho) const
void initialize(int showerType, double energy, double globalTime, double charge, Gflash3Vector &position, Gflash3Vector &momentum, double magneticField)
double energyScale[Gflash::kNumberCalorimeter]
void updateShowino(double deltaStep)