BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
CosmicGenerator Class Reference

#include <CosmicGenerator.h>

Inheritance diagram for CosmicGenerator:

Public Member Functions

 CosmicGenerator (const std::string &name, ISvcLocator *pSvcLocator)
 ~CosmicGenerator ()
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()
HepLorentzVector generateVertex (void)

Static Public Attributes

static IBesRndmGenSvcp_BesRndmGenSvc = 0

Detailed Description

Definition at line 45 of file CosmicGenerator.h.

Constructor & Destructor Documentation

◆ CosmicGenerator()

CosmicGenerator::CosmicGenerator ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 143 of file CosmicGenerator.cxx.

144 : Algorithm( name, pSvcLocator )
145//--------------------------------------------------------------------------
146{
147 //
148 // Migration to MeV and mm units: all conversions are done in this interface
149 // to the CosmicGun. The CosmicGun itself uses GeV units internally - to call
150 // the fortran code.
151 //
152
153 m_GeV = 1000;
154 m_mm = 10;
155 m_readfile = false;
156 m_exzCut = false;
157 m_tuple = 0;
158 m_tuple1 = 0;
159 declareProperty( "eventfile", m_infile = "NONE" );
160 declareProperty( "emin", m_emin = 0.1 );
161 declareProperty( "emax", m_emax = 10. );
162 declareProperty( "xvert_low", m_xlow = -110.7 ); // EMC BSCRmax2
163 declareProperty( "xvert_hig", m_xhig = 110.7 );
164 declareProperty( "zvert_low", m_zlow = -171.2 ); // EMC WorldZposition+0.5*CrystalLength
165 declareProperty( "zvert_hig", m_zhig = 171.2 );
166 declareProperty( "yvert_val", m_yval = 0 );
167 declareProperty( "tmin", m_tmin = 0. );
168 declareProperty( "tmax", m_tmax = 24. );
169 declareProperty( "tcor", m_tcor = 0. );
170 declareProperty( "IPx", m_IPx = 0. );
171 declareProperty( "IPy", m_IPy = 0. );
172 declareProperty( "IPz", m_IPz = 0. );
173 declareProperty( "Radius", m_radius = 0. );
174 declareProperty( "ExzCut", m_exzCut );
175 declareProperty( "CubeProjection", m_cubeProj = true );
176 declareProperty( "OptimizeSphere", m_sphereOpt = false );
177
178 declareProperty( "SwapYZAxis", m_swapYZAxis = false );
179 declareProperty( "ctcut", m_ctcut = 0.0 ); // according to sin(acos(0.93)) =0.368
180 // declareProperty("ReadTTR", m_readTTR =false );
181 // declareProperty("ReadTR", m_readTTR =false );
182 declareProperty( "PrintEvent", m_printEvent = 10 );
183 declareProperty( "PrintMod", m_printMod = 100 );
184 declareProperty( "RMax", m_rmax = 10000000. );
185 declareProperty( "ThetaMin", m_thetamin = 0. );
186 declareProperty( "ThetaMax", m_thetamax = 1. );
187 declareProperty( "PhiMin", m_phimin = -1 * PI );
188 declareProperty( "PhiMax", m_phimax = PI );
189 declareProperty( "Xposition", m_xpos = 263.5 - 0.0001 ); // 263.5*cm,263.5*cm,287.5*cm
190 declareProperty( "Yposition", m_ypos = 263.5 - 0.0001 );
191 declareProperty( "Zposition", m_zpos = 287.5 - 0.0001 );
192
193 declareProperty( "DoublePlaneTrigger", m_doublePlaneTrigger = false );
194 declareProperty( "xMinTop", m_xposMin_top = -16 ); // in cm
195 declareProperty( "xMaxTop", m_xposMax_top = 16 ); // in cm
196 declareProperty( "yTop", m_ypos_top = 52 ); // in cm
197 declareProperty( "zMinTop", m_zposMin_top = -25 ); // in cm
198 declareProperty( "zMaxTop", m_zposMax_top = 25 ); // in cm
199 declareProperty( "xMinBottom", m_xposMin_bottom = -8 ); // in cm
200 declareProperty( "xMaxBottom", m_xposMax_bottom = 8 ); // in cm
201 declareProperty( "yBottom", m_ypos_bottom = -26 ); // in cm
202 declareProperty( "zMinBottom", m_zposMin_bottom = -25 ); // in cm
203 declareProperty( "zMaxBottom", m_zposMax_bottom = 25 ); // in cm
204
205 declareProperty( "DumpMC", m_dumpMC = 0 );
206}
#define PI

