BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
GenModule Class Reference

#include <GenModule.h>

Inheritance diagram for GenModule:

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)
 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)
 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)
void StripPartonsInit (void)
void StripPartons (GenEvent *evt)
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

Constructor & Destructor Documentation

◆ GenModule() [1/3]

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

Definition at line 37 of file GenModule.cxx.

38 : Algorithm( name, pSvcLocator )
39 , m_pRandomEngine( 0 )
41//---------------------------------------------------------------------------
42{
43 declareProperty( "FixedMode", m_fixedMode = true );
44 declareProperty( "MeanInt", m_meanInteractions = 1.0 );
45 declareProperty( "RandomSeed", m_randomSeed = 1234567 );
46 declareProperty( "StripPartons", m_StripVector );
47 m_StripVector.push_back( 0 );
48}

Referenced by GenModule(), and SingleParticleGun::SingleParticleGun().

◆ ~GenModule() [1/3]

GenModule::~GenModule ( )
virtual

Definition at line 51 of file GenModule.cxx.

51 {
52 // Delete random number objects if they were created
53
55 if ( m_pRandomEngine ) delete m_pRandomEngine;
56}

◆ GenModule() [2/3]

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

◆ ~GenModule() [2/3]

virtual GenModule::~GenModule ( )
virtual

◆ GenModule() [3/3]

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

◆ ~GenModule() [3/3]

virtual GenModule::~GenModule ( )
virtual

Member Function Documentation

◆ callGenerator() [1/3]

StatusCode GenModule::callGenerator ( )
virtual

Reimplemented in SingleParticleGun.

Definition at line 217 of file GenModule.cxx.

217 {
218 //---------------------------------------------------------------------------
219 return StatusCode::SUCCESS;
220}

Referenced by execute().

◆ callGenerator() [2/3]

virtual StatusCode GenModule::callGenerator ( )
virtual

Reimplemented in SingleParticleGun.

◆ callGenerator() [3/3]

virtual StatusCode GenModule::callGenerator ( )
virtual

Reimplemented in SingleParticleGun.

◆ execute() [1/3]

StatusCode GenModule::execute ( )

Definition at line 124 of file GenModule.cxx.

124 {
125 //---------------------------------------------------------------------------
126
127 int numToGenerate;
128 StatusCode status;
129
130 MsgStream log( msgSvc(), name() );
131
132 log << MSG::DEBUG << "GenModule::execute()" << endmsg;
133
134 // Decide how many interactions to generate
135 if ( m_fixedMode ) { numToGenerate = (int)m_meanInteractions; }
136 else { numToGenerate = m_pPoissonGenerator->fire(); }
137
138 // Generate as many interactions as requested
139 for ( int i = 0; i < numToGenerate; i++ )
140 {
141
142 // Call the code that generates an event
143 status = this->callGenerator();
144
145 // Create the MC event and send the GeneratorEvent stored in it to fillEvt
146 GenEvent* evt = new GenEvent( 1, 1 );
147 status = this->fillEvt( evt );
148
149 // Strip out the requested partons here.
150 if ( m_StripPartonSwitch ) StripPartons( evt );
151
152 // Check if the McCollection already exists
153 SmartDataPtr<McGenEventCol> anMcCol( eventSvc(), "/Event/Gen" );
154 if ( anMcCol != 0 )
155 {
156 // Add event to existing collection
157 MsgStream log( msgSvc(), name() );
158 log << MSG::INFO << "Add McGenEvent to existing collection" << endmsg;
159 McGenEvent* mcEvent = new McGenEvent( evt );
160 anMcCol->push_back( mcEvent );
161 }
162 else
163 {
164 // Create Collection and add to the transient store
165 McGenEventCol* mcColl = new McGenEventCol;
166 McGenEvent* mcEvent = new McGenEvent( evt );
167 mcColl->push_back( mcEvent );
168
169 StatusCode sc = eventSvc()->registerObject( "/Event/Gen", mcColl );
170
171 if ( sc != StatusCode::SUCCESS )
172 {
173 MsgStream log( msgSvc(), name() );
174 log << MSG::ERROR << "Could not register McGenEvent" << endmsg;
175 delete mcColl;
176 delete evt;
177 delete mcEvent;
178 return StatusCode::FAILURE;
179 }
180 else
181 {
182 // std::cout << " McGenEventCol made and stored" << std::endl;
183 }
184 }
185 }
186
187 // now call the incident service and set the signal.
188 IIncidentSvc* incSvc;
189 service( "IncidentSvc", incSvc );
190 incSvc->fireIncident( Incident( name(), "McGenEvent Generated" ) );
191
192 return status;
193}
ObjectVector< McGenEvent > McGenEventCol
IMessageSvc * msgSvc()
void StripPartons(GenEvent *evt)
virtual StatusCode callGenerator()
virtual StatusCode fillEvt(GenEvent *evt)

