GenModule Class Reference

#include <GenModule.h>

Inheritance diagram for GenModule:

BesGenModule SingleParticleGun List of all members.

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

bool m_fixedMode
double m_meanInteractions
int m_randomSeed
std::vector< int > m_AllPartons
std::vector< int > m_StripVector
bool m_StripPartonSwitch
CLHEP::HepRandomEngine * m_pRandomEngine
CLHEP::RandPoisson * m_pPoissonGenerator
HepPDT::ParticleDataTable * m_particleTable

Detailed Description

Definition at line 41 of file GenModule.h.


Constructor & Destructor Documentation

GenModule::GenModule ( const std::string name,
ISvcLocator *  pSvcLocator 
)

Definition at line 38 of file GenModule.cxx.

References m_fixedMode, m_meanInteractions, m_randomSeed, and m_StripVector.

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]

Definition at line 53 of file GenModule.cxx.

References m_pPoissonGenerator, and m_pRandomEngine.

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 } 


Member Function Documentation

StatusCode GenModule::callGenerator (  )  [virtual]

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 218 of file GenModule.cxx.

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

StatusCode GenModule::execute (  ) 

Definition at line 125 of file GenModule.cxx.

References Bes_Common::DEBUG, calibUtil::ERROR, fillEvt(), genRecEmupikp::i, Bes_Common::INFO, m_fixedMode, m_meanInteractions, m_pPoissonGenerator, m_StripPartonSwitch, and StripPartons().

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 }

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

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 230 of file GenModule.cxx.

Referenced by execute().

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

StatusCode GenModule::finalize (  ) 

Definition at line 197 of file GenModule.cxx.

References genFinalize().

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

StatusCode GenModule::genFinalize (  )  [virtual]

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 224 of file GenModule.cxx.

Referenced by finalize().

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

StatusCode GenModule::genInitialize (  )  [virtual]

Reimplemented in BesGenModule, and SingleParticleGun.

Definition at line 206 of file GenModule.cxx.

Referenced by initialize().

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

StatusCode GenModule::genuserInitialize (  )  [virtual]

Definition at line 212 of file GenModule.cxx.

Referenced by initialize().

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

StatusCode GenModule::initialize (  ) 

Definition at line 63 of file GenModule.cxx.

References calibUtil::ERROR, genInitialize(), genuserInitialize(), Bes_Common::INFO, m_fixedMode, m_meanInteractions, m_particleTable, m_pPoissonGenerator, m_pRandomEngine, m_randomSeed, m_StripPartonSwitch, m_StripVector, and StripPartonsInit().

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 CLHEP::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 CLHEP::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]

Definition at line 274 of file GenModule.cxx.

References m_StripVector.

Referenced by execute().

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]

Definition at line 236 of file GenModule.cxx.

References genRecEmupikp::i, Bes_Common::INFO, m_AllPartons, m_StripPartonSwitch, and m_StripVector.

Referenced by initialize().

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]

Definition at line 60 of file GenModule.h.

Referenced by StripPartonsInit().

bool GenModule::m_fixedMode [protected]

Definition at line 57 of file GenModule.h.

Referenced by execute(), GenModule(), and initialize().

double GenModule::m_meanInteractions [protected]

Definition at line 58 of file GenModule.h.

Referenced by execute(), GenModule(), and initialize().

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

Definition at line 73 of file GenModule.h.

Referenced by SingleParticleGun::genInitialize(), and initialize().

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

Definition at line 68 of file GenModule.h.

Referenced by execute(), initialize(), and ~GenModule().

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

Definition at line 67 of file GenModule.h.

Referenced by initialize(), and ~GenModule().

int GenModule::m_randomSeed [protected]

Definition at line 59 of file GenModule.h.

Referenced by GenModule(), and initialize().

bool GenModule::m_StripPartonSwitch [protected]

Definition at line 62 of file GenModule.h.

Referenced by execute(), initialize(), and StripPartonsInit().

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

Definition at line 61 of file GenModule.h.

Referenced by GenModule(), initialize(), StripPartons(), and StripPartonsInit().


Generated on Tue Nov 29 23:19:38 2016 for BOSS_7.0.2 by  doxygen 1.4.7