TauolaHEPEVTParticle.cxx

00001 #include "TauolaHEPEVTParticle.h"
00002 
00003 #include "Log.h"
00004 
00005 namespace Tauolapp
00006 {
00007 
00008 TauolaHEPEVTParticle::~TauolaHEPEVTParticle()
00009 {
00010   // Cleanup particles that do not belong to event
00011   for(unsigned int i=0;i<cache.size();i++)
00012     if(cache[i]->m_barcode<0)
00013       delete cache[i];
00014 }
00015 
00016 TauolaHEPEVTParticle::TauolaHEPEVTParticle(int pdgid, int status, double px, double py, double pz, double e, double m, int ms, int me, int ds, int de){
00017   m_px = px;
00018   m_py = py;
00019   m_pz = pz;
00020   m_e  = e;
00021   m_generated_mass = m;
00022 
00023   m_pdgid  = pdgid;
00024   m_status = status;
00025 
00026   m_first_mother   = ms;
00027   m_second_mother  = me;
00028   m_daughter_start = ds;
00029   m_daughter_end   = de;
00030 
00031   m_barcode = -1;
00032   m_event = NULL;
00033 }
00034 
00035 void TauolaHEPEVTParticle::undecay(){
00036 
00037   Log::Info()<<"TauolaHEPEVTParticle::undecay not implemented for HEPEVT"<<endl;
00038 }
00039 
00040 void TauolaHEPEVTParticle::setMothers(vector<TauolaParticle*> mothers){
00041 
00042   // If this particle has not yet been added to the event record
00043   // then add it to the mothers' event record
00044   if(m_barcode<0 && mothers.size()>0)
00045   {
00046     TauolaHEPEVTEvent *evt = ((TauolaHEPEVTParticle*)mothers[0])->m_event;
00047     evt->addParticle(this);
00048   }
00049 
00050   if(mothers.size()>2) Log::Fatal("TauolaHEPEVTParticle::setMothers: HEPEVT does not allow more than two mothers!");
00051   
00052   if(mothers.size()>0) m_first_mother  = mothers[0]->getBarcode();
00053   if(mothers.size()>1) m_second_mother = mothers[1]->getBarcode();
00054 }
00055 
00056 void TauolaHEPEVTParticle::setDaughters(vector<TauolaParticle*> daughters){
00057 
00058   // This particle must be inside some event record to be able to add daughters
00059   if(m_event==NULL) Log::Fatal("TauolaHEPEVTParticle::setDaughters: particle not inside event record.");
00060 
00061   int beg = 65535, end = -1;
00062 
00063   for(unsigned int i=0;i<daughters.size();i++)
00064   {
00065     int bc = daughters[i]->getBarcode();
00066     if(bc<0) Log::Fatal("TauolaHEPEVTParticle::setDaughters: all daughters has to be in event record first");
00067     if(bc<beg) beg = bc;
00068     if(bc>end) end = bc;
00069   }
00070   if(end == -1) beg = -1;
00071 
00072   m_daughter_start = beg;
00073   m_daughter_end   = end;
00074 }
00075 
00076 std::vector<TauolaParticle*> TauolaHEPEVTParticle::getMothers(){
00077 
00078   std::vector<TauolaParticle*> mothers;
00079 
00080   TauolaParticle *p1 = NULL;
00081   TauolaParticle *p2 = NULL;
00082   
00083   if(m_first_mother>=0)  p1 = m_event->getParticle(m_first_mother);
00084   if(m_second_mother>=0) p2 = m_event->getParticle(m_second_mother);
00085 
00086   if(p1) mothers.push_back(p1);
00087   if(p2) mothers.push_back(p2);
00088 
00089   return mothers;
00090 }
00091 
00092 // WARNING: this method also corrects daughter indices 
00093 //          if such were not defined
00094 std::vector<TauolaParticle*> TauolaHEPEVTParticle::getDaughters(){
00095 
00096   std::vector<TauolaParticle*> daughters;
00097 
00098   if(!m_event) return daughters;
00099 
00100   // Check if m_daughter_start and m_daughter_end are set
00101   // If not - try to get list of daughters from event
00102   if(m_daughter_end<0)
00103   {
00104     int min_d=65535, max_d=-1;
00105     for(int i=0;i<m_event->getParticleCount();i++)
00106     {
00107       if(m_event->getParticle(i)->isDaughterOf(this))
00108       {
00109         if(i<min_d) min_d = i;
00110         if(i>max_d) max_d = i;
00111       }
00112     }
00113     if(max_d>=0)
00114     {
00115       m_daughter_start = min_d;
00116       m_daughter_end   = max_d;
00117       m_status         = 2;
00118     }
00119   }
00120 
00121   // If m_daughter_end is still not set - there are no daughters
00122   // Otherwsie - get daughters
00123   if(m_daughter_end>=0)
00124   {
00125     for(int i=m_daughter_start;i<=m_daughter_end;i++)
00126     {
00127       TauolaParticle *p = m_event->getParticle(i);
00128       if(p==NULL)
00129       {
00130         Log::Warning()<<"TauolaHEPEVTParticle::getDaughters(): No particle with index "<<i<<endl;
00131         return daughters;
00132       }
00133 
00134       daughters.push_back(p);
00135     }
00136   }
00137 
00138   return daughters;
00139 }
00140 
00141 void TauolaHEPEVTParticle::checkMomentumConservation(){
00142 
00143   if(!m_event)           return;
00144   if(m_daughter_end < 0) return;
00145 
00146   TauolaHEPEVTParticle *buf = m_event->getParticle(m_daughter_start);
00147 
00148   int first_mother_idx  = buf->getFirstMotherIndex();
00149   int second_mother_idx = buf->getSecondMotherIndex();
00150 
00151   double px =0.0, py =0.0, pz =0.0, e =0.0;
00152   double px2=0.0, py2=0.0, pz2=0.0, e2=0.0;
00153 
00154   for(int i=m_daughter_start;i<=m_daughter_end;i++)
00155   {
00156     buf = m_event->getParticle(i);
00157     px += buf->getPx();
00158     py += buf->getPy();
00159     pz += buf->getPz();
00160     e  += buf->getE ();
00161   }
00162 
00163   if(first_mother_idx>=0)
00164   {
00165     buf = m_event->getParticle(first_mother_idx);
00166     px2 += buf->getPx();
00167     py2 += buf->getPy();
00168     pz2 += buf->getPz();
00169     e2  += buf->getE();
00170   }
00171   
00172   if(second_mother_idx>=0)
00173   {
00174     buf = m_event->getParticle(second_mother_idx);
00175     px2 += buf->getPx();
00176     py2 += buf->getPy();
00177     pz2 += buf->getPz();
00178     e2  += buf->getE();
00179   }
00180   // 3-momentum  // test HepMC style
00181   double dp = sqrt( (px-px2)*(px-px2) + (py-py2)*(py-py2) + (pz-pz2)*(pz-pz2) );
00182   // virtuality test as well.
00183   double m1 = sqrt( fabs( e*e   - px*px   - py*py   - pz*pz   ) );
00184   double m2 = sqrt( fabs( e2*e2 - px2*px2 - py2*py2 - pz2*pz2 ) );
00185 
00186   if( fabs(m1-m2) > 0.0001 || dp > 0.0001*(e+e2))
00187   {
00188     Log::RedirectOutput( Log::Warning()<<"Momentum not conserved in vertex: " );
00189     if(first_mother_idx >=0) m_event->getParticle(first_mother_idx) ->print();
00190     if(second_mother_idx>=0) m_event->getParticle(second_mother_idx)->print();
00191     for(int i=m_daughter_start;i<=m_daughter_end;i++) m_event->getParticle(i)->print();
00192     Log::RevertOutput();
00193   }
00194 }
00195 
00196 TauolaHEPEVTParticle * TauolaHEPEVTParticle::createNewParticle(
00197                         int pdg_id, int status, double mass,
00198                         double px, double py, double pz, double e){
00199 
00200   // New particles created using this method are added to cache
00201   // They will be deleted when this particle will be deleted
00202 
00203   cache.push_back(new TauolaHEPEVTParticle(pdg_id,status,px,py,pz,e,mass,-1,-1,-1,-1));
00204   return cache.back();
00205 }
00206 
00207 bool TauolaHEPEVTParticle::isDaughterOf(TauolaHEPEVTParticle *p)
00208 {
00209   int bc = p->getBarcode();
00210   if(bc==m_first_mother || bc==m_second_mother) return true;
00211 
00212   return false;
00213 }
00214 
00215 bool TauolaHEPEVTParticle::isMotherOf  (TauolaHEPEVTParticle *p)
00216 {
00217   int bc = p->getBarcode();
00218   if(bc>=m_daughter_start && bc<=m_daughter_end) return true;
00219 
00220   return false;
00221 }
00222 
00223 void TauolaHEPEVTParticle::print(){
00224   char buf[256];
00225   sprintf(buf,"P: (%2i) %6i %2i | %11.4e %11.4e %11.4e %11.4e | %11.4e | M: %2i %2i | D: %2i %2i\n",
00226           m_barcode, m_pdgid, m_status, m_px, m_py, m_pz, m_e, m_generated_mass,
00227           m_first_mother, m_second_mother,   m_daughter_start, m_daughter_end);
00228 
00229   cout<<buf;
00230 }
00231 
00232 /******** Getter and Setter methods: ***********************/
00233 
00234 void TauolaHEPEVTParticle::setPdgID(int pdg_id){
00235   m_pdgid = pdg_id;
00236 }
00237 
00238 void TauolaHEPEVTParticle::setStatus(int status){
00239   m_status = status;
00240 }
00241 
00242 void TauolaHEPEVTParticle::setMass(double mass){
00243   m_generated_mass = mass;
00244 }
00245 
00246 int TauolaHEPEVTParticle::getPdgID(){
00247   return m_pdgid;
00248 }
00249 
00250 int TauolaHEPEVTParticle::getStatus(){
00251   return m_status;
00252 }
00253 
00254 double TauolaHEPEVTParticle::getMass(){
00255   return m_generated_mass;
00256 }
00257 
00258 inline double TauolaHEPEVTParticle::getPx(){
00259   return m_px;
00260 }
00261 
00262 inline double TauolaHEPEVTParticle::getPy(){
00263   return m_py;
00264 }
00265 
00266 double TauolaHEPEVTParticle::getPz(){
00267   return m_pz;
00268 }
00269 
00270 double TauolaHEPEVTParticle::getE(){
00271   return m_e;
00272 }
00273 
00274 void TauolaHEPEVTParticle::setPx(double px){
00275   m_px = px;
00276 }
00277 
00278 void TauolaHEPEVTParticle::setPy(double py){
00279   m_py = py;
00280 }
00281 
00282 
00283 void TauolaHEPEVTParticle::setPz(double pz){
00284   m_pz = pz;
00285 }
00286 
00287 void TauolaHEPEVTParticle::setE(double e){
00288   m_e = e;
00289 }
00290 
00291 int TauolaHEPEVTParticle::getBarcode(){
00292   return m_barcode;
00293 }
00294 
00295 void TauolaHEPEVTParticle::setBarcode(int barcode){
00296   m_barcode = barcode;
00297 }
00298 
00299 void TauolaHEPEVTParticle::setEvent(TauolaHEPEVTEvent *event){
00300   m_event = event;
00301 }
00302 
00303 int TauolaHEPEVTParticle::getFirstMotherIndex(){
00304   return m_first_mother;
00305 }
00306 
00307 int TauolaHEPEVTParticle::getSecondMotherIndex(){
00308   return m_second_mother;
00309 }
00310 
00311 int TauolaHEPEVTParticle::getDaughterRangeStart(){
00312   return m_daughter_start;
00313 }
00314 
00315 int TauolaHEPEVTParticle::getDaughterRangeEnd(){
00316   return m_daughter_end;
00317 }
00318 
00319 } // namespace Tauolapp
Generated on Sun Oct 20 20:24:11 2013 for C++InterfacetoTauola by  doxygen 1.6.3