CMS 3D CMS Logo

BetafuncEvtVtxGenerator.cc
Go to the documentation of this file.
1 /*
2 ________________________________________________________________________
3 
4  BetafuncEvtVtxGenerator
5 
6  Smear vertex according to the Beta function on the transverse plane
7  and a Gaussian on the z axis. It allows the beam to have a crossing
8  angle (slopes dxdz and dydz).
9 
10  Based on GaussEvtVtxGenerator
11  implemented by Francisco Yumiceva (yumiceva@fnal.gov)
12 
13  FERMILAB
14  2006
15 ________________________________________________________________________
16 */
17 
23 
24 #include "CLHEP/Random/RandGaussQ.h"
25 #include "CLHEP/Units/GlobalSystemOfUnits.h"
26 #include "CLHEP/Units/GlobalPhysicalConstants.h"
27 //#include "CLHEP/Vector/ThreeVector.h"
28 #include "HepMC/SimpleVector.h"
29 
30 #include <iostream>
31 
33  readDB_ = p.getParameter<bool>("readDB");
34  if (!readDB_) {
35  fX0 = p.getParameter<double>("X0") * cm;
36  fY0 = p.getParameter<double>("Y0") * cm;
37  fZ0 = p.getParameter<double>("Z0") * cm;
38  fSigmaZ = p.getParameter<double>("SigmaZ") * cm;
39  fbetastar = p.getParameter<double>("BetaStar") * cm;
40  femittance = p.getParameter<double>("Emittance") * cm; // this is not the normalized emittance
41  fTimeOffset = p.getParameter<double>("TimeOffset") * ns * c_light; // HepMC distance units are mm
42 
43  setBoost(p.getParameter<double>("Alpha") * radian, p.getParameter<double>("Phi") * radian);
44  if (fSigmaZ <= 0) {
45  throw cms::Exception("Configuration") << "Error in BetafuncEvtVtxGenerator: "
46  << "Illegal resolution in Z (SigmaZ is negative)";
47  }
48  }
49  if (readDB_) {
50  // NOTE: this is currently watching LS transitions, while it should watch Run transitions,
51  // even though in reality there is no Run Dependent MC (yet) in CMS
52  beamToken_ = esConsumes<SimBeamSpotObjects, SimBeamSpotObjectsRcd, edm::Transition::BeginLuminosityBlock>();
53  }
54 }
55 
57 
59  update(iEventSetup);
60 }
61 
63  if (readDB_ && parameterWatcher_.check(iEventSetup)) {
64  edm::ESHandle<SimBeamSpotObjects> beamhandle = iEventSetup.getHandle(beamToken_);
65  fX0 = beamhandle->x() * cm;
66  fY0 = beamhandle->y() * cm;
67  fZ0 = beamhandle->z() * cm;
68  fSigmaZ = beamhandle->sigmaZ() * cm;
69  fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC distance units are in mm
70  fbetastar = beamhandle->betaStar() * cm;
71  femittance = beamhandle->emittance() * cm;
72  setBoost(beamhandle->alpha() * radian, beamhandle->phi() * radian);
73  }
74 }
75 
76 HepMC::FourVector BetafuncEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
77  double X, Y, Z;
78 
79  double tmp_sigz = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
80  Z = tmp_sigz + fZ0;
81 
82  double tmp_sigx = BetaFunction(Z, fZ0);
83  // need sqrt(2) for beamspot width relative to single beam width
84  tmp_sigx /= sqrt(2.0);
85  X = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigx) + fX0; // + Z*fdxdz ;
86 
87  double tmp_sigy = BetaFunction(Z, fZ0);
88  // need sqrt(2) for beamspot width relative to single beam width
89  tmp_sigy /= sqrt(2.0);
90  Y = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigy) + fY0; // + Z*fdydz;
91 
92  double tmp_sigt = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
93  double T = tmp_sigt + fTimeOffset;
94 
95  return HepMC::FourVector(X, Y, Z, T);
96 }
97 
98 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0) const {
99  return sqrt(femittance * (fbetastar + (((z - z0) * (z - z0)) / fbetastar)));
100 }
101 
103  //boost_.ResizeTo(4,4);
104  //boost_ = new TMatrixD(4,4);
105  TMatrixD tmpboost(4, 4);
106 
107  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
108 
109  // Lorentz boost to frame where the collision is head-on
110  // phi is the half crossing angle in the plane ZS
111  // alpha is the angle to the S axis from the X axis in the XY plane
112 
113  tmpboost(0, 0) = 1. / cos(phi);
114  tmpboost(0, 1) = -cos(alpha) * sin(phi);
115  tmpboost(0, 2) = -tan(phi) * sin(phi);
116  tmpboost(0, 3) = -sin(alpha) * sin(phi);
117  tmpboost(1, 0) = -cos(alpha) * tan(phi);
118  tmpboost(1, 1) = 1.;
119  tmpboost(1, 2) = cos(alpha) * tan(phi);
120  tmpboost(1, 3) = 0.;
121  tmpboost(2, 0) = 0.;
122  tmpboost(2, 1) = -cos(alpha) * sin(phi);
123  tmpboost(2, 2) = cos(phi);
124  tmpboost(2, 3) = -sin(alpha) * sin(phi);
125  tmpboost(3, 0) = -sin(alpha) * tan(phi);
126  tmpboost(3, 1) = 0.;
127  tmpboost(3, 2) = sin(alpha) * tan(phi);
128  tmpboost(3, 3) = 1.;
129 
130  tmpboost.Invert();
131  boost_ = tmpboost;
132  //boost_->Print();
133 }
134 
136  if (s >= 0) {
137  fSigmaZ = s;
138  } else {
139  throw cms::Exception("LogicError") << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
140  << "Illegal resolution in Z (negative)";
141  }
142 }
143 
144 TMatrixD const* BetafuncEvtVtxGenerator::GetInvLorentzBoost() const { return &boost_; }
double sigmaZ() const
get sigmaZ
void sigmaZ(double s=1.0)
set resolution in Z in cm
double BetaFunction(double z, double z0) const
beta function
BetafuncEvtVtxGenerator(const edm::ParameterSet &p)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define X(str)
Definition: MuonsGrabber.cc:38
void setBoost(double alpha, double phi)
double alpha() const
get Alpha
float float float z
TMatrixD const * GetInvLorentzBoost() const override
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
edm::ESGetToken< SimBeamSpotObjects, SimBeamSpotObjectsRcd > beamToken_
void update(const edm::EventSetup &iEventSetup)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
double timeOffset() const
get TimeOffset
HepMC::FourVector newVertex(CLHEP::HepRandomEngine *) const override
return a new event vertex
edm::ESWatcher< SimBeamSpotObjectsRcd > parameterWatcher_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
double z() const
get Z position
double emittance() const
get Emittance
double phi() const
get Phi
double betaStar() const
get BetaStar
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
double x() const
get X position
double y() const
get Y position
long double T