CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/IOMC/EventVertexGenerators/src/GaussEvtVtxGenerator.cc

Go to the documentation of this file.
00001 
00002 // $Id: GaussEvtVtxGenerator.cc,v 1.6 2009/05/25 12:46:04 fabiocos Exp $
00003 
00004 #include "IOMC/EventVertexGenerators/interface/GaussEvtVtxGenerator.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 
00009 #include "CLHEP/Random/RandGaussQ.h"
00010 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00011 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00012 //#include "CLHEP/Vector/ThreeVector.h"
00013 #include "HepMC/SimpleVector.h"
00014 
00015 GaussEvtVtxGenerator::GaussEvtVtxGenerator(const edm::ParameterSet & p )
00016 : BaseEvtVtxGenerator(p)
00017 { 
00018   
00019   fRandom = new CLHEP::RandGaussQ(getEngine());
00020   
00021   fMeanX =  p.getParameter<double>("MeanX")*cm;
00022   fMeanY =  p.getParameter<double>("MeanY")*cm;
00023   fMeanZ =  p.getParameter<double>("MeanZ")*cm;
00024   fSigmaX = p.getParameter<double>("SigmaX")*cm;
00025   fSigmaY = p.getParameter<double>("SigmaY")*cm;
00026   fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
00027   fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light;
00028   
00029   if (fSigmaX < 0) {
00030     throw cms::Exception("Configuration")
00031       << "Error in GaussEvtVtxGenerator: "
00032       << "Illegal resolution in X (SigmaX is negative)";
00033   }
00034   if (fSigmaY < 0) {
00035     throw cms::Exception("Configuration")
00036       << "Error in GaussEvtVtxGenerator: "
00037       << "Illegal resolution in Y (SigmaY is negative)";
00038   }
00039   if (fSigmaZ < 0) {
00040     throw cms::Exception("Configuration")
00041       << "Error in GaussEvtVtxGenerator: "
00042       << "Illegal resolution in Z (SigmaZ is negative)";
00043   }
00044 }
00045 
00046 GaussEvtVtxGenerator::~GaussEvtVtxGenerator() 
00047 {
00048   delete fRandom; 
00049 }
00050 
00051 
00052 //Hep3Vector* GaussEvtVtxGenerator::newVertex() {
00053 HepMC::FourVector* GaussEvtVtxGenerator::newVertex() {
00054   double X,Y,Z;
00055   X = fSigmaX * fRandom->fire() + fMeanX ;
00056   Y = fSigmaY * fRandom->fire() + fMeanY ;
00057   Z = fSigmaZ * fRandom->fire() + fMeanZ ;
00058 
00059   //if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
00060   if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
00061   fVertex->set( X, Y, Z, fTimeOffset ) ;
00062 
00063   return fVertex;
00064 }
00065 
00066 void GaussEvtVtxGenerator::sigmaX(double s) 
00067 { 
00068   if (s>=0 ) {
00069     fSigmaX=s; 
00070   }
00071   else {
00072     throw cms::Exception("LogicError")
00073       << "Error in GaussEvtVtxGenerator::sigmaX: "
00074       << "Illegal resolution in X (negative)";
00075   }
00076 }
00077 
00078 void GaussEvtVtxGenerator::sigmaY(double s) 
00079 { 
00080   if (s>=0 ) {
00081     fSigmaY=s; 
00082   }
00083   else {
00084     throw cms::Exception("LogicError")
00085       << "Error in GaussEvtVtxGenerator::sigmaY: "
00086       << "Illegal resolution in Y (negative)";
00087   }
00088 }
00089 
00090 void GaussEvtVtxGenerator::sigmaZ(double s) 
00091 { 
00092   if (s>=0 ) {
00093     fSigmaZ=s; 
00094   }
00095   else {
00096     throw cms::Exception("LogicError")
00097       << "Error in GaussEvtVtxGenerator::sigmaZ: "
00098       << "Illegal resolution in Z (negative)";
00099   }
00100 }