Referenced by CosmicGenerator().

◆ ~CosmicGenerator()

CosmicGenerator::~CosmicGenerator ( )

Definition at line 209 of file CosmicGenerator.cxx.

211{}

Member Function Documentation

◆ execute()

StatusCode CosmicGenerator::execute ( )

Definition at line 387 of file CosmicGenerator.cxx.

387 {
388 //---------------------------------------------------------------------------
389 MsgStream log( msgSvc(), name() );
390 log << MSG::INFO << "CosmicGenerator executing" << endmsg;
391
392 ++m_events;
393 // MsgStream log(msgSvc(), name());
394 log << MSG::DEBUG << "Event #" << m_events << endmsg;
395
396 // clear up the vectors
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 // units are already converted to MeV's and mm.
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;
439 CosmicGun* gun = CosmicGun::GetCosmicGun();
440 HepLorentzVector vert;
441 HepLorentzVector vert_proj;
442 while ( !accepted )
443 {
444 m_tried++;
445 vert = generateVertex();
446 Hep3Vector vert3( vert.x(), vert.y(), vert.z() );
447
448 pp = gun->GenerateEvent();
449 if ( m_dumpMC == 1 )
450 {
451 m_cosmicE = pp.e() * m_GeV;
452 m_cosmicTheta = pp.theta();
453 m_cosmicPhi = pp.phi();
454 m_cosmicCharge = gun->GetMuonCharge();
455 m_tuple->write();
456 }
457 double theta1 = pp.theta();
458 double phi1 = pp.phi();
459 double mag1 = pp.vect().mag();
460
461 Hep3Vector pp_corr( mag1 * sin( theta1 ) * cos( phi1 ), -mag1 * cos( theta1 ),
462 mag1 * sin( theta1 ) * sin( phi1 ) );
463 Hep3Vector direction( pp_corr.x(), pp_corr.y(), pp_corr.z() );
464 Hep3Vector center_dir = m_center - vert3;
465 // if optimization activated, check for the direction of the generated muon
466
467 if ( m_cubeProj )
468 {
469 double alpha, beta;
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;
491 HepPoint3D vert_pro0;
492 HepPoint3D vert_pro1;
493 HepPoint3D vert_pro2;
494 HepPoint3D vert_org( vert3 );
495
496 coor_y0 = m_ypos; // defined in jobOpt.
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; // defined in jobOpt.
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; // defined in jobOpt.
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 // reset vert(x,y,z,t), after projection
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; // intersection with the top plane
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; // intersection with the bottom plane
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; // if no opt required accept the first muon
581 }
582
583 // pp.setX(pp.x()*m_GeV);
584 // pp.setY(pp.y()*m_GeV);
585 // pp.setZ(pp.z()*m_GeV);
586 // pp.setT(pp.t()*m_GeV);
587
588 pp.setX( pp.x() );
589 pp.setY( pp.y() );
590 pp.setZ( pp.z() );
591 pp.setT( pp.t() );
592 // Get the mass of the particle to be generated
593 int charge = gun->GetMuonCharge();
594 // m_pdgCode.push_back(charge*13);
595 m_pdgCode.push_back( charge * -13 );
596
597 // const ParticleData* pdtparticle =
598 // m_particleTable->particle(ParticleID(abs(m_pdgCode.back()))); double mass =
599 // pdtparticle->mass().value(); double mass =105.5658;
600
601 // Compute the kinematic values. First, the vertex 4-vector:
602
603 // Set the polarization. Realistically, this is going to be zero
604 // for most studies, but you never know...
605 double polx = 0;
606 double poly = 0;
607 double polz = 0;
608 // m_polarization.set_normal3d(HepNormal3D(polx,poly,polz));
609 Polarization thePolarization;
610
611 // Do we need to swap Y- and Z-axis for the PixelEndCap C Cosmic test ?
612 // if not...do nothing...if so, invert position of y- and z- coordinate
613 //
614 // well and don't forget about the direction of the incoming cosmic muon(s) either
615 // that means: y -> -y
616 //
617 if ( !m_swapYZAxis )
618 {
619 // thePolarization.set_normal3d(HepNormal3D(polx,-poly,polz));
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 // The method of calculating e, theta, and phi depends on the user's
627 // commands. Let the KinematicManager handle it.
628 double e = pp.e();
629 double theta = pp.theta();
630 double phi = pp.phi();
631
632 // At this point, we have e, theta, and phi. Put them together to
633 // get the four-momentum.
634
635 double p2 = e * e - mass * mass;
636 if ( p2 < 0 )
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 // Do we need to swap Y- and Z-axis for the PixelEndCap C Cosmic test ?
650 // if not...do nothing...if so, invert position of y- and z- coordinate
651 //
652 // well and don't forget about the direction of the incoming cosmic muon(s) either
653 // that means: y -> -y
654 //
655 if ( !m_swapYZAxis )
656 {
657 // Line below corrupted py sign and forces muons to be upwards, not downwards.
658 // m_fourMom.push_back(HepLorentzVector(px,-py,pz,pp.e()));
659 m_fourMom.push_back( HepLorentzVector( px, py, pz, pp.e() ) );
660 }
661 else m_fourMom.push_back( HepLorentzVector( px, pz, -py, pp.e() ) );
662 double x = vert.x();
663 double y = vert.y();
664 double z = vert.z();
665 double t = vert.t();
666 if ( projected )
667 {
668
669 x = vert_proj.x();
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 // log << MSG::DEBUG
675 // << "proj:"<<m_cubeProj<<" ("<<x<<", "<<y<<", "<<z<<", "<<t<<")"
676 // <<endmsg;
677 // Do we need to swap Y- and Z-axis for the PixelEndCap A Cosmic test ?
678 // if not...do nothing...if so, invert position of y- and z- coordinate
679 //
680 // but not only that...change also the direction of the incoming cosmic muon(s),
681 // they must go towards the pixel endcap A, i.e. y -> -y
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 // m_cosmicE=pp.e()*m_GeV;
698 // m_cosmicTheta=pp.theta();
699 // m_cosmicPhi=pp.phi();
700 // m_cosmicCharge=gun->GetMuonCharge();
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 // m_cosmicE=pz;
707 m_tuple1->write();
708 }
709 }
710
711 // fill evt
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 // Note: The vertex and particle are owned by the event, so the
722 // event is responsible for those pointers.
723
724 // Create the particle, and specify its polarization.
725
726 GenParticle* particle = new GenParticle( m_fourMom[v], m_pdgCode[v], 1 );
727 particle->set_polarization( m_polarization[v] );
728
729 // Create the vertex, and add the particle to the vertex.
730 GenVertex* vertex = new GenVertex( m_fourPos[v] );
731 vertex->add_particle_out( particle );
732
733 // Add the vertex to the event.
734 event->add_vertex( vertex );
735 }
736
737 event->set_event_number( m_events ); // Set the event number
738 }
739 else
740 {
741
742 log << MSG::ERROR << "Wrong different number of vertexes/momenta/polaritazions!" << endmsg;
743 return StatusCode::FAILURE;
744 }
745 // Check if the McCollection already exists
746 SmartDataPtr<McGenEventCol> anMcCol( eventSvc(), "/Event/Gen" );
747 if ( anMcCol != 0 )
748 {
749 // Add event to existing collection
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 // Create Collection and add to the transient store
758 McGenEventCol* mcColl = new McGenEventCol;
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}
double p2[4]
double mass
HepGeom::Point3D< double > HepPoint3D
HepGeom::Normal3D< float > HepNormal3D
Double_t x[10]
Double_t phi1
ObjectVector< McGenEvent > McGenEventCol
double alpha
**********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
Definition KarLud.h:35
IMessageSvc * msgSvc()
const HepLorentzVector & Vertex(void)
const HepLorentzVector & Momentum(void)
HepLorentzVector generateVertex(void)
int GetMuonCharge(void)
HepLorentzVector GenerateEvent(void)
static CosmicGun * GetCosmicGun(void)
Definition CosmicGun.cxx:49
int t()
Definition t.c:1

