CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HepMCProduct.cc
Go to the documentation of this file.
1 /*************************
2  *
3  * Date: 2005/08 $
4  * \author J Weng - F. Moortgat'
5  */
6 
7 #include <iostream>
8 #include <algorithm> // because we use std::swap
9 
10 //#include "CLHEP/Vector/ThreeVector.h"
11 
13 
14 using namespace edm;
15 using namespace std;
16 
17 HepMCProduct::HepMCProduct( HepMC::GenEvent * evt ) {
18  evt_ = evt;
19  cout << "Contructing HepMCProduct" << endl;
20 
21  //note: this is not quite safe, because GenEvent does NOT
22  // know if vertex smearing applied or nor - only the
23  // HepMCProduct itself knows !
24  // isVtxGenApplied_ = 0 ; // ???
25 }
26 
28 
29  delete evt_; evt_ = 0; isVtxGenApplied_ = false;
30  isVtxBoostApplied_ = false;
31  isPBoostApplied_ = false;
32 }
33 
34 
35 void HepMCProduct::addHepMCData( HepMC::GenEvent *evt){
36  // evt->print();
37  // cout <<sizeof (evt) <<" " << sizeof ( HepMC::GenEvent) << endl;
38  evt_ = evt;
39 
40  // same story about vertex smearing - GenEvent won't know it...
41  // in fact, would be better to implement CmsGenEvent...
42 
43 }
44 
45 void HepMCProduct::applyVtxGen( HepMC::FourVector* vtxShift ) const
46 {
47  //std::cout<< " applyVtxGen called " << isVtxGenApplied_ << endl;
48  //fTimeOffset = 0;
49 
50  if ( isVtxGenApplied() ) return ;
51 
52  for ( HepMC::GenEvent::vertex_iterator vt=evt_->vertices_begin();
53  vt!=evt_->vertices_end(); ++vt )
54  {
55 
56  double x = (*vt)->position().x() + vtxShift->x() ;
57  double y = (*vt)->position().y() + vtxShift->y() ;
58  double z = (*vt)->position().z() + vtxShift->z() ;
59  double t = (*vt)->position().t() + vtxShift->t() ;
60  //std::cout << " vertex (x,y,z)= " << x <<" " << y << " " << z << std::endl;
61  (*vt)->set_position( HepMC::FourVector(x,y,z,t) ) ;
62  }
63 
64  isVtxGenApplied_ = true ;
65 
66  return ;
67 
68 }
69 
70 void HepMCProduct::boostToLab( TMatrixD* lorentz, std::string type ) const {
71 
72  //std::cout << "from boostToLab:" << std::endl;
73 
74 
75 
76  if ( lorentz == 0 ) {
77 
78  //std::cout << " lorentz = 0 " << std::endl;
79  return;
80  }
81 
82  //lorentz->Print();
83 
84  TMatrixD tmplorentz(*lorentz);
85  //tmplorentz.Print();
86 
87  if ( type == "vertex") {
88 
89  if ( isVtxBoostApplied() ) {
90  //std::cout << " isVtxBoostApplied true " << std::endl;
91  return ;
92  }
93 
94  for ( HepMC::GenEvent::vertex_iterator vt=evt_->vertices_begin();
95  vt!=evt_->vertices_end(); ++vt ) {
96 
97  // change basis to lorentz boost definition: (t,x,z,y)
98  TMatrixD p4(4,1);
99  p4(0,0) = (*vt)->position().t();
100  p4(1,0) = (*vt)->position().x();
101  p4(2,0) = (*vt)->position().z();
102  p4(3,0) = (*vt)->position().y();
103 
104  TMatrixD p4lab(4,1);
105  p4lab = tmplorentz * p4;
106  //std::cout << " vertex lorentz: " << p4lab(1,0) << " " << p4lab(3,0) << " " << p4lab(2,0) << std::endl;
107  (*vt)->set_position( HepMC::FourVector(p4lab(1,0),p4lab(3,0),p4lab(2,0), p4lab(0,0) ) ) ;
108  }
109 
110  isVtxBoostApplied_ = true ;
111  }
112  else if ( type == "momentum") {
113 
114  if ( isPBoostApplied() ) {
115  //std::cout << " isPBoostApplied true " << std::endl;
116  return ;
117  }
118 
119  for ( HepMC::GenEvent::particle_iterator part=evt_->particles_begin();
120  part!=evt_->particles_end(); ++part ) {
121 
122  // change basis to lorentz boost definition: (E,Px,Pz,Py)
123  TMatrixD p4(4,1);
124  p4(0,0) = (*part)->momentum().e();
125  p4(1,0) = (*part)->momentum().x();
126  p4(2,0) = (*part)->momentum().z();
127  p4(3,0) = (*part)->momentum().y();
128 
129  TMatrixD p4lab(4,1);
130  p4lab = tmplorentz * p4;
131  //std::cout << " momentum lorentz: " << p4lab(1,0) << " " << p4lab(3,0) << " " << p4lab(2,0) << std::endl;
132  (*part)->set_momentum( HepMC::FourVector(p4lab(1,0),p4lab(3,0),p4lab(2,0),p4lab(0,0) ) ) ;
133  }
134 
135  isPBoostApplied_ = true ;
136  }
137  else {
138  std::cout << " no type found for boostToLab(std::string), options are vertex or momentum" << std::endl;
139  }
140 
141 
142  return ;
143 }
144 
145 
146 const HepMC::GenEvent&
148 
149  return * evt_;
150 }
151 
152 // copy constructor
154  evt_(0) {
155 
156  if (other.evt_) evt_=new HepMC::GenEvent(*other.evt_);
160  //fTimeOffset = other.fTimeOffset;
161 }
162 
163 // swap
164 void
166  std::swap(evt_, other.evt_);
170  //std::swap(fTimeOffset, other.fTimeOffset);
171 }
172 
173 // assignment: use copy/swap idiom for exception safety.
176  HepMCProduct temp(other);
177  swap(temp);
178  return *this;
179 }
type
Definition: HCALResponse.h:22
virtual ~HepMCProduct()
Definition: HepMCProduct.cc:27
void swap(HepMCProduct &other)
void addHepMCData(HepMC::GenEvent *evt)
Definition: HepMCProduct.cc:35
HepMC::GenEvent * evt_
Definition: HepMCProduct.h:46
double double double z
void applyVtxGen(HepMC::FourVector *vtxShift) const
Definition: HepMCProduct.cc:45
HepMCProduct & operator=(HepMCProduct const &other)
const HepMC::GenEvent & getHepMCData() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double p4[4]
Definition: TauolaWrapper.h:92
part
Definition: HCALResponse.h:21
tuple cout
Definition: gather_cfg.py:121
void boostToLab(TMatrixD *lorentz, std::string type) const
Definition: HepMCProduct.cc:70
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19
Definition: DDAxes.h:10