◆ execute() [2/3]

StatusCode GenModule::execute ( )

◆ execute() [3/3]

StatusCode GenModule::execute ( )

◆ fillEvt() [1/3]

StatusCode GenModule::fillEvt ( GenEvent * evt)
virtual

Reimplemented in SingleParticleGun.

Definition at line 229 of file GenModule.cxx.

229 {
230 //---------------------------------------------------------------------------
231 return StatusCode::SUCCESS;
232}

Referenced by execute().

◆ fillEvt() [2/3]

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

Reimplemented in SingleParticleGun.

◆ fillEvt() [3/3]

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

Reimplemented in SingleParticleGun.

◆ finalize() [1/3]

StatusCode GenModule::finalize ( )

Definition at line 196 of file GenModule.cxx.

196 {
197 //---------------------------------------------------------------------------
198
199 StatusCode status = this->genFinalize();
200
201 return status;
202}
virtual StatusCode genFinalize()

◆ finalize() [2/3]

StatusCode GenModule::finalize ( )

◆ finalize() [3/3]

StatusCode GenModule::finalize ( )

◆ genFinalize() [1/3]

StatusCode GenModule::genFinalize ( )
virtual

Reimplemented in SingleParticleGun.

Definition at line 223 of file GenModule.cxx.

223 {
224 //---------------------------------------------------------------------------
225 return StatusCode::SUCCESS;
226}

Referenced by finalize().

◆ genFinalize() [2/3]

virtual StatusCode GenModule::genFinalize ( )
virtual

Reimplemented in SingleParticleGun.

◆ genFinalize() [3/3]

virtual StatusCode GenModule::genFinalize ( )
virtual

Reimplemented in SingleParticleGun.

◆ genInitialize() [1/3]

StatusCode GenModule::genInitialize ( )
virtual

Reimplemented in SingleParticleGun.

Definition at line 205 of file GenModule.cxx.

205 {
206 //---------------------------------------------------------------------------
207 return StatusCode::SUCCESS;
208}

Referenced by initialize().

◆ genInitialize() [2/3]

virtual StatusCode GenModule::genInitialize ( )
virtual

Reimplemented in SingleParticleGun.

◆ genInitialize() [3/3]

virtual StatusCode GenModule::genInitialize ( )
virtual

Reimplemented in SingleParticleGun.

◆ genuserInitialize() [1/3]

StatusCode GenModule::genuserInitialize ( )
virtual

Definition at line 211 of file GenModule.cxx.

211 {
212 //---------------------------------------------------------------------------
213 return StatusCode::SUCCESS;
214}

Referenced by initialize().

◆ genuserInitialize() [2/3]

virtual StatusCode GenModule::genuserInitialize ( )
virtual

◆ genuserInitialize() [3/3]

virtual StatusCode GenModule::genuserInitialize ( )
virtual

◆ initialize() [1/3]

StatusCode GenModule::initialize ( )

Definition at line 60 of file GenModule.cxx.

