CMS 3D CMS Logo

BetafuncEvtVtxGenerator.cc

Go to the documentation of this file.
00001 
00002 // $Id: BetafuncEvtVtxGenerator.cc,v 1.8 2008/04/04 21:38:25 yumiceva 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/SystemOfUnits.h"
00028 #include "CLHEP/Units/PhysicalConstants.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(tmp_sigz,fZ0); 
00077         X = fRandom->fire(0.,tmp_sigx) + fX0; // + Z*fdxdz ;
00078 
00079         double tmp_sigy = BetaFunction(tmp_sigz,fZ0);
00080         Y = fRandom->fire(0.,tmp_sigy) + fY0; // + Z*fdydz;
00081           
00082         //if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
00083         //fVertex->set(X, Y, Z);
00084         if ( fVertex == 0 ) fVertex = new HepMC::FourVector();
00085         fVertex->set(X,Y,Z,fTimeOffset);
00086                 
00087         return fVertex;
00088 }
00089 
00090 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0)
00091 {
00092         return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
00093 
00094 }
00095 
00096 
00097 void BetafuncEvtVtxGenerator::sigmaZ(double s) 
00098 { 
00099         if (s>=0 ) {
00100                 fSigmaZ=s; 
00101         }
00102         else {
00103                 throw cms::Exception("LogicError")
00104                         << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
00105                         << "Illegal resolution in Z (negative)";
00106         }
00107 }
00108 
00109 TMatrixD* BetafuncEvtVtxGenerator::GetInvLorentzBoost() {
00110 
00111         //alpha_ = 0;
00112         //phi_ = 142.e-6;
00113         
00114         if (boost_ != 0 ) return boost_;
00115         
00116         //boost_.ResizeTo(4,4);
00117         //boost_ = new TMatrixD(4,4);
00118         TMatrixD tmpboost(4,4);
00119         
00120         //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
00121         
00122         // Lorentz boost to frame where the collision is head-on
00123         // phi is the half crossing angle in the plane ZS
00124         // alpha is the angle to the S axis from the X axis in the XY plane
00125         
00126         tmpboost(0,0) = 1./cos(phi_);
00127         tmpboost(0,1) = - cos(alpha_)*sin(phi_);
00128         tmpboost(0,2) = - tan(phi_)*sin(phi_);
00129         tmpboost(0,3) = - sin(alpha_)*sin(phi_);
00130         tmpboost(1,0) = - cos(alpha_)*tan(phi_);
00131         tmpboost(1,1) = 1.;
00132         tmpboost(1,2) = cos(alpha_)*tan(phi_);
00133         tmpboost(1,3) = 0.;
00134         tmpboost(2,0) = 0.;
00135         tmpboost(2,1) = - cos(alpha_)*sin(phi_);
00136         tmpboost(2,2) = cos(phi_);
00137         tmpboost(2,3) = - sin(alpha_)*sin(phi_);
00138         tmpboost(3,0) = - sin(alpha_)*tan(phi_);
00139         tmpboost(3,1) = 0.;
00140         tmpboost(3,2) = sin(alpha_)*tan(phi_);
00141         tmpboost(3,3) = 1.;
00142 
00143         tmpboost.Invert();
00144         boost_ = new TMatrixD(tmpboost);
00145         //boost_->Print();
00146         
00147         return boost_;
00148 }

Generated on Tue Jun 9 17:39:05 2009 for CMSSW by  doxygen 1.5.4