1 #include "TauolaParticle.h"
8 double TauolaParticle::getPolarimetricX(){
12 double TauolaParticle::getPolarimetricY(){
16 double TauolaParticle::getPolarimetricZ(){
21 TauolaParticle * TauolaParticle::clone(){
23 return createNewParticle(getPdgID(),getStatus(),getMass(),
24 getPx(),getPy(),getPz(),getE());
28 // NOTE: Not executed by release examples
29 double TauolaParticle::getAngle(TauolaParticle * other_particle){
35 double x2 = other_particle->getPx();
36 double y2 = other_particle->getPy();
37 double z2 = other_particle->getPz();
39 return acos( (x1*x2+y1*y2+z1*z2) / sqrt((x1*x1+y1*y1+z1*z1)*(x2*x2+y2*y2+z2*z2)) );
43 // NOTE: Not executed by release examples
44 void TauolaParticle::add(TauolaParticle * other_particle){
46 setPx(getPx() + other_particle->getPx());
47 setPy(getPy() + other_particle->getPy());
48 setPz(getPz() + other_particle->getPz());
49 setE(getE() + other_particle->getE());
50 setMass( sqrt( getE()*getE()-getPx()*getPx()-getPy()*getPy()-getPz()*getPz() ));
53 void TauolaParticle::subtract(TauolaParticle * other_particle){
55 setPx(getPx() - other_particle->getPx());
56 setPy(getPy() - other_particle->getPy());
57 setPz(getPz() - other_particle->getPz());
58 setE(getE() - other_particle->getE());
59 setMass( sqrt( getE()*getE()-getPx()*getPx()-getPy()*getPy()-getPz()*getPz() ));
62 int TauolaParticle::getSign(){
63 if(getPdgID()== Tauola::getDecayingParticle())
65 else if(getPdgID()== -1 * Tauola::getDecayingParticle())
71 bool TauolaParticle::hasDaughters(){
72 if(getDaughters().size()==0)
78 TauolaParticle * TauolaParticle::findLastSelf(){
79 vector<TauolaParticle*> daughters = getDaughters();
80 vector<TauolaParticle*>::iterator pcl_itr = daughters.begin();
82 //get all daughters and look for stable with same pgd id
83 for(;pcl_itr != daughters.end();pcl_itr++){
84 if((*pcl_itr)->getPdgID()==this->getPdgID())
85 return (*pcl_itr)->findLastSelf();
91 std::vector<TauolaParticle*> TauolaParticle::findProductionMothers(){
92 vector<TauolaParticle*> mothers = getMothers();
93 vector<TauolaParticle*>::iterator pcl_itr = mothers.begin();
95 //get all mothers and check none have pdg id of this one
96 for(;pcl_itr != mothers.end();pcl_itr++){
97 if((*pcl_itr)->getPdgID()==this->getPdgID())
98 return (*pcl_itr)->findProductionMothers();
103 void TauolaParticle::decay(){
105 //Do the decay and set the polarimetric vectors
106 TauolaDecay(getSign(),&m_pol_x, &m_pol_y, &m_pol_z, &m_pol_n);
109 void TauolaParticle::addDecayToEventRecord(){
111 //Add to decay list used by f_filhep.c
112 DecayList::addToEnd(this);
113 TauolaWriteDecayToEventRecord(getSign());
122 try{ x=DecayList::getParticle(i); }
123 catch(std::out_of_range d) {break;}
124 if(x->getPdgID()==221){
126 // Fix 28.04.2011 The pp vector must have boost for eta undone
127 TauolaParticle *x_copy = x->clone();
128 if(getP(TauolaParticle::Z_AXIS)>0)
129 x_copy->boostAlongZ(-getP(),getE());
131 x_copy->boostAlongZ(getP(),getE());
133 pp[3]=x_copy->getE();
134 pp[0]=x_copy->getPx();
135 pp[1]=x_copy->getPy();
136 pp[2]=x_copy->getPz();
145 try{ x=DecayList::getParticle(i); }
146 catch(std::out_of_range d) {break;}
147 if(x->getPdgID()==310){
149 // Fix 28.04.2011 The pp vector must have boost for k0 undone
150 TauolaParticle *x_copy = x->clone();
151 if(getP(TauolaParticle::Z_AXIS)>0)
152 x_copy->boostAlongZ(-getP(),getE());
154 x_copy->boostAlongZ(getP(),getE());
156 pp[3]=x_copy->getE();
157 pp[0]=x_copy->getPx();
158 pp[1]=x_copy->getPy();
159 pp[2]=x_copy->getPz();
168 try{ x=DecayList::getParticle(i); }
169 catch(std::out_of_range d) {break;}
170 if(x->getPdgID()==111){
172 // Fix 28.04.2011 The pp vector must have boost for pi0 undone
173 TauolaParticle *x_copy = x->clone();
174 if(getP(TauolaParticle::Z_AXIS)>0)
175 x_copy->boostAlongZ(-getP(),getE());
177 x_copy->boostAlongZ(getP(),getE());
179 pp[3]=x_copy->getE();
180 pp[0]=x_copy->getPx();
181 pp[1]=x_copy->getPy();
182 pp[2]=x_copy->getPz();
189 Log::Fatal("TAUOLA failed. No decay was created",5);
190 // checkMomentumConservation();
191 // decayEndgame(); // vertex shift was wrongly calculated,
192 // used 4-momenta should be in lab frame,
193 // thanks to Sho Iwamoto for debug info.
198 void TauolaParticle::boostDaughtersFromRestFrame(TauolaParticle * tau_momentum){
200 if(!hasDaughters()) //if there are no daughters
203 vector<TauolaParticle*> daughters = getDaughters();
204 vector<TauolaParticle*>::iterator pcl_itr = daughters.begin();
206 //get all daughters then rotate and boost them.
207 for(;pcl_itr != daughters.end();pcl_itr++){
209 (*pcl_itr)->boostFromRestFrame(tau_momentum);
210 (*pcl_itr)->boostDaughtersFromRestFrame(tau_momentum);
212 //checkMomentumConservation();
215 void TauolaParticle::boostDaughtersToRestFrame(TauolaParticle * tau_momentum){
217 if(!hasDaughters()) //if there are no daughters
219 // NOTE: Not executed by release examples
220 // because !hasDaughters() is always true
221 vector<TauolaParticle*> daughters = getDaughters();
222 vector<TauolaParticle*>::iterator pcl_itr = daughters.begin();
224 //get all daughters then rotate and boost them.
225 for(;pcl_itr != daughters.end();pcl_itr++){
227 (*pcl_itr)->boostToRestFrame(tau_momentum);
228 (*pcl_itr)->boostDaughtersToRestFrame(tau_momentum);
230 //checkMomentumConservation();
234 void TauolaParticle::boostToRestFrame(TauolaParticle * tau_momentum){
236 double theta = tau_momentum->getRotationAngle(Y_AXIS);
237 tau_momentum->rotate(Y_AXIS,theta);
238 double phi = tau_momentum->getRotationAngle(X_AXIS);
239 tau_momentum->rotate(Y_AXIS,-theta);
241 //Now rotate coordinates to get boost in Z direction.
242 rotate(Y_AXIS,theta);
244 boostAlongZ(-1*tau_momentum->getP(),tau_momentum->getE());
246 rotate(Y_AXIS,-theta);
250 void TauolaParticle::boostFromRestFrame(TauolaParticle * tau_momentum){
251 //get the rotation angles
254 double theta = tau_momentum->getRotationAngle(Y_AXIS);
255 tau_momentum->rotate(Y_AXIS,theta);
256 double phi = tau_momentum->getRotationAngle(X_AXIS);
257 tau_momentum->rotate(Y_AXIS,-theta);
259 //Now rotate coordinates to get boost in Z direction.
260 rotate(Y_AXIS,theta);
262 boostAlongZ(tau_momentum->getP(),tau_momentum->getE());
264 rotate(Y_AXIS,-theta);
267 /** Get the angle needed to rotate the 4 momentum vector so that
268 the x (y) component disapears. (and the Z component is > 0) */
269 double TauolaParticle::getRotationAngle(int axis, int second_axis){
271 /**if(getP(axis)==0){
273 return 0; //no rotaion required
277 if(getP(second_axis)==0){
283 if(getP(second_axis)>0)
284 return -atan(getP(axis)/getP(second_axis));
286 return M_PI-atan(getP(axis)/getP(second_axis));
290 /** Boost this vector along the Z direction.
291 Assume no momentum components in the X or Y directions. */
292 void TauolaParticle::boostAlongZ(double boost_pz, double boost_e){
294 // Boost along the Z axis
295 double m=sqrt(boost_e*boost_e-boost_pz*boost_pz);
300 setPz((boost_e*p + boost_pz*e)/m);
301 setE((boost_pz*p + boost_e*e )/m);
304 /** Rotation around an axis X or Y */
305 void TauolaParticle::rotate(int axis,double theta, int second_axis){
307 double temp_px=getP(axis);
308 double temp_pz=getP(second_axis);
309 setP(axis,cos(theta)*temp_px + sin(theta)*temp_pz);
310 setP(second_axis,-sin(theta)*temp_px + cos(theta)*temp_pz);
313 void TauolaParticle::rotateDaughters(int axis,double theta, int second_axis){
314 if(!hasDaughters()) //if there are no daughters
317 vector<TauolaParticle*> daughters = getDaughters();
318 vector<TauolaParticle*>::iterator pcl_itr = daughters.begin();
320 //get all daughters then rotate and boost them.
321 for(;pcl_itr != daughters.end();pcl_itr++){
323 (*pcl_itr)->rotate(axis,theta,second_axis);
324 (*pcl_itr)->rotateDaughters(axis,theta,second_axis);
326 //checkMomentumConservation();
329 double TauolaParticle::getMass(){
330 double e_sq=getE()*getE();
331 double p_sq=getP()*getP();
334 return sqrt(e_sq-p_sq);
336 return -1*sqrt(p_sq-e_sq); //if it's negative
339 double TauolaParticle::getP(){
340 return sqrt(getPx()*getPx()+getPy()*getPy()+getPz()*getPz());
343 double TauolaParticle::getP(int axis){
356 void TauolaParticle::setP(int axis, double p_component){
365 } // namespace Tauolapp