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 /*
3 ________________________________________________________________________
4 
5  MixBoostEvtVtxGenerator
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 
32 
33 #include "CLHEP/Random/RandGaussQ.h"
34 #include "CLHEP/Units/GlobalSystemOfUnits.h"
35 #include "CLHEP/Units/GlobalPhysicalConstants.h"
36 //#include "CLHEP/Vector/ThreeVector.h"
37 #include "HepMC/SimpleVector.h"
38 #include "TMatrixD.h"
39 
40 #include <iostream>
41 
42 using namespace edm;
43 using namespace std;
44 using namespace CLHEP;
45 
46 class RandGaussQ;
47 class FourVector ;
48 
50 public:
52  virtual ~MixBoostEvtVtxGenerator();
53 
55  //virtual CLHEP::Hep3Vector * newVertex();
56  virtual HepMC::FourVector* newVertex() ;
57  virtual void produce( edm::Event&, const edm::EventSetup& ) override;
58  virtual TMatrixD* GetInvLorentzBoost();
59  virtual HepMC::FourVector* getVertex(edm::Event&);
60  virtual HepMC::FourVector* getRecVertex(edm::Event&);
61 
63  void sigmaZ(double s=1.0);
64 
66  void X0(double m=0) { fX0=m; }
68  void Y0(double m=0) { fY0=m; }
70  void Z0(double m=0) { fZ0=m; }
71 
73  void Phi(double m=0) { phi_=m; }
75  void Alpha(double m=0) { alpha_=m; }
76  void Beta(double m=0) { beta_=m; }
77 
79  void betastar(double m=0) { fbetastar=m; }
81  void emittance(double m=0) { femittance=m; }
82 
84  double BetaFunction(double z, double z0);
85 
86 private:
90  MixBoostEvtVtxGenerator& operator = (const MixBoostEvtVtxGenerator & rhs );
91 
92  double alpha_, phi_;
93  //TMatrixD boost_;
94  double beta_;
95  double fX0, fY0, fZ0;
96  double fSigmaZ;
97  //double fdxdz, fdydz;
98  double fbetastar, femittance;
99  double falpha;
100 
101  HepMC::FourVector* fVertex ;
102  TMatrixD *boost_;
103  double fTimeOffset;
104 
106 
107  CLHEP::RandGaussQ* fRandom ;
108 
112  std::vector<double> vtxOffset;
113 
114 };
115 
116 
118  fVertex(0), boost_(0), fTimeOffset(0),
119  signalLabel(pset.getParameter<edm::InputTag>("signalLabel")),
120  hiLabel(pset.getParameter<edm::InputTag>("heavyIonLabel")),
121  useRecVertex(pset.exists("useRecVertex")?pset.getParameter<bool>("useRecVertex"):false)
122 {
123 
124  vtxOffset.resize(3);
125  if(pset.exists("vtxOffset")) vtxOffset=pset.getParameter< std::vector<double> >("vtxOffset");
126 
127  produces<bool>("matchedVertex");
128 
129 }
130 
132 {
133  delete fVertex ;
134  if (boost_ != 0 ) delete boost_;
135  delete fRandom;
136 }
137 
138 
139 //Hep3Vector* MixBoostEvtVtxGenerator::newVertex() {
141 
142 
143  double X,Y,Z;
144 
145  double tmp_sigz = fRandom->fire(0., fSigmaZ);
146  Z = tmp_sigz + fZ0;
147 
148  double tmp_sigx = BetaFunction(Z,fZ0);
149  // need sqrt(2) for beamspot width relative to single beam width
150  tmp_sigx /= sqrt(2.0);
151  X = fRandom->fire(0.,tmp_sigx) + fX0; // + Z*fdxdz ;
152 
153  double tmp_sigy = BetaFunction(Z,fZ0);
154  // need sqrt(2) for beamspot width relative to single beam width
155  tmp_sigy /= sqrt(2.0);
156  Y = fRandom->fire(0.,tmp_sigy) + fY0; // + Z*fdydz;
157 
158  double tmp_sigt = fRandom->fire(0., fSigmaZ);
159  double T = tmp_sigt + fTimeOffset;
160 
161  if ( fVertex == 0 ) fVertex = new HepMC::FourVector();
162  fVertex->set(X,Y,Z,T);
163 
164  return fVertex;
165 }
166 
167 double MixBoostEvtVtxGenerator::BetaFunction(double z, double z0)
168 {
169  return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
170 
171 }
172 
173 
175 {
176  if (s>=0 ) {
177  fSigmaZ=s;
178  }
179  else {
180  throw cms::Exception("LogicError")
181  << "Error in MixBoostEvtVtxGenerator::sigmaZ: "
182  << "Illegal resolution in Z (negative)";
183  }
184 }
185 
187 
188  //alpha_ = 0;
189  //phi_ = 142.e-6;
190 // if (boost_ != 0 ) return boost_;
191 
192  //boost_.ResizeTo(4,4);
193  //boost_ = new TMatrixD(4,4);
194  TMatrixD tmpboost(4,4);
195  TMatrixD tmpboostZ(4,4);
196  TMatrixD tmpboostXYZ(4,4);
197 
198  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
199 
200  // Lorentz boost to frame where the collision is head-on
201  // phi is the half crossing angle in the plane ZS
202  // alpha is the angle to the S axis from the X axis in the XY plane
203 
204  tmpboost(0,0) = 1./cos(phi_);
205  tmpboost(0,1) = - cos(alpha_)*sin(phi_);
206  tmpboost(0,2) = - tan(phi_)*sin(phi_);
207  tmpboost(0,3) = - sin(alpha_)*sin(phi_);
208  tmpboost(1,0) = - cos(alpha_)*tan(phi_);
209  tmpboost(1,1) = 1.;
210  tmpboost(1,2) = cos(alpha_)*tan(phi_);
211  tmpboost(1,3) = 0.;
212  tmpboost(2,0) = 0.;
213  tmpboost(2,1) = - cos(alpha_)*sin(phi_);
214  tmpboost(2,2) = cos(phi_);
215  tmpboost(2,3) = - sin(alpha_)*sin(phi_);
216  tmpboost(3,0) = - sin(alpha_)*tan(phi_);
217  tmpboost(3,1) = 0.;
218  tmpboost(3,2) = sin(alpha_)*tan(phi_);
219  tmpboost(3,3) = 1.;
220  //cout<<"beta "<<beta_;
221  double gama=1.0/sqrt(1-beta_*beta_);
222  tmpboostZ(0,0)=gama;
223  tmpboostZ(0,1)=0.;
224  tmpboostZ(0,2)=-1.0*beta_*gama;
225  tmpboostZ(0,3)=0.;
226  tmpboostZ(1,0)=0.;
227  tmpboostZ(1,1) = 1.;
228  tmpboostZ(1,2)=0.;
229  tmpboostZ(1,3)=0.;
230  tmpboostZ(2,0)=-1.0*beta_*gama;
231  tmpboostZ(2,1) = 0.;
232  tmpboostZ(2,2)=gama;
233  tmpboostZ(2,3) = 0.;
234  tmpboostZ(3,0)=0.;
235  tmpboostZ(3,1)=0.;
236  tmpboostZ(3,2)=0.;
237  tmpboostZ(3,3) = 1.;
238 
239  tmpboostXYZ=tmpboost*tmpboostZ;
240  tmpboost.Invert();
241 
242 
243 
244  boost_ = new TMatrixD(tmpboostXYZ);
245  boost_->Print();
246 
247  return boost_;
248 }
249 
250 HepMC::FourVector* MixBoostEvtVtxGenerator::getVertex( Event& evt){
251 
253  evt.getByLabel(hiLabel,input);
254 
255  const HepMC::GenEvent* inev = input->GetEvent();
256  HepMC::GenVertex* genvtx = inev->signal_process_vertex();
257  if(!genvtx){
258  cout<<"No Signal Process Vertex!"<<endl;
259  HepMC::GenEvent::particle_const_iterator pt=inev->particles_begin();
260  HepMC::GenEvent::particle_const_iterator ptend=inev->particles_end();
261  while(!genvtx || ( genvtx->particles_in_size() == 1 && pt != ptend ) ){
262  if(!genvtx) cout<<"No Gen Vertex!"<<endl;
263  if(pt == ptend) cout<<"End reached!"<<endl;
264  genvtx = (*pt)->production_vertex();
265  ++pt;
266  }
267  }
268  double aX,aY,aZ,aT;
269 
270  aX = genvtx->position().x();
271  aY = genvtx->position().y();
272  aZ = genvtx->position().z();
273  aT = genvtx->position().t();
274 
275  if(!fVertex) fVertex = new HepMC::FourVector();
276  fVertex->set(aX,aY,aZ,aT);
277 
278  return fVertex;
279 
280 }
281 
282 
284 
286  evt.getByLabel(hiLabel,input);
287 
288  double aX,aY,aZ;
289 
290  aX = input->begin()->position().x() + vtxOffset[0];
291  aY = input->begin()->position().y() + vtxOffset[1];
292  aZ = input->begin()->position().z() + vtxOffset[2];
293 
294  if(!fVertex) fVertex = new HepMC::FourVector();
295  fVertex->set(10.0*aX,10.0*aY,10.0*aZ,0.0); // HepMC positions in mm (RECO in cm)
296 
297  return fVertex;
298 
299 }
300 
301 
303 {
304 
305 
306  Handle<HepMCProduct> HepMCEvt ;
307 
308  evt.getByLabel( signalLabel, HepMCEvt ) ;
309 
310  // generate new vertex & apply the shift
311  //
312 
313  HepMCEvt->applyVtxGen( useRecVertex ? getRecVertex(evt) : getVertex(evt) ) ;
314 
315  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
316  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
317 
318  // OK, create a (pseudo)product and put in into edm::Event
319  //
320  auto_ptr<bool> NewProduct(new bool(true)) ;
321  evt.put( NewProduct ,"matchedVertex") ;
322 
323  return ;
324 
325 }
326 
const double Z[kNumberCalorimeter]
T getParameter(std::string const &) const
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:48
float float float z
static std::string const input
Definition: EdmProvDump.cc:43
return((rh^lh)&mask)
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:115
T sqrt(T t)
Definition: SSEVec.h:48
virtual void produce(edm::Event &, const edm::EventSetup &) override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual HepMC::FourVector * newVertex()
return a new event vertex
virtual TMatrixD * GetInvLorentzBoost()
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
MixBoostEvtVtxGenerator(const edm::ParameterSet &p)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
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
tuple cout
Definition: gather_cfg.py:121
virtual HepMC::FourVector * getRecVertex(edm::Event &)
volatile std::atomic< bool > shutdown_flag false
long double T
virtual HepMC::FourVector * getVertex(edm::Event &)
double BetaFunction(double z, double z0)
beta function