386 {
387
388 MsgStream log(messageService(), name());
389 log << MSG::INFO << "CosmicGenerator executing" << endreq;
390
391
392 ++m_events;
393
394 log << MSG::DEBUG << "Event #" << m_events << endreq;
395
396
397
398 m_fourPos.clear();
399 m_fourMom.clear();
400 m_polarization.clear();
401 m_pdgCode.clear();
402
403
404 if(m_readfile)
405 {
406 if(!m_ffile.eof())
407 {
409 m_ffile >> evt;
410
411 std::cout << evt << std::endl;
412
413 double polx = 0;
414 double poly = 0;
415 double polz = 0;
416 Polarization thePolarization;
417 thePolarization.set_normal3d(
HepNormal3D(polx,poly,polz));
418 m_polarization.push_back(thePolarization);
419
420
421
422
423 m_fourPos.push_back(evt.
Vertex());
424 m_fourMom.push_back(evt.
Momentum());
425 m_pdgCode.push_back(evt.
pdgID());
426
427 }
428 else
429 {
430 log << MSG::FATAL << "End of file reached - stop " << endreq;
431 exit(1);
432 return StatusCode::FAILURE;
433 }
434 }
435
436 else
437 {
438
439 bool accepted=false;
440 bool projected=false;
441 HepLorentzVector pp;
443 HepLorentzVector vert;
444 HepLorentzVector vert_proj;
445 while(!accepted){
446 m_tried++;
448 Hep3Vector vert3(vert.x(),vert.y(),vert.z());
449
451 if(m_dumpMC==1) {
452 m_cosmicE=pp.e()*m_GeV;
453 m_cosmicTheta=pp.theta();
454 m_cosmicPhi=pp.phi();
456 m_tuple->write();
457 }
459 double phi1=pp.phi();
460 double mag1=pp.vect().mag();
461
465 Hep3Vector direction(pp_corr.x(),pp_corr.y(), pp_corr.z());
466 Hep3Vector center_dir=m_center-vert3;
467
468
469
470 if (m_cubeProj) {
472 if(m_sphereOpt){
473
474 beta=direction.angle(center_dir);
475 alpha=asin(m_radius/center_dir.mag());
476 if(fabs(beta)>
alpha){
477 log<<MSG::DEBUG<<
alpha<<
", "<<beta<<
" rejected muon due to sphere cut! "<<endreq;
478 m_rejected++;
479 continue;
480 }
481 }
482
483 double l_fight0,l_fight1, l_fight2;
484 double coor_x0, coor_y0, coor_z0;
485 double coor_x1, coor_y1, coor_z1;
486 double coor_x2, coor_y2, coor_z2;
487 bool isIn0=false;
488 bool isIn1=false;
489 bool isIn2=false;
494
495 coor_y0 = m_ypos;
496 coor_x0 = direction.x()*(coor_y0 - vert.y())/direction.y() +vert.x();
497 coor_z0 = direction.z()*(coor_y0 - vert.y())/direction.y() +vert.z();
498
499
500
501 if( fabs(coor_x0) <= m_xpos && fabs(coor_z0) <= m_zpos){
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 coor_z1 = sign(coor_z0-vert.z())*m_zpos;
509 coor_x1 = direction.x()*(coor_z1 - vert.z())/direction.z() +vert.x();
510 coor_y1 = direction.y()*(coor_z1 - vert.z())/direction.z() +vert.y();
511
512 vert_pro1=
HepPoint3D (coor_x1, coor_y1, coor_z1);
513 l_fight1=vert_org.distance(vert_pro1);
514
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)
522 isIn1=true;
523 else
524 isIn2=true;
525 }
526
527 if(isIn0){
528 vert_proj=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 vert_proj=HepLorentzVector (vert_pro1.x(),vert_pro1.y(),vert_pro1.z() , l_fight1);
536
537 projected =true;
538 accepted = true;
539 m_accepted++;
540 }
541 else if(isIn2){
542 vert_proj=HepLorentzVector (vert_pro2.x(),vert_pro2.y(),vert_pro2.z() , l_fight2);
543
544 projected =true;
545 accepted = true;
546 m_accepted++;
547 } else {
548 log<<MSG::DEBUG<<" rejected muon due to cube projection request! "<<endreq;
549 m_rejected++;
550 }
551
552
553
554
555 }
556 else if(m_doublePlaneTrigger)
557 {
558 double coor_x0, coor_y0, coor_z0;
559 coor_y0 = m_ypos_top;
560 coor_x0 = direction.x()*(coor_y0 - vert.y())/direction.y() +vert.x();
561 coor_z0 = direction.z()*(coor_y0 - vert.y())/direction.y() +vert.z();
562
563 double coor_x1, coor_y1, coor_z1;
564 coor_y1 = m_ypos_bottom;
565 coor_x1 = direction.x()*(coor_y1 - vert.y())/direction.y() +vert.x();
566 coor_z1 = direction.z()*(coor_y1 - vert.y())/direction.y() +vert.z();
567
568 if(coor_x0>m_xposMin_top && coor_x0<m_xposMax_top && coor_z0>m_zposMin_top && coor_z0<m_zposMax_top
569 && coor_x1>m_xposMin_bottom && coor_x1<m_xposMax_bottom && coor_z1>m_zposMin_bottom && coor_z1<m_zposMax_bottom)
570 {
571 accepted = true;
572 m_accepted++;
573 }
574 else m_rejected++;
575 }
576 else accepted=true;
577 }
578
579
580
581
582
583
584 pp.setX(pp.x());
585 pp.setY(pp.y());
586 pp.setZ(pp.z());
587 pp.setT(pp.t());
588
590
591 m_pdgCode.push_back(charge*-13);
592
593
594
595
596
597
598
599
600
601
602 double polx = 0;
603 double poly = 0;
604 double polz = 0;
605
606 Polarization thePolarization;
607
608
609
610
611
612
613
614 if(!m_swapYZAxis){
615
616 thePolarization.set_normal3d(
HepNormal3D(polx,poly,polz));
617 }
618 else
619 thePolarization.set_normal3d(
HepNormal3D(polx,polz,-poly));
620
621 m_polarization.push_back(thePolarization);
622
623
624
625
626 double e = pp.e();
627 double theta = pp.theta();
628 double phi = pp.phi();
629
630
631
632
634 if ( p2 < 0 )
635 {
636 log << MSG::ERROR
637 << "Event #" << m_events
638 <<
" 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
656
657 if(!m_swapYZAxis) {
658
659
660 m_fourMom.push_back(HepLorentzVector(px,py,pz,pp.e()));
661 }
662 else
663 m_fourMom.push_back(HepLorentzVector(px,pz,-py,pp.e()));
665 double y = vert.y();
666 double z = vert.z();
668 if(projected){
669
671 y = vert_proj.y();
672 z = vert_proj.z();
673 t = vert.t()-vert_proj.t()/HepLorentzVector(px,py,pz,pp.e()).beta()
674 +m_tcor;
675
676
677
678 }
679
680
681
682
683
684
685
686
687
688
689
690 if(!m_swapYZAxis)
691 m_fourPos.push_back(HepLorentzVector(x,y,z,
t));
692 else
693 m_fourPos.push_back(HepLorentzVector(x,z,y,
t));
694
695 log << MSG::DEBUG
696 << " (x,y,z,t) = ("
697 << m_fourPos.back().x() << ","
698 << m_fourPos.back().y() << ","
699 << m_fourPos.back().z() << ","
700 << m_fourPos.back().t() << "), (Px,Py,Pz,E) = ("
701 << m_fourMom.back().px() << ","
702 << m_fourMom.back().py() << ","
703 << m_fourMom.back().pz() << ","
704 << m_fourMom.back().e() << ")"
705 << endreq;
706 log << MSG::DEBUG
707 << " (theta,phi) = (" << theta << "," << phi << "), "
708 << "polarization(x,y,z) = ("
709 << m_polarization.back().normal3d().x() << ","
710 << m_polarization.back().normal3d().y() << ","
711 << m_polarization.back().normal3d().z() << ")"
712 << endreq;
713 if(m_dumpMC==1) {
714
715
716
717
718 mc_theta=m_fourMom.back().theta();
719 mc_phi=m_fourMom.back().phi();
720 mc_px=m_fourMom.back().px();
721 mc_py=m_fourMom.back().py();
722 mc_pz=m_fourMom.back().pz();
723
724 m_tuple1->write();
725 }
726 }
727
728
729
730 GenEvent* event = new GenEvent(1,1);
731
732 if(m_fourMom.size()==m_fourPos.size()&&m_fourMom.size()==m_polarization.size()){
733
734 for(std::size_t
v=0;
v<m_fourMom.size();++
v){
735
736
737
738
739
740
741 GenParticle* particle =
new GenParticle( m_fourMom[
v], m_pdgCode[
v], 1);
742 particle->set_polarization( m_polarization[
v] );
743
744
745 GenVertex* vertex =
new GenVertex(m_fourPos[
v]);
746 vertex->add_particle_out( particle );
747
748
749 event->add_vertex( vertex );
750
751 }
752
753 event->set_event_number(m_events);
754
755
756
757 } else {
758
759 log<<MSG::ERROR<<"Wrong different number of vertexes/momenta/polaritazions!"<<endreq;
760 return StatusCode::FAILURE;
761 }
762
763 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
764 if (anMcCol!=0)
765 {
766
767
768 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
770 anMcCol->push_back(mcEvent);
771 }
772 else
773 {
774
777 mcColl->push_back(mcEvent);
778 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
779 if (sc != StatusCode::SUCCESS)
780 {
781 log << MSG::ERROR << "Could not register McGenEvent" << endreq;
782 delete mcColl;
783 delete event;
784 delete mcEvent;
785 return StatusCode::FAILURE;
786 }
787
788 }
789
790
791
792
793
794 return StatusCode::SUCCESS;
795
796}
double sin(const BesAngle a)
double cos(const BesAngle a)
HepGeom::Point3D< double > HepPoint3D
HepGeom::Normal3D< float > HepNormal3D
**********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
ObjectVector< McGenEvent > McGenEventCol
const HepLorentzVector & Vertex(void)
const HepLorentzVector & Momentum(void)
HepLorentzVector generateVertex(void)
HepLorentzVector GenerateEvent(void)
static CosmicGun * GetCosmicGun(void)