60 {
61 //---------------------------------------------------------------------------
62
63 // Inform the user what the mode and conditions are:
64 MsgStream log( msgSvc(), name() );
65
66 // Initialize StripPartons variables
67 if ( m_StripVector[0] > 0 ) { StripPartonsInit(); }
68 else
69 {
70 m_StripPartonSwitch = false;
71 m_StripVector.clear();
72 }
73
74 // Get the Particle Properties Service
75 IPartPropSvc* p_PartPropSvc;
76 // static const bool CREATEIFNOTTHERE(true);
77 // StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
78 StatusCode PartPropStatus = service( "PartPropSvc", p_PartPropSvc );
79 if ( !PartPropStatus.isSuccess() || 0 == p_PartPropSvc )
80 {
81 log << MSG::ERROR << " Could not initialize Particle Properties Service" << endmsg;
82 return PartPropStatus;
83 }
84
85 m_particleTable = p_PartPropSvc->PDT();
86
87 m_pRandomEngine = new CLHEP::Ranlux64Engine( m_randomSeed );
88
89 if ( m_fixedMode )
90 {
91 if ( m_meanInteractions == 1.0 )
92 { log << MSG::INFO << "Standard Initialization: Single Interaction Mode " << endmsg; }
93 else
94 {
95 log << MSG::INFO << "Fixed Number of Interactions per Event is: " << m_meanInteractions
96 << endmsg;
97 }
98 }
99 else
100 {
101 m_pPoissonGenerator = new CLHEP::RandPoisson( *m_pRandomEngine, m_meanInteractions );
102
103 log << MSG::INFO
104 << "Poisson Distribution of Interactions per Event with Mean: " << m_meanInteractions
105 << endmsg;
106 }
107 // Initialize the generator itself
108 StatusCode status = this->genInitialize();
109 if ( status.isFailure() )
110 {
111 log << MSG::ERROR << "Could not initialize Generator properly" << endmsg;
112 return status;
113 }
114 StatusCode status1 = this->genuserInitialize();
115 if ( status1.isFailure() )
116 {
117 log << MSG::ERROR << "Could not initialize user part properly" << endmsg;
118 return status1;
119 }
120 return status;
121}
HepPDT::ParticleDataTable * m_particleTable
virtual StatusCode genuserInitialize()
void StripPartonsInit(void)
virtual StatusCode genInitialize()

◆ initialize() [2/3]

StatusCode GenModule::initialize ( )

◆ initialize() [3/3]

StatusCode GenModule::initialize ( )

◆ StripPartons() [1/3]

void GenModule::StripPartons ( GenEvent * evt)
protected

Definition at line 277 of file GenModule.cxx.

277 {
278 // for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
279 // p != evt->particles_end(); ++p )
280 // {
281 // // std::cout << " PDG, BAR " << (*p)->pdg_id() << " " << (*p)->barcode() <<
282 // std::endl; if ( std::find(m_StripVector.begin(), m_StripVector.end(),
283 // (*p)->pdg_id()) != m_StripVector.end() )
284 // {
285 // // std::cout << " REMOVING " << (*p)->pdg_id() << " " << (*p)->barcode()
286 // << std::endl; HepMC::GenVertex* pvtx = (*p)->production_vertex();
287 // HepMC::GenVertex* evtx = (*p)->end_vertex();
288 // if (pvtx) pvtx->remove_particle(*p);
289 // if (evtx) evtx->remove_particle(*p);
290 // delete *p;
291 // }
292
293 // }
294
295 // Loop on all vertices of the event and remove the particle from the vertex
296 for ( HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin();
297 vtx != evt->vertices_end(); ++vtx )
298 {
299 // Loop on all children particles and remove the ones that should be stripped out
300 for ( HepMC::GenVertex::particle_iterator p = ( *vtx )->particles_begin( HepMC::children );
301 p != ( *vtx )->particles_end( HepMC::children ); ++p )
302 {
303 if ( std::find( m_StripVector.begin(), m_StripVector.end(), ( *p )->pdg_id() ) !=
304 m_StripVector.end() )
305 {
306 if ( ( *p )->end_vertex() ) ( *p )->end_vertex()->remove_particle( *p );
307 if ( ( *p )->production_vertex() ) ( *p )->production_vertex()->remove_particle( *p );
308 delete *p;
309 }
310 }
311 // Loop on all parents particles and remove the ones that should be stripped out
312 for ( HepMC::GenVertex::particle_iterator p = ( *vtx )->particles_begin( HepMC::parents );
313 p != ( *vtx )->particles_end( HepMC::parents ); ++p )
314 {
315 if ( std::find( m_StripVector.begin(), m_StripVector.end(), ( *p )->pdg_id() ) !=
316 m_StripVector.end() )
317 {
318 if ( ( *p )->end_vertex() ) ( *p )->end_vertex()->remove_particle( *p );
319 if ( ( *p )->production_vertex() ) ( *p )->production_vertex()->remove_particle( *p );
320 delete *p;
321 }
322 }
323 }
324}

