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

GenModule Class Reference

#include <GenModule.h>

Inheritance diagram for GenModule:

BesGenModule BesGenModule SingleParticleGun SingleParticleGun List of all members.

Public Member Functions

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 ()
 GenModule (const std::string &name, ISvcLocator *pSvcLocator)
 GenModule (const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode genuserInitialize ()
virtual StatusCode genuserInitialize ()
StatusCode initialize ()
StatusCode initialize ()
virtual ~GenModule ()
virtual ~GenModule ()

Protected Member Functions

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

Protected Attributes

std::vector< int > m_AllPartons
std::vector< int > m_AllPartons
bool m_fixedMode
double m_meanInteractions
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
bool m_StripPartonSwitch
std::vector< int > m_StripVector
std::vector< int > m_StripVector

Constructor & Destructor Documentation

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

00039   :     Algorithm(name, pSvcLocator),
00040         m_pRandomEngine(0),
00041         m_pPoissonGenerator(0)
00042   //---------------------------------------------------------------------------
00043 {
00044   declareProperty("FixedMode",m_fixedMode=true);
00045   declareProperty("MeanInt",m_meanInteractions=1.0);
00046   declareProperty("RandomSeed",m_randomSeed=1234567);
00047   declareProperty("StripPartons",m_StripVector);
00048   m_StripVector.push_back(0);
00049 
00050 }

GenModule::~GenModule  )  [virtual]
 

00053                      {
00054   // Delete random number objects if they were created
00055 
00056   if(m_pPoissonGenerator) delete m_pPoissonGenerator;
00057   if(m_pRandomEngine) delete m_pRandomEngine;
00058 
00059 } 

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

virtual GenModule::~GenModule  )  [virtual]
 


Member Function Documentation

virtual StatusCode GenModule::callGenerator  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

StatusCode GenModule::callGenerator  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

00218                                     { 
00219   //---------------------------------------------------------------------------
00220   return StatusCode::SUCCESS;
00221 }

StatusCode GenModule::execute  ) 
 

StatusCode GenModule::execute  ) 
 

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 GenModule::fillEvt GenEvent *  evt  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

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

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

00230                                                  {
00231   //---------------------------------------------------------------------------
00232   return StatusCode::SUCCESS;
00233 }

StatusCode GenModule::finalize  ) 
 

StatusCode GenModule::finalize  ) 
 

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

virtual StatusCode GenModule::genFinalize  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

StatusCode GenModule::genFinalize  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

00224                                   { 
00225   //---------------------------------------------------------------------------
00226   return StatusCode::SUCCESS;
00227 }

virtual StatusCode GenModule::genInitialize  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

StatusCode GenModule::genInitialize  )  [virtual]
 

Reimplemented in BesGenModule, SingleParticleGun, BesGenModule, and SingleParticleGun.

00206                                     { 
00207   //---------------------------------------------------------------------------
00208   return StatusCode::SUCCESS;
00209 }

virtual StatusCode GenModule::genuserInitialize  )  [virtual]
 

StatusCode GenModule::genuserInitialize  )  [virtual]
 

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

StatusCode GenModule::initialize  ) 
 

StatusCode GenModule::initialize  ) 
 

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]
 

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

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]
 

void GenModule::StripPartonsInit void   )  [protected]
 

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::vector<int> GenModule::m_AllPartons [protected]
 

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

bool GenModule::m_fixedMode [protected]
 

double GenModule::m_meanInteractions [protected]
 

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

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

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

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

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

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

int GenModule::m_randomSeed [protected]
 

bool GenModule::m_StripPartonSwitch [protected]
 

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

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


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