Belle II Software  release-06-01-15
PhotosParticle.cc
1 #include <vector>
2 #include <math.h>
3 #include "PhotosParticle.h"
4 #include "Log.h"
5 using std::vector;
6 
7 namespace Photospp {
8 
10  {
11  if (getDaughters().size() == 0) return false;
12  else return true;
13  }
14 
16  {
17  vector<PhotosParticle*> daughters = getDaughters();
18  vector<PhotosParticle*>::iterator pcl_itr = daughters.begin();
19 
20  //get all daughters and look for stable with same pgd id
21  for (; pcl_itr != daughters.end(); pcl_itr++) {
22  if ((*pcl_itr)->getPdgID() == this->getPdgID())
23  return (*pcl_itr)->findLastSelf();
24  }
25 
26  return this;
27  }
28 
29  vector<PhotosParticle*> PhotosParticle::findProductionMothers()
30  {
31  vector<PhotosParticle*> mothers = getMothers();
32  vector<PhotosParticle*>::iterator pcl_itr = mothers.begin();
33 
34  //get all mothers and check none have pdg id of this one
35  for (; pcl_itr != mothers.end(); pcl_itr++) {
36  if ((*pcl_itr)->getPdgID() == this->getPdgID())
37  return (*pcl_itr)->findProductionMothers();
38  }
39  return mothers;
40  }
41 
42  vector<PhotosParticle*> PhotosParticle::getDecayTree()
43  {
44  vector<PhotosParticle*> particles;
45  particles.push_back(this);
46  vector<PhotosParticle*> daughters = getDaughters();
47  for (int i = 0; i < (int)daughters.size(); i++) {
48  // Check if we are the first mother of each daughters
49  // If not - skip this daughter
50  PhotosParticle* p = daughters.at(i);
51  vector<PhotosParticle*> mothers = p->getMothers();
52  if (mothers.size() > 1 && mothers.at(0)->getBarcode() != getBarcode()) continue;
53  vector<PhotosParticle*> tree = p->getDecayTree();
54  particles.insert(particles.end(), tree.begin(), tree.end());
55  }
56  return particles;
57  }
58 
60  {
61  if (!hasDaughters()) //if there are no daughters
62  return;
63 
64  // get all daughters, granddaughters, etc. then rotate and boost them
65  vector<PhotosParticle*> list = getAllDecayProducts();
66  vector<PhotosParticle*>::iterator pcl_itr = list.begin();
67 
68  for (; pcl_itr != list.end(); pcl_itr++) {
69  (*pcl_itr)->boostFromRestFrame(tau_momentum);
70  }
71 
72  //checkMomentumConservation();
73  }
74 
76  {
77  if (!hasDaughters()) //if there are no daughters
78  return;
79 
80  // get all daughters, granddaughters, etc. then rotate and boost them
81  vector<PhotosParticle*> list = getAllDecayProducts();
82  vector<PhotosParticle*>::iterator pcl_itr = list.begin();
83 
84  for (; pcl_itr != list.end(); pcl_itr++) {
85  (*pcl_itr)->boostToRestFrame(tau_momentum);
86  }
87 
88  //checkMomentumConservation();
89  }
90 
91 
93  {
94  double theta = tau_momentum->getRotationAngle(Y_AXIS);
95  tau_momentum->rotate(Y_AXIS, theta);
96 
97  double phi = tau_momentum->getRotationAngle(X_AXIS);
98  tau_momentum->rotate(Y_AXIS, -theta);
99 
100  //Now rotate coordinates to get boost in Z direction.
101  rotate(Y_AXIS, theta);
102  rotate(X_AXIS, phi);
103  boostAlongZ(-1 * tau_momentum->getP(), tau_momentum->getE());
104  rotate(X_AXIS, -phi);
105  rotate(Y_AXIS, -theta);
106  }
107 
109  {
110  //get the rotation angles
111  //and boost z
112 
113  double theta = tau_momentum->getRotationAngle(Y_AXIS);
114  tau_momentum->rotate(Y_AXIS, theta);
115 
116  double phi = tau_momentum->getRotationAngle(X_AXIS);
117  tau_momentum->rotate(Y_AXIS, -theta);
118 
119  //Now rotate coordinates to get boost in Z direction.
120  rotate(Y_AXIS, theta);
121  rotate(X_AXIS, phi);
122  boostAlongZ(tau_momentum->getP(), tau_momentum->getE());
123  rotate(X_AXIS, -phi);
124  rotate(Y_AXIS, -theta);
125  }
126 
129  double PhotosParticle::getRotationAngle(int axis, int second_axis)
130  {
137  if (getP(second_axis) == 0) {
138  if (getP(axis) > 0) return -M_PI / 2.0;
139  else return M_PI / 2.0;
140  }
141  if (getP(second_axis) > 0) return -atan(getP(axis) / getP(second_axis));
142  else return M_PI - atan(getP(axis) / getP(second_axis));
143 
144  }
145 
148  void PhotosParticle::boostAlongZ(double boost_pz, double boost_e)
149  {
150  // Boost along the Z axis
151  double m_tau = sqrt(boost_e * boost_e - boost_pz * boost_pz);
152 
153  double p = getPz();
154  double e = getE();
155 
156  setPz((boost_e * p + boost_pz * e) / m_tau);
157  setE((boost_pz * p + boost_e * e) / m_tau);
158  }
159 
161  void PhotosParticle::rotate(int axis, double theta, int second_axis)
162  {
163  double temp_px = getP(axis);
164  double temp_pz = getP(second_axis);
165  setP(axis, cos(theta)*temp_px + sin(theta)*temp_pz);
166  setP(second_axis, -sin(theta)*temp_px + cos(theta)*temp_pz);
167  }
168 
169  void PhotosParticle::rotateDaughters(int axis, double theta, int second_axis)
170  {
171  if (!hasDaughters()) //if there are no daughters
172  return;
173 
174  vector<PhotosParticle*> daughters = getDaughters();
175  vector<PhotosParticle*>::iterator pcl_itr = daughters.begin();
176 
177  //get all daughters then rotate and boost them.
178  for (; pcl_itr != daughters.end(); pcl_itr++) {
179  (*pcl_itr)->rotate(axis, theta, second_axis);
180  (*pcl_itr)->rotateDaughters(axis, theta, second_axis);
181  }
182  //checkMomentumConservation();
183  }
184 
186  {
187  double e_sq = getE() * getE();
188  double p_sq = getP() * getP();
189 
190  if (e_sq > p_sq) return sqrt(e_sq - p_sq);
191  else return -1 * sqrt(p_sq - e_sq); //if it's negative
192  }
193 
195  {
196  return sqrt(getPx() * getPx() + getPy() * getPy() + getPz() * getPz());
197  }
198 
199  double PhotosParticle::getP(int axis)
200  {
201  if (axis == X_AXIS) return getPx();
202  if (axis == Y_AXIS) return getPy();
203  if (axis == Z_AXIS) return getPz();
204  return 0;
205  }
206 
207  void PhotosParticle::setP(int axis, double p_component)
208  {
209  if (axis == X_AXIS) setPx(p_component);
210  if (axis == Y_AXIS) setPy(p_component);
211  if (axis == Z_AXIS) setPz(p_component);
212  }
213 
214 } // namespace Photospp
virtual void setE(double e)=0
Set the energy component of the four vector.
void rotate(int axis, double phi, int second_axis=Z_AXIS)
rotate this particles 4-momentum by an angle phi from the axisis "axis" towards the axis "second_axis...
static const int Y_AXIS
Y Axis.
PhotosParticle * findLastSelf()
Traverse the event structure and find the final version of this particle which does not have a partic...
void boostToRestFrame(PhotosParticle *boost)
Transform this particles four momentum from the lab frome into the rest frame of the paramter PhotosP...
virtual int getBarcode()=0
Get the barcode of this particle.
virtual void setPy(double py)=0
Set the px component of the four vector.
void rotateDaughters(int axis, double phi, int second_axis=Z_AXIS)
rotate 4-momentum of daughters of this particle by an angle phi from the axisis "axis" towards the ax...
virtual double getPz()=0
Returns the pz component of the four vector.
virtual double getE()=0
Returns the energy component of the four vector.
virtual double getPy()=0
Returns the py component of the four vector.
virtual double getPx()=0
Returns the px component of the four vector.
void setP(int axis, double p_component)
Set momentum component in the direction of "axis" (x,y,z)
std::vector< PhotosParticle * > getDecayTree()
Return whole decay tree starting from this particle.
virtual std::vector< PhotosParticle * > getDaughters()=0
Returns the daughters of this particle via a vector of PhotosParticle.
virtual std::vector< PhotosParticle * > getMothers()=0
Returns the mothers of this particle via a vector of PhotosParticle.
virtual double getVirtuality()
Get sqrt(e^2-p^2)
std::vector< PhotosParticle * > findProductionMothers()
Traverse the event structure and find the first set of mothers which are not of the same type as this...
virtual void setPx(double px)=0
Set the px component of the four vector.
static const int Z_AXIS
Z Axis.
bool hasDaughters()
Return whether the particle has any chidren.
virtual std::vector< PhotosParticle * > getAllDecayProducts()=0
Returns all particles in the decay tree of this particle via a vector of PhotosParticle.
void boostAlongZ(double pz, double e)
Do a Lorenz transformation along the Z axis.
double getP()
Get scalar momentum.
virtual void setPz(double pz)=0
Set the pz component of the four vector.
double getRotationAngle(int axis, int second_axis=Z_AXIS)
Returns the angle around the axis "axis" needed to rotate the four momenum is such a way that the non...
static const int X_AXIS
X Axis.
void boostDaughtersFromRestFrame(PhotosParticle *boost)
Transform this particles four momentum from the lab frame to the rest frame of the parameter PhotosPa...
void boostFromRestFrame(PhotosParticle *boost)
Transform this particles four momentum from the rest frame of the paramter PhotosParticle,...
void boostDaughtersToRestFrame(PhotosParticle *boost)
Transform the four momentum of all the daughters recursively into the frame of the "particle" PhotosP...