CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GaussEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 
5 
7 
8 #include "CLHEP/Random/RandGaussQ.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::RandGaussQ(getEngine());
19 
20  fMeanX = p.getParameter<double>("MeanX")*cm;
21  fMeanY = p.getParameter<double>("MeanY")*cm;
22  fMeanZ = p.getParameter<double>("MeanZ")*cm;
23  fSigmaX = p.getParameter<double>("SigmaX")*cm;
24  fSigmaY = p.getParameter<double>("SigmaY")*cm;
25  fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
26  fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light;
27 
28  if (fSigmaX < 0) {
29  throw cms::Exception("Configuration")
30  << "Error in GaussEvtVtxGenerator: "
31  << "Illegal resolution in X (SigmaX is negative)";
32  }
33  if (fSigmaY < 0) {
34  throw cms::Exception("Configuration")
35  << "Error in GaussEvtVtxGenerator: "
36  << "Illegal resolution in Y (SigmaY is negative)";
37  }
38  if (fSigmaZ < 0) {
39  throw cms::Exception("Configuration")
40  << "Error in GaussEvtVtxGenerator: "
41  << "Illegal resolution in Z (SigmaZ is negative)";
42  }
43 }
44 
46 {
47  delete fRandom;
48 }
49 
50 
51 //Hep3Vector* GaussEvtVtxGenerator::newVertex() {
52 HepMC::FourVector* GaussEvtVtxGenerator::newVertex() {
53  double X,Y,Z;
54  X = fSigmaX * fRandom->fire() + fMeanX ;
55  Y = fSigmaY * fRandom->fire() + fMeanY ;
56  Z = fSigmaZ * fRandom->fire() + fMeanZ ;
57 
58  //if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
59  if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
60  fVertex->set( X, Y, Z, fTimeOffset ) ;
61 
62  return fVertex;
63 }
64 
66 {
67  if (s>=0 ) {
68  fSigmaX=s;
69  }
70  else {
71  throw cms::Exception("LogicError")
72  << "Error in GaussEvtVtxGenerator::sigmaX: "
73  << "Illegal resolution in X (negative)";
74  }
75 }
76 
78 {
79  if (s>=0 ) {
80  fSigmaY=s;
81  }
82  else {
83  throw cms::Exception("LogicError")
84  << "Error in GaussEvtVtxGenerator::sigmaY: "
85  << "Illegal resolution in Y (negative)";
86  }
87 }
88 
90 {
91  if (s>=0 ) {
92  fSigmaZ=s;
93  }
94  else {
95  throw cms::Exception("LogicError")
96  << "Error in GaussEvtVtxGenerator::sigmaZ: "
97  << "Illegal resolution in Z (negative)";
98  }
99 }
const double Z[kNumberCalorimeter]
T getParameter(std::string const &) const
CLHEP::HepRandomEngine & getEngine()
void sigmaY(double s=1.0)
set resolution in Y in cm
HepMC::FourVector * fVertex
#define X(str)
Definition: MuonsGrabber.cc:48
void sigmaX(double s=1.0)
set resolution in X in cm
GaussEvtVtxGenerator(const edm::ParameterSet &p)
CLHEP::RandGaussQ * fRandom
virtual HepMC::FourVector * newVertex()
return a new event vertex
void sigmaZ(double s=1.0)
set resolution in Z in cm