CMS 3D CMS Logo

BetafuncEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 /*
3 ________________________________________________________________________
4 
5  BetafuncEvtVtxGenerator
6 
7  Smear vertex according to the Beta function on the transverse plane
8  and a Gaussian on the z axis. It allows the beam to have a crossing
9  angle (slopes dxdz and dydz).
10 
11  Based on GaussEvtVtxGenerator
12  implemented by Francisco Yumiceva (yumiceva@fnal.gov)
13 
14  FERMILAB
15  2006
16 ________________________________________________________________________
17 */
18 
19 
20 
26 
27 #include "CLHEP/Random/RandGaussQ.h"
28 #include "CLHEP/Units/GlobalSystemOfUnits.h"
29 #include "CLHEP/Units/GlobalPhysicalConstants.h"
30 //#include "CLHEP/Vector/ThreeVector.h"
31 #include "HepMC/SimpleVector.h"
32 
35 
36 #include <iostream>
37 
38 
39 
42  boost_(4,4)
43 {
44  readDB_=p.getParameter<bool>("readDB");
45  if (!readDB_){
46  fX0 = p.getParameter<double>("X0")*cm;
47  fY0 = p.getParameter<double>("Y0")*cm;
48  fZ0 = p.getParameter<double>("Z0")*cm;
49  fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
50  fbetastar = p.getParameter<double>("BetaStar")*cm;
51  femittance = p.getParameter<double>("Emittance")*cm; // this is not the normalized emittance
52  fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light; // HepMC time units are mm
53 
54  setBoost(p.getParameter<double>("Alpha")*radian,
55  p.getParameter<double>("Phi")*radian);
56  if (fSigmaZ <= 0) {
57  throw cms::Exception("Configuration")
58  << "Error in BetafuncEvtVtxGenerator: "
59  << "Illegal resolution in Z (SigmaZ is negative)";
60  }
61  }
62 }
63 
65 {
66 }
67 
69  update(iEventSetup);
70 }
71 void BetafuncEvtVtxGenerator::beginRun(const edm::Run & , const edm::EventSetup& iEventSetup){
72  update(iEventSetup);
73 }
74 
76  if (readDB_ && parameterWatcher_.check(iEventSetup)){
78  iEventSetup.get<SimBeamSpotObjectsRcd>().get(beamhandle);
79 
80  fX0=beamhandle->fX0;
81  fY0=beamhandle->fY0;
82  fZ0=beamhandle->fZ0;
83  // falpha=beamhandle->fAlpha;
84  fSigmaZ=beamhandle->fSigmaZ;
85  fTimeOffset=beamhandle->fTimeOffset;
86  fbetastar=beamhandle->fbetastar;
87  femittance=beamhandle->femittance;
88  setBoost(beamhandle->fAlpha,beamhandle->fPhi);
89 
90  }
91 }
92 
93 HepMC::FourVector BetafuncEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
94 
95 
96  double X,Y,Z;
97 
98  double tmp_sigz = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
99  Z = tmp_sigz + fZ0;
100 
101  double tmp_sigx = BetaFunction(Z,fZ0);
102  // need sqrt(2) for beamspot width relative to single beam width
103  tmp_sigx /= sqrt(2.0);
104  X = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigx) + fX0; // + Z*fdxdz ;
105 
106  double tmp_sigy = BetaFunction(Z,fZ0);
107  // need sqrt(2) for beamspot width relative to single beam width
108  tmp_sigy /= sqrt(2.0);
109  Y = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigy) + fY0; // + Z*fdydz;
110 
111  double tmp_sigt = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
112  double T = tmp_sigt + fTimeOffset;
113 
114  return HepMC::FourVector(X,Y,Z,T);
115 }
116 
117 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0) const
118 {
119  return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
120 
121 }
122 
124 {
125  //boost_.ResizeTo(4,4);
126  //boost_ = new TMatrixD(4,4);
127  TMatrixD tmpboost(4,4);
128 
129  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
130 
131  // Lorentz boost to frame where the collision is head-on
132  // phi is the half crossing angle in the plane ZS
133  // alpha is the angle to the S axis from the X axis in the XY plane
134 
135  tmpboost(0,0) = 1./cos(phi);
136  tmpboost(0,1) = - cos(alpha)*sin(phi);
137  tmpboost(0,2) = - tan(phi)*sin(phi);
138  tmpboost(0,3) = - sin(alpha)*sin(phi);
139  tmpboost(1,0) = - cos(alpha)*tan(phi);
140  tmpboost(1,1) = 1.;
141  tmpboost(1,2) = cos(alpha)*tan(phi);
142  tmpboost(1,3) = 0.;
143  tmpboost(2,0) = 0.;
144  tmpboost(2,1) = - cos(alpha)*sin(phi);
145  tmpboost(2,2) = cos(phi);
146  tmpboost(2,3) = - sin(alpha)*sin(phi);
147  tmpboost(3,0) = - sin(alpha)*tan(phi);
148  tmpboost(3,1) = 0.;
149  tmpboost(3,2) = sin(alpha)*tan(phi);
150  tmpboost(3,3) = 1.;
151 
152  tmpboost.Invert();
153  boost_ = tmpboost;
154  //boost_->Print();
155 }
156 
158 {
159  if (s>=0 ) {
160  fSigmaZ=s;
161  }
162  else {
163  throw cms::Exception("LogicError")
164  << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
165  << "Illegal resolution in Z (negative)";
166  }
167 }
168 
170 
171  return &boost_;
172 }
T getParameter(std::string const &) const
float alpha
Definition: AMPTWrapper.h:95
void sigmaZ(double s=1.0)
set resolution in Z in cm
BetafuncEvtVtxGenerator(const edm::ParameterSet &p)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define X(str)
Definition: MuonsGrabber.cc:48
void setBoost(double alpha, double phi)
void beginRun(const edm::Run &, const edm::EventSetup &) override
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
void update(const edm::EventSetup &iEventSetup)
TMatrixD const * GetInvLorentzBoost() const override
edm::ESWatcher< SimBeamSpotObjectsRcd > parameterWatcher_
double BetaFunction(double z, double z0) const
beta function
const T & get() const
Definition: EventSetup.h:55
HepMC::FourVector newVertex(CLHEP::HepRandomEngine *) const override
return a new event vertex
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
long double T
Definition: Run.h:43