File indexing completed on 2023-05-03 04:04:35
0001
0002
0003 #include "IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008
0009 #include "CLHEP/Random/RandFlat.h"
0010 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0011 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0012
0013 #include "HepMC/SimpleVector.h"
0014
0015 FlatEvtVtxGenerator::FlatEvtVtxGenerator(const edm::ParameterSet& p) : BaseEvtVtxGenerator(p) {
0016 fMinX = p.getParameter<double>("MinX") * cm;
0017 fMinY = p.getParameter<double>("MinY") * cm;
0018 fMinZ = p.getParameter<double>("MinZ") * cm;
0019 fMaxX = p.getParameter<double>("MaxX") * cm;
0020 fMaxY = p.getParameter<double>("MaxY") * cm;
0021 fMaxZ = p.getParameter<double>("MaxZ") * cm;
0022 fMinT = p.getParameter<double>("MinT") * ns * c_light;
0023 fMaxT = p.getParameter<double>("MaxT") * ns * c_light;
0024
0025 if (fMinX > fMaxX) {
0026 throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: "
0027 << "MinX is greater than MaxX";
0028 }
0029 if (fMinY > fMaxY) {
0030 throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: "
0031 << "MinY is greater than MaxY";
0032 }
0033 if (fMinZ > fMaxZ) {
0034 throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: "
0035 << "MinZ is greater than MaxZ";
0036 }
0037 if (fMinT > fMaxT) {
0038 throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: "
0039 << "MinT is greater than MaxT";
0040 }
0041 edm::LogVerbatim("FlatEvtVtx") << "FlatEvtVtxGenerator Initialized with x[" << fMinX << ":" << fMaxX << "] cm; y["
0042 << fMinY << ":" << fMaxY << "] cm; z[" << fMinZ << ":" << fMaxZ << "] cm; t[" << fMinT
0043 << ":" << fMaxT << "]";
0044 }
0045
0046 FlatEvtVtxGenerator::~FlatEvtVtxGenerator() {}
0047
0048
0049 HepMC::FourVector FlatEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
0050 double aX, aY, aZ, aT;
0051 aX = CLHEP::RandFlat::shoot(engine, fMinX, fMaxX);
0052 aY = CLHEP::RandFlat::shoot(engine, fMinY, fMaxY);
0053 aZ = CLHEP::RandFlat::shoot(engine, fMinZ, fMaxZ);
0054 aT = CLHEP::RandFlat::shoot(engine, fMinT, fMaxT);
0055
0056 edm::LogVerbatim("FlatEvtVtx") << "FlatEvtVtxGenerator Vertex at [" << aX << ", " << aY << ", " << aZ << ", " << aT
0057 << "]";
0058
0059 return HepMC::FourVector(aX, aY, aZ, aT);
0060 }
0061
0062 void FlatEvtVtxGenerator::minX(double min) { fMinX = min; }
0063
0064 void FlatEvtVtxGenerator::minY(double min) { fMinY = min; }
0065
0066 void FlatEvtVtxGenerator::minZ(double min) { fMinZ = min; }
0067
0068 void FlatEvtVtxGenerator::maxX(double max) { fMaxX = max; }
0069
0070 void FlatEvtVtxGenerator::maxY(double max) { fMaxY = max; }
0071
0072 void FlatEvtVtxGenerator::maxZ(double max) { fMaxZ = max; }