BOSS 7.1.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 51 of file CosmicGenerator.h.

Constructor & Destructor Documentation

◆ CosmicGenerator()

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

Definition at line 154 of file CosmicGenerator.cxx.

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

◆ ~CosmicGenerator()

CosmicGenerator::~CosmicGenerator ( )

Definition at line 221 of file CosmicGenerator.cxx.

223{}

Member Function Documentation

◆ execute()

StatusCode CosmicGenerator::execute ( )

Definition at line 387 of file CosmicGenerator.cxx.

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

◆ finalize()

StatusCode CosmicGenerator::finalize ( )

Definition at line 801 of file CosmicGenerator.cxx.

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

◆ generateVertex()

HepLorentzVector CosmicGenerator::generateVertex ( void  )

Definition at line 358 of file CosmicGenerator.cxx.

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

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