Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BesGenModule Class Reference

#include <BesGenModule.h>

Inheritance diagram for BesGenModule:

GenModule GenModule List of all members.

Public Member Functions

 BesGenModule (const std::string &name, ISvcLocator *pSvcLocator)
 BesGenModule (const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode callGenerator ()
virtual StatusCode callGenerator ()
StatusCode execute ()
StatusCode execute ()
virtual StatusCode fillEvt (GenEvent *evt)
virtual StatusCode fillEvt (GenEvent *evt)
StatusCode finalize ()
StatusCode finalize ()
virtual StatusCode genFinalize ()
virtual StatusCode genFinalize ()
virtual StatusCode genInitialize ()
virtual StatusCode genInitialize ()
virtual StatusCode genuserInitialize ()
virtual StatusCode genuserInitialize ()
StatusCode initialize ()
StatusCode initialize ()
virtual ~BesGenModule ()
virtual ~BesGenModule ()

Public Attributes

IBesRndmGenSvcp_BesRndmGenSvc
IBesRndmGenSvcp_BesRndmGenSvc

Static Public Attributes

std::string besMcGen_stream = "PHOTOS_INIT"

Protected Member Functions

void StripPartons (GenEvent *evt)
void StripPartons (GenEvent *evt)
void StripPartonsInit (void)
void StripPartonsInit (void)

Protected Attributes

const char * cardname
const char * cardname
std::vector< int > m_AllPartons
std::vector< int > m_AllPartons
int m_events
bool m_fixedMode
int m_fortout
int m_GenIndex
double m_meanInteractions
std::vector< int > m_par
std::vector< int > m_par
HepPDT::ParticleDataTable * m_particleTable
HepPDT::ParticleDataTable * m_particleTable
CLHEP::RandPoisson * m_pPoissonGenerator
CLHEP::RandPoisson * m_pPoissonGenerator
CLHEP::HepRandomEngine * m_pRandomEngine
CLHEP::HepRandomEngine * m_pRandomEngine
int m_randomSeed
std::vector< long int > m_seeds
std::vector< long int > m_seeds
bool m_StripPartonSwitch
std::vector< int > m_StripVector
std::vector< int > m_StripVector
int m_SubIndex
int m_SuperIndex
int mvec [10]
int n
int n1
int Nr
int nvec [10]
std::string runname

Constructor & Destructor Documentation

BesGenModule::BesGenModule const std::string &  name,
ISvcLocator *  pSvcLocator
 

00074                                : GenModule(name,pSvcLocator)
00075 {
00076 //--------------------------------------------------------------------------  
00077   besMcGen_stream       =       "PHOTOS_INIT";
00078 //  declareProperty("BesMcGenCommand", m_BesMcGenCommandVector);
00079 
00080   declareProperty("Runcards",  runname = "run.cards");
00081   declareProperty("Ratio",     Nr = 1);  
00082 
00083 }

BesGenModule::~BesGenModule  )  [virtual]
 

00086 {}

BesGenModule::BesGenModule const std::string &  name,
ISvcLocator *  pSvcLocator
 

virtual BesGenModule::~BesGenModule  )  [virtual]
 


Member Function Documentation

virtual StatusCode BesGenModule::callGenerator  )  [virtual]
 

Reimplemented from GenModule.

StatusCode BesGenModule::callGenerator  )  [virtual]
 

Reimplemented from GenModule.

