CMS 3D CMS Logo

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), isVtxGenApplied_(false), isVtxBoostApplied_(false), isPBoostApplied_(false) {
19 }
20 
22 
23  delete evt_; evt_ = nullptr; isVtxGenApplied_ = false;
24  isVtxBoostApplied_ = false;
25  isPBoostApplied_ = false;
26 }
27 
28 
29 void HepMCProduct::addHepMCData( HepMC::GenEvent *evt){
30  // evt->print();
31  // cout <<sizeof (evt) <<" " << sizeof ( HepMC::GenEvent) << endl;
32  evt_ = evt;
33 
34  // same story about vertex smearing - GenEvent won't know it...
35  // in fact, would be better to implement CmsGenEvent...
36 
37 }
38 
39 void HepMCProduct::applyVtxGen( HepMC::FourVector const& vtxShift )
40 {
41  //std::cout<< " applyVtxGen called " << isVtxGenApplied_ << endl;
42  //fTimeOffset = 0;
43 
44  if ( isVtxGenApplied() ) return ;
45 
46  for ( HepMC::GenEvent::vertex_iterator vt=evt_->vertices_begin();
47  vt!=evt_->vertices_end(); ++vt )
48  {
49 
50  double x = (*vt)->position().x() + vtxShift.x() ;
51  double y = (*vt)->position().y() + vtxShift.y() ;
52  double z = (*vt)->position().z() + vtxShift.z() ;
53  double t = (*vt)->position().t() + vtxShift.t() ;
54  //std::cout << " vertex (x,y,z)= " << x <<" " << y << " " << z << std::endl;
55  (*vt)->set_position( HepMC::FourVector(x,y,z,t) ) ;
56  }
57 
59 
60  return ;
61 
62 }
63 
64 void HepMCProduct::boostToLab( TMatrixD const* lorentz, std::string const& type ) {
65 
66  //std::cout << "from boostToLab:" << std::endl;
67 
68 
69 
70  if ( lorentz == nullptr ) {
71 
72  //std::cout << " lorentz = 0 " << std::endl;
73  return;
74  }
75 
76  //lorentz->Print();
77 
78  TMatrixD tmplorentz(*lorentz);
79  //tmplorentz.Print();
80 
81  if ( type == "vertex") {
82 
83  if ( isVtxBoostApplied() ) {
84  //std::cout << " isVtxBoostApplied true " << std::endl;
85  return ;
86  }
87 
88  for ( HepMC::GenEvent::vertex_iterator vt=evt_->vertices_begin();
89  vt!=evt_->vertices_end(); ++vt ) {
90 
91  // change basis to lorentz boost definition: (t,x,z,y)
92  TMatrixD p4(4,1);
93  p4(0,0) = (*vt)->position().t();
94  p4(1,0) = (*vt)->position().x();
95  p4(2,0) = (*vt)->position().z();
96  p4(3,0) = (*vt)->position().y();
97 
98  TMatrixD p4lab(4,1);
99  p4lab = tmplorentz * p4;
100  //std::cout << " vertex lorentz: " << p4lab(1,0) << " " << p4lab(3,0) << " " << p4lab(2,0) << std::endl;
101  (*vt)->set_position( HepMC::FourVector(p4lab(1,0),p4lab(3,0),p4lab(2,0), p4lab(0,0) ) ) ;
102  }
103 
105  }
106  else if ( type == "momentum") {
107 
108  if ( isPBoostApplied() ) {
109  //std::cout << " isPBoostApplied true " << std::endl;
110  return ;
111  }
112 
113  for ( HepMC::GenEvent::particle_iterator part=evt_->particles_begin();
114  part!=evt_->particles_end(); ++part ) {
115 
116  // change basis to lorentz boost definition: (E,Px,Pz,Py)
117  TMatrixD p4(4,1);
118  p4(0,0) = (*part)->momentum().e();
119  p4(1,0) = (*part)->momentum().x();
120  p4(2,0) = (*part)->momentum().z();
121  p4(3,0) = (*part)->momentum().y();
122 
123  TMatrixD p4lab(4,1);
124  p4lab = tmplorentz * p4;
125  //std::cout << " momentum lorentz: " << p4lab(1,0) << " " << p4lab(3,0) << " " << p4lab(2,0) << std::endl;
126  (*part)->set_momentum( HepMC::FourVector(p4lab(1,0),p4lab(3,0),p4lab(2,0),p4lab(0,0) ) ) ;
127  }
128 
130  }
131  else {
132  std::cout << " no type found for boostToLab(std::string), options are vertex or momentum" << std::endl;
133  }
134 
135 
136  return ;
137 }
138 
139 
140 const HepMC::GenEvent&
142 
143  return * evt_;
144 }
145 
146 // copy constructor
148  evt_(nullptr) {
149 
150  if (other.evt_) evt_=new HepMC::GenEvent(*other.evt_);
154  //fTimeOffset = other.fTimeOffset;
155 }
156 
157 // swap
158 void
160  std::swap(evt_, other.evt_);
164  //std::swap(fTimeOffset, other.fTimeOffset);
165 }
166 
167 // assignment: use copy/swap idiom for exception safety.
170  HepMCProduct temp(other);
171  swap(temp);
172  return *this;
173 }
type
Definition: HCALResponse.h:21
virtual ~HepMCProduct()
Definition: HepMCProduct.cc:21
bool isVtxBoostApplied() const
Definition: HepMCProduct.h:41
void swap(HepMCProduct &other)
void addHepMCData(HepMC::GenEvent *evt)
Definition: HepMCProduct.cc:29
HepMC::GenEvent * evt_
Definition: HepMCProduct.h:49
#define nullptr
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
void applyVtxGen(HepMC::FourVector const *vtxShift)
Definition: HepMCProduct.h:29
bool isPBoostApplied() const
Definition: HepMCProduct.h:42
void boostToLab(TMatrixD const *lorentz, std::string const &type)
Definition: HepMCProduct.cc:64
part
Definition: HCALResponse.h:20
bool isVtxGenApplied() const
Definition: HepMCProduct.h:40
return(e1-e2)*(e1-e2)+dp *dp
HLT enums.
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19