387 {
388
389 MsgStream log(
msgSvc(), name() );
390 log << MSG::INFO << "CosmicGenerator executing" << endmsg;
391
392 ++m_events;
393
394 log << MSG::DEBUG << "Event #" << m_events << endmsg;
395
396
397 m_fourPos.clear();
398 m_fourMom.clear();
399 m_polarization.clear();
400 m_pdgCode.clear();
401
402 if ( m_readfile )
403 {
404 if ( !m_ffile.eof() )
405 {
406 CosmicEventParser evt;
407 m_ffile >> evt;
408
409 std::cout << evt << std::endl;
410
411 double polx = 0;
412 double poly = 0;
413 double polz = 0;
414 Polarization thePolarization;
415 thePolarization.set_normal3d(
HepNormal3D( polx, poly, polz ) );
416 m_polarization.push_back( thePolarization );
417
418
419
420
421 m_fourPos.push_back( evt.
Vertex() );
422 m_fourMom.push_back( evt.
Momentum() );
423 m_pdgCode.push_back( evt.
pdgID() );
424 }
425 else
426 {
427 log << MSG::FATAL << "End of file reached - stop " << endmsg;
428 exit( 1 );
429 return StatusCode::FAILURE;
430 }
431 }
432
433 else
434 {
435
436 bool accepted = false;
437 bool projected = false;
438 HepLorentzVector pp;
440 HepLorentzVector vert;
441 HepLorentzVector vert_proj;
442 while ( !accepted )
443 {
444 m_tried++;
446 Hep3Vector vert3( vert.x(), vert.y(), vert.z() );
447
449 if ( m_dumpMC == 1 )
450 {
451 m_cosmicE = pp.e() * m_GeV;
452 m_cosmicTheta = pp.theta();
453 m_cosmicPhi = pp.phi();
455 m_tuple->write();
456 }
457 double theta1 = pp.theta();
458 double phi1 = pp.phi();
459 double mag1 = pp.vect().mag();
460
463 Hep3Vector direction( pp_corr.x(), pp_corr.y(), pp_corr.z() );
464 Hep3Vector center_dir = m_center - vert3;
465
466
467 if ( m_cubeProj )
468 {
470 if ( m_sphereOpt )
471 {
472
473 beta = direction.angle( center_dir );
474 alpha = asin( m_radius / center_dir.mag() );
475 if ( fabs( beta ) >
alpha )
476 {
477 log << MSG::DEBUG <<
alpha <<
", " << beta <<
" rejected muon due to sphere cut! "
478 << endmsg;
479 m_rejected++;
480 continue;
481 }
482 }
483
484 double l_fight0, l_fight1, l_fight2;
485 double coor_x0, coor_y0, coor_z0;
486 double coor_x1, coor_y1, coor_z1;
487 double coor_x2, coor_y2, coor_z2;
488 bool isIn0 = false;
489 bool isIn1 = false;
490 bool isIn2 = false;
495
496 coor_y0 = m_ypos;
497 coor_x0 = direction.x() * ( coor_y0 - vert.y() ) / direction.y() + vert.x();
498 coor_z0 = direction.z() * ( coor_y0 - vert.y() ) / direction.y() + vert.z();
499
500 if ( fabs( coor_x0 ) <= m_xpos && fabs( coor_z0 ) <= m_zpos )
501 {
502 vert_pro0 =
HepPoint3D( coor_x0, coor_y0, coor_z0 );
503 l_fight0 = vert_org.distance( vert_pro0 );
504 isIn0 = true;
505 }
506 else
507 {
508
509 coor_z1 = sign( coor_z0 - vert.z() ) * m_zpos;
510 coor_x1 = direction.x() * ( coor_z1 - vert.z() ) / direction.z() + vert.x();
511 coor_y1 = direction.y() * ( coor_z1 - vert.z() ) / direction.z() + vert.y();
512
513 vert_pro1 =
HepPoint3D( coor_x1, coor_y1, coor_z1 );
514 l_fight1 = vert_org.distance( vert_pro1 );
515
516 coor_x2 = sign( coor_x0 - vert.x() ) * m_xpos;
517 coor_z2 = direction.z() * ( coor_x2 - vert.x() ) / direction.x() + vert.z();
518 coor_y2 = direction.y() * ( coor_x2 - vert.x() ) / direction.x() + vert.y();
519 vert_pro2 =
HepPoint3D( coor_x2, coor_y2, coor_z2 );
520 l_fight2 = vert_org.distance( vert_pro2 );
521 if ( l_fight1 < l_fight2 ) isIn1 = true;
522 else isIn2 = true;
523 }
524
525 if ( isIn0 )
526 {
527 vert_proj =
528 HepLorentzVector( vert_pro0.x(), vert_pro0.y(), vert_pro0.z(), l_fight0 );
529
530 projected = true;
531 accepted = true;
532 m_accepted++;
533 }
534 else if ( isIn1 )
535 {
536 vert_proj =
537 HepLorentzVector( vert_pro1.x(), vert_pro1.y(), vert_pro1.z(), l_fight1 );
538
539 projected = true;
540 accepted = true;
541 m_accepted++;
542 }
543 else if ( isIn2 )
544 {
545 vert_proj =
546 HepLorentzVector( vert_pro2.x(), vert_pro2.y(), vert_pro2.z(), l_fight2 );
547
548 projected = true;
549 accepted = true;
550 m_accepted++;
551 }
552 else
553 {
554 log << MSG::DEBUG << " rejected muon due to cube projection request! " << endmsg;
555 m_rejected++;
556 }
557 }
558 else if ( m_doublePlaneTrigger )
559 {
560 double coor_x0, coor_y0, coor_z0;
561 coor_y0 = m_ypos_top;
562 coor_x0 = direction.x() * ( coor_y0 - vert.y() ) / direction.y() + vert.x();
563 coor_z0 = direction.z() * ( coor_y0 - vert.y() ) / direction.y() + vert.z();
564
565 double coor_x1, coor_y1, coor_z1;
566 coor_y1 = m_ypos_bottom;
567 coor_x1 = direction.x() * ( coor_y1 - vert.y() ) / direction.y() + vert.x();
568 coor_z1 = direction.z() * ( coor_y1 - vert.y() ) / direction.y() + vert.z();
569
570 if ( coor_x0 > m_xposMin_top && coor_x0 < m_xposMax_top && coor_z0 > m_zposMin_top &&
571 coor_z0 < m_zposMax_top && coor_x1 > m_xposMin_bottom &&
572 coor_x1 < m_xposMax_bottom && coor_z1 > m_zposMin_bottom &&
573 coor_z1 < m_zposMax_bottom )
574 {
575 accepted = true;
576 m_accepted++;
577 }
578 else m_rejected++;
579 }
580 else accepted = true;
581 }
582
583
584
585
586
587
588 pp.setX( pp.x() );
589 pp.setY( pp.y() );
590 pp.setZ( pp.z() );
591 pp.setT( pp.t() );
592
594
595 m_pdgCode.push_back( charge * -13 );
596
597
598
599
600
601
602
603
604
605 double polx = 0;
606 double poly = 0;
607 double polz = 0;
608
609 Polarization thePolarization;
610
611
612
613
614
615
616
617 if ( !m_swapYZAxis )
618 {
619
620 thePolarization.set_normal3d(
HepNormal3D( polx, poly, polz ) );
621 }
622 else thePolarization.set_normal3d(
HepNormal3D( polx, polz, -poly ) );
623
624 m_polarization.push_back( thePolarization );
625
626
627
628 double e = pp.e();
629 double theta = pp.theta();
630 double phi = pp.phi();
631
632
633
634
637 {
638 log << MSG::ERROR <<
"Event #" << m_events <<
" E=" << e <<
", mass=" <<
mass
639 << " -- you have generated a tachyon! Increase energy or change particle ID."
640 << endmsg;
641 return StatusCode::FAILURE;
642 }
643
644 double p = sqrt(
p2 );
645 double px = p *
sin( theta ) *
cos( phi );
646 double pz = p *
sin( theta ) *
sin( phi );
647 double py = -p *
cos( theta );
648
649
650
651
652
653
654
655 if ( !m_swapYZAxis )
656 {
657
658
659 m_fourMom.push_back( HepLorentzVector( px, py, pz, pp.e() ) );
660 }
661 else m_fourMom.push_back( HepLorentzVector( px, pz, -py, pp.e() ) );
663 double y = vert.y();
664 double z = vert.z();
666 if ( projected )
667 {
668
670 y = vert_proj.y();
671 z = vert_proj.z();
672 t = vert.t() - vert_proj.t() / HepLorentzVector( px, py, pz, pp.e() ).beta() + m_tcor;
673 }
674
675
676
677
678
679
680
681
682
683
684 if ( !m_swapYZAxis ) m_fourPos.push_back( HepLorentzVector(
x, y, z,
t ) );
685 else m_fourPos.push_back( HepLorentzVector(
x, z, y,
t ) );
686
687 log << MSG::DEBUG << " (x,y,z,t) = (" << m_fourPos.back().x() << ","
688 << m_fourPos.back().y() << "," << m_fourPos.back().z() << "," << m_fourPos.back().t()
689 << "), (Px,Py,Pz,E) = (" << m_fourMom.back().px() << "," << m_fourMom.back().py()
690 << "," << m_fourMom.back().pz() << "," << m_fourMom.back().e() << ")" << endmsg;
691 log << MSG::DEBUG << " (theta,phi) = (" << theta << "," << phi << "), "
692 << "polarization(x,y,z) = (" << m_polarization.back().normal3d().x() << ","
693 << m_polarization.back().normal3d().y() << "," << m_polarization.back().normal3d().z()
694 << ")" << endmsg;
695 if ( m_dumpMC == 1 )
696 {
697
698
699
700
701 mc_theta = m_fourMom.back().theta();
702 mc_phi = m_fourMom.back().phi();
703 mc_px = m_fourMom.back().px();
704 mc_py = m_fourMom.back().py();
705 mc_pz = m_fourMom.back().pz();
706
707 m_tuple1->write();
708 }
709 }
710
711
712
713 GenEvent* event = new GenEvent( 1, 1 );
714
715 if ( m_fourMom.size() == m_fourPos.size() && m_fourMom.size() == m_polarization.size() )
716 {
717
718 for ( std::size_t
v = 0;
v < m_fourMom.size(); ++
v )
719 {
720
721
722
723
724
725
726 GenParticle* particle =
new GenParticle( m_fourMom[
v], m_pdgCode[
v], 1 );
727 particle->set_polarization( m_polarization[
v] );
728
729
730 GenVertex* vertex =
new GenVertex( m_fourPos[
v] );
731 vertex->add_particle_out( particle );
732
733
734 event->add_vertex( vertex );
735 }
736
737 event->set_event_number( m_events );
738 }
739 else
740 {
741
742 log << MSG::ERROR << "Wrong different number of vertexes/momenta/polaritazions!" << endmsg;
743 return StatusCode::FAILURE;
744 }
745
746 SmartDataPtr<McGenEventCol> anMcCol( eventSvc(), "/Event/Gen" );
747 if ( anMcCol != 0 )
748 {
749
750
751 log << MSG::INFO << "Add McGenEvent to existing collection" << endmsg;
752 McGenEvent* mcEvent = new McGenEvent( event );
753 anMcCol->push_back( mcEvent );
754 }
755 else
756 {
757
759 McGenEvent* mcEvent = new McGenEvent( event );
760 mcColl->push_back( mcEvent );
761 StatusCode sc = eventSvc()->registerObject( "/Event/Gen", mcColl );
762 if ( sc != StatusCode::SUCCESS )
763 {
764 log << MSG::ERROR << "Could not register McGenEvent" << endmsg;
765 delete mcColl;
766 delete event;
767 delete mcEvent;
768 return StatusCode::FAILURE;
769 }
770 }
771
772 return StatusCode::SUCCESS;
773}
HepGeom::Point3D< double > HepPoint3D
HepGeom::Normal3D< float > HepNormal3D
ObjectVector< McGenEvent > McGenEventCol
double sin(const BesAngle a)
double cos(const BesAngle a)
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
const HepLorentzVector & Vertex(void)
const HepLorentzVector & Momentum(void)
HepLorentzVector generateVertex(void)
HepLorentzVector GenerateEvent(void)
static CosmicGun * GetCosmicGun(void)