00143                                        {
00144 //---------------------------------------------------------------------------
00145   MsgStream log(messageService(), name());
00146   log << MSG::INFO << " BesGenModule generating.  \n"  << endreq;
00147 
00148   StatusCode status = StatusCode::SUCCESS;
00149   int iq;  
00150 
00151 //  n=1;
00152 
00153 
00154   mainexe_(&Nr,mvec);
00155 
00156 /*
00157     for (int iq = 1; iq < 11; iq++) {
00158        nvec[iq-1]=mvec[iq];
00159     }
00160 */
00161 
00162     McEvent* aMcEvent = new McEvent;
00163     StatusCode sc = eventSvc()->registerObject("/Event/MC",aMcEvent);
00164 
00165 
00166     SmartDataPtr<DecayMode> anMcCol(eventSvc(), "/Event/MC/DecayMode");
00167     if (anMcCol!=0) {
00168 //     log << MSG::INFO << "Add McEvent to existing collection" << endreq;
00169     }
00170     else {
00171 //     log << MSG::INFO << "No decay mode now" << endreq;
00172         DecayMode *decayMode = new DecayMode;
00173         decayMode->putData(mvec, 10);
00174     StatusCode sc = eventSvc()->registerObject("/Event/MC/DecayMode",decayMode);   
00175     }
00176 
00177 
00178     SmartDataPtr<DecayMode> aMcCol(eventSvc(), "/Event/MC/DecayMode");
00179     if (aMcCol!=0) {   
00180 //     log << MSG::INFO << "Haha signal exist!!!!" << endreq;
00181     }
00182 
00183 
00184 
00185 
00186 //  HEPEVT_Wrapper::print_hepevt();
00187 
00188   ++m_events;
00189   
00190 
00191 
00192   log << MSG::INFO << " BESGenModule generating done.  \n"  << endreq;
00193   return status;
00194 
00195 }

StatusCode GenModule::execute  )  [inherited]
 

StatusCode GenModule::execute  )  [inherited]
 

00125                               {
00126   //---------------------------------------------------------------------------
00127     
00128   int numToGenerate;
00129   StatusCode status;
00130 
00131   MsgStream log(messageService(), name());
00132 
00133   log << MSG::DEBUG << "GenModule::execute()" << endreq;
00134 
00135   // Decide how many interactions to generate
00136   if(m_fixedMode)  {
00137     numToGenerate = (int) m_meanInteractions;
00138   }
00139   else {
00140     numToGenerate = m_pPoissonGenerator->fire();
00141   }
00142 
00143   // Generate as many interactions as requested
00144   for(int i=0; i<numToGenerate; i++) {
00145 
00146     // Call the code that generates an event
00147     status = this->callGenerator();
00148 
00149     // Create the MC event and send the GeneratorEvent stored in it to fillEvt
00150     GenEvent* evt = new GenEvent(1,1);
00151     status = this->fillEvt(evt);
00152 
00153     // Strip out the requested partons here.
00154     if (m_StripPartonSwitch)    StripPartons(evt);
00155     
00156     // Check if the McCollection already exists
00157     SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
00158     if (anMcCol!=0) {
00159       // Add event to existing collection
00160       MsgStream log(messageService(), name());
00161       log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
00162       McGenEvent* mcEvent = new McGenEvent(evt);
00163       anMcCol->push_back(mcEvent);
00164     }
00165     else {
00166       // Create Collection and add  to the transient store
00167       McGenEventCol *mcColl = new McGenEventCol;
00168       McGenEvent* mcEvent = new McGenEvent(evt);
00169       mcColl->push_back(mcEvent);
00170 
00171       StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
00172 
00173       if (sc != StatusCode::SUCCESS) {
00174         MsgStream log(messageService(), name());
00175         log << MSG::ERROR << "Could not register McGenEvent" << endreq;
00176         delete mcColl;
00177         delete evt;
00178         delete mcEvent;
00179         return StatusCode::FAILURE;
00180       }
00181       else {
00182 //        std::cout << " McGenEventCol made and stored" << std::endl;
00183       }
00184       
00185     }
00186   }
00187 
00188   // now call the incident service and set the signal.
00189   IIncidentSvc *incSvc;
00190   service("IncidentSvc",incSvc);
00191   incSvc->fireIncident( Incident( name(), "McGenEvent Generated") );
00192 
00193   return status;
00194 }

virtual StatusCode BesGenModule::fillEvt GenEvent *  evt  )  [virtual]
 

Reimplemented from GenModule.

StatusCode BesGenModule::fillEvt GenEvent *  evt  )  [virtual]
 

Reimplemented from GenModule.

