CMS 3D CMS Logo

BetaBoostEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 /*
3  ________________________________________________________________________
4 
5  BetaBoostEvtVtxGenerator
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 //lingshan: add beta for z-axis boost
20 
21 //#include "IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h"
22 
26 
34 
35 #include "CLHEP/Random/RandGaussQ.h"
36 #include "CLHEP/Units/GlobalSystemOfUnits.h"
37 #include "CLHEP/Units/GlobalPhysicalConstants.h"
38 //#include "CLHEP/Vector/ThreeVector.h"
39 #include "HepMC/SimpleVector.h"
40 #include "TMatrixD.h"
41 
42 #include <iostream>
43 
44 using namespace edm;
45 using namespace std;
46 using namespace CLHEP;
47 
48 namespace CLHEP {
49  class HepRandomEngine;
50 }
51 
53 public:
55  ~BetaBoostEvtVtxGenerator() override;
56 
58  //virtual CLHEP::Hep3Vector * newVertex();
59  virtual HepMC::FourVector* newVertex(CLHEP::HepRandomEngine*) ;
60  void produce( edm::Event&, const edm::EventSetup& ) override;
61  virtual TMatrixD* GetInvLorentzBoost();
62 
63 
65  void sigmaZ(double s=1.0);
66 
68  void X0(double m=0) { fX0=m; }
70  void Y0(double m=0) { fY0=m; }
72  void Z0(double m=0) { fZ0=m; }
73 
75  void Phi(double m=0) { phi_=m; }
77  void Alpha(double m=0) { alpha_=m; }
78  void Beta(double m=0) { beta_=m; }
79 
81  void betastar(double m=0) { fbetastar=m; }
83  void emittance(double m=0) { femittance=m; }
84 
86  double BetaFunction(double z, double z0);
87 
88 private:
92  BetaBoostEvtVtxGenerator& operator = (const BetaBoostEvtVtxGenerator & rhs ) = delete;
93 
94  double alpha_, phi_;
95  //TMatrixD boost_;
96  double beta_;
97  double fX0, fY0, fZ0;
98  double fSigmaZ;
99  //double fdxdz, fdydz;
100  double fbetastar, femittance;
101  double falpha;
102 
103  HepMC::FourVector* fVertex ;
104  TMatrixD *boost_;
105  double fTimeOffset;
106 
108 
110 };
111 
112 
114  fVertex(nullptr), boost_(nullptr), fTimeOffset(0),
115  sourceLabel(consumes<HepMCProduct>(p.getParameter<edm::InputTag>("src"))),
116  verbosity_(p.getUntrackedParameter<bool>("verbosity",false))
117 {
118  fX0 = p.getParameter<double>("X0")*cm;
119  fY0 = p.getParameter<double>("Y0")*cm;
120  fZ0 = p.getParameter<double>("Z0")*cm;
121  fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
122  alpha_ = p.getParameter<double>("Alpha")*radian;
123  phi_ = p.getParameter<double>("Phi")*radian;
124  fbetastar = p.getParameter<double>("BetaStar")*cm;
125  femittance = p.getParameter<double>("Emittance")*cm; // this is not the normalized emittance
126  fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light; // HepMC time units are mm
127  beta_=p.getParameter<double>("Beta");
128  if (fSigmaZ <= 0) {
129  throw cms::Exception("Configuration")
130  << "Error in BetaBoostEvtVtxGenerator: "
131  << "Illegal resolution in Z (SigmaZ is negative)";
132  }
133 
134  produces<edm::HepMCProduct>();
135 
136 }
137 
139 {
140  delete fVertex ;
141  if (boost_ != nullptr ) delete boost_;
142 }
143 
144 //Hep3Vector* BetaBoostEvtVtxGenerator::newVertex() {
145 HepMC::FourVector* BetaBoostEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) {
146 
147 
148  double X,Y,Z;
149 
150  double tmp_sigz = CLHEP::RandGaussQ::shoot(engine, 0.0, fSigmaZ);
151  Z = tmp_sigz + fZ0;
152 
153  double tmp_sigx = BetaFunction(Z,fZ0);
154  // need sqrt(2) for beamspot width relative to single beam width
155  tmp_sigx /= sqrt(2.0);
156  X = CLHEP::RandGaussQ::shoot(engine, 0.0, tmp_sigx) + fX0; // + Z*fdxdz ;
157 
158  double tmp_sigy = BetaFunction(Z,fZ0);
159  // need sqrt(2) for beamspot width relative to single beam width
160  tmp_sigy /= sqrt(2.0);
161  Y = CLHEP::RandGaussQ::shoot(engine, 0.0, tmp_sigy) + fY0; // + Z*fdydz;
162 
163  double tmp_sigt = CLHEP::RandGaussQ::shoot(engine, 0.0, fSigmaZ);
164  double T = tmp_sigt + fTimeOffset;
165 
166  if ( fVertex == nullptr ) fVertex = new HepMC::FourVector();
167  fVertex->set(X,Y,Z,T);
168 
169  return fVertex;
170 }
171 
172 double BetaBoostEvtVtxGenerator::BetaFunction(double z, double z0)
173 {
174  return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
175 
176 }
177 
178 
180 {
181  if (s>=0 ) {
182  fSigmaZ=s;
183  }
184  else {
185  throw cms::Exception("LogicError")
186  << "Error in BetaBoostEvtVtxGenerator::sigmaZ: "
187  << "Illegal resolution in Z (negative)";
188  }
189 }
190 
192 
193  //alpha_ = 0;
194  //phi_ = 142.e-6;
195  // if (boost_ != 0 ) return boost_;
196 
197  //boost_.ResizeTo(4,4);
198  //boost_ = new TMatrixD(4,4);
199  TMatrixD tmpboost(4,4);
200  TMatrixD tmpboostZ(4,4);
201  TMatrixD tmpboostXYZ(4,4);
202 
203  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
204 
205  // Lorentz boost to frame where the collision is head-on
206  // phi is the half crossing angle in the plane ZS
207  // alpha is the angle to the S axis from the X axis in the XY plane
208 
209  tmpboost(0,0) = 1./cos(phi_);
210  tmpboost(0,1) = - cos(alpha_)*sin(phi_);
211  tmpboost(0,2) = - tan(phi_)*sin(phi_);
212  tmpboost(0,3) = - sin(alpha_)*sin(phi_);
213  tmpboost(1,0) = - cos(alpha_)*tan(phi_);
214  tmpboost(1,1) = 1.;
215  tmpboost(1,2) = cos(alpha_)*tan(phi_);
216  tmpboost(1,3) = 0.;
217  tmpboost(2,0) = 0.;
218  tmpboost(2,1) = - cos(alpha_)*sin(phi_);
219  tmpboost(2,2) = cos(phi_);
220  tmpboost(2,3) = - sin(alpha_)*sin(phi_);
221  tmpboost(3,0) = - sin(alpha_)*tan(phi_);
222  tmpboost(3,1) = 0.;
223  tmpboost(3,2) = sin(alpha_)*tan(phi_);
224  tmpboost(3,3) = 1.;
225  //cout<<"beta "<<beta_;
226  double gama=1.0/sqrt(1-beta_*beta_);
227  tmpboostZ(0,0)=gama;
228  tmpboostZ(0,1)=0.;
229  tmpboostZ(0,2)=-1.0*beta_*gama;
230  tmpboostZ(0,3)=0.;
231  tmpboostZ(1,0)=0.;
232  tmpboostZ(1,1) = 1.;
233  tmpboostZ(1,2)=0.;
234  tmpboostZ(1,3)=0.;
235  tmpboostZ(2,0)=-1.0*beta_*gama;
236  tmpboostZ(2,1) = 0.;
237  tmpboostZ(2,2)=gama;
238  tmpboostZ(2,3) = 0.;
239  tmpboostZ(3,0)=0.;
240  tmpboostZ(3,1)=0.;
241  tmpboostZ(3,2)=0.;
242  tmpboostZ(3,3) = 1.;
243 
244  tmpboostXYZ=tmpboostZ*tmpboost;
245  tmpboostXYZ.Invert();
246 
247 
248 
249  boost_ = new TMatrixD(tmpboostXYZ);
250  if ( verbosity_ ) { boost_->Print(); }
251 
252  return boost_;
253 }
254 
256 {
258  if (!rng.isAvailable()) {
259  throw cms::Exception("Configuration")
260  << "Attempt to get a random engine when the RandomNumberGeneratorService is not configured.\n"
261  "You must configure the service if you want an engine.\n";
262  }
263  CLHEP::HepRandomEngine* engine = &rng->getEngine(evt.streamID());
264 
265  Handle<HepMCProduct> HepUnsmearedMCEvt;
266  evt.getByToken(sourceLabel, HepUnsmearedMCEvt);
267 
268  // Copy the HepMC::GenEvent
269  HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
270  std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
271 
272  // generate new vertex & apply the shift
273  //
274  HepMCEvt->applyVtxGen( newVertex(engine) ) ;
275 
276  //HepMCEvt->LorentzBoost( 0., 142.e-6 );
277  HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
278  HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
279  evt.put(std::move(HepMCEvt));
280 
281  return ;
282 }
283 
T getParameter(std::string const &) const
void Y0(double m=0)
set mean in Y in cm
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void emittance(double m=0)
emittance (no the normalized)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual HepMC::FourVector * newVertex(CLHEP::HepRandomEngine *)
return a new event vertex
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::EDGetTokenT< HepMCProduct > sourceLabel
#define X(str)
Definition: MuonsGrabber.cc:48
void X0(double m=0)
set mean in X in cm
#define nullptr
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void sigmaZ(double s=1.0)
set resolution in Z in cm
return((rh^lh)&mask)
BetaBoostEvtVtxGenerator(const edm::ParameterSet &p)
void Phi(double m=0)
set half crossing angle
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool isAvailable() const
Definition: Service.h:46
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
void produce(edm::Event &, const edm::EventSetup &) override
void betastar(double m=0)
set beta_star
double BetaFunction(double z, double z0)
beta function
void Alpha(double m=0)
angle between crossing plane and horizontal plane
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
HLT enums.
StreamID streamID() const
Definition: Event.h:96
void Z0(double m=0)
set mean in Z in cm
long double T
virtual TMatrixD * GetInvLorentzBoost()
def move(src, dest)
Definition: eostools.py:510