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