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;
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));
256 m_xposMin_bottom*=m_mm;
257 m_xposMax_bottom*=m_mm;
259 m_zposMin_bottom*=m_mm;
260 m_zposMax_bottom*=m_mm;
262 ISvcLocator* svcLocator = Gaudi::svcLocator();
264 StatusCode result = svcLocator->service(
"MessageSvc", p_msgSvc);
266 if ( !result.isSuccess() || p_msgSvc == 0 )
268 std::cerr <<
"VGenCommand(): could not initialize MessageSvc!" << std::endl;
269 throw GaudiException(
"Could not initalize MessageSvc",
"CosmicGenerator",StatusCode::FAILURE);
272 MsgStream log (p_msgSvc,
"CosmicGenerator");
278 m_tuple =
ntupleSvc()->book (
"FILE1/comp", CLID_ColumnWiseTuple,
"ks N-Tuple example");
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);
286 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple) << endmsg;
287 return StatusCode::FAILURE;
290 NTuplePtr nt1(
ntupleSvc(),
"FILE1/compp");
291 if(nt1) m_tuple1 = nt1;
293 m_tuple1 =
ntupleSvc()->book (
"FILE1/compp", CLID_ColumnWiseTuple,
"ks N-Tuple example");
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);
302 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
303 return StatusCode::FAILURE;
312 static const bool CREATEIFNOTTHERE(
true);
313 StatusCode RndmStatus = svcLocator->service(
"BesRndmGenSvc",
p_BesRndmGenSvc, CREATEIFNOTTHERE);
317 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
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;
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;
342 log << MSG::INFO <<
"Cosmics are read from file " << m_infile << endreq;
343 m_ffile.open(m_infile.c_str());
346 log << MSG::FATAL <<
"Could not open input file - stop! " << endreq;
347 return StatusCode::FAILURE;
352 m_center=Hep3Vector(m_IPx, m_IPy, m_IPz);
353 log << MSG::INFO <<
"Initialisation done" << endreq;
354 return StatusCode::SUCCESS;
389 MsgStream log(messageService(), name());
390 log << MSG::INFO <<
"CosmicGenerator executing" << endreq;
395 log << MSG::DEBUG <<
"Event #" << m_events << endreq;
401 m_polarization.clear();
412 std::cout << evt << std::endl;
417 Polarization thePolarization;
418 thePolarization.set_normal3d(
HepNormal3D(polx,poly,polz));
419 m_polarization.push_back(thePolarization);
424 m_fourPos.push_back(evt.
Vertex());
425 m_fourMom.push_back(evt.
Momentum());
426 m_pdgCode.push_back(evt.
pdgID());
431 log << MSG::FATAL <<
"End of file reached - stop " << endreq;
433 return StatusCode::FAILURE;
441 bool projected=
false;
444 HepLorentzVector vert;
445 HepLorentzVector vert_proj;
449 Hep3Vector vert3(vert.x(),vert.y(),vert.z());
453 m_cosmicE=pp.e()*m_GeV;
454 m_cosmicTheta=pp.theta();
455 m_cosmicPhi=pp.phi();
460 double phi1=pp.phi();
461 double mag1=pp.vect().mag();
466 Hep3Vector direction(pp_corr.x(),pp_corr.y(), pp_corr.z());
467 Hep3Vector center_dir=m_center-vert3;
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;
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;
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();
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);
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();
513 vert_pro1=
HepPoint3D (coor_x1, coor_y1, coor_z1);
514 l_fight1=vert_org.distance(vert_pro1);
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)
529 vert_proj=HepLorentzVector (vert_pro0.x(),vert_pro0.y(),vert_pro0.z() , l_fight0);
536 vert_proj=HepLorentzVector (vert_pro1.x(),vert_pro1.y(),vert_pro1.z() , l_fight1);
543 vert_proj=HepLorentzVector (vert_pro2.x(),vert_pro2.y(),vert_pro2.z() , l_fight2);
549 log<<MSG::DEBUG<<
" rejected muon due to cube projection request! "<<endreq;
557 else if(m_doublePlaneTrigger)
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();
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();
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)
592 m_pdgCode.push_back(
charge*-13);
607 Polarization thePolarization;
617 thePolarization.set_normal3d(
HepNormal3D(polx,poly,polz));
620 thePolarization.set_normal3d(
HepNormal3D(polx,polz,-poly));
622 m_polarization.push_back(thePolarization);
628 double theta = pp.theta();
629 double phi = pp.phi();
638 <<
"Event #" << m_events
639 <<
" E=" << e <<
", mass=" <<
mass
640 <<
" -- you have generated a tachyon! Increase energy or change particle ID."
642 return StatusCode::FAILURE;
646 double px = p*
sin(theta)*
cos(phi);
647 double pz = p*
sin(theta)*
sin(phi);
648 double py = -p*
cos(theta);
661 m_fourMom.push_back(HepLorentzVector(px,py,pz,pp.e()));
664 m_fourMom.push_back(HepLorentzVector(px,pz,-py,pp.e()));
674 t = vert.t()-vert_proj.t()/HepLorentzVector(px,py,pz,pp.e()).beta()
692 m_fourPos.push_back(HepLorentzVector(
x,
y,z,
t));
694 m_fourPos.push_back(HepLorentzVector(
x,z,
y,
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() <<
")"
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() <<
")"
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();
731 GenEvent*
event =
new GenEvent(1,1);
733 if(m_fourMom.size()==m_fourPos.size()&&m_fourMom.size()==m_polarization.size()){
735 for(std::size_t
v=0;
v<m_fourMom.size();++
v){
742 GenParticle* particle =
new GenParticle( m_fourMom[
v], m_pdgCode[
v], 1);
743 particle->set_polarization( m_polarization[
v] );
746 GenVertex* vertex =
new GenVertex(m_fourPos[
v]);
747 vertex->add_particle_out( particle );
750 event->add_vertex( vertex );
754 event->set_event_number(m_events);
760 log<<MSG::ERROR<<
"Wrong different number of vertexes/momenta/polaritazions!"<<endreq;
761 return StatusCode::FAILURE;
764 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(),
"/Event/Gen");
769 log << MSG::INFO <<
"Add McGenEvent to existing collection" << endreq;
771 anMcCol->push_back(mcEvent);
778 mcColl->push_back(mcEvent);
779 StatusCode sc = eventSvc()->registerObject(
"/Event/Gen",mcColl);
780 if (sc != StatusCode::SUCCESS)
782 log << MSG::ERROR <<
"Could not register McGenEvent" << endreq;
786 return StatusCode::FAILURE;
795 return StatusCode::SUCCESS;