00206                                               {
00207   //---------------------------------------------------------------------------
00208   MsgStream log(messageService(), name());
00209   log << MSG:: INFO << " BESGenModule Filling...  \n"  << endreq;
00210 
00211       evt->set_event_number(m_events);
00212       HepMC::IO_HEPEVT hepio;
00213       hepio.fill_next_event(evt);
00214 //   cmTomm(evt);
00215 //   GeVToMeV(evt);
00216 
00217 
00218  return StatusCode::SUCCESS;
00219 }

StatusCode GenModule::finalize  )  [inherited]
 

StatusCode GenModule::finalize  )  [inherited]
 

00197                                {
00198   //---------------------------------------------------------------------------
00199 
00200   StatusCode status = this->genFinalize();
00201 
00202   return status;
00203 }

virtual StatusCode BesGenModule::genFinalize  )  [virtual]
 

Reimplemented from GenModule.

StatusCode BesGenModule::genFinalize  )  [virtual]
 

Reimplemented from GenModule.

00198                                      {
00199   //---------------------------------------------------------------------------
00200   MsgStream log(messageService(), name());
00201  mainfin_(&n);
00202   log << MSG:: INFO << " BESGenModule Ending...  \n"  << endreq;
00203   return StatusCode::SUCCESS;
00204 }

virtual StatusCode BesGenModule::genInitialize  )  [virtual]
 

Reimplemented from GenModule.

StatusCode BesGenModule::genInitialize  )  [virtual]
 

Reimplemented from GenModule.

00104                                        {
00105 //---------------------------------------------------------------------------
00106 
00107   MsgStream log(messageService(), name());
00108   log << MSG::INFO << " BES PHOTOS INITIALISING.  \n"  << endreq;
00109 //  log << MSG::INFO << " BES PHOTOS 2.  \n"  << endreq;
00110 
00111   //caogf add for random seed of genbes
00112   StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, true);
00113   if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
00114   {
00115      log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
00116      return RndmStatus;
00117   }
00118 
00119   BesGenModule::besMcGen_stream =       "PHOTOS_INIT";
00120 
00121   BesGenModule::besMcGen_stream =       "PHOTOS111";
00122 
00123   m_events = 0;
00124   n=0;
00125   cardname = runname.c_str();
00126 
00127 
00128   mainini_(&n,cardname);
00129 
00130   int theseed;
00131   runi_seed_(&theseed);
00132   p_BesRndmGenSvc->setGenseed(theseed+1);
00133 
00134   HepMC::HEPEVT_Wrapper::set_sizeof_int(4);
00135   HepMC::HEPEVT_Wrapper::set_sizeof_real(4);
00136   HepMC::HEPEVT_Wrapper::set_max_number_entries(2000);
00137 
00138  
00139   return StatusCode::SUCCESS;
00140 }

virtual StatusCode GenModule::genuserInitialize  )  [virtual, inherited]
 

StatusCode GenModule::genuserInitialize  )  [virtual, inherited]
 

00212                                         { 
00213   //---------------------------------------------------------------------------
00214   return StatusCode::SUCCESS;
00215 }

StatusCode GenModule::initialize  )  [inherited]
 

StatusCode GenModule::initialize  )  [inherited]
 