◆ finalize()

StatusCode CosmicGenerator::finalize ( )

Definition at line 776 of file CosmicGenerator.cxx.

776 {
777 //---------------------------------------------------------------------------
778 // Get the KinematicManager.
779
780 if ( m_cubeProj )
781 {
782
783 MsgStream log( msgSvc(), name() );
784
785 log << MSG::INFO << "***************************************************" << endmsg;
786 log << MSG::INFO << "** you have run CosmicGenerator with some " << endmsg;
787 log << MSG::INFO << "** filters for cosmic muon simulation" << endmsg;
788 log << MSG::INFO << "** " << m_tried << " muons were tried" << endmsg;
789 log << MSG::INFO << "** " << m_accepted << " muons were accepted" << endmsg;
790 log << MSG::INFO << "** " << m_rejected << " muons were rejected" << endmsg;
791 log << MSG::INFO << "***************************************************" << endmsg;
792 std::cout << "***************************************************" << std::endl;
793 std::cout << "** you have run CosmicGenerator with some " << std::endl;
794 std::cout << "** filters for cosmic muon simulation" << std::endl;
795 std::cout << "** " << m_tried << " muons were tried" << std::endl;
796 std::cout << "** " << m_accepted << " muons were accepted" << std::endl;
797 std::cout << "** " << m_rejected << " muons were rejected" << std::endl;
798 std::cout << "***************************************************" << std::endl;
799 }
800
801 return StatusCode::SUCCESS;
802}

