1 #include "TauolaHEPEVTParticle.h"
8 TauolaHEPEVTParticle::~TauolaHEPEVTParticle()
10 // Cleanup particles that do not belong to event
11 for(unsigned int i=0;i<cache.size();i++)
12 if(cache[i]->m_barcode<0)
16 TauolaHEPEVTParticle::TauolaHEPEVTParticle(int pdgid, int status, double px, double py, double pz, double e, double m, int ms, int me, int ds, int de){
28 m_daughter_start = ds;
35 void TauolaHEPEVTParticle::undecay(){
37 Log::Info()<<"TauolaHEPEVTParticle::undecay not implemented for HEPEVT"<<endl;
40 void TauolaHEPEVTParticle::setMothers(vector<TauolaParticle*> mothers){
42 // If this particle has not yet been added to the event record
43 // then add it to the mothers' event record
44 if(m_barcode<0 && mothers.size()>0)
46 TauolaHEPEVTEvent *evt = ((TauolaHEPEVTParticle*)mothers[0])->m_event;
47 evt->addParticle(this);
50 if(mothers.size()>2) Log::Fatal("TauolaHEPEVTParticle::setMothers: HEPEVT does not allow more than two mothers!");
52 if(mothers.size()>0) m_first_mother = mothers[0]->getBarcode();
53 if(mothers.size()>1) m_second_mother = mothers[1]->getBarcode();
56 void TauolaHEPEVTParticle::setDaughters(vector<TauolaParticle*> daughters){
58 // This particle must be inside some event record to be able to add daughters
59 if(m_event==NULL) Log::Fatal("TauolaHEPEVTParticle::setDaughters: particle not inside event record.");
61 int beg = 65535, end = -1;
63 for(unsigned int i=0;i<daughters.size();i++)
65 int bc = daughters[i]->getBarcode();
66 if(bc<0) Log::Fatal("TauolaHEPEVTParticle::setDaughters: all daughters has to be in event record first");
70 if(end == -1) beg = -1;
72 m_daughter_start = beg;
76 std::vector<TauolaParticle*> TauolaHEPEVTParticle::getMothers(){
78 std::vector<TauolaParticle*> mothers;
80 TauolaParticle *p1 = NULL;
81 TauolaParticle *p2 = NULL;
83 if(m_first_mother>=0) p1 = m_event->getParticle(m_first_mother);
84 if(m_second_mother>=0) p2 = m_event->getParticle(m_second_mother);
86 if(p1) mothers.push_back(p1);
87 if(p2) mothers.push_back(p2);
92 // WARNING: this method also corrects daughter indices
93 // if such were not defined
94 std::vector<TauolaParticle*> TauolaHEPEVTParticle::getDaughters(){
96 std::vector<TauolaParticle*> daughters;
98 if(!m_event) return daughters;
100 // Check if m_daughter_start and m_daughter_end are set
101 // If not - try to get list of daughters from event
104 int min_d=65535, max_d=-1;
105 for(int i=0;i<m_event->getParticleCount();i++)
107 if(m_event->getParticle(i)->isDaughterOf(this))
109 if(i<min_d) min_d = i;
110 if(i>max_d) max_d = i;
115 m_daughter_start = min_d;
116 m_daughter_end = max_d;
121 // If m_daughter_end is still not set - there are no daughters
122 // Otherwsie - get daughters
123 if(m_daughter_end>=0)
125 for(int i=m_daughter_start;i<=m_daughter_end;i++)
127 TauolaParticle *p = m_event->getParticle(i);
130 Log::Warning()<<"TauolaHEPEVTParticle::getDaughters(): No particle with index "<<i<<endl;
134 daughters.push_back(p);
141 void TauolaHEPEVTParticle::checkMomentumConservation(){
144 if(m_daughter_end < 0) return;
146 TauolaHEPEVTParticle *buf = m_event->getParticle(m_daughter_start);
148 int first_mother_idx = buf->getFirstMotherIndex();
149 int second_mother_idx = buf->getSecondMotherIndex();
151 double px =0.0, py =0.0, pz =0.0, e =0.0;
152 double px2=0.0, py2=0.0, pz2=0.0, e2=0.0;
154 for(int i=m_daughter_start;i<=m_daughter_end;i++)
156 buf = m_event->getParticle(i);
163 if(first_mother_idx>=0)
165 buf = m_event->getParticle(first_mother_idx);
172 if(second_mother_idx>=0)
174 buf = m_event->getParticle(second_mother_idx);
180 // 3-momentum // test HepMC style
181 double dp = sqrt( (px-px2)*(px-px2) + (py-py2)*(py-py2) + (pz-pz2)*(pz-pz2) );
182 // virtuality test as well.
183 double m1 = sqrt( fabs( e*e - px*px - py*py - pz*pz ) );
184 double m2 = sqrt( fabs( e2*e2 - px2*px2 - py2*py2 - pz2*pz2 ) );
186 if( fabs(m1-m2) > 0.0001 || dp > 0.0001*(e+e2))
188 Log::RedirectOutput( Log::Warning()<<"Momentum not conserved in vertex: " );
189 if(first_mother_idx >=0) m_event->getParticle(first_mother_idx) ->print();
190 if(second_mother_idx>=0) m_event->getParticle(second_mother_idx)->print();
191 for(int i=m_daughter_start;i<=m_daughter_end;i++) m_event->getParticle(i)->print();
196 TauolaHEPEVTParticle * TauolaHEPEVTParticle::createNewParticle(
197 int pdg_id, int status, double mass,
198 double px, double py, double pz, double e){
200 // New particles created using this method are added to cache
201 // They will be deleted when this particle will be deleted
203 cache.push_back(new TauolaHEPEVTParticle(pdg_id,status,px,py,pz,e,mass,-1,-1,-1,-1));
207 bool TauolaHEPEVTParticle::isDaughterOf(TauolaHEPEVTParticle *p)
209 int bc = p->getBarcode();
210 if(bc==m_first_mother || bc==m_second_mother) return true;
215 bool TauolaHEPEVTParticle::isMotherOf (TauolaHEPEVTParticle *p)
217 int bc = p->getBarcode();
218 if(bc>=m_daughter_start && bc<=m_daughter_end) return true;
223 void TauolaHEPEVTParticle::print(){
225 sprintf(buf,"P: (%2i) %6i %2i | %11.4e %11.4e %11.4e %11.4e | %11.4e | M: %2i %2i | D: %2i %2i\n",
226 m_barcode, m_pdgid, m_status, m_px, m_py, m_pz, m_e, m_generated_mass,
227 m_first_mother, m_second_mother, m_daughter_start, m_daughter_end);
232 /******** Getter and Setter methods: ***********************/
234 void TauolaHEPEVTParticle::setPdgID(int pdg_id){
238 void TauolaHEPEVTParticle::setStatus(int status){
242 void TauolaHEPEVTParticle::setMass(double mass){
243 m_generated_mass = mass;
246 int TauolaHEPEVTParticle::getPdgID(){
250 int TauolaHEPEVTParticle::getStatus(){
254 double TauolaHEPEVTParticle::getMass(){
255 return m_generated_mass;
258 inline double TauolaHEPEVTParticle::getPx(){
262 inline double TauolaHEPEVTParticle::getPy(){
266 double TauolaHEPEVTParticle::getPz(){
270 double TauolaHEPEVTParticle::getE(){
274 void TauolaHEPEVTParticle::setPx(double px){
278 void TauolaHEPEVTParticle::setPy(double py){
283 void TauolaHEPEVTParticle::setPz(double pz){
287 void TauolaHEPEVTParticle::setE(double e){
291 int TauolaHEPEVTParticle::getBarcode(){
295 void TauolaHEPEVTParticle::setBarcode(int barcode){
299 void TauolaHEPEVTParticle::setEvent(TauolaHEPEVTEvent *event){
303 int TauolaHEPEVTParticle::getFirstMotherIndex(){
304 return m_first_mother;
307 int TauolaHEPEVTParticle::getSecondMotherIndex(){
308 return m_second_mother;
311 int TauolaHEPEVTParticle::getDaughterRangeStart(){
312 return m_daughter_start;
315 int TauolaHEPEVTParticle::getDaughterRangeEnd(){
316 return m_daughter_end;
319 } // namespace Tauolapp