CMS 3D CMS Logo

GaussEvtVtxGenerator.cc
Go to the documentation of this file.
4 
5 #include <CLHEP/Random/RandGaussQ.h>
6 #include <CLHEP/Units/SystemOfUnits.h>
7 #include <CLHEP/Units/GlobalPhysicalConstants.h>
8 #include "HepMC/SimpleVector.h"
9 
10 using CLHEP::cm;
11 using CLHEP::ns;
12 
14  readDB_ = p.getParameter<bool>("readDB");
15  if (!readDB_) {
16  fMeanX = p.getParameter<double>("MeanX") * cm;
17  fMeanY = p.getParameter<double>("MeanY") * cm;
18  fMeanZ = p.getParameter<double>("MeanZ") * cm;
19  fSigmaX = p.getParameter<double>("SigmaX") * cm;
20  fSigmaY = p.getParameter<double>("SigmaY") * cm;
21  fSigmaZ = p.getParameter<double>("SigmaZ") * cm;
22  fTimeOffset = p.getParameter<double>("TimeOffset") * ns * c_light; // HepMC distance units are in mm
23 
24  if (fSigmaX < 0) {
25  throw cms::Exception("Configuration") << "Error in GaussEvtVtxGenerator: "
26  << "Illegal resolution in X (SigmaX is negative)";
27  }
28  if (fSigmaY < 0) {
29  throw cms::Exception("Configuration") << "Error in GaussEvtVtxGenerator: "
30  << "Illegal resolution in Y (SigmaY is negative)";
31  }
32  if (fSigmaZ < 0) {
33  throw cms::Exception("Configuration") << "Error in GaussEvtVtxGenerator: "
34  << "Illegal resolution in Z (SigmaZ is negative)";
35  }
36  }
37  if (readDB_) {
38  // NOTE: this is currently watching LS transitions, while it should watch Run transitions,
39  // even though in reality there is no Run Dependent MC (yet) in CMS
40  beamToken_ = esConsumes<SimBeamSpotObjects, SimBeamSpotObjectsRcd, edm::Transition::BeginLuminosityBlock>();
41  }
42 }
43 
45  update(iEventSetup);
46 }
47 
49  if (readDB_ && parameterWatcher_.check(iEventSetup)) {
50  edm::ESHandle<SimBeamSpotObjects> beamhandle = iEventSetup.getHandle(beamToken_);
51  fMeanX = beamhandle->meanX() * cm;
52  fMeanY = beamhandle->meanY() * cm;
53  fMeanZ = beamhandle->meanZ() * cm;
54  fSigmaX = beamhandle->sigmaX() * cm;
55  fSigmaY = beamhandle->sigmaY() * cm;
56  fSigmaZ = beamhandle->sigmaZ() * cm;
57  fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC distance units are in mm
58  }
59 }
60 
61 HepMC::FourVector GaussEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
62  double X, Y, Z, T;
63  X = CLHEP::RandGaussQ::shoot(engine, fMeanX, fSigmaX);
64  Y = CLHEP::RandGaussQ::shoot(engine, fMeanY, fSigmaY);
65  Z = CLHEP::RandGaussQ::shoot(engine, fMeanZ, fSigmaZ);
66  T = CLHEP::RandGaussQ::shoot(engine, fTimeOffset, fSigmaZ);
67 
68  return HepMC::FourVector(X, Y, Z, T);
69 }
70 
72  if (s >= 0) {
73  fSigmaX = s;
74  } else {
75  throw cms::Exception("LogicError") << "Error in GaussEvtVtxGenerator::sigmaX: "
76  << "Illegal resolution in X (negative)";
77  }
78 }
79 
81  if (s >= 0) {
82  fSigmaY = s;
83  } else {
84  throw cms::Exception("LogicError") << "Error in GaussEvtVtxGenerator::sigmaY: "
85  << "Illegal resolution in Y (negative)";
86  }
87 }
88 
90  if (s >= 0) {
91  fSigmaZ = s;
92  } else {
93  throw cms::Exception("LogicError") << "Error in GaussEvtVtxGenerator::sigmaZ: "
94  << "Illegal resolution in Z (negative)";
95  }
96 }
97 
100  desc.add<double>("MeanX", 0.0)->setComment("in cm");
101  desc.add<double>("MeanY", 0.0)->setComment("in cm");
102  desc.add<double>("MeanZ", 0.0)->setComment("in cm");
103  desc.add<double>("SigmaX", 0.0)->setComment("in cm");
104  desc.add<double>("SigmaY", 0.0)->setComment("in cm");
105  desc.add<double>("SigmaZ", 0.0)->setComment("in cm");
106  desc.add<double>("TimeOffset", 0.0)->setComment("in ns");
107  desc.add<edm::InputTag>("src");
108  desc.add<bool>("readDB");
109  descriptions.add("GaussEvtVtxGenerator", desc);
110 }
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