CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MixBoostEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 // $Id: MixBoostEvtVtxGenerator.cc,v 1.1 2012/06/08 22:19:37 yilmaz Exp $
3 /*
4 ________________________________________________________________________
5 
6  MixBoostEvtVtxGenerator
7 
8  Smear vertex according to the Beta function on the transverse plane
9  and a Gaussian on the z axis. It allows the beam to have a crossing
10  angle (slopes dxdz and dydz).
11 
12  Based on GaussEvtVtxGenerator
13  implemented by Francisco Yumiceva (yumiceva@fnal.gov)
14 
15  FERMILAB
16  2006
17 ________________________________________________________________________
18 */
19 
20 //lingshan: add beta for z-axis boost
21 
22 //#include "IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h"
23 
27 
35 
36 #include "CLHEP/Random/RandGaussQ.h"
37 #include "CLHEP/Units/GlobalSystemOfUnits.h"
38 #include "CLHEP/Units/GlobalPhysicalConstants.h"
39 //#include "CLHEP/Vector/ThreeVector.h"
40 #include "HepMC/SimpleVector.h"
41 #include "TMatrixD.h"
42 
43 #include <iostream>
44 
45 using namespace edm;
46 using namespace std;
47 using namespace CLHEP;
48 
49 class RandGaussQ;
50 class FourVector ;
51 
53 public:
55  virtual ~MixBoostEvtVtxGenerator();
56 
58  //virtual CLHEP::Hep3Vector * newVertex();
59  virtual HepMC::FourVector* newVertex() ;
60  virtual void produce( edm::Event&, const edm::EventSetup& );
61  virtual TMatrixD* GetInvLorentzBoost();
62  virtual HepMC::FourVector* getVertex(edm::Event&);
63  virtual HepMC::FourVector* getRecVertex(edm::Event&);
64 
66  void sigmaZ(double s=1.0);
67 
69  void X0(double m=0) { fX0=m; }
71  void Y0(double m=0) { fY0=m; }
73  void Z0(double m=0) { fZ0=m; }
74 
76  void Phi(double m=0) { phi_=m; }
78  void Alpha(double m=0) { alpha_=m; }
79  void Beta(double m=0) { beta_=m; }
80 
82  void betastar(double m=0) { fbetastar=m; }
84  void emittance(double m=0) { femittance=m; }
85 
87  double BetaFunction(double z, double z0);
88  CLHEP::HepRandomEngine& getEngine();
89 
90 private:
95 
96  double alpha_, phi_;
97  //TMatrixD boost_;
98  double beta_;
99  double fX0, fY0, fZ0;
100  double fSigmaZ;
101  //double fdxdz, fdydz;
102  double fbetastar, femittance;
103  double falpha;
104 
105  HepMC::FourVector* fVertex ;
106  TMatrixD *boost_;
107  double fTimeOffset;
108 
109  CLHEP::HepRandomEngine* fEngine;
111 
112  CLHEP::RandGaussQ* fRandom ;
113 
117  std::vector<double> vtxOffset;
118 
119 };
120 
121 
123  fVertex(0), boost_(0), fTimeOffset(0), fEngine(0),
124  signalLabel(pset.getParameter<edm::InputTag>("signalLabel")),
125  hiLabel(pset.getParameter<edm::InputTag>("heavyIonLabel")),
126  useRecVertex(pset.exists("useRecVertex")?pset.getParameter<bool>("useRecVertex"):false)
127 {
128 
129  vtxOffset.resize(3);
130  if(pset.exists("vtxOffset")) vtxOffset=pset.getParameter< std::vector<double> >("vtxOffset");
132 
133  if ( ! rng.isAvailable()) {
134 
135  throw cms::Exception("Configuration")
136  << "The BaseEvtVtxGenerator requires the RandomNumberGeneratorService\n"
137  "which is not present in the configuration file. You must add the service\n"
138  "in the configuration file or remove the modules that require it.";
139  }
140 
141  CLHEP::HepRandomEngine& engine = rng->getEngine();
142  fEngine = &engine;
143 
144  produces<bool>("matchedVertex");
145 
146 }
147 
149 {
150 }
151 
152 CLHEP::HepRandomEngine& MixBoostEvtVtxGenerator::getEngine(){
153  return *fEngine;
154 }
155 
156 
157 //Hep3Vector* MixBoostEvtVtxGenerator::newVertex() {
159 
160 
161  double X,Y,Z;
162 
163  double tmp_sigz = fRandom->fire(0., fSigmaZ);
164  Z = tmp_sigz + fZ0;
165 
166  double tmp_sigx = BetaFunction(Z,fZ0);
167  // need sqrt(2) for beamspot width relative to single beam width
168  tmp_sigx /= sqrt(2.0);
169  X = fRandom->fire(0.,tmp_sigx) + fX0; // + Z*fdxdz ;
170 
171  double tmp_sigy = BetaFunction(Z,fZ0);
172  // need sqrt(2) for beamspot width relative to single beam width
173  tmp_sigy /= sqrt(2.0);
174  Y = fRandom->fire(0.,tmp_sigy) + fY0; // + Z*fdydz;
175 
176  double tmp_sigt = fRandom->fire(0., fSigmaZ);
177  double T = tmp_sigt + fTimeOffset;
178 
179  if ( fVertex == 0 ) fVertex = new HepMC::FourVector();
180  fVertex->set(X,Y,Z,T);
181 
182  return fVertex;
183 }
184 
185 double MixBoostEvtVtxGenerator::BetaFunction(double z, double z0)
186 {
187  return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
188 
189 }
190 
191 
193 {
194  if (s>=0 ) {
195  fSigmaZ=s;
196  }
197  else {
198  throw cms::Exception("LogicError")
199  << "Error in MixBoostEvtVtxGenerator::sigmaZ: "
200  << "Illegal resolution in Z (negative)";
201  }
202 }
203 
205 
206  //alpha_ = 0;
207  //phi_ = 142.e-6;
208 // if (boost_ != 0 ) return boost_;
209 
210  //boost_.ResizeTo(4,4);
211  //boost_ = new TMatrixD(4,4);
212  TMatrixD tmpboost(4,4);
213  TMatrixD tmpboostZ(4,4);
214  TMatrixD tmpboostXYZ(4,4);
215 
216  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
217 
218  // Lorentz boost to frame where the collision is head-on
219  // phi is the half crossing angle in the plane ZS
220  // alpha is the angle to the S axis from the X axis in the XY plane
221 
222  tmpboost(0,0) = 1./cos(phi_);
223  tmpboost(0,1) = - cos(alpha_)*sin(phi_);
224  tmpboost(0,2) = - tan(phi_)*sin(phi_);
225  tmpboost(0,3) = - sin(alpha_)*sin(phi_);
226  tmpboost(1,0) = - cos(alpha_)*tan(phi_);
227  tmpboost(1,1) = 1.;
228  tmpboost(1,2) = cos(alpha_)*tan(phi_);
229  tmpboost(1,3) = 0.;
230  tmpboost(2,0) = 0.;
231  tmpboost(2,1) = - cos(alpha_)*sin(phi_);
232  tmpboost(2,2) = cos(phi_);
233  tmpboost(2,3) = - sin(alpha_)*sin(phi_);
234  tmpboost(3,0) = - sin(alpha_)*tan(phi_);
235  tmpboost(3,1) = 0.;
236  tmpboost(3,2) = sin(alpha_)*tan(phi_);
237  tmpboost(3,3) = 1.;
238  //cout<<"beta "<<beta_;
239  double gama=1.0/sqrt(1-beta_*beta_);
240  tmpboostZ(0,0)=gama;
241  tmpboostZ(0,1)=0.;
242  tmpboostZ(0,2)=-1.0*beta_*gama;
243  tmpboostZ(0,3)=0.;
244  tmpboostZ(1,0)=0.;
245  tmpboostZ(1,1) = 1.;
246  tmpboostZ(1,2)=0.;
247  tmpboostZ(1,3)=0.;
248  tmpboostZ(2,0)=-1.0*beta_*gama;
249  tmpboostZ(2,1) = 0.;
250  tmpboostZ(2,2)=gama;
251  tmpboostZ(2,3) = 0.;
252  tmpboostZ(3,0)=0.;
253  tmpboostZ(3,1)=0.;
254  tmpboostZ(3,2)=0.;
255  tmpboostZ(3,3) = 1.;
256 
257  tmpboostXYZ=tmpboost*tmpboostZ;
258  tmpboost.Invert();
259 
260 
261 
262  boost_ = new TMatrixD(tmpboostXYZ);
263  boost_->Print();
264 
265  return boost_;
266 }
267 
268 HepMC::FourVector* MixBoostEvtVtxGenerator::getVertex( Event& evt){
269 
271  evt.getByLabel(hiLabel,input);
272 
273  const HepMC::GenEvent* inev = input->GetEvent();
274  HepMC::GenVertex* genvtx = inev->signal_process_vertex();
275  if(!genvtx){
276  cout<<"No Signal Process Vertex!"<<endl;
277  HepMC::GenEvent::particle_const_iterator pt=inev->particles_begin();
278  HepMC::GenEvent::particle_const_iterator ptend=inev->particles_end();
279  while(!genvtx || ( genvtx->particles_in_size() == 1 && pt != ptend ) ){
280  if(!genvtx) cout<<"No Gen Vertex!"<<endl;
281  if(pt == ptend) cout<<"End reached!"<<endl;
282  genvtx = (*pt)->production_vertex();
283  ++pt;
284  }
285  }
286  double aX,aY,aZ,aT;
287 
288  aX = genvtx->position().x();
289  aY = genvtx->position().y();
290  aZ = genvtx->position().z();
291  aT = genvtx->position().t();
292 
293  if(!fVertex) fVertex = new HepMC::FourVector();
294  fVertex->set(aX,aY,aZ,aT);
295 
296  return fVertex;
297 
298 }
299 
300 
302 
304  evt.getByLabel(hiLabel,input);
305 
306  double aX,aY,aZ;
307 
308  aX = input->begin()->position().x() + vtxOffset[0];
309  aY = input->begin()->position().y() + vtxOffset[1];
310  aZ = input->begin()->position().z() + vtxOffset[2];
311 
312  if(!fVertex) fVertex = new HepMC::FourVector();
313  fVertex->set(10.0*aX,10.0*aY,10.0*aZ,0.0); // HepMC positions in mm (RECO in cm)
314 
315  return fVertex;
316 
317 }
318 
319 
321 {
322 
323 
324  Handle<HepMCProduct> HepMCEvt ;
325 
326  evt.getByLabel( signalLabel, HepMCEvt ) ;
327 
328  // generate new vertex & apply the shift
329  //
330 
331  HepMCEvt->applyVtxGen( useRecVertex ? getRecVertex(evt) : getVertex(evt) ) ;
332 
333  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
334  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
335 
336  // OK, create a (pseudo)product and put in into edm::Event
337  //
338  auto_ptr<bool> NewProduct(new bool(true)) ;
339  evt.put( NewProduct ,"matchedVertex") ;
340 
341  return ;
342 
343 }
344 
const double Z[kNumberCalorimeter]
nocap nocap const skelname & operator=(const skelname &)
T getParameter(std::string const &) const
CLHEP::HepRandomEngine * fEngine
void Z0(double m=0)
set mean in Z in cm
std::vector< double > vtxOffset
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void emittance(double m=0)
emittance (no the normalized)
void X0(double m=0)
set mean in X in cm
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define X(str)
Definition: MuonsGrabber.cc:49
double double double z
void sigmaZ(double s=1.0)
set resolution in Z in cm
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
CLHEP::HepRandomEngine & getEngine()
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual HepMC::FourVector * newVertex()
return a new event vertex
bool isAvailable() const
Definition: Service.h:47
virtual TMatrixD * GetInvLorentzBoost()
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
MixBoostEvtVtxGenerator(const edm::ParameterSet &p)
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void Alpha(double m=0)
angle between crossing plane and horizontal plane
void Phi(double m=0)
set half crossing angle
void betastar(double m=0)
set beta_star
void Y0(double m=0)
set mean in Y in cm
virtual void produce(edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121
virtual HepMC::FourVector * getRecVertex(edm::Event &)
long double T
virtual HepMC::FourVector * getVertex(edm::Event &)
double BetaFunction(double z, double z0)
beta function