00063                                 {
00064   //---------------------------------------------------------------------------
00065 
00066   // Inform the user what the mode and conditions are:
00067   MsgStream log(messageService(), name());
00068 
00069   // Initialize StripPartons variables
00070   if (m_StripVector[0] > 0) {
00071     StripPartonsInit();
00072   } else {
00073     m_StripPartonSwitch =       false;
00074     m_StripVector.clear();
00075   }
00076 
00077    
00078   // Get the Particle Properties Service
00079   IPartPropSvc* p_PartPropSvc;
00080   //static const bool CREATEIFNOTTHERE(true);
00081   //StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
00082   StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc);
00083   if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
00084     log << MSG::ERROR << " Could not initialize Particle Properties Service" << endreq;
00085     return PartPropStatus;
00086   }      
00087 
00088   m_particleTable = p_PartPropSvc->PDT();
00089   
00090   m_pRandomEngine = new Ranlux64Engine(m_randomSeed);
00091 
00092   if(m_fixedMode) {
00093     if(m_meanInteractions == 1.0) {
00094       log << MSG::INFO << "Standard Initialization:  Single Interaction Mode "
00095           << endreq;
00096     }
00097     else {
00098       log << MSG::INFO << "Fixed Number of Interactions per Event is: "
00099           << m_meanInteractions << endreq;
00100     }
00101   }
00102   else {
00103     m_pPoissonGenerator = new RandPoisson(*m_pRandomEngine, 
00104                                           m_meanInteractions);
00105 
00106     log << MSG::INFO << 
00107       "Poisson Distribution of Interactions per Event with Mean: "
00108         << m_meanInteractions << endreq;
00109   }
00110   // Initialize the generator itself
00111   StatusCode status = this->genInitialize();
00112   if (status.isFailure()) {
00113     log << MSG::ERROR << "Could not initialize Generator properly" << endreq;
00114     return status;
00115   }  
00116   StatusCode  status1 = this->genuserInitialize();
00117   if (status1.isFailure()) {
00118     log << MSG::ERROR << "Could not initialize user part properly" << endreq;
00119     return status1;
00120   } 
00121   return status;
00122 }

void GenModule::StripPartons GenEvent *  evt  )  [protected, inherited]
 

void GenModule::StripPartons GenEvent *  evt  )  [protected, inherited]
 

00275 {
00276   //    for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
00277   //              p != evt->particles_end(); ++p )
00278   //    {
00279   //  //            std::cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() << std::endl;
00280   //        if ( std::find(m_StripVector.begin(),
00281   //                       m_StripVector.end(),
00282   //                       (*p)->pdg_id()) != m_StripVector.end() )
00283   //        {
00284   //  //                std::cout << " REMOVING " << (*p)->pdg_id() << " " << (*p)->barcode() << std::endl;
00285   //            HepMC::GenVertex*       pvtx    =       (*p)->production_vertex();
00286   //            HepMC::GenVertex*       evtx    =       (*p)->end_vertex();
00287   //            if (pvtx) pvtx->remove_particle(*p);
00288   //            if (evtx) evtx->remove_particle(*p);
00289   //            delete  *p;
00290   //        }
00291             
00292   //    }
00293         
00294   // Loop on all vertices of the event and remove the particle from the vertex
00295   for ( HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin();
00296         vtx != evt->vertices_end(); ++vtx ) {
00297     // Loop on all children particles and remove the ones that should be stripped out
00298     for ( HepMC::GenVertex::particle_iterator p = (*vtx)-> particles_begin(HepMC::children);
00299           p != (*vtx)->particles_end(HepMC::children);
00300           ++p ){
00301       if ( std::find(m_StripVector.begin(),
00302                      m_StripVector.end(),
00303                      (*p)->pdg_id()) != m_StripVector.end() ) {
00304         if ( (*p)->end_vertex() ) (*p)->end_vertex()->remove_particle(*p);
00305         if ( (*p)->production_vertex() ) (*p)->production_vertex()->remove_particle(*p);
00306         delete *p;
00307       }
00308     }
00309     // Loop on all parents particles and remove the ones that should be stripped out
00310     for ( HepMC::GenVertex::particle_iterator p = (*vtx)-> particles_begin(HepMC::parents);
00311           p != (*vtx)->particles_end(HepMC::parents);
00312           ++p ) {
00313       if ( std::find(m_StripVector.begin(),
00314                      m_StripVector.end(),
00315                      (*p)->pdg_id()) != m_StripVector.end() ) {
00316         if ( (*p)->end_vertex() ) (*p)->end_vertex()->remove_particle(*p);
00317         if ( (*p)->production_vertex() ) (*p)->production_vertex()->remove_particle(*p);
00318         delete *p;
00319       }
00320     }
00321   }
00322 }

void GenModule::StripPartonsInit void   )  [protected, inherited]
 

void GenModule::StripPartonsInit void   )  [protected, inherited]
 

