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;
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));
255 m_xposMin_bottom*=m_mm;
256 m_xposMax_bottom*=m_mm;
258 m_zposMin_bottom*=m_mm;
259 m_zposMax_bottom*=m_mm;
261 ISvcLocator* svcLocator = Gaudi::svcLocator();
263 StatusCode result = svcLocator->service(
"MessageSvc", p_msgSvc);
265 if ( !result.isSuccess() || p_msgSvc == 0 )
267 std::cerr <<
"VGenCommand(): could not initialize MessageSvc!" << std::endl;
268 throw GaudiException(
"Could not initalize MessageSvc",
"CosmicGenerator",StatusCode::FAILURE);
271 MsgStream log (p_msgSvc,
"CosmicGenerator");
277 m_tuple =
ntupleSvc()->book (
"FILE1/comp", CLID_ColumnWiseTuple,
"ks N-Tuple example");
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);
285 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple) << endmsg;
286 return StatusCode::FAILURE;
289 NTuplePtr nt1(
ntupleSvc(),
"FILE1/compp");
290 if(nt1) m_tuple1 = nt1;
292 m_tuple1 =
ntupleSvc()->book (
"FILE1/compp", CLID_ColumnWiseTuple,
"ks N-Tuple example");
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);
301 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
302 return StatusCode::FAILURE;
311 static const bool CREATEIFNOTTHERE(
true);
312 StatusCode RndmStatus = svcLocator->service(
"BesRndmGenSvc",
p_BesRndmGenSvc, CREATEIFNOTTHERE);
316 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
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;
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;
341 log << MSG::INFO <<
"Cosmics are read from file " << m_infile << endreq;
342 m_ffile.open(m_infile.c_str());
345 log << MSG::FATAL <<
"Could not open input file - stop! " << endreq;
346 return StatusCode::FAILURE;
351 m_center=Hep3Vector(m_IPx, m_IPy, m_IPz);
352 log << MSG::INFO <<
"Initialisation done" << endreq;
353 return StatusCode::SUCCESS;
388 MsgStream log(messageService(), name());
389 log << MSG::INFO <<
"CosmicGenerator executing" << endreq;
394 log << MSG::DEBUG <<
"Event #" << m_events << endreq;
400 m_polarization.clear();
411 std::cout << evt << std::endl;
416 Polarization thePolarization;
417 thePolarization.set_normal3d(
HepNormal3D(polx,poly,polz));
418 m_polarization.push_back(thePolarization);
423 m_fourPos.push_back(evt.
Vertex());
424 m_fourMom.push_back(evt.
Momentum());
425 m_pdgCode.push_back(evt.
pdgID());
430 log << MSG::FATAL <<
"End of file reached - stop " << endreq;
432 return StatusCode::FAILURE;
440 bool projected=
false;
443 HepLorentzVector vert;
444 HepLorentzVector vert_proj;
448 Hep3Vector vert3(vert.x(),vert.y(),vert.z());
452 m_cosmicE=pp.e()*m_GeV;
453 m_cosmicTheta=pp.theta();
454 m_cosmicPhi=pp.phi();
459 double phi1=pp.phi();
460 double mag1=pp.vect().mag();
465 Hep3Vector direction(pp_corr.x(),pp_corr.y(), pp_corr.z());
466 Hep3Vector center_dir=m_center-vert3;
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;
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;
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();
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);
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();
512 vert_pro1=
HepPoint3D (coor_x1, coor_y1, coor_z1);
513 l_fight1=vert_org.distance(vert_pro1);
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)
528 vert_proj=HepLorentzVector (vert_pro0.x(),vert_pro0.y(),vert_pro0.z() , l_fight0);
535 vert_proj=HepLorentzVector (vert_pro1.x(),vert_pro1.y(),vert_pro1.z() , l_fight1);
542 vert_proj=HepLorentzVector (vert_pro2.x(),vert_pro2.y(),vert_pro2.z() , l_fight2);
548 log<<MSG::DEBUG<<
" rejected muon due to cube projection request! "<<endreq;
556 else if(m_doublePlaneTrigger)
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();
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();
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)
591 m_pdgCode.push_back(charge*-13);
606 Polarization thePolarization;
616 thePolarization.set_normal3d(
HepNormal3D(polx,poly,polz));
619 thePolarization.set_normal3d(
HepNormal3D(polx,polz,-poly));
621 m_polarization.push_back(thePolarization);
627 double theta = pp.theta();
628 double phi = pp.phi();
637 <<
"Event #" << m_events
638 <<
" E=" << e <<
", mass=" <<
mass
639 <<
" -- you have generated a tachyon! Increase energy or change particle ID."
641 return StatusCode::FAILURE;
645 double px = p*
sin(theta)*
cos(phi);
646 double pz = p*
sin(theta)*
sin(phi);
647 double py = -p*
cos(theta);
660 m_fourMom.push_back(HepLorentzVector(px,py,pz,pp.e()));
663 m_fourMom.push_back(HepLorentzVector(px,pz,-py,pp.e()));
673 t = vert.t()-vert_proj.t()/HepLorentzVector(px,py,pz,pp.e()).beta()
691 m_fourPos.push_back(HepLorentzVector(
x,y,z,
t));
693 m_fourPos.push_back(HepLorentzVector(
x,z,y,
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() <<
")"
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() <<
")"
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();
730 GenEvent*
event =
new GenEvent(1,1);
732 if(m_fourMom.size()==m_fourPos.size()&&m_fourMom.size()==m_polarization.size()){
734 for(std::size_t
v=0;
v<m_fourMom.size();++
v){
741 GenParticle* particle =
new GenParticle( m_fourMom[
v], m_pdgCode[
v], 1);
742 particle->set_polarization( m_polarization[
v] );
745 GenVertex* vertex =
new GenVertex(m_fourPos[
v]);
746 vertex->add_particle_out( particle );
749 event->add_vertex( vertex );
753 event->set_event_number(m_events);
759 log<<MSG::ERROR<<
"Wrong different number of vertexes/momenta/polaritazions!"<<endreq;
760 return StatusCode::FAILURE;
763 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(),
"/Event/Gen");
768 log << MSG::INFO <<
"Add McGenEvent to existing collection" << endreq;
770 anMcCol->push_back(mcEvent);
777 mcColl->push_back(mcEvent);
778 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
779 if (sc != StatusCode::SUCCESS)
781 log << MSG::ERROR <<
"Could not register McGenEvent" << endreq;
785 return StatusCode::FAILURE;
794 return StatusCode::SUCCESS;