11 #include <CLHEP/Random/RandFlat.h> 12 #include <CLHEP/Units/SystemOfUnits.h> 13 #include <CLHEP/Units/GlobalPhysicalConstants.h> 14 #include "HepMC/SimpleVector.h" 20 constexpr double gamma34 = 1.22541670246517764513;
21 constexpr double gamma14 = 3.62560990822190831193;
22 constexpr double gamma54 = 0.90640247705547798267;
24 constexpr double sqrt2to5 = 5.65685424949;
30 desc.add<
double>(
"MeanXIncm", 0.0);
31 desc.add<
double>(
"MeanYIncm", 0.0);
32 desc.add<
double>(
"MeanZIncm", 0.0);
33 desc.add<
double>(
"TimeOffsetInns", 0.0);
34 desc.add<
double>(
"EprotonInGeV", 7000.0);
35 desc.add<
double>(
"CrossingAngleInurad", 510.0);
36 desc.add<
double>(
"CrabbingAngleCrossingInurad", 380.0);
37 desc.add<
double>(
"CrabbingAngleSeparationInurad", 0.0);
38 desc.add<
double>(
"CrabFrequencyInMHz", 400.0);
39 desc.add<
bool>(
"RF800",
false);
40 desc.add<
double>(
"BetaCrossingPlaneInm", 0.20);
41 desc.add<
double>(
"BetaSeparationPlaneInm", 0.20);
42 desc.add<
double>(
"HorizontalEmittance", 2.5e-06);
43 desc.add<
double>(
"VerticalEmittance", 2.05e-06);
44 desc.add<
double>(
"BunchLengthInm", 0.09);
46 desc.add<
bool>(
"readDB");
47 descriptions.
add(
"HLLHCEvtVtxGenerator",
desc);
51 readDB_ =
p.getParameter<
bool>(
"readDB");
54 fMeanX =
p.getParameter<
double>(
"MeanXIncm") * CLHEP::cm;
55 fMeanY =
p.getParameter<
double>(
"MeanYIncm") * CLHEP::cm;
56 fMeanZ =
p.getParameter<
double>(
"MeanZIncm") * CLHEP::cm;
58 fEProton =
p.getParameter<
double>(
"EprotonInGeV") * 1e9;
61 fRF800 =
p.getParameter<
bool>(
"RF800");
83 esConsumes<SimBeamSpotHLLHCObjects, SimBeamSpotHLLHCObjectsRcd, edm::Transition::BeginLuminosityBlock>();
92 if (readDB_ && parameterWatcher_.check(iEventSetup)) {
95 fMeanX = beamhandle->
meanX() * CLHEP::cm;
96 fMeanY = beamhandle->
meanY() * CLHEP::cm;
97 fMeanZ = beamhandle->
meanZ() * CLHEP::cm;
98 fEProton = beamhandle->
eProton() * 1e9;
101 fRF800 = beamhandle->
rf800();
109 fTimeOffset_c_light = beamhandle->
timeOffset() * CLHEP::ns * CLHEP::c_light;
111 gamma = fEProton / pmass;
114 oncc = fCrabbingAngleCrossing / fCrossingAngle;
115 epsx = fHorizontalEmittance / (betagamma);
117 sigx =
std::sqrt(epsx * fBetaCrossingPlane);
118 phiCR = oncc * fCrossingAngle;
123 double imax = intensity(0., 0., 0., 0.);
125 double x(0.),
y(0.),
z(0.),
t(0.),
i(0.);
129 auto shoot = [&]() {
return CLHEP::RandFlat::shoot(engine); };
132 z = (shoot() - 0.5) * 6.0 * fBunchLength;
133 t = (shoot() - 0.5) * 6.0 * fBunchLength;
134 x = (shoot() - 0.5) * 12.0 * sigma(0.0, fHorizontalEmittance, fBetaCrossingPlane, betagamma);
135 y = (shoot() - 0.5) * 12.0 * sigma(0.0, fVerticalEmittance, fBetaSeparationPlane, betagamma);
137 i = intensity(
x,
y,
z,
t);
140 edm::LogError(
"Too large intensity") <<
"i>imax : " <<
i <<
" > " << imax << endl;
142 }
while ((
i < imax * shoot()) &&
count < 10000);
156 t += fTimeOffset_c_light;
158 return HepMC::FourVector(
x,
y,
z,
t);
170 const double sigmay = sigma(
z, fVerticalEmittance, fBetaSeparationPlane, betagamma);
172 const double alphay_mod = fCrabbingAngleSeparation *
std::cos(fCrabFrequency * (
z -
t) /
c);
174 const double cay =
std::cos(alphay_mod);
175 const double say =
std::sin(alphay_mod);
177 const double dy = -(
z -
t) * say -
y * cay;
179 const double xzt_density = integrandCC(
x,
z,
t);
181 const double norm = two_pi * sigmay;
183 return (
std::exp(-
dy *
dy / (sigmay * sigmay)) * xzt_density / norm);
190 const double k2 =
k *
k;
193 const double cos2 =
cos *
cos;
194 const double sin2 =
sin *
sin;
196 const double sigx2 = sigx * sigx;
197 const double sigmax2 = sigx2 * (1 +
z *
z / (fBetaCrossingPlane * fBetaCrossingPlane));
199 const double sigs2 = fBunchLength * fBunchLength;
202 1. / sqrt2 / gamma34 * gamma14;
203 constexpr double NormFactorGauss4 = sqrt2to5 * gamma54 * gamma54;
205 const double sinCR =
std::sin(phiCR / 2.0);
206 const double sinCR2 = sinCR * sinCR;
211 const double norm = 2.0 / (two_pi * sigs2);
216 1.0 / (4 *
k2 * sigmax2) *
221 4 *
k2 *
z *
z * sin2) -
222 x *
x * (cos2 / sigmax2 + sin2 / sigs2)
224 + 2 *
x *
cos * cosks * sinkct * sinCR /
k / sigmax2
228 (1.0 + (
z *
z) / (fBetaCrossingPlane * fBetaCrossingPlane)) /
229 std::sqrt(1.0 + (
z *
z) / (fBetaSeparationPlane * fBetaSeparationPlane));
232 const double norm = 2.0 / (NormFactorGauss4 * sigs2 * factorRMSgauss4);
233 const double sigs4 = sigs2 * sigs2 * factorRMSgauss4 * factorRMSgauss4;
239 sin2 / (4 *
k2 * sigmax2) *
242 std::sqrt((1 +
z *
z / (fBetaCrossingPlane * fBetaCrossingPlane)) /
243 (1 +
z *
z / (fBetaSeparationPlane * fBetaSeparationPlane)));
double crabbingAngleSeparation() const
double fCrabbingAngleSeparation
HepMC::FourVector newVertex(CLHEP::HepRandomEngine *) const override
return a new event vertex
HLLHCEvtVtxGenerator(const edm::ParameterSet &p)
double fBetaCrossingPlane
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Sin< T >::type sin(const T &t)
double sigma(double z, double epsilon, double beta, double betagamma) const
Log< level::Error, false > LogError
double eProton() const
get EProton, fCrabFrequency, RF800
double crabFrequency() const
double meanX() const
get meanX, meanY, meanZ position
Cos< T >::type cos(const T &t)
double crossingAngle() const
set Crossing and Crabbing angles
double fTimeOffset_c_light
double intensity(double x, double y, double z, double t) const
edm::ESGetToken< SimBeamSpotHLLHCObjects, SimBeamSpotHLLHCObjectsRcd > beamToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
double fCrabbingAngleCrossing
void update(const edm::EventSetup &iEventSetup)
double fVerticalEmittance
double horizontalEmittance() const
double fHorizontalEmittance
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double betaCrossingPlane() const
get BetaStar and Emittance
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
static constexpr float local_c_light
double fBetaSeparationPlane
double bunchLenght() const
get BunchLength and TimeOffset
double verticalEmittance() const
double integrandCC(double x, double z, double t) const
double betaSeparationPlane() const
double timeOffset() const
double crabbingAngleCrossing() const