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 
24 
25 #include "CLHEP/Random/RandGaussQ.h"
26 #include "CLHEP/Units/GlobalSystemOfUnits.h"
27 #include "CLHEP/Units/GlobalPhysicalConstants.h"
28 //#include "CLHEP/Vector/ThreeVector.h"
29 #include "HepMC/SimpleVector.h"
30 
33 
34 #include <iostream>
35 
37  readDB_ = p.getParameter<bool>("readDB");
38  if (!readDB_) {
39  fX0 = p.getParameter<double>("X0") * cm;
40  fY0 = p.getParameter<double>("Y0") * cm;
41  fZ0 = p.getParameter<double>("Z0") * cm;
42  fSigmaZ = p.getParameter<double>("SigmaZ") * cm;
43  fbetastar = p.getParameter<double>("BetaStar") * cm;
44  femittance = p.getParameter<double>("Emittance") * cm; // this is not the normalized emittance
45  fTimeOffset = p.getParameter<double>("TimeOffset") * ns * c_light; // HepMC time units are mm
46 
47  setBoost(p.getParameter<double>("Alpha") * radian, p.getParameter<double>("Phi") * radian);
48  if (fSigmaZ <= 0) {
49  throw cms::Exception("Configuration") << "Error in BetafuncEvtVtxGenerator: "
50  << "Illegal resolution in Z (SigmaZ is negative)";
51  }
52  }
53 }
54 
56 
58  update(iEventSetup);
59 }
60 void BetafuncEvtVtxGenerator::beginRun(const edm::Run&, const edm::EventSetup& iEventSetup) { update(iEventSetup); }
61 
63  if (readDB_ && parameterWatcher_.check(iEventSetup)) {
65  iEventSetup.get<SimBeamSpotObjectsRcd>().get(beamhandle);
66 
67  fX0 = beamhandle->fX0;
68  fY0 = beamhandle->fY0;
69  fZ0 = beamhandle->fZ0;
70  // falpha=beamhandle->fAlpha;
71  fSigmaZ = beamhandle->fSigmaZ;
72  fTimeOffset = beamhandle->fTimeOffset;
73  fbetastar = beamhandle->fbetastar;
74  femittance = beamhandle->femittance;
75  setBoost(beamhandle->fAlpha, beamhandle->fPhi);
76  }
77 }
78 
79 HepMC::FourVector BetafuncEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
80  double X, Y, Z;
81 
82  double tmp_sigz = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
83  Z = tmp_sigz + fZ0;
84 
85  double tmp_sigx = BetaFunction(Z, fZ0);
86  // need sqrt(2) for beamspot width relative to single beam width
87  tmp_sigx /= sqrt(2.0);
88  X = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigx) + fX0; // + Z*fdxdz ;
89 
90  double tmp_sigy = BetaFunction(Z, fZ0);
91  // need sqrt(2) for beamspot width relative to single beam width
92  tmp_sigy /= sqrt(2.0);
93  Y = CLHEP::RandGaussQ::shoot(engine, 0., tmp_sigy) + fY0; // + Z*fdydz;
94 
95  double tmp_sigt = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
96  double T = tmp_sigt + fTimeOffset;
97 
98  return HepMC::FourVector(X, Y, Z, T);
99 }
100 
101 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0) const {
102  return sqrt(femittance * (fbetastar + (((z - z0) * (z - z0)) / fbetastar)));
103 }
104 
106  //boost_.ResizeTo(4,4);
107  //boost_ = new TMatrixD(4,4);
108  TMatrixD tmpboost(4, 4);
109 
110  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
111 
112  // Lorentz boost to frame where the collision is head-on
113  // phi is the half crossing angle in the plane ZS
114  // alpha is the angle to the S axis from the X axis in the XY plane
115 
116  tmpboost(0, 0) = 1. / cos(phi);
117  tmpboost(0, 1) = -cos(alpha) * sin(phi);
118  tmpboost(0, 2) = -tan(phi) * sin(phi);
119  tmpboost(0, 3) = -sin(alpha) * sin(phi);
120  tmpboost(1, 0) = -cos(alpha) * tan(phi);
121  tmpboost(1, 1) = 1.;
122  tmpboost(1, 2) = cos(alpha) * tan(phi);
123  tmpboost(1, 3) = 0.;
124  tmpboost(2, 0) = 0.;
125  tmpboost(2, 1) = -cos(alpha) * sin(phi);
126  tmpboost(2, 2) = cos(phi);
127  tmpboost(2, 3) = -sin(alpha) * sin(phi);
128  tmpboost(3, 0) = -sin(alpha) * tan(phi);
129  tmpboost(3, 1) = 0.;
130  tmpboost(3, 2) = sin(alpha) * tan(phi);
131  tmpboost(3, 3) = 1.;
132 
133  tmpboost.Invert();
134  boost_ = tmpboost;
135  //boost_->Print();
136 }
137 
139  if (s >= 0) {
140  fSigmaZ = s;
141  } else {
142  throw cms::Exception("LogicError") << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
143  << "Illegal resolution in Z (negative)";
144  }
145 }
146 
147 TMatrixD const* BetafuncEvtVtxGenerator::GetInvLorentzBoost() const { return &boost_; }
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
BetafuncEvtVtxGenerator::BetafuncEvtVtxGenerator
BetafuncEvtVtxGenerator(const edm::ParameterSet &p)
Definition: BetafuncEvtVtxGenerator.cc:36
BetafuncEvtVtxGenerator::~BetafuncEvtVtxGenerator
~BetafuncEvtVtxGenerator() override
Definition: BetafuncEvtVtxGenerator.cc:55
SimBeamSpotObjects::fTimeOffset
double fTimeOffset
Definition: SimBeamSpotObjects.h:27
ESHandle.h
BetafuncEvtVtxGenerator::fZ0
double fZ0
Definition: BetafuncEvtVtxGenerator.h:72
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
BetafuncEvtVtxGenerator::sigmaZ
void sigmaZ(double s=1.0)
set resolution in Z in cm
Definition: BetafuncEvtVtxGenerator.cc:138
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
X
#define X(str)
Definition: MuonsGrabber.cc:38
edm::Run
Definition: Run.h:45
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
BetafuncEvtVtxGenerator::fbetastar
double fbetastar
Definition: BetafuncEvtVtxGenerator.h:75
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SimBeamSpotObjects.h
SimBeamSpotObjects::fX0
double fX0
Definition: SimBeamSpotObjects.h:21
BetafuncEvtVtxGenerator::fTimeOffset
double fTimeOffset
Definition: BetafuncEvtVtxGenerator.h:77
SimBeamSpotObjects::fY0
double fY0
Definition: SimBeamSpotObjects.h:21
BetafuncEvtVtxGenerator::BetaFunction
double BetaFunction(double z, double z0) const
beta function
Definition: BetafuncEvtVtxGenerator.cc:101
SimBeamSpotObjects::femittance
double femittance
Definition: SimBeamSpotObjects.h:25
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
BetafuncEvtVtxGenerator::fY0
double fY0
Definition: BetafuncEvtVtxGenerator.h:72
BetafuncEvtVtxGenerator::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: BetafuncEvtVtxGenerator.cc:60
alignCSCRings.s
s
Definition: alignCSCRings.py:92
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
BetafuncEvtVtxGenerator::fSigmaZ
double fSigmaZ
Definition: BetafuncEvtVtxGenerator.h:73
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
BetafuncEvtVtxGenerator::setBoost
void setBoost(double alpha, double phi)
Definition: BetafuncEvtVtxGenerator.cc:105
BetafuncEvtVtxGenerator::femittance
double femittance
Definition: BetafuncEvtVtxGenerator.h:75
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
edm::ESHandle
Definition: DTSurvey.h:22
SimBeamSpotObjects::fbetastar
double fbetastar
Definition: SimBeamSpotObjects.h:25
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
BetafuncEvtVtxGenerator.h
BetafuncEvtVtxGenerator::newVertex
HepMC::FourVector newVertex(CLHEP::HepRandomEngine *) const override
return a new event vertex
Definition: BetafuncEvtVtxGenerator.cc:79
BetafuncEvtVtxGenerator::parameterWatcher_
edm::ESWatcher< SimBeamSpotObjectsRcd > parameterWatcher_
Definition: BetafuncEvtVtxGenerator.h:82
SimBeamSpotObjects::fSigmaZ
double fSigmaZ
Definition: SimBeamSpotObjects.h:24
edm::ParameterSet
Definition: ParameterSet.h:36
SimBeamSpotObjectsRcd.h
PVValHelper::phi
Definition: PVValidationHelpers.h:68
BetafuncEvtVtxGenerator::GetInvLorentzBoost
TMatrixD const * GetInvLorentzBoost() const override
Definition: BetafuncEvtVtxGenerator.cc:147
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
DOFs::Z
Definition: AlignPCLThresholdsWriter.cc:37
SimBeamSpotObjects::fAlpha
double fAlpha
Definition: SimBeamSpotObjects.h:26
edm::EventSetup
Definition: EventSetup.h:57
SimBeamSpotObjects::fPhi
double fPhi
Definition: SimBeamSpotObjects.h:26
get
#define get
BetafuncEvtVtxGenerator::readDB_
bool readDB_
Definition: BetafuncEvtVtxGenerator.h:70
SimBeamSpotObjectsRcd
Definition: SimBeamSpotObjectsRcd.h:24
BetafuncEvtVtxGenerator::update
void update(const edm::EventSetup &iEventSetup)
Definition: BetafuncEvtVtxGenerator.cc:62
DDAxes::phi
DOFs::Y
Definition: AlignPCLThresholdsWriter.cc:37
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:246
EventSetup.h
Exception.h
BetafuncEvtVtxGenerator::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: BetafuncEvtVtxGenerator.cc:57
ParameterSet.h
BaseEvtVtxGenerator
Definition: BaseEvtVtxGenerator.h:23
SimBeamSpotObjects::fZ0
double fZ0
Definition: SimBeamSpotObjects.h:21
BetafuncEvtVtxGenerator::boost_
TMatrixD boost_
Definition: BetafuncEvtVtxGenerator.h:79
BetafuncEvtVtxGenerator::fX0
double fX0
Definition: BetafuncEvtVtxGenerator.h:72