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:
94  MixBoostEvtVtxGenerator& operator = (const MixBoostEvtVtxGenerator & rhs );
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  delete fVertex ;
151  if (boost_ != 0 ) delete boost_;
152  delete fRandom;
153 }
154 
155 CLHEP::HepRandomEngine& MixBoostEvtVtxGenerator::getEngine(){
156  return *fEngine;
157 }
158 
159 
160 //Hep3Vector* MixBoostEvtVtxGenerator::newVertex() {
162 
163 
164  double X,Y,Z;
165 
166  double tmp_sigz = fRandom->fire(0., fSigmaZ);
167  Z = tmp_sigz + fZ0;
168 
169  double tmp_sigx = BetaFunction(Z,fZ0);
170  // need sqrt(2) for beamspot width relative to single beam width
171  tmp_sigx /= sqrt(2.0);
172  X = fRandom->fire(0.,tmp_sigx) + fX0; // + Z*fdxdz ;
173 
174  double tmp_sigy = BetaFunction(Z,fZ0);
175  // need sqrt(2) for beamspot width relative to single beam width
176  tmp_sigy /= sqrt(2.0);
177  Y = fRandom->fire(0.,tmp_sigy) + fY0; // + Z*fdydz;
178 
179  double tmp_sigt = fRandom->fire(0., fSigmaZ);
180  double T = tmp_sigt + fTimeOffset;
181 
182  if ( fVertex == 0 ) fVertex = new HepMC::FourVector();
183  fVertex->set(X,Y,Z,T);
184 
185  return fVertex;
186 }
187 
188 double MixBoostEvtVtxGenerator::BetaFunction(double z, double z0)
189 {
190  return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
191 
192 }
193 
194 
196 {
197  if (s>=0 ) {
198  fSigmaZ=s;
199  }
200  else {
201  throw cms::Exception("LogicError")
202  << "Error in MixBoostEvtVtxGenerator::sigmaZ: "
203  << "Illegal resolution in Z (negative)";
204  }
205 }
206 
208 
209  //alpha_ = 0;
210  //phi_ = 142.e-6;
211 // if (boost_ != 0 ) return boost_;
212 
213  //boost_.ResizeTo(4,4);
214  //boost_ = new TMatrixD(4,4);
215  TMatrixD tmpboost(4,4);
216  TMatrixD tmpboostZ(4,4);
217  TMatrixD tmpboostXYZ(4,4);
218 
219  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
220 
221  // Lorentz boost to frame where the collision is head-on
222  // phi is the half crossing angle in the plane ZS
223  // alpha is the angle to the S axis from the X axis in the XY plane
224 
225  tmpboost(0,0) = 1./cos(phi_);
226  tmpboost(0,1) = - cos(alpha_)*sin(phi_);
227  tmpboost(0,2) = - tan(phi_)*sin(phi_);
228  tmpboost(0,3) = - sin(alpha_)*sin(phi_);
229  tmpboost(1,0) = - cos(alpha_)*tan(phi_);
230  tmpboost(1,1) = 1.;
231  tmpboost(1,2) = cos(alpha_)*tan(phi_);
232  tmpboost(1,3) = 0.;
233  tmpboost(2,0) = 0.;
234  tmpboost(2,1) = - cos(alpha_)*sin(phi_);
235  tmpboost(2,2) = cos(phi_);
236  tmpboost(2,3) = - sin(alpha_)*sin(phi_);
237  tmpboost(3,0) = - sin(alpha_)*tan(phi_);
238  tmpboost(3,1) = 0.;
239  tmpboost(3,2) = sin(alpha_)*tan(phi_);
240  tmpboost(3,3) = 1.;
241  //cout<<"beta "<<beta_;
242  double gama=1.0/sqrt(1-beta_*beta_);
243  tmpboostZ(0,0)=gama;
244  tmpboostZ(0,1)=0.;
245  tmpboostZ(0,2)=-1.0*beta_*gama;
246  tmpboostZ(0,3)=0.;
247  tmpboostZ(1,0)=0.;
248  tmpboostZ(1,1) = 1.;
249  tmpboostZ(1,2)=0.;
250  tmpboostZ(1,3)=0.;
251  tmpboostZ(2,0)=-1.0*beta_*gama;
252  tmpboostZ(2,1) = 0.;
253  tmpboostZ(2,2)=gama;
254  tmpboostZ(2,3) = 0.;
255  tmpboostZ(3,0)=0.;
256  tmpboostZ(3,1)=0.;
257  tmpboostZ(3,2)=0.;
258  tmpboostZ(3,3) = 1.;
259 
260  tmpboostXYZ=tmpboost*tmpboostZ;
261  tmpboost.Invert();
262 
263 
264 
265  boost_ = new TMatrixD(tmpboostXYZ);
266  boost_->Print();
267 
268  return boost_;
269 }
270 
271 HepMC::FourVector* MixBoostEvtVtxGenerator::getVertex( Event& evt){
272 
274  evt.getByLabel(hiLabel,input);
275 
276  const HepMC::GenEvent* inev = input->GetEvent();
277  HepMC::GenVertex* genvtx = inev->signal_process_vertex();
278  if(!genvtx){
279  cout<<"No Signal Process Vertex!"<<endl;
280  HepMC::GenEvent::particle_const_iterator pt=inev->particles_begin();
281  HepMC::GenEvent::particle_const_iterator ptend=inev->particles_end();
282  while(!genvtx || ( genvtx->particles_in_size() == 1 && pt != ptend ) ){
283  if(!genvtx) cout<<"No Gen Vertex!"<<endl;
284  if(pt == ptend) cout<<"End reached!"<<endl;
285  genvtx = (*pt)->production_vertex();
286  ++pt;
287  }
288  }
289  double aX,aY,aZ,aT;
290 
291  aX = genvtx->position().x();
292  aY = genvtx->position().y();
293  aZ = genvtx->position().z();
294  aT = genvtx->position().t();
295 
296  if(!fVertex) fVertex = new HepMC::FourVector();
297  fVertex->set(aX,aY,aZ,aT);
298 
299  return fVertex;
300 
301 }
302 
303 
305 
307  evt.getByLabel(hiLabel,input);
308 
309  double aX,aY,aZ;
310 
311  aX = input->begin()->position().x() + vtxOffset[0];
312  aY = input->begin()->position().y() + vtxOffset[1];
313  aZ = input->begin()->position().z() + vtxOffset[2];
314 
315  if(!fVertex) fVertex = new HepMC::FourVector();
316  fVertex->set(10.0*aX,10.0*aY,10.0*aZ,0.0); // HepMC positions in mm (RECO in cm)
317 
318  return fVertex;
319 
320 }
321 
322 
324 {
325 
326 
327  Handle<HepMCProduct> HepMCEvt ;
328 
329  evt.getByLabel( signalLabel, HepMCEvt ) ;
330 
331  // generate new vertex & apply the shift
332  //
333 
334  HepMCEvt->applyVtxGen( useRecVertex ? getRecVertex(evt) : getVertex(evt) ) ;
335 
336  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
337  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
338 
339  // OK, create a (pseudo)product and put in into edm::Event
340  //
341  auto_ptr<bool> NewProduct(new bool(true)) ;
342  evt.put( NewProduct ,"matchedVertex") ;
343 
344  return ;
345 
346 }
347 
const double Z[kNumberCalorimeter]
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
float float float 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:94
T sqrt(T t)
Definition: SSEVec.h:48
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:361
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