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