00237 {
00238   MsgStream log(messageService(), name());
00239 
00240   for (int i = 1; i < 9; ++i) { m_AllPartons.push_back(i); m_AllPartons.push_back(-i); } // Quarks
00241   m_AllPartons.push_back(21); // gluon
00242 
00243   m_StripPartonSwitch = true;
00244   m_StripVector.erase(m_StripVector.begin(), m_StripVector.begin()+1);
00245   // When the user specifies only the StripPartonSwitch or gives a Particle Code
00246   // which is NOT a parton then strip ALL partons
00247   if (m_StripVector.size() == 0) {
00248     log << MSG::INFO << " !!!! NO SPECIFIC PARTON FOR STRIPOUT WAS REQUESTED => STRIPOUT ALL "
00249         << endreq;
00250     m_StripVector = m_AllPartons;
00251   } else {
00252     bool        value_ok        =       true;
00253     std::vector<int>::const_iterator    i =     m_StripVector.begin();
00254     do {
00255       if ( std::find(m_AllPartons.begin(),
00256                      m_AllPartons.end(),
00257                      *i) == m_AllPartons.end() ) value_ok = false;
00258       ++i;
00259     } while (i != m_StripVector.end() && value_ok);
00260     if (!value_ok) {
00261       log << MSG::INFO << " !!!! ILEGAL PDG-ID FOR STRIPOUT WAS REQUESTED => STRIPOUT ALL "
00262           << endreq;
00263       m_StripVector = m_AllPartons;
00264     }
00265   }
00266   log << MSG::INFO << " THE FOLLOWING PARTON(S) WILL BE STRIPED OUT ";
00267   for (std::vector<int>::const_iterator ip = m_StripVector.begin(); ip != m_StripVector.end(); ++ip)
00268     log << *ip << "  ";
00269   log << endreq;
00270   
00271 }


Member Data Documentation

std::string BesGenModule::besMcGen_stream = "PHOTOS_INIT" [static]
 

const char* BesGenModule::cardname [protected]
 

const char* BesGenModule::cardname [protected]
 

std::vector<int> GenModule::m_AllPartons [protected, inherited]
 

std::vector<int> GenModule::m_AllPartons [protected, inherited]
 

int BesGenModule::m_events [protected]
 

bool GenModule::m_fixedMode [protected, inherited]
 

int BesGenModule::m_fortout [protected]
 

int BesGenModule::m_GenIndex [protected]
 

double GenModule::m_meanInteractions [protected, inherited]
 

std::vector<int> BesGenModule::m_par [protected]
 

std::vector<int> BesGenModule::m_par [protected]
 

HepPDT::ParticleDataTable* GenModule::m_particleTable [protected, inherited]
 

HepPDT::ParticleDataTable* GenModule::m_particleTable [protected, inherited]
 

CLHEP::RandPoisson* GenModule::m_pPoissonGenerator [protected, inherited]
 

CLHEP::RandPoisson* GenModule::m_pPoissonGenerator [protected, inherited]
 

CLHEP::HepRandomEngine* GenModule::m_pRandomEngine [protected, inherited]
 

CLHEP::HepRandomEngine* GenModule::m_pRandomEngine [protected, inherited]
 

int GenModule::m_randomSeed [protected, inherited]
 

std::vector<long int> BesGenModule::m_seeds [protected]
 

std::vector<long int> BesGenModule::m_seeds [protected]
 

bool GenModule::m_StripPartonSwitch [protected, inherited]
 

std::vector<int> GenModule::m_StripVector [protected, inherited]
 

std::vector<int> GenModule::m_StripVector [protected, inherited]
 

int BesGenModule::m_SubIndex [protected]
 

int BesGenModule::m_SuperIndex [protected]
 

int BesGenModule::mvec [protected]
 

int BesGenModule::n [protected]
 

int BesGenModule::n1 [protected]
 

int BesGenModule::Nr [protected]
 

int BesGenModule::nvec [protected]
 

IBesRndmGenSvc* BesGenModule::p_BesRndmGenSvc
 

IBesRndmGenSvc* BesGenModule::p_BesRndmGenSvc
 

std::string BesGenModule::runname [protected]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 15:52:28 2011 for BOSS6.5.5 by  doxygen 1.3.9.1