CMS 3D CMS Logo

GaussEvtVtxGenerator.cc
Go to the documentation of this file.
4 
5 #include "CLHEP/Random/RandGaussQ.h"
6 #include "CLHEP/Units/GlobalSystemOfUnits.h"
7 #include "CLHEP/Units/GlobalPhysicalConstants.h"
8 #include "HepMC/SimpleVector.h"
9 
11  readDB_ = p.getParameter<bool>("readDB");
12  if (!readDB_) {
13  fMeanX = p.getParameter<double>("MeanX") * cm;
14  fMeanY = p.getParameter<double>("MeanY") * cm;
15  fMeanZ = p.getParameter<double>("MeanZ") * cm;
16  fSigmaX = p.getParameter<double>("SigmaX") * cm;
17  fSigmaY = p.getParameter<double>("SigmaY") * cm;
18  fSigmaZ = p.getParameter<double>("SigmaZ") * cm;
19  fTimeOffset = p.getParameter<double>("TimeOffset") * ns * c_light; // HepMC distance units are in mm
20 
21  if (fSigmaX < 0) {
22  throw cms::Exception("Configuration") << "Error in GaussEvtVtxGenerator: "
23  << "Illegal resolution in X (SigmaX is negative)";
24  }
25  if (fSigmaY < 0) {
26  throw cms::Exception("Configuration") << "Error in GaussEvtVtxGenerator: "
27  << "Illegal resolution in Y (SigmaY is negative)";
28  }
29  if (fSigmaZ < 0) {
30  throw cms::Exception("Configuration") << "Error in GaussEvtVtxGenerator: "
31  << "Illegal resolution in Z (SigmaZ is negative)";
32  }
33  }
34  if (readDB_) {
35  // NOTE: this is currently watching LS transitions, while it should watch Run transitions,
36  // even though in reality there is no Run Dependent MC (yet) in CMS
37  beamToken_ = esConsumes<SimBeamSpotObjects, SimBeamSpotObjectsRcd, edm::Transition::BeginLuminosityBlock>();
38  }
39 }
40 
42  update(iEventSetup);
43 }
44 
46  if (readDB_ && parameterWatcher_.check(iEventSetup)) {
47  edm::ESHandle<SimBeamSpotObjects> beamhandle = iEventSetup.getHandle(beamToken_);
48  fMeanX = beamhandle->meanX() * cm;
49  fMeanY = beamhandle->meanY() * cm;
50  fMeanZ = beamhandle->meanZ() * cm;
51  fSigmaX = beamhandle->sigmaX() * cm;
52  fSigmaY = beamhandle->sigmaY() * cm;
53  fSigmaZ = beamhandle->sigmaZ() * cm;
54  fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC distance units are in mm
55  }
56 }
57 
58 HepMC::FourVector GaussEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
59  double X, Y, Z, T;
60  X = CLHEP::RandGaussQ::shoot(engine, fMeanX, fSigmaX);
61  Y = CLHEP::RandGaussQ::shoot(engine, fMeanY, fSigmaY);
62  Z = CLHEP::RandGaussQ::shoot(engine, fMeanZ, fSigmaZ);
63  T = CLHEP::RandGaussQ::shoot(engine, fTimeOffset, fSigmaZ);
64 
65  return HepMC::FourVector(X, Y, Z, T);
66 }
67 
69  if (s >= 0) {
70  fSigmaX = s;
71  } else {
72  throw cms::Exception("LogicError") << "Error in GaussEvtVtxGenerator::sigmaX: "
73  << "Illegal resolution in X (negative)";
74  }
75 }
76 
78  if (s >= 0) {
79  fSigmaY = s;
80  } else {
81  throw cms::Exception("LogicError") << "Error in GaussEvtVtxGenerator::sigmaY: "
82  << "Illegal resolution in Y (negative)";
83  }
84 }
85 
87  if (s >= 0) {
88  fSigmaZ = s;
89  } else {
90  throw cms::Exception("LogicError") << "Error in GaussEvtVtxGenerator::sigmaZ: "
91  << "Illegal resolution in Z (negative)";
92  }
93 }
94 
97  desc.add<double>("MeanX", 0.0)->setComment("in cm");
98  desc.add<double>("MeanY", 0.0)->setComment("in cm");
99  desc.add<double>("MeanZ", 0.0)->setComment("in cm");
100  desc.add<double>("SigmaX", 0.0)->setComment("in cm");
101  desc.add<double>("SigmaY", 0.0)->setComment("in cm");
102  desc.add<double>("SigmaZ", 0.0)->setComment("in cm");
103  desc.add<double>("TimeOffset", 0.0)->setComment("in ns");
104  desc.add<edm::InputTag>("src");
105  desc.add<bool>("readDB");
106  descriptions.add("GaussEvtVtxGenerator", desc);
107 }
double sigmaZ() const
double sigmaX() const
get sigmaX, sigmaY, sigmaZ
void sigmaY(double s=1.0)
set resolution in Y in cm
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESGetToken< SimBeamSpotObjects, SimBeamSpotObjectsRcd > beamToken_
double meanX() const
get meanX, meanY, meanZ position
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
#define X(str)
Definition: MuonsGrabber.cc:38
void sigmaX(double s=1.0)
set resolution in X in cm
void update(const edm::EventSetup &iEventSetup)
edm::ESWatcher< SimBeamSpotObjectsRcd > parameterWatcher_
GaussEvtVtxGenerator(const edm::ParameterSet &p)
HepMC::FourVector newVertex(CLHEP::HepRandomEngine *) const override
return a new event vertex
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
double timeOffset() const
double meanY() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
double meanZ() const
void sigmaZ(double s=1.0)
set resolution in Z in cm
long double T