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;
65 while(stepLengthLeft > 0.0) {
69 deltaStep = stepLengthLeft;
74 stepLengthLeft -= deltaStep;
77 showerDepth += deltaStep;
78 showerDepthR50 += deltaStep;
84 double heightProfile = 0.;
85 double deltaEnergy = 0.;
95 if(heightProfile < 1.00
e-08 )
continue;
102 double hadronicFraction = 1.0;
103 double fluctuatedEnergy = deltaEnergy;
105 int nSpotsInStep =
std::max(1,static_cast<int>(
getNumberOfSpots(whichCalor)*(deltaEnergy/energyScale[whichCalor]) ));
106 double sampleSpotEnergy = hadronicFraction*fluctuatedEnergy/nSpotsInStep;
111 firstHcalHit =
false;
119 double hitEnergy = sampleSpotEnergy*CLHEP::GeV;
124 for (
int ispot = 0 ; ispot < nSpotsInStep ; ispot++) {
129 + (deltaStep/nSpotsInStep)*(ispot+0.5 - 0.5*nSpotsInStep);
141 hitPosition *= CLHEP::cm;
159 double r0 = CLHEP::HepUniformRand();
164 if( r0 < nonzeroProb && leftoverE > 0.0) {
176 while(stepLengthLeft > 0.0) {
180 deltaStep = stepLengthLeft;
181 stepLengthLeft = 0.0;
185 stepLengthLeft -= deltaStep;
188 showerDepth += deltaStep;
194 double heightProfile = 0.;
195 double deltaEnergy = 0.;
208 double hoFraction = 1.00;
209 double poissonProb = CLHEP::RandPoissonQ::shoot(1.0);
211 double fluctuatedEnergy = deltaEnergy*poissonProb;
212 double sampleSpotEnergy = hoFraction*fluctuatedEnergy/nSpotsInStep;
219 double hitEnergy = sampleSpotEnergy*CLHEP::GeV;
222 for (
int ispot = 0 ; ispot < nSpotsInStep ; ispot++) {
225 + (deltaStep/nSpotsInStep)*(ispot+0.5 - 0.5*nSpotsInStep);
232 hitPosition *= CLHEP::cm;
234 if(std::fabs(hitPosition.getZ()/CLHEP::cm) >
Gflash::Zmax[Gflash::kHO] )
continue;
252 edm::LogInfo(
"SimGeneralGFlash") <<
"GflashHadronShowerProfile::loadParameters() "
253 <<
"should be implimented for each particle type";
258 double lateralArm = 0.0;
268 double sigmaSq =
std::log(varinanceR50/(R50*R50)+1.0);
270 double meanR50 =
std::log(R50) - (sigmaSq/2.);
272 lateralArm =
std::exp(meanR50 + sigmaR50* CLHEP::RandGaussQ::shoot());
281 double rnunif = CLHEP::HepUniformRand();
282 double rxPDF =
std::sqrt(rnunif/(1.-rnunif));
283 double rShower = lateralArm*rxPDF;
289 double azimuthalAngle = CLHEP::twopi*CLHEP::HepUniformRand();
308 double heightProfile = 0.0;
323 if(showerType == 0 || showerType == 4 ) {
325 if(shiftDepth > 0 ) {
333 else if(showerType == 1 || showerType == 5 ) {
340 else heightProfile = 0.;
342 else if (showerType == 2 || showerType == 6 ) {
344 if((showerDepth - transDepth) > 0.0) {
347 else heightProfile = 0.;
349 else if (showerType == 3 || showerType == 7 ) {
354 return heightProfile;
359 double heightProfile = 0;
365 heightProfile =
std::exp(-1.0*refDepth/dint);
367 return heightProfile;
374 double **xr =
new double *[dim];
375 double **xrho =
new double *[dim];
377 for(
int j=0;
j<dim;
j++) {
378 xr[
j] =
new double [dim];
379 xrho[
j] =
new double [dim];
382 for(
int i = 0;
i < dim;
i++) {
383 for(
int j = 0;
j <
i+1 ;
j++) {
384 if(
j==i) xrho[
i][
j] = 1.0;
386 xrho[
i][
j] = lowTriangle[i*(i-1)/2 +
j];
387 xrho[
j][
i] = xrho[
i][
j];
394 for(
int i = 0 ;
i < dim ;
i++) {
395 for (
int j = 0 ;
j <
i+1 ;
j++){
396 correlationVector[i*(i+1)/2 +
j] = xr[i][
j];
400 for(
int j=0;
j<dim;
j++)
delete [] xr[
j];
402 for(
int j=0;
j<dim;
j++)
delete [] xrho[
j];
414 for(
int j=1 ;
j < ndim ;
j++) {
415 cc[
j][0] = vv[
j][0]/cc[0][0];
418 for(
int j=1 ;
j < ndim ;
j++) {
421 for (
int k=0 ;
k <
j ;
k++) sumCjkSquare += cc[j][
k]*cc[j][
k];
423 vjjLess = vv[
j][
j] - sumCjkSquare;
428 for (
int i=j+1 ;
i < ndim ;
i++) {
430 for(
int k=0 ;
k <
j ;
k++) sumCikjk += cc[
i][
k]*cc[j][
k];
431 cc[
i][
j] = (vv[
i][
j] - sumCikjk)/cc[j][j];
444 int numberOfSpots = 0;
448 if(showerType == 0 || showerType == 1 || showerType == 4 || showerType == 5 ) {
450 nmean = 10000 + 5000*
log(einc);
454 nmean = 5000 + 2500*
log(einc);
458 else if (showerType == 2 || showerType == 3 || showerType == 6 || showerType == 7 ) {
460 nmean = 5000 + 2500*
log(einc);
471 numberOfSpots =
std::max(500,static_cast<int> (nmean+nsigma* CLHEP::RandGaussQ::shoot()));
476 numberOfSpots =
static_cast<int>(numberOfSpots/100);
479 numberOfSpots =
static_cast<int>(numberOfSpots/3.0);
482 return numberOfSpots;
487 if(einc>0.0) func = par[0]+par[1]*std::tanh(par[2]*(
std::log(einc)-par[3])) + par[4]*
std::log(einc);
493 if(einc>0.0) func = par[0]+par[1]*
std::log(einc);
499 if(length>0.0) func =
std::pow((ssp-ssp0)/length,2.0);
506 if(showerDepth>0.0) {
507 Genfun::LogGamma lgam;
508 double x = showerDepth*(beta/lengthUnit);
515 double twoGamma = 0.0;
517 longPar[0] =
std::min(1.0,longPar[0]);
518 longPar[0] =
std::max(0.0,longPar[0]);
520 if(longPar[3] > 4.0 || longPar[4] > 4.0) {
521 double rfactor = 2.0/
std::max(longPar[3],longPar[4]);
522 longPar[3] = rfactor*(longPar[3]+1.0);
523 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)
const double EtaMax[kNumberCalorimeter]
virtual ~GflashHadronShowerProfile()
static int position[TOTALCHAMBERS][3]
GflashHistogram * theHisto
void doCholeskyReduction(double **cc, double **vv, const int ndim)
void addEnergyDeposited(double energy)
double getStepLengthToHcal()
void setTime(const double time)
const double ho_nonzero[5]
double longEcal[Gflash::NPar]
CalorimeterNumber getCalorimeterNumber(const Gflash3Vector &position)
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]
GflashHadronShowerProfile(const edm::ParameterSet &parSet)
CLHEP::Hep3Vector Gflash3Vector
double getPathLengthOnEcal()
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)
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)