CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/IOMC/EventVertexGenerators/src/FlatEvtVtxGenerator.cc

Go to the documentation of this file.
00001 
00002 // $Id: FlatEvtVtxGenerator.cc,v 1.5 2009/05/25 12:46:04 fabiocos Exp $
00003 
00004 #include "IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 
00009 #include "CLHEP/Random/RandFlat.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 FlatEvtVtxGenerator::FlatEvtVtxGenerator(const edm::ParameterSet& p )
00016 : BaseEvtVtxGenerator(p)
00017 { 
00018   
00019   fRandom = new CLHEP::RandFlat(getEngine()) ;
00020   
00021   fMinX = p.getParameter<double>("MinX")*cm;
00022   fMinY = p.getParameter<double>("MinY")*cm;
00023   fMinZ = p.getParameter<double>("MinZ")*cm;
00024   fMaxX = p.getParameter<double>("MaxX")*cm;
00025   fMaxY = p.getParameter<double>("MaxY")*cm;
00026   fMaxZ = p.getParameter<double>("MaxZ")*cm;     
00027   fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light;
00028   
00029   if (fMinX > fMaxX) {
00030     throw cms::Exception("Configuration")
00031       << "Error in FlatEvtVtxGenerator: "
00032       << "MinX is greater than MaxX";
00033   }
00034   if (fMinY > fMaxY) {
00035     throw cms::Exception("Configuration")
00036       << "Error in FlatEvtVtxGenerator: "
00037       << "MinY is greater than MaxY";
00038   }
00039   if (fMinZ > fMaxZ) {
00040     throw cms::Exception("Configuration")
00041       << "Error in FlatEvtVtxGenerator: "
00042       << "MinZ is greater than MaxZ";
00043   }
00044 }
00045 
00046 FlatEvtVtxGenerator::~FlatEvtVtxGenerator() 
00047 {
00048   delete fRandom; 
00049 }
00050 
00051 
00052 //Hep3Vector * FlatEvtVtxGenerator::newVertex() {
00053 HepMC::FourVector* FlatEvtVtxGenerator::newVertex() {
00054   double aX,aY,aZ;
00055   aX = fRandom->fire(fMinX,fMaxX) ;
00056   aY = fRandom->fire(fMinY,fMaxY) ;
00057   aZ = fRandom->fire(fMinZ,fMaxZ) ;
00058 
00059   //if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
00060   //fVertex->set(aX,aY,aZ);
00061   if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
00062   fVertex->set(aX,aY,aZ,fTimeOffset);
00063 
00064   return fVertex;
00065 }
00066 
00067 void FlatEvtVtxGenerator::minX(double min) 
00068 {
00069   fMinX = min;
00070 }
00071 
00072 void FlatEvtVtxGenerator::minY(double min) 
00073 {
00074   fMinY = min;
00075 }
00076 
00077 void FlatEvtVtxGenerator::minZ(double min) 
00078 {
00079   fMinZ = min;
00080 }
00081 
00082 void FlatEvtVtxGenerator::maxX(double max) 
00083 {
00084   fMaxX = max;
00085 }
00086 
00087 void FlatEvtVtxGenerator::maxY(double max) 
00088 {
00089   fMaxY = max;
00090 }
00091 
00092 void FlatEvtVtxGenerator::maxZ(double max) 
00093 {
00094   fMaxZ = max;
00095 }