Referenced by execute().

◆ StripPartons() [2/3]

void GenModule::StripPartons ( GenEvent * evt)
protected

◆ StripPartons() [3/3]

void GenModule::StripPartons ( GenEvent * evt)
protected

◆ StripPartonsInit() [1/3]

void GenModule::StripPartonsInit ( void )
protected

Definition at line 234 of file GenModule.cxx.

234 {
235 MsgStream log( msgSvc(), name() );
236
237 for ( int i = 1; i < 9; ++i )
238 {
239 m_AllPartons.push_back( i );
240 m_AllPartons.push_back( -i );
241 } // Quarks
242 m_AllPartons.push_back( 21 ); // gluon
243
244 m_StripPartonSwitch = true;
245 m_StripVector.erase( m_StripVector.begin(), m_StripVector.begin() + 1 );
246 // When the user specifies only the StripPartonSwitch or gives a Particle Code
247 // which is NOT a parton then strip ALL partons
248 if ( m_StripVector.size() == 0 )
249 {
250 log << MSG::INFO << " !!!! NO SPECIFIC PARTON FOR STRIPOUT WAS REQUESTED => STRIPOUT ALL "
251 << endmsg;
253 }
254 else
255 {
256 bool value_ok = true;
257 std::vector<int>::const_iterator i = m_StripVector.begin();
258 do {
259 if ( std::find( m_AllPartons.begin(), m_AllPartons.end(), *i ) == m_AllPartons.end() )
260 value_ok = false;
261 ++i;
262 } while ( i != m_StripVector.end() && value_ok );
263 if ( !value_ok )
264 {
265 log << MSG::INFO << " !!!! ILEGAL PDG-ID FOR STRIPOUT WAS REQUESTED => STRIPOUT ALL "
266 << endmsg;
268 }
269 }
270 log << MSG::INFO << " THE FOLLOWING PARTON(S) WILL BE STRIPED OUT ";
271 for ( std::vector<int>::const_iterator ip = m_StripVector.begin(); ip != m_StripVector.end();
272 ++ip )
273 log << *ip << " ";
274 log << endmsg;
275}

Referenced by initialize().

◆ StripPartonsInit() [2/3]

void GenModule::StripPartonsInit ( void )
protected

◆ StripPartonsInit() [3/3]

void GenModule::StripPartonsInit ( void )
protected

Member Data Documentation

◆ m_AllPartons

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

◆ m_fixedMode

bool GenModule::m_fixedMode
protected

◆ m_meanInteractions

double GenModule::m_meanInteractions
protected

◆ m_particleTable

HepPDT::ParticleDataTable * GenModule::m_particleTable
protected

◆ m_pPoissonGenerator

CLHEP::RandPoisson * GenModule::m_pPoissonGenerator
protected

◆ m_pRandomEngine

CLHEP::HepRandomEngine * GenModule::m_pRandomEngine
protected

◆ m_randomSeed

int GenModule::m_randomSeed
protected

◆ m_StripPartonSwitch

bool GenModule::m_StripPartonSwitch
protected

◆ m_StripVector

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

The documentation for this class was generated from the following files: