8 #include "HepMC/SimpleVector.h"
9 #include "HepMC/GenEvent.h"
10 #include "HepMC/IO_HEPEVT.h"
11 #include "HepMC/HEPEVT_Wrapper.h"
15 namespace PhotosInterface53XLegacyVar {
76 for (
int ip=0; ip<evt->particles_size(); ip++ )
84 bool tau_leptonic_decay =
false;
85 int iTauDescCounter = 0;
88 for (
int iv=1; iv<=evt->vertices_size(); iv++ )
91 bool legalVtx =
false;
93 HepMC::GenVertex* vtx = evt->barcode_to_vertex( -iv ) ;
95 if ( vtx->particles_in_size() != 1 )
continue;
96 if ( vtx->particles_out_size() <= 1 )
continue;
98 if ( (*(vtx->particles_in_const_begin()))->pdg_id() == 111 )
continue;
102 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
103 pitr != vtx->particles_end(HepMC::children); ++pitr)
107 if (
abs((*pitr)->pdg_id()) >=1 &&
abs((*pitr)->pdg_id()) <=8 )
break;
108 if (
abs((*pitr)->pdg_id()) == 21 )
break;
110 if ( (*pitr)->status() == 1 || (*pitr)->end_vertex() )
118 if ( !legalVtx )
continue;
124 HepMC::HEPEVT_Wrapper::zero_everything();
130 HepMC::HEPEVT_Wrapper::set_id( index, (*(vtx->particles_in_const_begin()))->pdg_id() );
131 HepMC::FourVector vec4;
132 vec4 = (*(vtx->particles_in_const_begin()))->momentum();
133 HepMC::HEPEVT_Wrapper::set_momentum( index, vec4.x(), vec4.y(), vec4.z(), vec4.e() );
134 HepMC::HEPEVT_Wrapper::set_mass( index, (*(vtx->particles_in_const_begin()))->generated_mass() );
135 HepMC::HEPEVT_Wrapper::set_position( index, vtx->position().x(), vtx->position().y(),
136 vtx->position().z(), vtx->position().t() );
137 HepMC::HEPEVT_Wrapper::set_status( index, (*(vtx->particles_in_const_begin()))->status() );
138 HepMC::HEPEVT_Wrapper::set_parents( index, 0, 0 );
139 fBarcodes.push_back( (*(vtx->particles_in_const_begin()))->barcode() );
146 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
147 pitr != vtx->particles_end(HepMC::children); ++pitr)
149 if (
abs((*pitr)->pdg_id()) == 11 ||
abs((*pitr)->pdg_id()) == 13 )
152 tau_leptonic_decay =
true;
156 if ( vtx->particles_begin(HepMC::children) == vtx->particles_begin(HepMC::descendants) &&
157 vtx->particles_end(HepMC::children) == vtx->particles_end(HepMC::descendants) )
161 nTauDesc = vtx->particles_out_size();
165 for ( HepMC::GenVertex::particle_iterator pitr1=vtx->particles_begin(HepMC::children);
166 pitr1 != vtx->particles_end(HepMC::children); ++pitr1)
179 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
180 pitr != vtx->particles_end(HepMC::children); ++pitr)
183 if ( (*pitr)->status() == 1 || (*pitr)->end_vertex() )
186 vec4 = (*pitr)->momentum();
187 HepMC::HEPEVT_Wrapper::set_id( index, (*pitr)->pdg_id() );
188 HepMC::HEPEVT_Wrapper::set_momentum( index, vec4.x(), vec4.y(), vec4.z(), vec4.e() );
189 HepMC::HEPEVT_Wrapper::set_mass( index, (*pitr)->generated_mass() );
190 vec4 = (*pitr)->production_vertex()->position();
191 HepMC::HEPEVT_Wrapper::set_position( index, vec4.x(), vec4.y(), vec4.z(), vec4.t() );
192 HepMC::HEPEVT_Wrapper::set_status( index, (*pitr)->status() );
193 HepMC::HEPEVT_Wrapper::set_parents( index, 1, 1 );
194 fBarcodes.push_back( (*pitr)->barcode() );
206 int nentries =
index;
210 HepMC::HEPEVT_Wrapper::set_children ( index, 2, lastDau );
215 HepMC::HEPEVT_Wrapper::set_number_entries( nentries );
239 tau_leptonic_decay =
false;
245 HepMC::HEPEVT_Wrapper::set_event_number( evt->event_number() );
254 if ( HepMC::HEPEVT_Wrapper::number_entries() > nentries )
265 int largestBarcode = -1;
268 for (
int ip=1; ip<Nbcodes; ip++ )
273 if ( bcode > largestBarcode ) largestBarcode = bcode;
274 double px = HepMC::HEPEVT_Wrapper::px(ip+1);
275 double py = HepMC::HEPEVT_Wrapper::py(ip+1);
276 double pz = HepMC::HEPEVT_Wrapper::pz(ip+1);
280 if ( prt->end_vertex() )
283 HepMC::GenVertex* endVtx = prt->end_vertex();
285 std::vector<int> secVtxStorage;
286 secVtxStorage.clear();
288 secVtxStorage.push_back( endVtx->barcode() );
290 HepMC::FourVector mom4 = prt->momentum();
293 double bet1[3], bet2[3], gam1, gam2, pb;
294 double mass = mom4.m();
295 bet1[0] = -(mom4.px()/
mass);
296 bet1[1] = -(mom4.py()/
mass);
297 bet1[2] = -(mom4.pz()/
mass);
301 gam1 = mom4.e()/
mass;
304 unsigned int vcounter = 0;
306 while ( vcounter < secVtxStorage.size() )
309 HepMC::GenVertex* theVtx = evt->barcode_to_vertex( secVtxStorage[vcounter] );
311 for ( HepMC::GenVertex::particle_iterator pitr=theVtx->particles_begin(HepMC::children);
312 pitr != theVtx->particles_end(HepMC::children); ++pitr)
315 if ( (*pitr)->end_vertex() )
317 secVtxStorage.push_back( (*pitr)->end_vertex()->barcode() );
320 if ( theVtx->particles_out_size() == 1 && (*pitr)->pdg_id() == prt->pdg_id() )
323 (*pitr)->set_momentum( HepMC::FourVector(px,py,pz,e) );
327 HepMC::FourVector dmom4 = (*pitr)->momentum();
330 pb = bet1[0]*dmom4.px() + bet1[1]*dmom4.py() + bet1[2]*dmom4.pz();
331 double dpx = dmom4.px() + bet1[0] * (dmom4.e() + pb/(gam1+1.) );
332 double dpy = dmom4.py() + bet1[1] * (dmom4.e() + pb/(gam1+1.) );
333 double dpz = dmom4.pz() + bet1[2] * (dmom4.e() + pb/(gam1+1.) );
334 double de = gam1*dmom4.e() + pb;
336 pb = bet2[0]*dpx + bet2[1]*dpy + bet2[2]*dpz;
337 dpx += bet2[0] * ( de + pb/(gam2+1.) );
338 dpy += bet2[1] * ( de + pb/(gam2+1.) );
339 dpz += bet2[2] * ( de + pb/(gam2+1.) );
343 (*pitr)->set_momentum( HepMC::FourVector(dpx,dpy,dpz,de) );
349 secVtxStorage.clear();
352 prt->set_momentum( HepMC::FourVector(px,py,pz,e) );
356 int newlyGen = HepMC::HEPEVT_Wrapper::number_entries() - nentries;
358 if ( largestBarcode < evt->particles_size() )
364 for (
int ipp=evt->particles_size(); ipp>largestBarcode; ipp-- )
366 (evt->barcode_to_particle(ipp))->suggest_barcode( ipp+newlyGen );
372 for (
int ipnw=1; ipnw<=newlyGen; ipnw++ )
374 int nbcode = largestBarcode+ipnw;
377 double px = HepMC::HEPEVT_Wrapper::px( nentries+ipnw );
378 double py = HepMC::HEPEVT_Wrapper::py( nentries+ipnw );
379 double pz = HepMC::HEPEVT_Wrapper::pz( nentries+ipnw );
385 NewPart->set_generated_mass( m );
386 NewPart->suggest_barcode( nbcode );
387 vtx->add_particle_out( NewPart ) ;
void attachParticles(HepMC::GenEvent *, HepMC::GenVertex *, int)
HepMC::GenEvent * apply(HepMC::GenEvent *)
CLHEP::HepRandomEngine * decayRandomEngine
double phoran_(int *idummy)
std::vector< int > fBarcodes
void SetDecayRandomEngine(CLHEP::HepRandomEngine *decayRandomEngine)
PhotosInterface53XLegacy()
CLHEP::HepRandomEngine * decayRandomEngine
bool fAvoidTauLeptonicDecays
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::string > fSpecialSettings