◆ generateVertex()

HepLorentzVector CosmicGenerator::generateVertex ( void )

Definition at line 361 of file CosmicGenerator.cxx.

361 {
362
363 MsgStream log( msgSvc(), name() );
364
365 // Get the pointer to the engine of the stream named SINGLE. If the
366 // stream does not exist is created automaticaly
367 // HepRandomEngine* engine = CosmicGenerator::p_AtRndmGenSvc->GetEngine("COSMICS");
368 HepRandomEngine* engine = CosmicGenerator::p_BesRndmGenSvc->GetEngine( "PYTHIA" );
369 // Generate a random number according to the distribution.
370
371 float x_val = RandFlat::shoot( engine, m_xlow, m_xhig );
372 float z_val = RandFlat::shoot( engine, m_zlow, m_zhig );
373
374 // Generate a random number for time offset
375 float t_val = 0;
376 if ( m_tmin < m_tmax ) { t_val = RandFlat::shoot( engine, m_tmin, m_tmax ); }
377 else if ( m_tmin == m_tmax ) { t_val = m_tmin; }
378 else
379 log << MSG::FATAL << " You specified m_tmin = " << m_tmin << " and m_tmax " << m_tmax
380 << endmsg;
381 HepLorentzVector p( x_val, m_yval, z_val, t_val * c_light );
382
383 return p;
384}
static IBesRndmGenSvc * p_BesRndmGenSvc
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.

Referenced by execute().

◆ initialize()

StatusCode CosmicGenerator::initialize ( )

Definition at line 214 of file CosmicGenerator.cxx.

