CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimGeneral/GFlash/src/GflashShowino.cc

Go to the documentation of this file.
00001 #include "SimGeneral/GFlash/interface/GflashShowino.h"
00002 #include <CLHEP/Random/Randomize.h>
00003 
00004 GflashShowino::GflashShowino() 
00005   : theShowerType(-1), theEnergy(0), thePositionAtShower(0,0,0), thePathLengthAtShower(0), 
00006     thePathLengthOnEcal(0), theStepLengthToHcal(0), theStepLengthToOut(0),  
00007     thePathLength(0), theGlobalTime(0), thePosition(0,0,0), theEnergyDeposited(0)
00008 {
00009   theHelix =  new GflashTrajectory;;
00010 }
00011 
00012 GflashShowino::~GflashShowino() 
00013 {
00014   delete theHelix;
00015 }
00016 
00017 void GflashShowino::initialize(int showerType, double energy, double globalTime, double charge, 
00018                                Gflash3Vector &position, Gflash3Vector &momentum,
00019                                double magneticField) {
00020 
00021   theEnergy = energy;
00022   theGlobalTime = globalTime;
00023   theEnergyDeposited = 0.0;
00024 
00025   // inside the magnetic field (tesla unit);
00026   theHelix->initializeTrajectory(momentum,position,charge,magneticField);
00027 
00028   if(showerType<100) {
00029     thePositionAtShower = position;  
00030     thePosition = thePositionAtShower;
00031     theShowerType = showerType;
00032 
00033   }
00034   else {
00035     //this input is from FastSimulation
00036     //1. simulate the shower starting position
00037     thePositionAtShower = simulateFirstInteractionPoint(showerType,position);
00038     thePosition = thePositionAtShower;
00039 
00040     //2. find shower type depending on where is the shower starting point
00041     theShowerType = Gflash::findShowerType(thePositionAtShower);
00042 
00043   }  
00044 
00045   evaluateLengths();
00046 
00047 }
00048 
00049 void GflashShowino::updateShowino(double deltaStep)
00050 {
00051   thePathLength += deltaStep;
00052   //trajectory point of showino along the shower depth at the pathLength
00053   GflashTrajectoryPoint trajectoryShowino;
00054   theHelix->getGflashTrajectoryPoint(trajectoryShowino,thePathLength);
00055 
00056   thePosition = trajectoryShowino.getPosition();
00057 
00058   theGlobalTime +=  (theEnergy/100.0)*deltaStep/30.0; //@@@calculate exact time change in nsec
00059 }
00060 
00061 void GflashShowino::evaluateLengths() {
00062   //thePathLengthAtShower: path Length from the origin to the shower starting point in cm
00063   //theStepLengthToOut: the total path length from the starting point of
00064   //                    shower to the maximum distance inside paramerized envelopes
00065   double eta = thePosition.getEta();
00066   
00067   if (std::fabs(eta) < Gflash::EtaMax[Gflash::kESPM]) {
00068     thePathLengthOnEcal   = theHelix->getPathLengthAtRhoEquals(Gflash::RFrontCrystalEB);
00069     thePathLengthAtShower = theHelix->getPathLengthAtRhoEquals(thePosition.getRho());
00070     theStepLengthToOut    = std::min(300.,theHelix->getPathLengthAtRhoEquals(Gflash::Rmax[Gflash::kHB]) - thePathLengthAtShower);
00071     theStepLengthToHcal   = theHelix->getPathLengthAtRhoEquals(Gflash::Rmin[Gflash::kHB]) - thePathLengthAtShower;
00072   }
00073   else if (std::fabs(eta) < Gflash::EtaMax[Gflash::kENCA] ) {
00074     double zsign = (eta > 0) ? 1.0 : -1.0 ; 
00075     thePathLengthOnEcal   = theHelix->getPathLengthAtZ(zsign*Gflash::ZFrontCrystalEE);
00076     thePathLengthAtShower = theHelix->getPathLengthAtZ(thePosition.getZ());
00077     theStepLengthToOut    = std::min(300.,theHelix->getPathLengthAtZ(zsign*Gflash::Zmax[Gflash::kHE]) - thePathLengthAtShower);
00078     theStepLengthToHcal   = theHelix->getPathLengthAtZ(zsign*Gflash::Zmin[Gflash::kHE]) - thePathLengthAtShower;
00079   }
00080   else { 
00081     //@@@extend for HF later
00082     theStepLengthToOut = 200.0;
00083   }
00084 
00085   thePathLength = thePathLengthAtShower;
00086 
00087 }
00088 
00089 
00090 Gflash3Vector& GflashShowino::simulateFirstInteractionPoint(int fastSimShowerType, Gflash3Vector &position) {
00091 
00092   //determine the shower starting point (ssp):
00093   //the position at the entrance + the mean free path till the inelastic interaction inside calo
00094 
00095   double depthAtShower = 0.0;
00096 
00097   //set thePathLengthOnEcal, the pathLength at the reference (r=123.8 for barrel and z=304.5 for endcap)
00098     
00099   //effective interaction length fitter to ssp from Geant4
00100   double effectiveLambda = 0.0;
00101   if(theEnergy > 0.0 &&  theEnergy < 15) {
00102     effectiveLambda = 24.6+2.6*std::tanh(3.0*(std::log(theEnergy)-1.43));
00103   }
00104   else {
00105     effectiveLambda = 28.4+1.20*std::tanh(1.5*(std::log(theEnergy)-4.3));
00106   }
00107   //fraction before the crystal, but inside Ecal
00108   //  double frac_ssp1 = 1.5196e-01+1.3300e-01*tanh(-4.6971e-01*(std::log(theEnergy)+2.4162e+00));
00109   //fraction after the crystal, but before Hcal
00110   double frac_ssp2 = 2.8310e+00+2.6766e+00*tanh(-4.8068e-01*(std::log(theEnergy)+3.4857e+00));
00111 
00112   if(fastSimShowerType == 100 ) { //fastTrack.onEcal() == 1
00113 
00114     //    double rhoTemp = Gflash::ROffCrystalEB + Gflash::LengthCrystalEB*std::sin(position.getTheta());
00115     double rhoTemp = Gflash::LengthCrystalEB*std::sin(position.getTheta());
00116     thePathLengthOnEcal  = theHelix->getPathLengthAtRhoEquals(Gflash::RFrontCrystalEB);
00117     double pathLengthAt2 = theHelix->getPathLengthAtRhoEquals(Gflash::RFrontCrystalEB + rhoTemp );
00118     double pathLengthAt3 = theHelix->getPathLengthAtRhoEquals(Gflash::Rmin[Gflash::kHB]);
00119 
00121     /*
00122     if(CLHEP::HepUniformRand() < frac_ssp1 ) {
00123       depthAtShower = (pathLengthAt1-thePathLengthOnEcal)*CLHEP::HepUniformRand();
00124     }
00125     else {
00126     */
00127     //inside the crystal
00128     //      depthAtShower = (pathLengthAt1-thePathLengthOnEcal) - effectiveLambda*log(CLHEP::HepUniformRand());
00129       depthAtShower = - effectiveLambda*log(CLHEP::HepUniformRand());
00130       //after the crystal
00131       if(depthAtShower > (pathLengthAt2 - thePathLengthOnEcal) ) {
00132         //before Hcal
00133         if(CLHEP::HepUniformRand() < frac_ssp2 ) {
00134           depthAtShower = (pathLengthAt2 - thePathLengthOnEcal) + (pathLengthAt3-pathLengthAt2)*CLHEP::HepUniformRand();
00135         }
00136         //inside Hcal
00137         else {
00138           depthAtShower = (pathLengthAt3 - thePathLengthOnEcal) - effectiveLambda*log(CLHEP::HepUniformRand());
00139           //check whether the shower starts beyond HB
00140           double pathLengthAt4 = theHelix->getPathLengthAtRhoEquals(Gflash::Rmax[Gflash::kHB]);
00141           if(depthAtShower > (pathLengthAt4 - thePathLengthOnEcal)) {
00142             depthAtShower = (pathLengthAt4 - pathLengthAt3)*CLHEP::HepUniformRand();
00143           }
00144         }
00145       }
00146       //    }
00147   }
00148   else if(fastSimShowerType == 101 ) { //fastTrack.onEcal() == 2 
00149 
00150     double zTemp = Gflash::LengthCrystalEE;
00151     double zsign = (position.getEta() > 0) ? 1.0 : -1.0 ; 
00152 
00153     thePathLengthOnEcal  = theHelix->getPathLengthAtZ(zsign*Gflash::ZFrontCrystalEE);
00154     double pathLengthAt2 = theHelix->getPathLengthAtZ(zsign*(Gflash::ZFrontCrystalEE + zTemp));
00155     double pathLengthAt3 = theHelix->getPathLengthAtZ(zsign*Gflash::Zmin[Gflash::kHE]);
00156       
00157     /*
00158     if(CLHEP::HepUniformRand() <  frac_ssp1 ) {
00159       depthAtShower = (pathLengthAt1-thePathLengthOnEcal)*CLHEP::HepUniformRand();
00160     }
00161     else {
00162     */
00163     //      depthAtShower = (pathLengthAt1-thePathLengthOnEcal)-effectiveLambda*std::log(CLHEP::HepUniformRand());
00164       depthAtShower = -effectiveLambda*std::log(CLHEP::HepUniformRand());
00165 
00166       if(depthAtShower > (pathLengthAt2 - thePathLengthOnEcal) ) {
00167         if(CLHEP::HepUniformRand() < frac_ssp2 ) {
00168           depthAtShower = (pathLengthAt2 - thePathLengthOnEcal) +(pathLengthAt3 - pathLengthAt2)*CLHEP::HepUniformRand();
00169         }
00170         else {
00171           depthAtShower = (pathLengthAt3 - thePathLengthOnEcal)-effectiveLambda*std::log(CLHEP::HepUniformRand());
00172           //shower starts beyond HE
00173           double pathLengthAt4 = theHelix->getPathLengthAtZ(zsign*Gflash::Zmax[Gflash::kHE]);
00174           if(depthAtShower > (pathLengthAt4 - thePathLengthOnEcal)) {
00175             depthAtShower = (pathLengthAt4 - pathLengthAt3)*CLHEP::HepUniformRand();
00176           }
00177         }
00178       }
00179       //    }
00180   }
00181   else {
00182     depthAtShower = 0.0; 
00183   }
00184 
00185   double pathLength  = thePathLengthOnEcal + depthAtShower;
00186   GflashTrajectoryPoint trajectoryPoint;
00187   theHelix->getGflashTrajectoryPoint(trajectoryPoint,pathLength);
00188 
00189   //return the initial showino position at the shower starting position
00190   return trajectoryPoint.getPosition();
00191 
00192 }