Skip to content

Commit 532aba3

Browse files
committed
add protections against mismatched SimBeamSpot types in BetafuncEvtVtxGenerator and GaussEvtVtxGenerator
1 parent 3301087 commit 532aba3

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,23 @@ class SimBeamSpotObjects {
8787
double alpha() const { return fAlpha; }
8888
double timeOffset() const { return fTimeOffset; }
8989

90+
/// Method to check if the object corresponds to GaussEvtVtxGenerator parameters
91+
bool isGaussian() const {
92+
// Check for the presence of GaussEvtVtxGenerator-specific parameters
93+
return ((fMeanX != 0.0 || fMeanY != 0.0 || fMeanZ != 0.0) || // either centroid is not 0,0,0
94+
(fSigmaX != -1.0 && fSigmaY != -1.0)); // or the withs are not defaults
95+
}
96+
9097
/// print sim beam spot parameters
9198
void print(std::stringstream& ss) const;
9299

93100
private:
94-
double fX0, fY0, fZ0;
95-
double fMeanX, fMeanY, fMeanZ;
96-
double fSigmaX, fSigmaY, fSigmaZ;
97-
double fbetastar, femittance;
98-
double fPhi, fAlpha;
99-
double fTimeOffset;
101+
double fX0, fY0, fZ0; // for beta-function
102+
double fMeanX, fMeanY, fMeanZ; // for gaussian
103+
double fSigmaX, fSigmaY, fSigmaZ; // for gaussian
104+
double fbetastar, femittance; // for beta-function
105+
double fPhi, fAlpha; // for beta-function
106+
double fTimeOffset; // for both
100107

101108
COND_SERIALIZABLE;
102109
};

IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ void BetafuncEvtVtxGenerator::beginLuminosityBlock(edm::LuminosityBlock const&,
6060
void BetafuncEvtVtxGenerator::update(const edm::EventSetup& iEventSetup) {
6161
if (readDB_ && parameterWatcher_.check(iEventSetup)) {
6262
edm::ESHandle<SimBeamSpotObjects> beamhandle = iEventSetup.getHandle(beamToken_);
63-
fX0 = beamhandle->x() * cm;
64-
fY0 = beamhandle->y() * cm;
65-
fZ0 = beamhandle->z() * cm;
66-
fSigmaZ = beamhandle->sigmaZ() * cm;
67-
fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC distance units are in mm
68-
fbetastar = beamhandle->betaStar() * cm;
69-
femittance = beamhandle->emittance() * cm;
70-
setBoost(beamhandle->alpha() * radian, beamhandle->phi() * radian);
63+
if (!beamhandle->isGaussian()) {
64+
fX0 = beamhandle->x() * cm;
65+
fY0 = beamhandle->y() * cm;
66+
fZ0 = beamhandle->z() * cm;
67+
fSigmaZ = beamhandle->sigmaZ() * cm;
68+
fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC distance units are in mm
69+
fbetastar = beamhandle->betaStar() * cm;
70+
femittance = beamhandle->emittance() * cm;
71+
setBoost(beamhandle->alpha() * radian, beamhandle->phi() * radian);
72+
} else {
73+
throw cms::Exception("Configuration")
74+
<< "Error in BetafuncEvtVtxGenerator::update: The provided SimBeamSpotObjects is Gaussian.\n"
75+
<< "Please check the configuration and ensure that the beam spot parameters are appropriate for a Betafunc "
76+
"distribution.";
77+
}
7178
}
7279
}
7380

IOMC/EventVertexGenerators/src/GaussEvtVtxGenerator.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ void GaussEvtVtxGenerator::beginLuminosityBlock(edm::LuminosityBlock const&, edm
4747
void GaussEvtVtxGenerator::update(const edm::EventSetup& iEventSetup) {
4848
if (readDB_ && parameterWatcher_.check(iEventSetup)) {
4949
edm::ESHandle<SimBeamSpotObjects> beamhandle = iEventSetup.getHandle(beamToken_);
50-
fMeanX = beamhandle->meanX() * cm;
51-
fMeanY = beamhandle->meanY() * cm;
52-
fMeanZ = beamhandle->meanZ() * cm;
53-
fSigmaX = beamhandle->sigmaX() * cm;
54-
fSigmaY = beamhandle->sigmaY() * cm;
55-
fSigmaZ = beamhandle->sigmaZ() * cm;
56-
fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC distance units are in mm
50+
if (beamhandle->isGaussian()) {
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+
} else {
59+
throw cms::Exception("Configuration")
60+
<< "Error in GaussEvtVtxGenerator::update: The provided SimBeamSpotObjects is not Gaussian.\n"
61+
<< "Please check the configuration and ensure that the beam spot parameters are appropriate for a Gaussian "
62+
"distribution.";
63+
}
5764
}
5865
}
5966

0 commit comments

Comments
 (0)