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 // $Id: GaussEvtVtxGenerator.cc,v 1.6 2009/05/25 12:46:04 fabiocos Exp $
3 
6 
8 
9 #include "CLHEP/Random/RandGaussQ.h"
10 #include "CLHEP/Units/GlobalSystemOfUnits.h"
11 #include "CLHEP/Units/GlobalPhysicalConstants.h"
12 //#include "CLHEP/Vector/ThreeVector.h"
13 #include "HepMC/SimpleVector.h"
14 
17 {
18 
19  fRandom = new CLHEP::RandGaussQ(getEngine());
20 
21  fMeanX = p.getParameter<double>("MeanX")*cm;
22  fMeanY = p.getParameter<double>("MeanY")*cm;
23  fMeanZ = p.getParameter<double>("MeanZ")*cm;
24  fSigmaX = p.getParameter<double>("SigmaX")*cm;
25  fSigmaY = p.getParameter<double>("SigmaY")*cm;
26  fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
27  fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light;
28 
29  if (fSigmaX < 0) {
30  throw cms::Exception("Configuration")
31  << "Error in GaussEvtVtxGenerator: "
32  << "Illegal resolution in X (SigmaX is negative)";
33  }
34  if (fSigmaY < 0) {
35  throw cms::Exception("Configuration")
36  << "Error in GaussEvtVtxGenerator: "
37  << "Illegal resolution in Y (SigmaY is negative)";
38  }
39  if (fSigmaZ < 0) {
40  throw cms::Exception("Configuration")
41  << "Error in GaussEvtVtxGenerator: "
42  << "Illegal resolution in Z (SigmaZ is negative)";
43  }
44 }
45 
47 {
48  delete fRandom;
49 }
50 
51 
52 //Hep3Vector* GaussEvtVtxGenerator::newVertex() {
53 HepMC::FourVector* GaussEvtVtxGenerator::newVertex() {
54  double X,Y,Z;
55  X = fSigmaX * fRandom->fire() + fMeanX ;
56  Y = fSigmaY * fRandom->fire() + fMeanY ;
57  Z = fSigmaZ * fRandom->fire() + fMeanZ ;
58 
59  //if (fVertex == 0) fVertex = new CLHEP::Hep3Vector;
60  if ( fVertex == 0 ) fVertex = new HepMC::FourVector() ;
61  fVertex->set( X, Y, Z, fTimeOffset ) ;
62 
63  return fVertex;
64 }
65 
67 {
68  if (s>=0 ) {
69  fSigmaX=s;
70  }
71  else {
72  throw cms::Exception("LogicError")
73  << "Error in GaussEvtVtxGenerator::sigmaX: "
74  << "Illegal resolution in X (negative)";
75  }
76 }
77 
79 {
80  if (s>=0 ) {
81  fSigmaY=s;
82  }
83  else {
84  throw cms::Exception("LogicError")
85  << "Error in GaussEvtVtxGenerator::sigmaY: "
86  << "Illegal resolution in Y (negative)";
87  }
88 }
89 
91 {
92  if (s>=0 ) {
93  fSigmaZ=s;
94  }
95  else {
96  throw cms::Exception("LogicError")
97  << "Error in GaussEvtVtxGenerator::sigmaZ: "
98  << "Illegal resolution in Z (negative)";
99  }
100 }
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:49
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