CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FlatEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 
5 
7 
8 #include "CLHEP/Random/RandFlat.h"
9 #include "CLHEP/Units/GlobalSystemOfUnits.h"
10 #include "CLHEP/Units/GlobalPhysicalConstants.h"
11 //#include "CLHEP/Vector/ThreeVector.h"
12 #include "HepMC/SimpleVector.h"
13 
16 {
17 
18  fRandom = new CLHEP::RandFlat(getEngine()) ;
19 
20  fMinX = p.getParameter<double>("MinX")*cm;
21  fMinY = p.getParameter<double>("MinY")*cm;
22  fMinZ = p.getParameter<double>("MinZ")*cm;
23  fMaxX = p.getParameter<double>("MaxX")*cm;
24  fMaxY = p.getParameter<double>("MaxY")*cm;
25  fMaxZ = p.getParameter<double>("MaxZ")*cm;
26  fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light;
27 
28  if (fMinX > fMaxX) {
29  throw cms::Exception("Configuration")
30  << "Error in FlatEvtVtxGenerator: "
31  << "MinX is greater than MaxX";
32  }
33  if (fMinY > fMaxY) {
34  throw cms::Exception("Configuration")
35  << "Error in FlatEvtVtxGenerator: "
36  << "MinY is greater than MaxY";
37  }
38  if (fMinZ > fMaxZ) {
39  throw cms::Exception("Configuration")
40  << "Error in FlatEvtVtxGenerator: "
41  << "MinZ is greater than MaxZ";
42  }
43 }
44 
46 {
47  delete fRandom;
48 }
49 
50 
51 //Hep3Vector * FlatEvtVtxGenerator::newVertex() {
52 HepMC::FourVector* FlatEvtVtxGenerator::newVertex() {
53  double aX,aY,aZ;
54  aX = fRandom->fire(fMinX,fMaxX) ;
55  aY = fRandom->fire(fMinY,fMaxY) ;
56  aZ = fRandom->fire(fMinZ,fMaxZ) ;
57 
58  //if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
59  //fVertex->set(aX,aY,aZ);
60  if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
61  fVertex->set(aX,aY,aZ,fTimeOffset);
62 
63  return fVertex;
64 }
65 
67 {
68  fMinX = min;
69 }
70 
72 {
73  fMinY = min;
74 }
75 
77 {
78  fMinZ = min;
79 }
80 
82 {
83  fMaxX = max;
84 }
85 
87 {
88  fMaxY = max;
89 }
90 
92 {
93  fMaxZ = max;
94 }
T getParameter(std::string const &) const
CLHEP::HepRandomEngine & getEngine()
HepMC::FourVector * fVertex
void minZ(double m=0.0)
set min in Z in cm
virtual HepMC::FourVector * newVertex()
return a new event vertex
const T & max(const T &a, const T &b)
CLHEP::RandFlat * fRandom
void maxZ(double m=0)
set max in Z in cm
FlatEvtVtxGenerator(const edm::ParameterSet &p)
void minX(double m=0.0)
set min in X in cm
void minY(double m=0.0)
set min in Y in cm
void maxX(double m=0)
set max in X in cm
void maxY(double m=0)
set max in Y in cm