9 #include "HepMC/GenEvent.h"
10 #include "HepMC/IO_HEPEVT.h"
11 #include "HepMC/HEPEVT_Wrapper.h"
95 for (
int ip=0; ip<4000; ip++ )
104 for (
int iv=1; iv<=evt->vertices_size(); iv++ )
107 bool legalVtx =
false;
111 HepMC::GenVertex* vtx = evt->barcode_to_vertex( -iv ) ;
113 if ( vtx->particles_in_size() != 1 )
continue;
114 if ( vtx->particles_out_size() <= 1 )
continue;
116 if ( (*(vtx->particles_in_const_begin()))->pdg_id() == 111 )
continue;
118 if (
fOnlyPDG != 1 && (*(vtx->particles_in_const_begin()))->pdg_id() !=
fOnlyPDG )
129 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
130 pitr != vtx->particles_end(HepMC::children); ++pitr)
132 if ( (*pitr)->pdg_id() ==
fOnlyPDG )
138 if ( same )
continue;
159 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
160 pitr != vtx->particles_end(HepMC::children); ++pitr)
164 if (
abs((*pitr)->pdg_id()) >=1 &&
abs((*pitr)->pdg_id()) <=8 )
break;
165 if (
abs((*pitr)->pdg_id()) == 21 )
break;
167 if ( (*pitr)->status() == 1 || (*pitr)->end_vertex() )
175 if ( !legalVtx )
continue;
182 HepMC::HEPEVT_Wrapper::set_event_number( evt->event_number() );
191 HepMC::GenVertex* vtx = evt->barcode_to_vertex( vtxbcode );
201 HepMC::HEPEVT_Wrapper::zero_everything();
207 HepMC::HEPEVT_Wrapper::set_id( index, (*(vtx->particles_in_const_begin()))->pdg_id() );
208 HepMC::FourVector
vec4;
209 vec4 = (*(vtx->particles_in_const_begin()))->momentum();
210 HepMC::HEPEVT_Wrapper::set_momentum( index, vec4.x(), vec4.y(), vec4.z(), vec4.e() );
211 HepMC::HEPEVT_Wrapper::set_mass( index, (*(vtx->particles_in_const_begin()))->generated_mass() );
212 HepMC::HEPEVT_Wrapper::set_position( index, vtx->position().x(), vtx->position().y(),
213 vtx->position().z(), vtx->position().t() );
214 HepMC::HEPEVT_Wrapper::set_status( index, (*(vtx->particles_in_const_begin()))->status() );
215 HepMC::HEPEVT_Wrapper::set_parents( index, 0, 0 );
216 fBarcodes.push_back( (*(vtx->particles_in_const_begin()))->barcode() );
221 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
222 pitr != vtx->particles_end(HepMC::children); ++pitr)
225 if ( (*pitr)->status() == 1 || (*pitr)->end_vertex() )
228 vec4 = (*pitr)->momentum();
229 HepMC::HEPEVT_Wrapper::set_id( index, (*pitr)->pdg_id() );
230 HepMC::HEPEVT_Wrapper::set_momentum( index, vec4.x(), vec4.y(), vec4.z(), vec4.e() );
231 HepMC::HEPEVT_Wrapper::set_mass( index, (*pitr)->generated_mass() );
232 vec4 = (*pitr)->production_vertex()->position();
233 HepMC::HEPEVT_Wrapper::set_position( index, vec4.x(), vec4.y(), vec4.z(), vec4.t() );
234 HepMC::HEPEVT_Wrapper::set_status( index, (*pitr)->status() );
235 HepMC::HEPEVT_Wrapper::set_parents( index, 1, 1 );
236 fBarcodes.push_back( (*pitr)->barcode() );
239 if ( (*pitr)->end_vertex() )
241 fSecVtxStore.push_back( (*pitr)->end_vertex()->barcode() );
247 int nentries =
index;
251 HepMC::HEPEVT_Wrapper::set_children ( index, 2, lastDau );
256 HepMC::HEPEVT_Wrapper::set_number_entries( nentries );
294 unsigned int vcounter = 0;
311 if ( HepMC::HEPEVT_Wrapper::number_entries() > nentries )
322 int largestBarcode = -1;
325 for (
int ip=1; ip<Nbcodes; ip++ )
330 if ( bcode > largestBarcode ) largestBarcode = bcode;
331 double px = HepMC::HEPEVT_Wrapper::px(ip+1);
332 double py = HepMC::HEPEVT_Wrapper::py(ip+1);
333 double pz = HepMC::HEPEVT_Wrapper::pz(ip+1);
337 if ( prt->end_vertex() )
340 HepMC::GenVertex* endVtx = prt->end_vertex();
342 std::vector<int> secVtxStorage;
343 secVtxStorage.clear();
345 secVtxStorage.push_back( endVtx->barcode() );
347 HepMC::FourVector mom4 = prt->momentum();
350 double bet1[3], bet2[3], gam1, gam2, pb;
351 double mass = mom4.m();
352 bet1[0] = -(mom4.px()/
mass);
353 bet1[1] = -(mom4.py()/
mass);
354 bet1[2] = -(mom4.pz()/
mass);
358 gam1 = mom4.e()/
mass;
361 unsigned int vcounter = 0;
363 while ( vcounter < secVtxStorage.size() )
366 HepMC::GenVertex* theVtx = evt->barcode_to_vertex( secVtxStorage[vcounter] );
368 for ( HepMC::GenVertex::particle_iterator pitr=theVtx->particles_begin(HepMC::children);
369 pitr != theVtx->particles_end(HepMC::children); ++pitr)
372 if ( (*pitr)->end_vertex() )
374 secVtxStorage.push_back( (*pitr)->end_vertex()->barcode() );
377 if ( theVtx->particles_out_size() == 1 && (*pitr)->pdg_id() == prt->pdg_id() )
380 (*pitr)->set_momentum( HepMC::FourVector(px,py,pz,e) );
384 HepMC::FourVector dmom4 = (*pitr)->momentum();
387 pb = bet1[0]*dmom4.px() + bet1[1]*dmom4.py() + bet1[2]*dmom4.pz();
388 double dpx = dmom4.px() + bet1[0] * (dmom4.e() + pb/(gam1+1.) );
389 double dpy = dmom4.py() + bet1[1] * (dmom4.e() + pb/(gam1+1.) );
390 double dpz = dmom4.pz() + bet1[2] * (dmom4.e() + pb/(gam1+1.) );
391 double de = gam1*dmom4.e() + pb;
393 pb = bet2[0]*dpx + bet2[1]*dpy + bet2[2]*dpz;
394 dpx += bet2[0] * ( de + pb/(gam2+1.) );
395 dpy += bet2[1] * ( de + pb/(gam2+1.) );
396 dpz += bet2[2] * ( de + pb/(gam2+1.) );
400 (*pitr)->set_momentum( HepMC::FourVector(dpx,dpy,dpz,de) );
406 secVtxStorage.clear();
409 prt->set_momentum( HepMC::FourVector(px,py,pz,e) );
413 int newlyGen = HepMC::HEPEVT_Wrapper::number_entries() - nentries;
415 if ( largestBarcode < evt->particles_size() )
421 for (
int ipp=evt->particles_size(); ipp>largestBarcode; ipp-- )
423 (evt->barcode_to_particle(ipp))->suggest_barcode( ipp+newlyGen );
429 for (
int ipnw=1; ipnw<=newlyGen; ipnw++ )
431 int nbcode = largestBarcode+ipnw;
432 int pdg_id = HepMC::HEPEVT_Wrapper::id( nentries+ipnw );
434 double px = HepMC::HEPEVT_Wrapper::px( nentries+ipnw );
435 double py = HepMC::HEPEVT_Wrapper::py( nentries+ipnw );
436 double pz = HepMC::HEPEVT_Wrapper::pz( nentries+ipnw );
442 NewPart->set_generated_mass( m );
443 NewPart->suggest_barcode( nbcode );
444 vtx->add_particle_out( NewPart ) ;
458 if (
abs((*(vtx->particles_in_const_begin()))->pdg_id()) != 15 )
return false;
460 for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
461 pitr != vtx->particles_end(HepMC::children); ++pitr)
463 if (
abs((*pitr)->pdg_id()) == 11 ||
abs((*pitr)->pdg_id()) == 13 )
477 <<
"PhotosInterface::flat: Attempt to generate random number when engine pointer is null\n"
478 <<
"This might mean that the code was modified to generate a random number outside the\n"
479 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
void attachParticles(HepMC::GenEvent *, HepMC::GenVertex *, int)
CLHEP::HepRandomEngine * decayRandomEngine
double phoran_(int *idummy)
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
std::vector< int > fBarcodes
void setRandomEngine(CLHEP::HepRandomEngine *decayRandomEngine)
bool fAvoidTauLeptonicDecays
Abs< T >::type abs(const T &t)
static CLHEP::HepRandomEngine * fRandomEngine
void applyToBranch(HepMC::GenEvent *, int)
std::vector< int > fSecVtxStore
void applyToVertex(HepMC::GenEvent *, int)
#define DEFINE_EDM_PLUGIN(factory, type, name)
bool isTauLeptonicDecay(HepMC::GenVertex *)
HepMC::GenEvent * apply(HepMC::GenEvent *)
std::vector< std::string > fSpecialSettings
void configureOnlyFor(int)