read_particles_from_TAUOLA.cxx
00001 #include "TauSpinner/read_particles_from_TAUOLA.h"
00002 using namespace TauSpinner;
00003
00004
00005
00006 HepMC::GenEvent *event = new HepMC::GenEvent();
00007 HepMC::GenEvent::particle_const_iterator it = event->particles_end();
00008
00009
00010
00011
00012
00013
00014 inline vector<SimpleParticle> *getDaughters(HepMC::GenParticle *x)
00015 {
00016 vector<SimpleParticle> *daughters = new vector<SimpleParticle>();
00017 if(!x->end_vertex()) return daughters;
00018
00019
00020 for(HepMC::GenVertex::particles_out_const_iterator p = x->end_vertex()->particles_out_const_begin(); p!=x->end_vertex()->particles_out_const_end(); ++p)
00021 {
00022 HepMC::GenParticle *pp = *p;
00023 HepMC::FourVector mm = pp->momentum();
00024
00025
00026
00027 if( pp->end_vertex() && pp->pdg_id()!=111)
00028 {
00029 vector<SimpleParticle> *sub_daughters = getDaughters(pp);
00030 daughters->insert(daughters->end(),sub_daughters->begin(),sub_daughters->end());
00031
00032 delete sub_daughters;
00033 }
00034
00035 else
00036 {
00037 SimpleParticle tp( mm.px(), mm.py(), mm.pz(), mm.e(), pp->pdg_id() );
00038 daughters->push_back(tp);
00039 }
00040 }
00041
00042 return daughters;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int readParticlesFromTAUOLA_HepMC(HepMC::IO_GenEvent &input_file, SimpleParticle &X, SimpleParticle &tau, SimpleParticle &tau2, vector<SimpleParticle> &tau_daughters, vector<SimpleParticle> &tau2_daughters)
00068 {
00069
00070 if(it == event->particles_end())
00071 {
00072
00073 delete event;
00074 event = new HepMC::GenEvent();
00075
00076
00077 input_file.fill_next_event(event);
00078
00079
00080 if(input_file.rdstate()) return 0;
00081
00082 it = event->particles_begin();
00083 }
00084
00085
00086 HepMC::GenParticle *hX=NULL, *hTau=NULL, *hTau2=NULL;
00087
00088 for(; it!=event->particles_end(); ++it)
00089 {
00090 int pdgid = (*it)->pdg_id();
00091 if(
00092 (
00093 abs(pdgid)==37 ||
00094 pdgid ==25 ||
00095 abs(pdgid)==24 ||
00096 pdgid ==23
00097 ) &&
00098 (*it)->end_vertex()->particles_out_size()==2
00099 )
00100 {
00101 hX = *it;
00102
00103
00104 HepMC::GenVertex *x_daughters = (*it)->end_vertex();
00105
00106
00107 HepMC::GenParticle *first_daughter = *x_daughters->particles_out_const_begin();
00108 HepMC::GenParticle *second_daughter = *(++(x_daughters->particles_out_const_begin()));
00109
00110
00111 if( abs(first_daughter->pdg_id())==15 && first_daughter->end_vertex()!=NULL)
00112 {
00113 hTau = first_daughter;
00114 hTau2 = second_daughter;
00115 ++it;
00116 break;
00117 }
00118 else if( abs(second_daughter->pdg_id())==15 && second_daughter->end_vertex()!=NULL)
00119 {
00120 hTau = second_daughter;
00121 hTau2 = first_daughter;
00122 ++it;
00123 break;
00124 }
00125 else hX = NULL;
00126 }
00127 }
00128
00129
00130 if(!hX) return 1;
00131
00132 if(!hTau || !hTau2)
00133 {
00134 cout<<"ERROR: Something is wrong with event record."<<endl;
00135 exit(-1);
00136 }
00137
00138
00139 X.setPx(hX->momentum().px());
00140 X.setPy(hX->momentum().py());
00141 X.setPz(hX->momentum().pz());
00142 X.setE (hX->momentum().e ());
00143 X.setPdgid(hX->pdg_id());
00144
00145 tau.setPx(hTau->momentum().px());
00146 tau.setPy(hTau->momentum().py());
00147 tau.setPz(hTau->momentum().pz());
00148 tau.setE (hTau->momentum().e ());
00149 tau.setPdgid(hTau->pdg_id());
00150
00151 tau2.setPx(hTau2->momentum().px());
00152 tau2.setPy(hTau2->momentum().py());
00153 tau2.setPz(hTau2->momentum().pz());
00154 tau2.setE (hTau2->momentum().e ());
00155 tau2.setPdgid(hTau2->pdg_id());
00156
00157
00158 vector<SimpleParticle> *buf = getDaughters(hTau);
00159 tau_daughters.clear();
00160 tau_daughters.insert(tau_daughters.end(),buf->begin(),buf->end());
00161
00162 delete buf;
00163
00164
00165
00166 buf = getDaughters(hTau2);
00167 tau2_daughters.clear();
00168 tau2_daughters.insert(tau2_daughters.end(),buf->begin(),buf->end());
00169
00170 delete buf;
00171
00172 return 2;
00173 }