CGEM BOSS 6.6.5.g
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 51 of file CosmicGenerator.h.

Constructor & Destructor Documentation

◆ CosmicGenerator()

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

Definition at line 153 of file CosmicGenerator.cxx.

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

◆ ~CosmicGenerator()

CosmicGenerator::~CosmicGenerator ( )

Definition at line 220 of file CosmicGenerator.cxx.

222{}

Member Function Documentation

◆ execute()

StatusCode CosmicGenerator::execute ( )

Definition at line 386 of file CosmicGenerator.cxx.

386 {
387//---------------------------------------------------------------------------
388 MsgStream log(messageService(), name());
389 log << MSG::INFO << "CosmicGenerator executing" << endreq;
390
391
392 ++m_events;
393 // MsgStream log(messageService(), name());
394 log << MSG::DEBUG << "Event #" << m_events << endreq;
395
396
397 // clear up the vectors
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 // units are already converted to MeV's and mm.
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++;
447 vert = generateVertex();
448 Hep3Vector vert3(vert.x(),vert.y(),vert.z());
449
450 pp = gun->GenerateEvent();
451 if(m_dumpMC==1) {
452 m_cosmicE=pp.e()*m_GeV;
453 m_cosmicTheta=pp.theta();
454 m_cosmicPhi=pp.phi();
455 m_cosmicCharge=gun->GetMuonCharge();
456 m_tuple->write();
457 }
458 double theta1=pp.theta();
459 double phi1=pp.phi();
460 double mag1=pp.vect().mag();
461
462 Hep3Vector pp_corr(mag1*sin(theta1)*cos(phi1),
463 -mag1*cos(theta1),
464 mag1*sin(theta1)*sin(phi1));
465 Hep3Vector direction(pp_corr.x(),pp_corr.y(), pp_corr.z());
466 Hep3Vector center_dir=m_center-vert3;
467 // if optimization activated, check for the direction of the generated muon
468
469
470 if (m_cubeProj) {
471 double alpha,beta;
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;
490 HepPoint3D vert_pro0;
491 HepPoint3D vert_pro1;
492 HepPoint3D vert_pro2;
493 HepPoint3D vert_org(vert3);
494
495 coor_y0 = m_ypos; // defined in jobOpt.
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; // defined in jobOpt.
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; // 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)
522 isIn1=true;
523 else
524 isIn2=true;
525 }
526 //reset vert(x,y,z,t), after projection
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;// intersection with the top plane
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;// intersection with the bottom plane
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; // if no opt required accept the first muon
577 }
578
579 // pp.setX(pp.x()*m_GeV);
580 // pp.setY(pp.y()*m_GeV);
581 // pp.setZ(pp.z()*m_GeV);
582 // pp.setT(pp.t()*m_GeV);
583
584 pp.setX(pp.x());
585 pp.setY(pp.y());
586 pp.setZ(pp.z());
587 pp.setT(pp.t());
588 // Get the mass of the particle to be generated
589 int charge = gun->GetMuonCharge();
590 // m_pdgCode.push_back(charge*13);
591 m_pdgCode.push_back(charge*-13);
592
593 // const ParticleData* pdtparticle = m_particleTable->particle(ParticleID(abs(m_pdgCode.back())));
594 // double mass = pdtparticle->mass().value();
595 // double mass =105.5658;
596
597 // Compute the kinematic values. First, the vertex 4-vector:
598
599
600 // Set the polarization. Realistically, this is going to be zero
601 // for most studies, but you never know...
602 double polx = 0;
603 double poly = 0;
604 double polz = 0;
605 //m_polarization.set_normal3d(HepNormal3D(polx,poly,polz));
606 Polarization thePolarization;
607
608 // Do we need to swap Y- and Z-axis for the PixelEndCap C Cosmic test ?
609 // if not...do nothing...if so, invert position of y- and z- coordinate
610 //
611 // well and don't forget about the direction of the incoming cosmic muon(s) either
612 // that means: y -> -y
613 //
614 if(!m_swapYZAxis){
615 // thePolarization.set_normal3d(HepNormal3D(polx,-poly,polz));
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 // The method of calculating e, theta, and phi depends on the user's
625 // commands. Let the KinematicManager handle it.
626 double e = pp.e();
627 double theta = pp.theta();
628 double phi = pp.phi();
629
630 // At this point, we have e, theta, and phi. Put them together to
631 // get the four-momentum.
632
633 double p2 = e*e - mass*mass;
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 // Do we need to swap Y- and Z-axis for the PixelEndCap C Cosmic test ?
652 // if not...do nothing...if so, invert position of y- and z- coordinate
653 //
654 // well and don't forget about the direction of the incoming cosmic muon(s) either
655 // that means: y -> -y
656 //
657 if(!m_swapYZAxis) {
658 // Line below corrupted py sign and forces muons to be upwards, not downwards.
659 // m_fourMom.push_back(HepLorentzVector(px,-py,pz,pp.e()));
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()));
664 double x = vert.x();
665 double y = vert.y();
666 double z = vert.z();
667 double t = vert.t();
668 if(projected){
669
670 x = vert_proj.x();
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 // log << MSG::DEBUG
680 // << "proj:"<<m_cubeProj<<" ("<<x<<", "<<y<<", "<<z<<", "<<t<<")"
681 // <<endreq;
682 // Do we need to swap Y- and Z-axis for the PixelEndCap A Cosmic test ?
683 // if not...do nothing...if so, invert position of y- and z- coordinate
684 //
685 // but not only that...change also the direction of the incoming cosmic muon(s),
686 // they must go towards the pixel endcap A, i.e. y -> -y
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// m_cosmicE=pp.e()*m_GeV;
715// m_cosmicTheta=pp.theta();
716// m_cosmicPhi=pp.phi();
717// m_cosmicCharge=gun->GetMuonCharge();
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 // m_cosmicE=pz;
724 m_tuple1->write();
725 }
726 }
727
728// fill evt
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 // Note: The vertex and particle are owned by the event, so the
737 // event is responsible for those pointers.
738
739 // Create the particle, and specify its polarization.
740
741 GenParticle* particle = new GenParticle( m_fourMom[v], m_pdgCode[v], 1);
742 particle->set_polarization( m_polarization[v] );
743
744 // Create the vertex, and add the particle to the vertex.
745 GenVertex* vertex = new GenVertex(m_fourPos[v]);
746 vertex->add_particle_out( particle );
747
748 // Add the vertex to the event.
749 event->add_vertex( vertex );
750
751 }
752
753 event->set_event_number(m_events); // Set the event number
754
755
756
757 } else {
758
759 log<<MSG::ERROR<<"Wrong different number of vertexes/momenta/polaritazions!"<<endreq;
760 return StatusCode::FAILURE;
761 }
762 // Check if the McCollection already exists
763 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
764 if (anMcCol!=0)
765 {
766 // Add event to existing collection
767
768 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
769 McGenEvent* mcEvent = new McGenEvent(event);
770 anMcCol->push_back(mcEvent);
771 }
772 else
773 {
774 // Create Collection and add to the transient store
775 McGenEventCol *mcColl = new McGenEventCol;
776 McGenEvent* mcEvent = new McGenEvent(event);
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)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double mass
HepGeom::Point3D< double > HepPoint3D
HepGeom::Normal3D< float > HepNormal3D
Double_t x[10]
Double_t phi1
const 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
ObjectVector< McGenEvent > McGenEventCol
Definition: McGenEvent.h:39
@ theta1
Definition: TrkKalDeriv.h:24
const HepLorentzVector & Vertex(void)
const HepLorentzVector & Momentum(void)
HepLorentzVector generateVertex(void)
int GetMuonCharge(void)
Definition: CosmicGun.cxx:134
HepLorentzVector GenerateEvent(void)
Definition: CosmicGun.cxx:109
static CosmicGun * GetCosmicGun(void)
Definition: CosmicGun.cxx:49
int t()
Definition: t.c:1

