PhotosParticle.cxx
00001 #include <vector>
00002 #include <math.h>
00003 #include "PhotosParticle.h"
00004 #include "Log.h"
00005 using std::vector;
00006
00007 namespace Photospp
00008 {
00009
00010 bool PhotosParticle::hasDaughters()
00011 {
00012 if(getDaughters().size()==0) return false;
00013 else return true;
00014 }
00015
00016 PhotosParticle * PhotosParticle::findLastSelf()
00017 {
00018 vector<PhotosParticle*> daughters = getDaughters();
00019 vector<PhotosParticle*>::iterator pcl_itr = daughters.begin();
00020
00021
00022 for(;pcl_itr != daughters.end();pcl_itr++)
00023 {
00024 if((*pcl_itr)->getPdgID()==this->getPdgID())
00025 return (*pcl_itr)->findLastSelf();
00026 }
00027
00028 return this;
00029 }
00030
00031 vector<PhotosParticle*> PhotosParticle::findProductionMothers()
00032 {
00033 vector<PhotosParticle*> mothers = getMothers();
00034 vector<PhotosParticle*>::iterator pcl_itr = mothers.begin();
00035
00036
00037 for(;pcl_itr != mothers.end();pcl_itr++)
00038 {
00039 if((*pcl_itr)->getPdgID()==this->getPdgID())
00040 return (*pcl_itr)->findProductionMothers();
00041 }
00042 return mothers;
00043 }
00044
00045 vector<PhotosParticle *> PhotosParticle::getDecayTree()
00046 {
00047 vector<PhotosParticle *> particles;
00048 particles.push_back(this);
00049 vector<PhotosParticle *> daughters = getDaughters();
00050 for(int i=0;i<(int)daughters.size();i++)
00051 {
00052
00053
00054 PhotosParticle *p = daughters.at(i);
00055 vector<PhotosParticle *> mothers = p->getMothers();
00056 if(mothers.size()>1 && mothers.at(0)->getBarcode()!=getBarcode()) continue;
00057 vector<PhotosParticle *> tree = p->getDecayTree();
00058 particles.insert(particles.end(),tree.begin(),tree.end());
00059 }
00060 return particles;
00061 }
00062
00063 void PhotosParticle::boostDaughtersFromRestFrame(PhotosParticle * tau_momentum)
00064 {
00065 if(!hasDaughters())
00066 return;
00067
00068
00069 vector<PhotosParticle*> list = getAllDecayProducts();
00070 vector<PhotosParticle*>::iterator pcl_itr = list.begin();
00071
00072 for(;pcl_itr != list.end();pcl_itr++)
00073 {
00074 (*pcl_itr)->boostFromRestFrame(tau_momentum);
00075 }
00076
00077
00078 }
00079
00080 void PhotosParticle::boostDaughtersToRestFrame(PhotosParticle * tau_momentum)
00081 {
00082 if(!hasDaughters())
00083 return;
00084
00085
00086 vector<PhotosParticle*> list = getAllDecayProducts();
00087 vector<PhotosParticle*>::iterator pcl_itr = list.begin();
00088
00089 for(;pcl_itr != list.end();pcl_itr++)
00090 {
00091 (*pcl_itr)->boostToRestFrame(tau_momentum);
00092 }
00093
00094
00095 }
00096
00097
00098 void PhotosParticle::boostToRestFrame(PhotosParticle * tau_momentum)
00099 {
00100 double theta = tau_momentum->getRotationAngle(Y_AXIS);
00101 tau_momentum->rotate(Y_AXIS,theta);
00102
00103 double phi = tau_momentum->getRotationAngle(X_AXIS);
00104 tau_momentum->rotate(Y_AXIS,-theta);
00105
00106
00107 rotate(Y_AXIS,theta);
00108 rotate(X_AXIS,phi);
00109 boostAlongZ(-1*tau_momentum->getP(),tau_momentum->getE());
00110 rotate(X_AXIS,-phi);
00111 rotate(Y_AXIS,-theta);
00112 }
00113
00114 void PhotosParticle::boostFromRestFrame(PhotosParticle * tau_momentum)
00115 {
00116
00117
00118
00119 double theta = tau_momentum->getRotationAngle(Y_AXIS);
00120 tau_momentum->rotate(Y_AXIS,theta);
00121
00122 double phi = tau_momentum->getRotationAngle(X_AXIS);
00123 tau_momentum->rotate(Y_AXIS,-theta);
00124
00125
00126 rotate(Y_AXIS,theta);
00127 rotate(X_AXIS,phi);
00128 boostAlongZ(tau_momentum->getP(),tau_momentum->getE());
00129 rotate(X_AXIS,-phi);
00130 rotate(Y_AXIS,-theta);
00131 }
00132
00133
00134
00135 double PhotosParticle::getRotationAngle(int axis, int second_axis)
00136 {
00137
00138
00139
00140
00141
00142
00143 if(getP(second_axis)==0)
00144 {
00145 if(getP(axis)>0) return -M_PI/2.0;
00146 else return M_PI/2.0;
00147 }
00148 if(getP(second_axis)>0) return -atan(getP(axis)/getP(second_axis));
00149 else return M_PI-atan(getP(axis)/getP(second_axis));
00150
00151 }
00152
00153
00154
00155 void PhotosParticle::boostAlongZ(double boost_pz, double boost_e)
00156 {
00157
00158 double m_tau=sqrt(boost_e*boost_e-boost_pz*boost_pz);
00159
00160 double p=getPz();
00161 double e=getE();
00162
00163 setPz((boost_e*p + boost_pz*e)/m_tau);
00164 setE((boost_pz*p + boost_e*e )/m_tau);
00165 }
00166
00167
00168 void PhotosParticle::rotate(int axis,double theta, int second_axis)
00169 {
00170 double temp_px=getP(axis);
00171 double temp_pz=getP(second_axis);
00172 setP(axis,cos(theta)*temp_px + sin(theta)*temp_pz);
00173 setP(second_axis,-sin(theta)*temp_px + cos(theta)*temp_pz);
00174 }
00175
00176 void PhotosParticle::rotateDaughters(int axis,double theta, int second_axis)
00177 {
00178 if(!hasDaughters())
00179 return;
00180
00181 vector<PhotosParticle*> daughters = getDaughters();
00182 vector<PhotosParticle*>::iterator pcl_itr = daughters.begin();
00183
00184
00185 for(;pcl_itr != daughters.end();pcl_itr++)
00186 {
00187 (*pcl_itr)->rotate(axis,theta,second_axis);
00188 (*pcl_itr)->rotateDaughters(axis,theta,second_axis);
00189 }
00190
00191 }
00192
00193 double PhotosParticle::getVirtuality()
00194 {
00195 double e_sq=getE()*getE();
00196 double p_sq=getP()*getP();
00197
00198 if(e_sq>p_sq) return sqrt(e_sq-p_sq);
00199 else return -1*sqrt(p_sq-e_sq);
00200 }
00201
00202 double PhotosParticle::getP()
00203 {
00204 return sqrt(getPx()*getPx()+getPy()*getPy()+getPz()*getPz());
00205 }
00206
00207 double PhotosParticle::getP(int axis)
00208 {
00209 if(axis==X_AXIS) return getPx();
00210 if(axis==Y_AXIS) return getPy();
00211 if(axis==Z_AXIS) return getPz();
00212 return 0;
00213 }
00214
00215 void PhotosParticle::setP(int axis, double p_component)
00216 {
00217 if(axis==X_AXIS) setPx(p_component);
00218 if(axis==Y_AXIS) setPy(p_component);
00219 if(axis==Z_AXIS) setPz(p_component);
00220 }
00221
00222 }