214 {
215 //---------------------------------------------------------------------------
216
217 // Initialize event count.
218
219 m_events = 0;
220 m_tried = 0;
221 m_accepted = 0;
222 m_rejected = 0;
223 if ( m_emin < 0.1 )
224 {
225 m_emin = 0.1;
226 std::cout << "WARNING: set emin to 0.1 GeV" << std::endl;
227 }
228 m_emin = m_emin * m_GeV;
229 m_emax = m_emax * m_GeV;
230 m_xlow = m_xlow * m_mm;
231 m_xhig = m_xhig * m_mm;
232 m_zlow = m_zlow * m_mm;
233 m_zhig = m_zhig * m_mm;
234 m_yval = m_yval * m_mm;
235 m_xpos = m_xpos * m_mm;
236 m_ypos = m_ypos * m_mm;
237 m_zpos = m_zpos * m_mm;
238 m_radius = m_radius * m_mm;
239 m_tcor = m_tcor + sqrt( ( m_xpos - m_xlow ) * ( m_xpos - m_xlow ) +
240 ( m_zpos - m_zlow ) * ( m_zpos - m_zlow ) +
241 ( m_ypos - m_yval ) * ( m_ypos - m_yval ) ) /
242 ( m_emin / sqrt( m_emin * m_emin + mass * mass * m_GeV * m_GeV ) );
243
244 m_xposMin_top *= m_mm;
245 m_xposMax_top *= m_mm;
246 m_ypos_top *= m_mm;
247 m_zposMin_top *= m_mm;
248 m_zposMax_top *= m_mm;
249 m_xposMin_bottom *= m_mm;
250 m_xposMax_bottom *= m_mm;
251 m_ypos_bottom *= m_mm;
252 m_zposMin_bottom *= m_mm;
253 m_zposMax_bottom *= m_mm;
254
255 ISvcLocator* svcLocator = Gaudi::svcLocator(); // from Bootstrap.h
256 p_msgSvc = 0;
257 StatusCode result = svcLocator->service( "MessageSvc", p_msgSvc );
258
259 if ( !result.isSuccess() || p_msgSvc == 0 )
260 {
261 std::cerr << "VGenCommand(): could not initialize MessageSvc!" << std::endl;
262 throw GaudiException( "Could not initalize MessageSvc", "CosmicGenerator",
263 StatusCode::FAILURE );
264 }
265
266 MsgStream log( p_msgSvc, "CosmicGenerator" );
267 if ( m_dumpMC == 1 )
268 {
269 StatusCode status;
270 NTuplePtr nt( ntupleSvc(), "FILE1/comp" );
271 if ( nt ) m_tuple = nt;
272 else
273 {
274 m_tuple = ntupleSvc()->book( "FILE1/comp", CLID_ColumnWiseTuple, "ks N-Tuple example" );
275 if ( m_tuple )
276 {
277 status = m_tuple->addItem( "cosmic_e", m_cosmicE );
278 status = m_tuple->addItem( "cosmic_theta", m_cosmicTheta );
279 status = m_tuple->addItem( "cosmic_phi", m_cosmicPhi );
280 status = m_tuple->addItem( "cosmic_charge", m_cosmicCharge );
281 }
282 else
283 {
284 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple ) << endmsg;
285 return StatusCode::FAILURE;
286 }
287 }
288 NTuplePtr nt1( ntupleSvc(), "FILE1/compp" );
289 if ( nt1 ) m_tuple1 = nt1;
290 else
291 {
292 m_tuple1 =
293 ntupleSvc()->book( "FILE1/compp", CLID_ColumnWiseTuple, "ks N-Tuple example" );
294 if ( m_tuple1 )
295 {
296 status = m_tuple1->addItem( "mc_theta", mc_theta );
297 status = m_tuple1->addItem( "mc_phi", mc_phi );
298 status = m_tuple1->addItem( "mc_px", mc_px );
299 status = m_tuple1->addItem( "mc_py", mc_py );
300 status = m_tuple1->addItem( "mc_pz", mc_pz );
301 }
302 else
303 {
304 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
305 return StatusCode::FAILURE;
306 }
307 }
308 }
309 if ( m_infile == "NONE" )
310
311 {
312 // Initialize the BES random number services.
313
314 static const bool CREATEIFNOTTHERE( true );
315 StatusCode RndmStatus =
316 svcLocator->service( "BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE );
317
318 if ( !RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc )
319 {
320 log << MSG::ERROR << " Could not initialize Random Number Service" << endmsg;
321 return RndmStatus;
322 }
323
324 CosmicGun* gun = CosmicGun::GetCosmicGun();
325
326 gun->SetEnergyRange( m_emin / m_GeV, m_emax / m_GeV );
327 gun->SetCosCut( m_ctcut );
328 gun->PrintLevel( m_printEvent, m_printMod );
329 float flux_withCT = gun->InitializeGenerator();
330
331 log << MSG::INFO << "Initialisation cosmic gun done." << endmsg;
332 log << MSG::INFO << "Accepted diff flux after E and cos(theta) cuts = " << flux_withCT
333 << " /cm^2/s" << endmsg;
334 log << MSG::INFO << "Accepted total flux after E and cos(theta) cuts = "
335 << flux_withCT * ( m_xhig - m_xlow ) / m_mm * ( m_zhig - m_zlow ) / m_mm << " /s"
336 << endmsg;
337
338 std::cout << "Accepted diff flux after E and cos(theta) cuts = " << flux_withCT
339 << " /cm^2/s" << std::endl;
340 std::cout << "Accepted total flux after E and cos(theta) cuts = "
341 << flux_withCT * ( m_xhig - m_xlow ) / m_mm * ( m_zhig - m_zlow ) / m_mm << " /s"
342 << std::endl;
343 }
344 else
345 {
346 log << MSG::INFO << "Cosmics are read from file " << m_infile << endmsg;
347 m_ffile.open( m_infile.c_str() );
348 if ( !m_ffile )
349 {
350 log << MSG::FATAL << "Could not open input file - stop! " << endmsg;
351 return StatusCode::FAILURE;
352 }
353 m_readfile = true;
354 }
355
356 m_center = Hep3Vector( m_IPx, m_IPy, m_IPz );
357 log << MSG::INFO << "Initialisation done" << endmsg;
358 return StatusCode::SUCCESS;
359}
INTupleSvc * ntupleSvc()
void PrintLevel(int printevt, int printmod)
Definition CosmicGun.cxx:88
void SetEnergyRange(float emin, float emax)
float InitializeGenerator()
Definition CosmicGun.cxx:79
void SetCosCut(float ctcut)

Member Data Documentation

◆ p_BesRndmGenSvc

IBesRndmGenSvc * CosmicGenerator::p_BesRndmGenSvc = 0
static

Definition at line 55 of file CosmicGenerator.h.

Referenced by cosmicrndm_(), generateVertex(), and initialize().


The documentation for this class was generated from the following files: