CMS 3D CMS Logo

HLLHCEvtVtxGenerator.cc
Go to the documentation of this file.
1 // $Id: HLLHCEvtVtxGenerator_Fix.cc, v 1.0 2015/03/15 10:32:11 Exp $
2 
5 
10 
11 #include "CLHEP/Random/RandFlat.h"
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
13 #include "CLHEP/Units/GlobalPhysicalConstants.h"
14 #include "HepMC/SimpleVector.h"
15 
16 using namespace std;
17 
18 namespace {
19 
20  constexpr double pmass = 0.9382720813e9; // eV
21  constexpr double gamma34 = 1.22541670246517764513; // Gamma(3/4)
22  constexpr double gamma14 = 3.62560990822190831193; // Gamma(1/4)
23  constexpr double gamma54 = 0.90640247705547798267; // Gamma(5/4)
24  constexpr double sqrt2 = 1.41421356237;
25  constexpr double sqrt2to5 = 5.65685424949;
26  constexpr double two_pi = 2.0 * M_PI;
27 } // namespace
28 
31  desc.add<double>("MeanXIncm", 0.0);
32  desc.add<double>("MeanYIncm", 0.0);
33  desc.add<double>("MeanZIncm", 0.0);
34  desc.add<double>("TimeOffsetInns", 0.0);
35  desc.add<double>("EprotonInGeV", 7000.0);
36  desc.add<double>("CrossingAngleInurad", 510.0);
37  desc.add<double>("CrabbingAngleCrossingInurad", 380.0);
38  desc.add<double>("CrabbingAngleSeparationInurad", 0.0);
39  desc.add<double>("CrabFrequencyInMHz", 400.0);
40  desc.add<bool>("RF800", false);
41  desc.add<double>("BetaCrossingPlaneInm", 0.20);
42  desc.add<double>("BetaSeparationPlaneInm", 0.20);
43  desc.add<double>("HorizontalEmittance", 2.5e-06);
44  desc.add<double>("VerticalEmittance", 2.05e-06);
45  desc.add<double>("BunchLengthInm", 0.09);
46  desc.add<edm::InputTag>("src");
47  desc.add<bool>("readDB");
48  descriptions.add("HLLHCEvtVtxGenerator", desc);
49 }
50 
53  fMeanX(p.getParameter<double>("MeanXIncm") * cm),
54  fMeanY(p.getParameter<double>("MeanYIncm") * cm),
55  fMeanZ(p.getParameter<double>("MeanZIncm") * cm),
56  fTimeOffset(p.getParameter<double>("TimeOffsetInns") * ns * c_light),
57  momeV(p.getParameter<double>("EprotonInGeV") * 1e9),
58  gamma(momeV / pmass + 1.0),
59  beta(std::sqrt((1.0 - 1.0 / gamma) * ((1.0 + 1.0 / gamma)))),
60  betagamma(beta * gamma),
61  phi(p.getParameter<double>("CrossingAngleInurad") * 1e-6),
62  wcc(p.getParameter<double>("CrabFrequencyInMHz") * 1e6),
63  RF800(p.getParameter<bool>("RF800")),
64  betx(p.getParameter<double>("BetaCrossingPlaneInm")),
65  bets(p.getParameter<double>("BetaSeparationPlaneInm")),
66  epsxn(p.getParameter<double>("HorizontalEmittance")),
67  epssn(p.getParameter<double>("VerticalEmittance")),
68  sigs(p.getParameter<double>("BunchLengthInm")),
69  alphax(p.getParameter<double>("CrabbingAngleCrossingInurad") * 1e-6),
70  alphay(p.getParameter<double>("CrabbingAngleSeparationInurad") * 1e-6),
71  oncc(alphax / phi),
72  epsx(epsxn / (betagamma)),
73  epss(epsx),
74  sigx(std::sqrt(epsx * betx)),
75  phiCR(oncc * phi)
76 
77 {}
78 
80 
81 HepMC::FourVector HLLHCEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
82  double imax = intensity(0., 0., 0., 0.);
83 
84  double x(0.), y(0.), z(0.), t(0.), i(0.);
85 
86  int count = 0;
87 
88  auto shoot = [&]() { return CLHEP::RandFlat::shoot(engine); };
89 
90  do {
91  z = (shoot() - 0.5) * 6.0 * sigs;
92  t = (shoot() - 0.5) * 6.0 * sigs;
93  x = (shoot() - 0.5) * 12.0 * sigma(0.0, epsxn, betx, betagamma);
94  y = (shoot() - 0.5) * 12.0 * sigma(0.0, epssn, bets, betagamma);
95 
96  i = intensity(x, y, z, t);
97 
98  if (i > imax)
99  edm::LogError("Too large intensity") << "i>imax : " << i << " > " << imax << endl;
100  ++count;
101  } while ((i < imax * shoot()) && count < 10000);
102 
103  if (count > 9999)
104  edm::LogError("Too many tries ") << " count : " << count << endl;
105 
106  //---convert to mm
107  x *= 1000.0;
108  y *= 1000.0;
109  z *= 1000.0;
110  t *= 1000.0;
111 
112  x += fMeanX;
113  y += fMeanY;
114  z += fMeanZ;
115  t += fTimeOffset;
116 
117  return HepMC::FourVector(x, y, z, t);
118 }
119 
120 double HLLHCEvtVtxGenerator::sigma(double z, double epsilon, double beta, double betagamma) const {
121  double sigma = std::sqrt(epsilon * (beta + z * z / beta) / betagamma);
122 
123  return sigma;
124 }
125 
126 double HLLHCEvtVtxGenerator::intensity(double x, double y, double z, double t) const {
127  //---c in m/s --- remember t is already in meters
128  constexpr double c = 2.99792458e+8; // m/s
129 
130  const double sigmay = sigma(z, epssn, bets, betagamma);
131 
132  const double alphay_mod = alphay * std::cos(wcc * (z - t) / c);
133 
134  const double cay = std::cos(alphay_mod);
135  const double say = std::sin(alphay_mod);
136 
137  const double dy = -(z - t) * say - y * cay;
138 
139  const double xzt_density = integrandCC(x, z, t);
140 
141  const double norm = two_pi * sigmay;
142 
143  return (std::exp(-dy * dy / (sigmay * sigmay)) * xzt_density / norm);
144 }
145 
146 double HLLHCEvtVtxGenerator::integrandCC(double x, double z, double ct) const {
147  constexpr double local_c_light = 2.99792458e8;
148 
149  const double k = wcc / local_c_light * two_pi;
150  const double k2 = k * k;
151  const double cos = std::cos(phi / 2.0);
152  const double sin = std::sin(phi / 2.0);
153  const double cos2 = cos * cos;
154  const double sin2 = sin * sin;
155 
156  const double sigx2 = sigx * sigx;
157  const double sigmax2 = sigx2 * (1 + z * z / (betx * betx));
158 
159  const double sigs2 = sigs * sigs;
160 
161  constexpr double factorRMSgauss4 =
162  1. / sqrt2 / gamma34 * gamma14; // # Factor to take rms sigma as input of the supergaussian
163  constexpr double NormFactorGauss4 = sqrt2to5 * gamma54 * gamma54;
164 
165  const double sinCR = std::sin(phiCR / 2.0);
166  const double sinCR2 = sinCR * sinCR;
167 
168  double result = -1.0;
169 
170  if (!RF800) {
171  const double norm = 2.0 / (two_pi * sigs2);
172  const double cosks = std::cos(k * z);
173  const double sinkct = std::sin(k * ct);
174  result = norm *
175  std::exp(-ct * ct / sigs2 - z * z * cos2 / sigs2 -
176  1.0 / (4 * k2 * sigmax2) *
177  (
178  //-4*cosks*cosks * sinkct*sinkct * sinCR2 // comes from integral over x
179  -8 * z * k * std::sin(k * z) * std::cos(k * ct) * sin * sinCR + 2 * sinCR2 -
180  std::cos(2 * k * (z - ct)) * sinCR2 - std::cos(2 * k * (z + ct)) * sinCR2 +
181  4 * k2 * z * z * sin2) -
182  x * x * (cos2 / sigmax2 + sin2 / sigs2) // contribution from x integrand
183  + x * ct * sin / sigs2 // contribution from x integrand
184  + 2 * x * cos * cosks * sinkct * sinCR / k / sigmax2 // contribution from x integrand
185  //+(2*ct/k)*np.cos(k*s)*np.sin(k*ct) *(sin*sinCR)/(sigs2*cos) # small term
186  //+ct**2*(sin2/sigs4)/(cos2/sigmax2) # small term
187  ) /
188  (1.0 + (z * z) / (betx * betx)) / std::sqrt(1.0 + (z * z) / (bets * bets));
189 
190  } else {
191  const double norm = 2.0 / (NormFactorGauss4 * sigs2 * factorRMSgauss4);
192  const double sigs4 = sigs2 * sigs2 * factorRMSgauss4 * factorRMSgauss4;
193  const double cosks = std::cos(k * z);
194  const double sinct = std::sin(k * ct);
195  result =
196  norm *
197  std::exp(-ct * ct * ct * ct / sigs4 - z * z * z * z * cos2 * cos2 / sigs4 - 6 * ct * ct * z * z * cos2 / sigs4 -
198  sin2 / (4 * k2 * sigmax2) *
199  (2 + 4 * k2 * z * z - std::cos(2 * k * (z - ct)) - std::cos(2 * k * (z + ct)) -
200  8 * k * s * std::cos(k * ct) * std::sin(k * z) - 4 * cosks * cosks * sinct * sinct)) /
201  std::sqrt(1 + z * z / (betx * betx)) / std::sqrt(1 + z * z / (bets * bets));
202  }
203 
204  return result;
205 }
ConfigurationDescriptions.h
DDAxes::y
HLLHCEvtVtxGenerator::epsxn
const double epsxn
Definition: HLLHCEvtVtxGenerator.h:71
HLLHCEvtVtxGenerator::integrandCC
double integrandCC(double x, double z, double t) const
Definition: HLLHCEvtVtxGenerator.cc:146
VtxSmearedParameters_cfi.RF800
RF800
Definition: VtxSmearedParameters_cfi.py:918
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
HLLHCEvtVtxGenerator::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLLHCEvtVtxGenerator.cc:29
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
HLT_FULL_cff.beta
beta
Definition: HLT_FULL_cff.py:8686
HLLHCEvtVtxGenerator::bets
const double bets
Definition: HLLHCEvtVtxGenerator.h:68
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLLHCEvtVtxGenerator::HLLHCEvtVtxGenerator
HLLHCEvtVtxGenerator(const edm::ParameterSet &p)
Definition: HLLHCEvtVtxGenerator.cc:51
HLLHCEvtVtxGenerator::beta
const double beta
Definition: HLLHCEvtVtxGenerator.h:52
CustomPhysics_cfi.gamma
gamma
Definition: CustomPhysics_cfi.py:17
DDAxes::x
HLLHCEvtVtxGenerator::phiCR
const double phiCR
Definition: HLLHCEvtVtxGenerator.h:98
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
HLLHCEvtVtxGenerator.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
HLLHCEvtVtxGenerator::intensity
double intensity(double x, double y, double z, double t) const
Definition: HLLHCEvtVtxGenerator.cc:126
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HLLHCEvtVtxGenerator::newVertex
HepMC::FourVector newVertex(CLHEP::HepRandomEngine *) const override
return a new event vertex
Definition: HLLHCEvtVtxGenerator.cc:81
HLLHCEvtVtxGenerator::RF800
const bool RF800
Definition: HLLHCEvtVtxGenerator.h:62
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
local_c_light
static constexpr float local_c_light
Definition: pTFrom2Stubs.cc:9
HLLHCEvtVtxGenerator::phi
const double phi
Definition: HLLHCEvtVtxGenerator.h:56
DDAxes::z
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
dqmdumpme.k
k
Definition: dqmdumpme.py:60
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLLHCEvtVtxGenerator::alphay
const double alphay
Definition: HLLHCEvtVtxGenerator.h:83
HLLHCEvtVtxGenerator::fMeanY
const double fMeanY
Definition: HLLHCEvtVtxGenerator.h:47
edm::ParameterSet
Definition: ParameterSet.h:47
HLLHCEvtVtxGenerator::betx
const double betx
Definition: HLLHCEvtVtxGenerator.h:65
HLLHCEvtVtxGenerator::wcc
const double wcc
Definition: HLLHCEvtVtxGenerator.h:59
HLLHCEvtVtxGenerator::fMeanX
const double fMeanX
Definition: HLLHCEvtVtxGenerator.h:47
HLLHCEvtVtxGenerator::betagamma
const double betagamma
Definition: HLLHCEvtVtxGenerator.h:53
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
PVValHelper::dy
Definition: PVValidationHelpers.h:50
HLLHCEvtVtxGenerator::~HLLHCEvtVtxGenerator
~HLLHCEvtVtxGenerator() override
Definition: HLLHCEvtVtxGenerator.cc:79
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HLLHCEvtVtxGenerator::sigs
const double sigs
Definition: HLLHCEvtVtxGenerator.h:77
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
HLLHCEvtVtxGenerator::fTimeOffset
const double fTimeOffset
Definition: HLLHCEvtVtxGenerator.h:47
genVertex_cff.x
x
Definition: genVertex_cff.py:12
HLLHCEvtVtxGenerator::epssn
const double epssn
Definition: HLLHCEvtVtxGenerator.h:74
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
Exception.h
HLLHCEvtVtxGenerator::sigx
const double sigx
Definition: HLLHCEvtVtxGenerator.h:95
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
HLLHCEvtVtxGenerator::sigma
double sigma(double z, double epsilon, double beta, double betagamma) const
Definition: HLLHCEvtVtxGenerator.cc:120
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
BaseEvtVtxGenerator
Definition: BaseEvtVtxGenerator.h:23
edm::InputTag
Definition: InputTag.h:15
HLLHCEvtVtxGenerator::fMeanZ
const double fMeanZ
Definition: HLLHCEvtVtxGenerator.h:47
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37