306{
307
309
310
311 ISvcLocator* svcLocator = Gaudi::svcLocator();
312 IG4Svc* tmpSvc;
313 G4Svc* m_G4Svc;
314 StatusCode sc = svcLocator->service( "G4Svc", tmpSvc );
315 m_G4Svc = dynamic_cast<G4Svc*>( tmpSvc );
316
317
318
320
321
323
324
327 {
328 for ( HepMC::GenEvent::vertex_const_iterator vitr = hepmcevt->vertices_begin();
329 vitr != hepmcevt->vertices_end(); ++vitr )
330 {
331 G4int vtxFlag = 0;
332 G4int pOut = ( *vitr )->particles_out_size();
333 HepMC::GenVertex::particle_iterator pitr = ( *vitr )->particles_begin( HepMC::children );
334 G4int pdgcode = ( *pitr )->pdg_id();
335 if ( pOut == 1 &&
abs( pdgcode ) == 11 ) vtxFlag = 1;
336 G4int barcodeVtx = ( *vitr )->barcode();
337
338 for ( HepMC::GenVertex::particle_iterator pitr =
339 ( *vitr )->particles_begin( HepMC::children );
340 pitr != ( *vitr )->particles_end( HepMC::children ); ++pitr )
341 {
342 G4int pdgcode = ( *pitr )->pdg_id();
343 if ( vtxFlag == 0 )
344 {
345 if ( pdgcode == -22 ) pdgcode = 22;
346 G4LorentzVector p;
347 p.setX( ( *pitr )->momentum().x() );
348 p.setY( ( *pitr )->momentum().y() );
349 p.setZ( ( *pitr )->momentum().z() );
350 p.setT( ( *pitr )->momentum().t() );
351 G4PrimaryParticle* particle = 0;
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376 particle = new G4PrimaryParticle( pdgcode, p.x() * GeV, p.y() * GeV, p.z() * GeV );
377
378
379
380
381
382 G4int ISTHEP = ( *pitr )->status();
383
384 G4int barcodeEndVtx = 0;
385 if ( ( *pitr )->end_vertex() ) barcodeEndVtx = ( *pitr )->end_vertex()->barcode();
386
387 G4HepMCParticle* hepmcParticle =
388 new G4HepMCParticle( particle, ISTHEP, barcodeEndVtx );
389 HPlist.push_back( hepmcParticle );
390
391 for (
size_t ii = 0; ii <
HPlist.size(); ii++ )
392 {
393 if ( barcodeVtx ==
HPlist[ii]->GetBarcodeEndVtx() )
394 {
395 HPlist[ii]->GetTheParticle()->SetDaughter( particle );
396 hepmcParticle->
Done();
397 break;
398 }
399 }
400 }
401 }
402 }
403 }
404 else
405 {
406 for ( HepMC::GenEvent::vertex_const_iterator vitr = hepmcevt->vertices_begin();
407 vitr != hepmcevt->vertices_end(); ++vitr )
408 {
409 for ( HepMC::GenVertex::particle_iterator pitr =
410 ( *vitr )->particles_begin( HepMC::children );
411 pitr != ( *vitr )->particles_end( HepMC::children ); ++pitr )
412 {
413 G4int ISTHEP = ( *pitr )->status();
414 G4LorentzVector p;
415 p.setX( ( *pitr )->momentum().x() );
416 p.setY( ( *pitr )->momentum().y() );
417 p.setZ( ( *pitr )->momentum().z() );
418 p.setT( ( *pitr )->momentum().t() );
419
420 G4int pdgcode = ( *pitr )->pdg_id();
421 G4int barcodeEndVtx = 0;
422 if ( ( *pitr )->end_vertex() ) barcodeEndVtx = ( *pitr )->end_vertex()->barcode();
423 G4PrimaryParticle* particle = 0;
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448 particle = new G4PrimaryParticle( pdgcode, p.x() * GeV, p.y() * GeV, p.z() * GeV );
449
450
451
452
453
454
455 G4HepMCParticle* hepmcParticle =
456 new G4HepMCParticle( particle, ISTHEP, barcodeEndVtx );
457 HPlist.push_back( hepmcParticle );
458 if ( ISTHEP > 1 ) hepmcParticle->
Done();
459 }
460 }
461 }
462
463
465
466
467 G4double pmPosX, pmPosY, pmPosZ, pmTime;
468 G4double tmpPosX, tmpPosY, tmpPosZ, tmpT;
469 G4double beamPosX = 0, beamPosY = 0, beamPosZ = 0, beamSizeX = 0, beamSizeY = 0,
470 beamSizeZ = 0;
471
472 if ( m_RealizationSvc->UseDBFlag() == false )
473 {
477
481 }
482 if ( m_RealizationSvc->UseDBFlag() == true && m_RealizationSvc->ifReadBunch() == true )
483 {
484 beamPosX = m_RealizationSvc->getBunchPosX();
485 beamPosY = m_RealizationSvc->getBunchPosY();
486 beamPosZ = m_RealizationSvc->getBunchPosZ();
487
488 beamSizeX = m_RealizationSvc->getBunchSizeX();
489 beamSizeY = m_RealizationSvc->getBunchSizeY();
490 beamSizeZ = m_RealizationSvc->getBunchSizeZ();
491 }
492 if ( m_RealizationSvc->UseDBFlag() == true && m_RealizationSvc->ifReadBunch() == false )
493 {
497
501 }
502
503 G4double gaussX = G4RandGauss::shoot();
504 G4double gaussY = G4RandGauss::shoot();
505 G4double gaussZ = G4RandGauss::shoot();
506 G4double gaussT = G4RandGauss::shoot();
507
512
513 G4double ran = G4UniformRand();
514 G4double beamTime = bunchTimeSigma * G4RandGauss::shoot() + beamStartTime +
515 beamDeltaTime * int( ran * nBunch );
516
517 tmpPosX = ( beamPosX + beamSizeX * gaussX ) * mm;
518 tmpPosY = ( beamPosY + beamSizeY * gaussY ) * mm;
519 tmpPosZ = ( beamPosZ + beamSizeZ * gaussZ ) * mm;
520 tmpT = ( beamSizeZ * gaussT ) * mm / c_light + beamTime;
521
522 G4LorentzVector tmpv( tmpPosX, tmpPosY, tmpPosZ, tmpT * c_light / mm );
523
524 HepMC::GenEvent::vertex_const_iterator vitr0 = hepmcevt->vertices_begin();
525 G4LorentzVector xvtx0;
526 xvtx0.setX( ( *vitr0 )->position().x() );
527 xvtx0.setY( ( *vitr0 )->position().y() );
528 xvtx0.setZ( ( *vitr0 )->position().z() );
529 xvtx0.setT( ( *vitr0 )->position().t() );
530 pmPosX = xvtx0.x() * mm + tmpPosX;
531 pmPosY = xvtx0.y() * mm + tmpPosY;
532 pmPosZ = xvtx0.z() * mm + tmpPosZ;
533 pmTime = xvtx0.t() * mm / c_light + tmpT;
534
536 {
537 G4cout << G4endl;
538 G4cout << xvtx0.x() << " " << xvtx0.y() << " " << xvtx0.z() << " " << beamSizeX * gaussX
539 << " " << beamSizeY * gaussY << " " << beamSizeZ * gaussZ << " " << G4endl;
540 G4cout << xvtx0.t() * mm / c_light << " " << beamSizeZ * gaussT / sqrt( 2 ) * mm / c_light
541 << " " << beamTime << G4endl;
542 }
543 for ( HepMC::GenEvent::vertex_const_iterator vitr = hepmcevt->vertices_begin();
544 vitr != hepmcevt->vertices_end(); ++vitr )
545 {
546 G4LorentzVector xvtx;
547 xvtx.setX( ( *vitr )->position().x() );
548 xvtx.setY( ( *vitr )->position().y() );
549 xvtx.setZ( ( *vitr )->position().z() );
550 xvtx.setT( ( *vitr )->position().t() );
551 ( *vitr )->set_position( xvtx + tmpv );
552 }
554
555 G4PrimaryVertex* g4vtx = new G4PrimaryVertex( pmPosX, pmPosY, pmPosZ, pmTime );
556
557
558 for (
size_t ii = 0; ii <
HPlist.size(); ii++ )
559 {
560 if (
HPlist[ii]->GetISTHEP() > 0 )
561
562 {
563 G4PrimaryParticle* initialParticle =
HPlist[ii]->GetTheParticle();
564 g4vtx->SetPrimary( initialParticle );
565 }
566 }
567
568
569 for (
size_t iii = 0; iii <
HPlist.size(); iii++ ) {
delete HPlist[iii]; }
571
572 g4event->AddPrimaryVertex( g4vtx );
573}
void Print(const HepMC::GenEvent *hepmcevt)
void Boost(HepMC::GenEvent *hepmcevt)
std::vector< G4HepMCParticle * > HPlist
G4int CheckType(const HepMC::GenEvent *hepmcevt)
double GetBeamDeltaTime()
double GetBunchTimeSigma()
double GetBeamStartTime()
void SetBeamTime(double value)