/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/Babayaga/Babayaga-00-00-26/src/Babayaga.cxx

Go to the documentation of this file.
00001 //*****************************************************************************
00002 //
00003 // BABAYAGA.cxx
00004 //
00005 // Algorithm runs BHABHA precess 
00006 //
00007 // July 2007 Rong-Gang Ping to migrate BABAYAGA3.5 for BES3
00008 // The accuracy is about 0.1% (see Nucl. Phys. B 758(2006) 227-253)
00009 //*****************************************************************************
00010 
00011 // Header for this module:-
00012 #include "../Babayaga/Babayaga.h"
00013 #include "../Babayaga/BabayagaRandom.h"
00014 #include "BesKernel/IBesRndmGenSvc.h"
00015 
00016 // Framework Related Headers:-
00017 #include "HepMC/GenEvent.h"
00018 #include "HepMC/GenVertex.h"
00019 #include "HepMC/GenParticle.h"
00020 
00021 #include "GaudiKernel/MsgStream.h"
00022 #include "GaudiKernel/ISvcLocator.h"
00023 #include "GaudiKernel/AlgFactory.h"
00024 #include "GaudiKernel/DataSvc.h"
00025 #include "GaudiKernel/SmartDataPtr.h"
00026 
00027 #include "GeneratorObject/McGenEvent.h"
00028 #include "CLHEP/Vector/LorentzVector.h"
00029 #include "cfortran/cfortran.h"
00030 
00031 #include <stdlib.h>
00032 
00033 //COMMON/MOMSET/PM,PP,PFINEL,PFINPOS,QPH
00034 //dimension PM(0:3),PP(0:3),PFINEL(0:3),PFINPOS(0:3),QPH(40,0:3)  //OUTPUT RESULTS PM(0:3),PP(0:3) for beam electron and positron 
00035 //particle
00036 
00037  typedef struct { 
00038  double q1[4][160001]; 
00039  double p1[4][160001]; 
00040  double q2[4][160001]; 
00041  double p2[4][160001]; 
00042  double phot[4][10][160001]; 
00043  } MOMSET_DEF;
00044 //MOMSET_DEF MOMSET; 
00045 #define MOMSET COMMON_BLOCK(MOMSET_DEF, momset)
00046 COMMON_BLOCK_DEF(MOMSET_DEF,MOMSET);
00047 typedef struct { 
00048   double CutNgam,CutEgam;
00049 } RADBB_DEF;
00050 //RADBB_DEF RADBB; 
00051 #define RADBB COMMON_BLOCK(RADBB_DEF, radbb)
00052 COMMON_BLOCK_DEF(RADBB_DEF,RADBB);
00053 
00054 //COMMON/ISRPHOTONS/NCQPH
00055 typedef struct{
00056   int ncqph[160000];
00057 }ISRPHOTONS_DEF; 
00058 #define ISRPHOTONS COMMON_BLOCK(ISRPHOTONS_DEF, isrphotons)
00059 COMMON_BLOCK_DEF(ISRPHOTONS_DEF,ISRPHOTONS);
00060  
00061 //common/beamEnergy/ebeam
00062 typedef struct {
00063 double ebeam;
00064 } BEAMENERGY_DEF;
00065 #define BEAMENERGY COMMON_BLOCK(BEAMENERGY_DEF, beamenergy)
00066 COMMON_BLOCK_DEF(BEAMENERGY_DEF,BEAMENERGY);
00067 //BEAMENERGY_DEF,BEAMENERGY
00068 
00069 //common/expcuts/thmin,thmax,emin,zmax,egmin,thgmin,thgmax
00070 typedef struct {
00071 double thmin,thmax,emin,zmax,egmin,thgmin,thgmax;
00072 } EXPCUTS_DEF;
00073 #define EXPCUTS COMMON_BLOCK(EXPCUTS_DEF, expcuts)
00074 COMMON_BLOCK_DEF(EXPCUTS_DEF,EXPCUTS);
00075 //EXPCUTS_DEF,EXPCUTS;
00076 
00077 //common/switchFSR/ON,ILL
00078 typedef struct{
00079 int on,ill;
00080 } SWITCH_DEF;
00081 #define SWITCH  COMMON_BLOCK(SWITCH_DEF,switchfsr)
00082 COMMON_BLOCK_DEF(SWITCH_DEF,SWITCH);
00083 
00084 //common/switcharun/IARUN
00085 typedef struct{
00086 int iarun;
00087 } SWITCHARUN_DEF;
00088 #define  SWITCHARUN  COMMON_BLOCK(SWITCHARUN_DEF,switcharun)
00089 COMMON_BLOCK_DEF(SWITCHARUN_DEF,SWITCHARUN);
00090 
00091 //COMMON/CHANNEL/ICH
00092 typedef struct{
00093 int ich;
00094 } CHANNEL_DEF;
00095 #define  CHANNEL  COMMON_BLOCK(CHANNEL_DEF,channel)
00096 COMMON_BLOCK_DEF(CHANNEL_DEF,CHANNEL);
00097 
00098 //common/resonances/IRES
00099 typedef struct{
00100 int ires;
00101 } RESONANCES_DEF;
00102 #define  RESONANCES  COMMON_BLOCK(RESONANCES_DEF,resonances)
00103 COMMON_BLOCK_DEF(RESONANCES_DEF,RESONANCES); 
00104 
00105 //COMMON/DECLAREINT/INT
00106 typedef struct{
00107 int seed;
00108 } DECLAREINT_DEF;
00109 #define  DECLAREINT  COMMON_BLOCK(DECLAREINT_DEF,declareint)
00110 COMMON_BLOCK_DEF(DECLAREINT_DEF, DECLAREINT );
00111 
00112 //COMMON/DECLARESTR/INTUPLE,PHCUT,CUTG
00113 typedef struct{
00114 char tuple,phcut,cutg;
00115 } DECLARESTR_DEF;   
00116 #define  DECLARESTR  COMMON_BLOCK(DECLARESTR_DEF,declarestr)
00117 COMMON_BLOCK_DEF(DECLARESTR_DEF,DECLARESTR);
00118 
00119 
00120 
00121 //--//Unify Babayaga random engine with Bes random servive 
00122 extern "C" {
00123   extern float flat_();
00124 }
00125  
00126 float flat_(){
00127   float rr;
00128   double rd=BabayagaRandom::random();
00129 //  std::cout<<"BabayagaRandom::random()="<<rd<<endl;
00130   rr=(float)rd;
00131   return (float)BabayagaRandom::random();
00132   //  return rr;
00133 }
00134 
00135 
00136 
00137 PROTOCCALLSFSUB1(BABAYAGA,babayaga,INT)
00138 #define BABAYAGA(NEVENTS) CCALLSFSUB1(BABAYAGA,babayaga,INT,NEVENTS)
00139                                                                                             
00140 
00141 Babayaga::Babayaga(const string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
00142 {
00143   //  declareProperty("Seed", m_Int = 62341342); // seed for random number generator
00144   declareProperty("Channel", m_Ich = 1); // 1: e+e-->e+e-;2:e+e_->mu+mu-;3:e+e-->gamma gamma;4:e+e--->pi+pi-
00145   declareProperty("Ebeam", m_Ebeam = 1.548); // Ecm = 2*Ebeam [GeV]
00146   declareProperty("MinThetaAngle", m_Thmin = 70); // [degree]
00147   declareProperty("MaxThetaAngle", m_Thmax = 178); // [degree]
00148   declareProperty("MinimumEnergy", m_Emin   = 0.4); // Minimum Energy(GeV)
00149   declareProperty("MaximumAcollinearity", m_Zmax   = 10); //Maximum acollinearity (degree)
00150   declareProperty("RunningAlpha", m_Iarun   = 1); //running alpha, 0=off, 1=on
00151   declareProperty("HadronicResonance", m_Ires   = 0); //hadronic resoances for ICH=1 or 2
00152   declareProperty("FSR_swich", m_on   = 0); // FSR switch for ICH=2  ( 0=off, 1=on) 
00153   declareProperty("MinEnerCutG", m_Egmin   = 0.01); // minimum energy for CUTG=Y (GeV)
00154   declareProperty("MinAngCutG", m_Thgmin   = 5); // minimum angle for cuts =Y (deg.)
00155   declareProperty("MaxAngCutG", m_Thgmax   = 21); //maximum angle for CUTG=Y (deg.)
00156   declareProperty("HBOOK",    HN= 1); //INTUPLE:  if events have to be stored (1/0)
00157   declareProperty("PHCUT",   m_PHCUT   = 0); //PHCUT:    to avoid double counting when ICH = 3  (1/0), for other channels, it set as 0 by default
00158   declareProperty("CUTG",    m_CUTG   = 0); //CUTG:      explicit cuts on the generated photons (1/0)
00159   declareProperty("CutNgam",    m_CutNgam   = 0); //mininum number of ISR photon cut on Radiative Bhabha events   
00160   declareProperty("CutEgam",    m_CutEgam   = 0); //in GeV, mininum energy of ISR photon cut on Radiative Bhabha events 
00161 }
00162 
00163 StatusCode Babayaga::initialize(){
00164 
00165   MsgStream log(messageService(), name());
00166   
00167   log << MSG::INFO << "Babayaga initialize" << endreq;
00168 
00169   //set Bes unified random engine
00170   static const bool CREATEIFNOTTHERE(true);
00171   StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
00172   if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
00173   {
00174     log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
00175     return RndmStatus;
00176   }
00177   CLHEP::HepRandomEngine* engine  = p_BesRndmGenSvc->GetEngine("Babayaga");
00178   std::cout<<"==============================="<<engine<<endl;
00179   BabayagaRandom::setRandomEngine(engine);
00180   //  *****************
00181 
00182   if(HN==1) {DECLARESTR.tuple='Y';} else DECLARESTR.tuple='N';
00183   if(m_PHCUT==1){ DECLARESTR.phcut='Y';} else  DECLARESTR.cutg='N';
00184   if(m_CUTG ==1){ DECLARESTR.cutg='Y';} else  DECLARESTR.cutg='N';
00185   CHANNEL.ich = m_Ich;
00186   BEAMENERGY.ebeam=m_Ebeam;
00187   EXPCUTS.thmin=m_Thmin;
00188   EXPCUTS.thmax=m_Thmax;
00189   EXPCUTS.emin =m_Emin;
00190   EXPCUTS.zmax=m_Zmax;
00191   SWITCHARUN.iarun=m_Iarun;
00192   RESONANCES.ires =m_Ires;
00193   SWITCH.on   =m_on;
00194   EXPCUTS.egmin=m_Egmin;
00195   EXPCUTS.thgmin=m_Thgmin;
00196   EXPCUTS.thgmax=m_Thgmax;
00197 
00198   //  std::cout<<"m_Ires= "<<m_Ires<<endl;
00199 
00200   getMaxEvent();
00201   std::cout<<"m_evtMax = "<<m_evtMax<<std::endl;
00202   DECLAREINT.seed=m_Int;
00203   BABAYAGA(m_evtMax);
00204 
00205   return StatusCode::SUCCESS;
00206 }
00207 
00208 static int evtgen=1;
00209 StatusCode Babayaga::execute() 
00210 { 
00211   MsgStream log(messageService(), name());
00212 // log << MSG::INFO << "BABAYAGA executing" << endreq;
00213 //  std::cout<<"BABAYAGA begin executing"<<std::endl;  
00214 
00215   int npart = 0;
00216   int pid1,pid2,pst1,pst2;
00217   if(m_Ich==1) {pid1=11;   pid2=-11;  pst1=1;pst2=1;}
00218   if(m_Ich==2) {pid1=13;   pid2=-13;  pst1=1;pst2=1;}
00219   if(m_Ich==3) {pid1=22;   pid2= 22;  pst1=1;pst2=1;}
00220   if(m_Ich==4) {pid1=-211; pid2= 211; pst1=1;pst2=1;}
00221 
00222   // Fill event information
00223   GenEvent* evt = new GenEvent(1,1);
00224 
00225   GenVertex* prod_vtx = new GenVertex();
00226 //  prod_vtx->add_particle_out( p );
00227   evt->add_vertex( prod_vtx );
00228                           
00229   // incoming beam e- HepLorentzVector(px,py,pz,energy) required!
00230   GenParticle* p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p1[1][evtgen],  MOMSET.p1[2][evtgen], 
00231                                                       MOMSET.p1[3][evtgen],  MOMSET.p1[0][evtgen]),
00232                                                       11, 3); 
00233   p->suggest_barcode( ++npart );
00234   prod_vtx->add_particle_in(p);
00235 
00236 //  std::cout<<"incoming beam e+"<<endl;
00237   // incoming beam e+, e+ moving along the z-direction
00238   p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q1[1][evtgen],  MOMSET.q1[2][evtgen],
00239                                          MOMSET.q1[3][evtgen],  MOMSET.q1[4][evtgen]),
00240                        -11, 3); 
00241 
00242   p->suggest_barcode( ++npart );
00243   prod_vtx->add_particle_in(p);
00244   
00245   // scattered lepton +
00246   p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p2[1][evtgen],  MOMSET.p2[2][evtgen], 
00247                                          MOMSET.p2[3][evtgen],  MOMSET.p2[0][evtgen]),
00248                                          pid1,pst1); 
00249   p->suggest_barcode( ++npart );
00250   prod_vtx->add_particle_out(p);
00251  
00252   // debuging pingrg
00253   //  std::cout<<"evtgen= "<<evtgen<<std::endl;
00254   //std::cout<<"b:e-: "<<MOMSET.p1[0][evtgen]<<"; "<< MOMSET.p1[1][evtgen]<<"; "<<MOMSET.p1[2][evtgen]<<"; "<< MOMSET.p1[3][evtgen]<<std::endl;
00255   //std::cout<<"b:e+: "<<MOMSET.q1[0][evtgen]<<"; "<< MOMSET.q1[1][evtgen]<<"; "<<MOMSET.q1[2][evtgen]<<"; "<< MOMSET.q1[3][evtgen]<<std::endl;
00256   //std::cout<<"e-: "<<MOMSET.p2[0][evtgen]<<"; "<< MOMSET.p2[1][evtgen]<<"; "<<MOMSET.p2[2][evtgen]<<"; "<< MOMSET.p2[3][evtgen]<<std::endl;
00257   //std::cout<<"e+: "<<MOMSET.q2[0][evtgen]<<"; "<< MOMSET.q2[1][evtgen]<<"; "<<MOMSET.q2[2][evtgen]<<"; "<< MOMSET.q2[3][evtgen]<<std::endl;
00258 
00259   // scattered lepton -
00260   p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q2[1][evtgen],  MOMSET.q2[2][evtgen],
00261                                          MOMSET.q2[3][evtgen],  MOMSET.q2[0][evtgen]),
00262                        pid2, pst2); 
00263   p->suggest_barcode( ++npart );
00264   prod_vtx->add_particle_out(p);
00265 
00266   
00267   int iphot=0;
00268   // std::cout<<"evtgen, ncqph[events#] "<<evtgen<<"; "<<ISRPHOTONS.ncqph[evtgen-1]<<std::endl;
00269   for (iphot=0; iphot<ISRPHOTONS.ncqph[evtgen-1]; iphot++)
00270   {
00271     // debuging, pingrg
00272     //    std::cout<<"evtgen, iphot= "<<evtgen<<"; "<<iphot<<std::endl;
00273     //std::cout<<MOMSET.phot[0][iphot][evtgen]<<", "<<MOMSET.phot[1][iphot][evtgen]<<", "<<MOMSET.phot[2][iphot][evtgen]<<", "<<MOMSET.phot[3][iphot][evtgen]<<std::endl;
00274      
00275     p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.phot[1][iphot][evtgen],  MOMSET.phot[2][iphot][evtgen], 
00276                                            MOMSET.phot[3][iphot][evtgen],  MOMSET.phot[0][iphot][evtgen]),
00277                                            22, 1); 
00278     p->suggest_barcode( ++npart );
00279     prod_vtx->add_particle_out(p);
00280     
00281   }
00282 
00283 
00284   evtgen++;
00285 
00286   if( log.level() < MSG::INFO )
00287   {
00288     evt->print();  
00289   }
00290 
00291   // Check if the McCollection already exists
00292   SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
00293   if (anMcCol!=0) 
00294   {
00295     // Add event to existing collection
00296     MsgStream log(messageService(), name());
00297     log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
00298     McGenEvent* mcEvent = new McGenEvent(evt);
00299     anMcCol->push_back(mcEvent);
00300   }
00301   else 
00302   {
00303     // Create Collection and add  to the transient store
00304     McGenEventCol *mcColl = new McGenEventCol;
00305     McGenEvent* mcEvent = new McGenEvent(evt);
00306     mcColl->push_back(mcEvent);
00307     StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
00308     if (sc != StatusCode::SUCCESS) 
00309     {
00310       log << MSG::ERROR << "Could not register McGenEvent" << endreq;
00311       delete mcColl;
00312       delete evt;
00313       delete mcEvent;
00314       return StatusCode::FAILURE;
00315     }
00316     else 
00317     {
00318       //   log << MSG::INFO << "McGenEventCol created and " << npart <<" particles stored in McGenEvent" << endreq;
00319     }
00320   }
00321      
00322   return StatusCode::SUCCESS; 
00323 }
00324 
00325 StatusCode Babayaga::finalize() 
00326 {
00327   MsgStream log(messageService(), name());
00328    char delcmd[300];
00329    strcpy(delcmd,"cat ");
00330    strcat(delcmd,"CrossSection.txt");
00331    system(delcmd);
00332 
00333   std::cout<< "BABAYAGA finalized" << endl;
00334   return StatusCode::SUCCESS;
00335 }
00336 
00337 StatusCode Babayaga::getMaxEvent() {
00338   IProperty* appPropMgr=0;
00339   StatusCode status = 
00340     serviceLocator()->getService("ApplicationMgr", IProperty::interfaceID(),
00341                                  reinterpret_cast<IInterface*&>( appPropMgr ));
00342   if( status.isFailure() ) return status;
00343     
00344   IntegerProperty evtMax("EvtMax",0);
00345   status = appPropMgr->getProperty( &evtMax );
00346   if (status.isFailure()) return status;
00347   
00348   m_evtMax = evtMax.value();
00349   return status;
00350 }
00351 

Generated on Tue Nov 29 23:12:11 2016 for BOSS_7.0.2 by  doxygen 1.4.7