CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc

Go to the documentation of this file.
00001 
00002 // $Id: BetafuncEvtVtxGenerator.cc,v 1.12 2011/03/08 16:09:22 burkett Exp $
00003 /*
00004 ________________________________________________________________________
00005 
00006  BetafuncEvtVtxGenerator
00007 
00008  Smear vertex according to the Beta function on the transverse plane
00009  and a Gaussian on the z axis. It allows the beam to have a crossing
00010  angle (slopes dxdz and dydz).
00011 
00012  Based on GaussEvtVtxGenerator
00013  implemented by Francisco Yumiceva (yumiceva@fnal.gov)
00014 
00015  FERMILAB
00016  2006
00017 ________________________________________________________________________
00018 */
00019 
00020 
00021 
00022 #include "IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h"
00023 #include "FWCore/Utilities/interface/Exception.h"
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025 
00026 #include "CLHEP/Random/RandGaussQ.h"
00027 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00028 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00029 //#include "CLHEP/Vector/ThreeVector.h"
00030 #include "HepMC/SimpleVector.h"
00031 
00032 #include <iostream>
00033 
00034 
00035 
00036 BetafuncEvtVtxGenerator::BetafuncEvtVtxGenerator(const edm::ParameterSet & p )
00037 : BaseEvtVtxGenerator(p)
00038 { 
00039   
00040   fRandom = new CLHEP::RandGaussQ(getEngine());
00041 
00042   fX0 =        p.getParameter<double>("X0")*cm;
00043   fY0 =        p.getParameter<double>("Y0")*cm;
00044   fZ0 =        p.getParameter<double>("Z0")*cm;
00045   fSigmaZ =    p.getParameter<double>("SigmaZ")*cm;
00046   alpha_ =     p.getParameter<double>("Alpha")*radian;
00047   phi_ =       p.getParameter<double>("Phi")*radian;
00048   fbetastar =  p.getParameter<double>("BetaStar")*cm;
00049   femittance = p.getParameter<double>("Emittance")*cm; // this is not the normalized emittance
00050   fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light; // HepMC time units are mm
00051  
00052   if (fSigmaZ <= 0) {
00053           throw cms::Exception("Configuration")
00054                   << "Error in BetafuncEvtVtxGenerator: "
00055                   << "Illegal resolution in Z (SigmaZ is negative)";
00056   }
00057 
00058   
00059 }
00060 
00061 BetafuncEvtVtxGenerator::~BetafuncEvtVtxGenerator() 
00062 {
00063     delete fRandom; 
00064 }
00065 
00066 
00067 //Hep3Vector* BetafuncEvtVtxGenerator::newVertex() {
00068 HepMC::FourVector* BetafuncEvtVtxGenerator::newVertex() {
00069 
00070         
00071         double X,Y,Z;
00072         
00073         double tmp_sigz = fRandom->fire(0., fSigmaZ);
00074         Z = tmp_sigz + fZ0;
00075 
00076         double tmp_sigx = BetaFunction(Z,fZ0); 
00077         // need sqrt(2) for beamspot width relative to single beam width
00078         tmp_sigx /= sqrt(2.0);
00079         X = fRandom->fire(0.,tmp_sigx) + fX0; // + Z*fdxdz ;
00080 
00081         double tmp_sigy = BetaFunction(Z,fZ0);
00082         // need sqrt(2) for beamspot width relative to single beam width
00083         tmp_sigy /= sqrt(2.0);
00084         Y = fRandom->fire(0.,tmp_sigy) + fY0; // + Z*fdydz;
00085 
00086         double tmp_sigt = fRandom->fire(0., fSigmaZ);
00087         double T = tmp_sigt + fTimeOffset; 
00088 
00089         if ( fVertex == 0 ) fVertex = new HepMC::FourVector();
00090         fVertex->set(X,Y,Z,T);
00091                 
00092         return fVertex;
00093 }
00094 
00095 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0)
00096 {
00097         return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
00098 
00099 }
00100 
00101 
00102 void BetafuncEvtVtxGenerator::sigmaZ(double s) 
00103 { 
00104         if (s>=0 ) {
00105                 fSigmaZ=s; 
00106         }
00107         else {
00108                 throw cms::Exception("LogicError")
00109                         << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
00110                         << "Illegal resolution in Z (negative)";
00111         }
00112 }
00113 
00114 TMatrixD* BetafuncEvtVtxGenerator::GetInvLorentzBoost() {
00115 
00116         //alpha_ = 0;
00117         //phi_ = 142.e-6;
00118         
00119         if (boost_ != 0 ) return boost_;
00120         
00121         //boost_.ResizeTo(4,4);
00122         //boost_ = new TMatrixD(4,4);
00123         TMatrixD tmpboost(4,4);
00124         
00125         //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
00126         
00127         // Lorentz boost to frame where the collision is head-on
00128         // phi is the half crossing angle in the plane ZS
00129         // alpha is the angle to the S axis from the X axis in the XY plane
00130         
00131         tmpboost(0,0) = 1./cos(phi_);
00132         tmpboost(0,1) = - cos(alpha_)*sin(phi_);
00133         tmpboost(0,2) = - tan(phi_)*sin(phi_);
00134         tmpboost(0,3) = - sin(alpha_)*sin(phi_);
00135         tmpboost(1,0) = - cos(alpha_)*tan(phi_);
00136         tmpboost(1,1) = 1.;
00137         tmpboost(1,2) = cos(alpha_)*tan(phi_);
00138         tmpboost(1,3) = 0.;
00139         tmpboost(2,0) = 0.;
00140         tmpboost(2,1) = - cos(alpha_)*sin(phi_);
00141         tmpboost(2,2) = cos(phi_);
00142         tmpboost(2,3) = - sin(alpha_)*sin(phi_);
00143         tmpboost(3,0) = - sin(alpha_)*tan(phi_);
00144         tmpboost(3,1) = 0.;
00145         tmpboost(3,2) = sin(alpha_)*tan(phi_);
00146         tmpboost(3,3) = 1.;
00147 
00148         tmpboost.Invert();
00149         boost_ = new TMatrixD(tmpboost);
00150         //boost_->Print();
00151         
00152         return boost_;
00153 }