◆ finalize()

StatusCode CosmicGenerator::finalize ( )

Definition at line 800 of file CosmicGenerator.cxx.

800 {
801//---------------------------------------------------------------------------
802 // Get the KinematicManager.
803
804 if(m_cubeProj) {
805
806 MsgStream log(messageService(), name());
807
808 log << MSG::INFO<<"***************************************************"<<endreq;
809 log << MSG::INFO <<"** you have run CosmicGenerator with some " <<endreq;
810 log << MSG::INFO <<"** filters for cosmic muon simulation" <<endreq;
811 log << MSG::INFO <<"** "<<m_tried<<" muons were tried" <<endreq;
812 log << MSG::INFO <<"** "<<m_accepted<<" muons were accepted" <<endreq;
813 log << MSG::INFO <<"** "<<m_rejected<<" muons were rejected" <<endreq;
814 log << MSG::INFO<<"***************************************************"<<endreq;
815 std::cout<<"***************************************************"<<std::endl;
816 std::cout <<"** you have run CosmicGenerator with some " <<std::endl;
817 std::cout <<"** filters for cosmic muon simulation" <<std::endl;
818 std::cout <<"** "<<m_tried<<" muons were tried" <<std::endl;
819 std::cout <<"** "<<m_accepted<<" muons were accepted" <<std::endl;
820 std::cout <<"** "<<m_rejected<<" muons were rejected" <<std::endl;
821 std::cout<<"***************************************************"<<std::endl;
822
823 }
824
825 return StatusCode::SUCCESS;
826}

◆ generateVertex()

HepLorentzVector CosmicGenerator::generateVertex ( void  )

Definition at line 357 of file CosmicGenerator.cxx.

357 {
358
359 MsgStream log(messageService(), name());
360
361 // Get the pointer to the engine of the stream named SINGLE. If the
362 // stream does not exist is created automaticaly
363// HepRandomEngine* engine = CosmicGenerator::p_AtRndmGenSvc->GetEngine("COSMICS");
364 HepRandomEngine* engine = CosmicGenerator::p_BesRndmGenSvc->GetEngine("PYTHIA");
365 // Generate a random number according to the distribution.
366
367 float x_val = RandFlat::shoot(engine, m_xlow, m_xhig);
368 float z_val = RandFlat::shoot(engine, m_zlow, m_zhig);
369
370 // Generate a random number for time offset
371 float t_val=0;
372 if(m_tmin < m_tmax){
373 t_val = RandFlat::shoot(engine, m_tmin, m_tmax);
374 }
375 else if(m_tmin == m_tmax){
376 t_val = m_tmin;
377 }
378 else log << MSG::FATAL << " You specified m_tmin = " << m_tmin << " and m_tmax " << m_tmax << endreq;
379 HepLorentzVector p(x_val,m_yval,z_val, t_val*c_light);
380
381 return p;
382
383}
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 225 of file CosmicGenerator.cxx.

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

Member Data Documentation

◆ p_BesRndmGenSvc

IBesRndmGenSvc * CosmicGenerator::p_BesRndmGenSvc = 0
static

Definition at line 62 of file CosmicGenerator.h.

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


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