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 in 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  update(iEventSetup);
58 }
59 
61  if (readDB_ && parameterWatcher_.check(iEventSetup)) {
62  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);
71  }
72 }
73 
74 HepMC::FourVector BetafuncEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
75  double X, Y, Z;
76 
77  double tmp_sigz = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
78  Z = tmp_sigz + fZ0;
79 
80  double tmp_sigx = BetaFunction(Z, fZ0);
81  // need sqrt(2) for beamspot width relative to single beam width
82  tmp_sigx /= sqrt(2.0);
83  X = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigx) + fX0; // + Z*fdxdz ;
84 
85  double tmp_sigy = BetaFunction(Z, fZ0);
86  // need sqrt(2) for beamspot width relative to single beam width
87  tmp_sigy /= sqrt(2.0);
88  Y = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigy) + fY0; // + Z*fdydz;
89 
90  double tmp_sigt = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
91  double T = tmp_sigt + fTimeOffset;
92 
93  return HepMC::FourVector(X, Y, Z, T);
94 }
95 
96 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0) const {
97  return sqrt(femittance * (fbetastar + (((z - z0) * (z - z0)) / fbetastar)));
98 }
99 
101  //boost_.ResizeTo(4,4);
102  //boost_ = new TMatrixD(4,4);
103  TMatrixD tmpboost(4, 4);
104 
105  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
106 
107  // Lorentz boost to frame where the collision is head-on
108  // phi is the half crossing angle in the plane ZS
109  // alpha is the angle to the S axis from the X axis in the XY plane
110 
111  tmpboost(0, 0) = 1. / cos(phi);
112  tmpboost(0, 1) = -cos(alpha) * sin(phi);
113  tmpboost(0, 2) = -tan(phi) * sin(phi);
114  tmpboost(0, 3) = -sin(alpha) * sin(phi);
115  tmpboost(1, 0) = -cos(alpha) * tan(phi);
116  tmpboost(1, 1) = 1.;
117  tmpboost(1, 2) = cos(alpha) * tan(phi);
118  tmpboost(1, 3) = 0.;
119  tmpboost(2, 0) = 0.;
120  tmpboost(2, 1) = -cos(alpha) * sin(phi);
121  tmpboost(2, 2) = cos(phi);
122  tmpboost(2, 3) = -sin(alpha) * sin(phi);
123  tmpboost(3, 0) = -sin(alpha) * tan(phi);
124  tmpboost(3, 1) = 0.;
125  tmpboost(3, 2) = sin(alpha) * tan(phi);
126  tmpboost(3, 3) = 1.;
127 
128  tmpboost.Invert();
129  boost_ = tmpboost;
130  //boost_->Print();
131 }
132 
134  if (s >= 0) {
135  fSigmaZ = s;
136  } else {
137  throw cms::Exception("LogicError") << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
138  << "Illegal resolution in Z (negative)";
139  }
140 }
141 
142 TMatrixD const* BetafuncEvtVtxGenerator::GetInvLorentzBoost() const { return &boost_; }
double sigmaZ() const
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
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
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 emittance() const
double phi() const
get Phi, Alpha and TimeOffset
double betaStar() const
get BetaStar and Emittance
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
double x() const
get X, Y, Z position
long double T